-
Notifications
You must be signed in to change notification settings - Fork 1
/
rpa_gw.F
6913 lines (5542 loc) · 309 KB
/
rpa_gw.F
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!--------------------------------------------------------------------------------------------------!
! CP2K: A general program to perform molecular dynamics simulations !
! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
! !
! SPDX-License-Identifier: GPL-2.0-or-later !
!--------------------------------------------------------------------------------------------------!
! **************************************************************************************************
!> \brief Routines for GW, continuous development [Jan Wilhelm]
!> \par History
!> 03.2019 created [Frederick Stein]
!> 12.2022 added periodic GW routines [Jan Wilhelm]
! **************************************************************************************************
MODULE rpa_gw
USE ai_overlap, ONLY: overlap
USE atomic_kind_types, ONLY: atomic_kind_type
USE basis_set_types, ONLY: gto_basis_set_p_type,&
gto_basis_set_type
USE cell_types, ONLY: cell_type,&
get_cell
USE core_ppnl, ONLY: build_core_ppnl
USE cp_cfm_basic_linalg, ONLY: cp_cfm_scale,&
cp_cfm_scale_and_add,&
cp_cfm_scale_and_add_fm,&
cp_cfm_transpose
USE cp_cfm_diag, ONLY: cp_cfm_geeig_canon
USE cp_cfm_types, ONLY: cp_cfm_create,&
cp_cfm_get_info,&
cp_cfm_release,&
cp_cfm_set_all,&
cp_cfm_to_fm,&
cp_cfm_type,&
cp_fm_to_cfm
USE cp_control_types, ONLY: dft_control_type
USE cp_dbcsr_api, ONLY: &
dbcsr_add_on_diag, dbcsr_copy, dbcsr_create, dbcsr_desymmetrize, dbcsr_filter, &
dbcsr_get_info, dbcsr_init_p, dbcsr_iterator_blocks_left, dbcsr_iterator_next_block, &
dbcsr_iterator_start, dbcsr_iterator_stop, dbcsr_iterator_type, dbcsr_multiply, &
dbcsr_p_type, dbcsr_release, dbcsr_release_p, dbcsr_scale, dbcsr_set, dbcsr_type, &
dbcsr_type_antisymmetric, dbcsr_type_no_symmetry
USE cp_dbcsr_cp2k_link, ONLY: cp_dbcsr_alloc_block_from_nbl
USE cp_dbcsr_operations, ONLY: copy_dbcsr_to_fm,&
copy_fm_to_dbcsr,&
dbcsr_allocate_matrix_set,&
dbcsr_deallocate_matrix_set
USE cp_files, ONLY: close_file,&
open_file
USE cp_fm_basic_linalg, ONLY: cp_fm_scale_and_add,&
cp_fm_upper_to_full
USE cp_fm_cholesky, ONLY: cp_fm_cholesky_decompose,&
cp_fm_cholesky_invert
USE cp_fm_diag, ONLY: cp_fm_syevd
USE cp_fm_struct, ONLY: cp_fm_struct_create,&
cp_fm_struct_release,&
cp_fm_struct_type
USE cp_fm_types, ONLY: &
cp_fm_copy_general, cp_fm_create, cp_fm_get_diag, cp_fm_get_info, cp_fm_release, &
cp_fm_set_all, cp_fm_to_fm, cp_fm_to_fm_submat, cp_fm_type
USE cp_log_handling, ONLY: cp_get_default_logger,&
cp_logger_get_default_unit_nr,&
cp_logger_type
USE cp_output_handling, ONLY: cp_print_key_finished_output,&
cp_print_key_unit_nr
USE cp_realspace_grid_cube, ONLY: cp_pw_to_cube
USE dbt_api, ONLY: &
dbt_batched_contract_finalize, dbt_batched_contract_init, dbt_clear, dbt_contract, &
dbt_copy, dbt_copy_matrix_to_tensor, dbt_copy_tensor_to_matrix, dbt_create, dbt_destroy, &
dbt_get_block, dbt_get_info, dbt_iterator_blocks_left, dbt_iterator_next_block, &
dbt_iterator_start, dbt_iterator_stop, dbt_iterator_type, dbt_nblks_total, &
dbt_pgrid_create, dbt_pgrid_destroy, dbt_pgrid_type, dbt_type
USE hfx_types, ONLY: block_ind_type,&
dealloc_containers,&
hfx_compression_type
USE input_constants, ONLY: gw_pade_approx,&
gw_two_pole_model,&
ri_rpa_g0w0_crossing_bisection,&
ri_rpa_g0w0_crossing_newton,&
ri_rpa_g0w0_crossing_z_shot,&
soc_none
USE input_section_types, ONLY: section_vals_get_subs_vals,&
section_vals_type
USE kinds, ONLY: default_path_length,&
dp
USE kpoint_methods, ONLY: kpoint_density_matrices,&
kpoint_density_transform,&
kpoint_init_cell_index
USE kpoint_types, ONLY: get_kpoint_info,&
kpoint_create,&
kpoint_release,&
kpoint_sym_create,&
kpoint_type
USE machine, ONLY: m_walltime
USE mathconstants, ONLY: fourpi,&
gaussi,&
pi,&
twopi,&
z_one,&
z_zero
USE message_passing, ONLY: mp_para_env_type
USE mp2_types, ONLY: mp2_type,&
one_dim_real_array,&
two_dim_int_array
USE parallel_gemm_api, ONLY: parallel_gemm
USE particle_list_types, ONLY: particle_list_type
USE particle_types, ONLY: particle_type
USE physcon, ONLY: evolt
USE pw_env_types, ONLY: pw_env_get,&
pw_env_type
USE pw_methods, ONLY: pw_axpy,&
pw_copy,&
pw_scale,&
pw_zero
USE pw_pool_types, ONLY: pw_pool_type
USE pw_types, ONLY: pw_c1d_gs_type,&
pw_r3d_rs_type
USE qs_band_structure, ONLY: calculate_kp_orbitals
USE qs_collocate_density, ONLY: calculate_rho_elec
USE qs_environment_types, ONLY: get_qs_env,&
qs_env_release,&
qs_environment_type
USE qs_force_types, ONLY: qs_force_type
USE qs_gamma2kp, ONLY: create_kp_from_gamma
USE qs_integral_utils, ONLY: basis_set_list_setup
USE qs_kind_types, ONLY: get_qs_kind,&
qs_kind_type
USE qs_ks_types, ONLY: qs_ks_env_type
USE qs_mo_types, ONLY: get_mo_set
USE qs_moments, ONLY: build_berry_moment_matrix
USE qs_neighbor_list_types, ONLY: neighbor_list_set_p_type,&
release_neighbor_list_sets
USE qs_neighbor_lists, ONLY: setup_neighbor_list
USE qs_overlap, ONLY: build_overlap_matrix_simple
USE qs_scf_types, ONLY: qs_scf_env_type
USE qs_subsys_types, ONLY: qs_subsys_get,&
qs_subsys_type
USE qs_tensors, ONLY: decompress_tensor
USE qs_tensors_types, ONLY: create_2c_tensor
USE rpa_gw_ic, ONLY: apply_ic_corr
USE rpa_gw_im_time_util, ONLY: get_tensor_3c_overl_int_gw
USE rpa_gw_kpoints_util, ONLY: get_mat_cell_T_from_mat_gamma,&
mat_kp_from_mat_gamma,&
real_space_to_kpoint_transform_rpa
USE rpa_im_time, ONLY: compute_periodic_dm
USE scf_control_types, ONLY: scf_control_type
USE util, ONLY: sort
USE virial_types, ONLY: virial_type
#include "./base/base_uses.f90"
IMPLICIT NONE
PRIVATE
CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'rpa_gw'
PUBLIC :: allocate_matrices_gw_im_time, allocate_matrices_gw, compute_GW_self_energy, compute_QP_energies, &
deallocate_matrices_gw_im_time, deallocate_matrices_gw, compute_minus_vxc_kpoints, trafo_to_mo_and_kpoints, &
get_fermi_level_offset, compute_W_cubic_GW, continuation_pade
CONTAINS
! **************************************************************************************************
!> \brief ...
!> \param gw_corr_lev_occ ...
!> \param gw_corr_lev_virt ...
!> \param homo ...
!> \param nmo ...
!> \param num_integ_points ...
!> \param unit_nr ...
!> \param RI_blk_sizes ...
!> \param do_ic_model ...
!> \param para_env ...
!> \param fm_mat_W ...
!> \param fm_mat_Q ...
!> \param mo_coeff ...
!> \param t_3c_overl_int_ao_mo ...
!> \param t_3c_O_mo_compressed ...
!> \param t_3c_O_mo_ind ...
!> \param t_3c_overl_int_gw_RI ...
!> \param t_3c_overl_int_gw_AO ...
!> \param starts_array_mc ...
!> \param ends_array_mc ...
!> \param t_3c_overl_nnP_ic ...
!> \param t_3c_overl_nnP_ic_reflected ...
!> \param matrix_s ...
!> \param mat_W ...
!> \param t_3c_overl_int ...
!> \param t_3c_O_compressed ...
!> \param t_3c_O_ind ...
!> \param qs_env ...
! **************************************************************************************************
SUBROUTINE allocate_matrices_gw_im_time(gw_corr_lev_occ, gw_corr_lev_virt, homo, nmo, &
num_integ_points, unit_nr, &
RI_blk_sizes, do_ic_model, &
para_env, fm_mat_W, fm_mat_Q, &
mo_coeff, &
t_3c_overl_int_ao_mo, t_3c_O_mo_compressed, t_3c_O_mo_ind, &
t_3c_overl_int_gw_RI, t_3c_overl_int_gw_AO, &
starts_array_mc, ends_array_mc, &
t_3c_overl_nnP_ic, t_3c_overl_nnP_ic_reflected, &
matrix_s, mat_W, t_3c_overl_int, &
t_3c_O_compressed, t_3c_O_ind, &
qs_env)
INTEGER, DIMENSION(:), INTENT(IN) :: gw_corr_lev_occ, gw_corr_lev_virt, homo
INTEGER, INTENT(IN) :: nmo, num_integ_points, unit_nr
INTEGER, DIMENSION(:), POINTER :: RI_blk_sizes
LOGICAL, INTENT(IN) :: do_ic_model
TYPE(mp_para_env_type), POINTER :: para_env
TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:), &
INTENT(OUT) :: fm_mat_W
TYPE(cp_fm_type), INTENT(IN) :: fm_mat_Q
TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: mo_coeff
TYPE(dbt_type) :: t_3c_overl_int_ao_mo
TYPE(hfx_compression_type), ALLOCATABLE, &
DIMENSION(:) :: t_3c_O_mo_compressed
TYPE(two_dim_int_array), ALLOCATABLE, &
DIMENSION(:), INTENT(OUT) :: t_3c_O_mo_ind
TYPE(dbt_type), ALLOCATABLE, DIMENSION(:), &
INTENT(INOUT) :: t_3c_overl_int_gw_RI, &
t_3c_overl_int_gw_AO
INTEGER, DIMENSION(:), INTENT(IN) :: starts_array_mc, ends_array_mc
TYPE(dbt_type), ALLOCATABLE, DIMENSION(:), &
INTENT(INOUT) :: t_3c_overl_nnP_ic, &
t_3c_overl_nnP_ic_reflected
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
TYPE(dbcsr_type), POINTER :: mat_W
TYPE(dbt_type), DIMENSION(:, :) :: t_3c_overl_int
TYPE(hfx_compression_type), DIMENSION(:, :, :) :: t_3c_O_compressed
TYPE(block_ind_type), DIMENSION(:, :, :) :: t_3c_O_ind
TYPE(qs_environment_type), POINTER :: qs_env
CHARACTER(LEN=*), PARAMETER :: routineN = 'allocate_matrices_gw_im_time'
INTEGER :: handle, jquad, nspins
LOGICAL :: my_open_shell
TYPE(dbt_type) :: t_3c_overl_int_ao_mo_beta
CALL timeset(routineN, handle)
nspins = SIZE(homo)
my_open_shell = (nspins == 2)
ALLOCATE (t_3c_O_mo_ind(nspins), t_3c_overl_int_gw_AO(nspins), t_3c_overl_int_gw_RI(nspins), &
t_3c_overl_nnP_ic(nspins), t_3c_overl_nnP_ic_reflected(nspins), t_3c_O_mo_compressed(nspins))
CALL get_tensor_3c_overl_int_gw(t_3c_overl_int, &
t_3c_O_compressed, t_3c_O_ind, &
t_3c_overl_int_ao_mo, t_3c_O_mo_compressed(1), t_3c_O_mo_ind(1)%array, &
t_3c_overl_int_gw_RI(1), t_3c_overl_int_gw_AO(1), &
starts_array_mc, ends_array_mc, &
mo_coeff(1), matrix_s, &
gw_corr_lev_occ(1), gw_corr_lev_virt(1), homo(1), nmo, &
para_env, &
do_ic_model, &
t_3c_overl_nnP_ic(1), t_3c_overl_nnP_ic_reflected(1), &
qs_env, unit_nr, do_alpha=.TRUE.)
IF (my_open_shell) THEN
CALL get_tensor_3c_overl_int_gw(t_3c_overl_int, &
t_3c_O_compressed, t_3c_O_ind, &
t_3c_overl_int_ao_mo_beta, t_3c_O_mo_compressed(2), t_3c_O_mo_ind(2)%array, &
t_3c_overl_int_gw_RI(2), t_3c_overl_int_gw_AO(2), &
starts_array_mc, ends_array_mc, &
mo_coeff(2), matrix_s, &
gw_corr_lev_occ(2), gw_corr_lev_virt(2), homo(2), nmo, &
para_env, &
do_ic_model, &
t_3c_overl_nnP_ic(2), t_3c_overl_nnP_ic_reflected(2), &
qs_env, unit_nr, do_alpha=.FALSE.)
IF (.NOT. qs_env%mp2_env%ri_g0w0%do_kpoints_Sigma) THEN
CALL dbt_destroy(t_3c_overl_int_ao_mo_beta)
END IF
END IF
ALLOCATE (fm_mat_W(num_integ_points))
DO jquad = 1, num_integ_points
CALL cp_fm_create(fm_mat_W(jquad), fm_mat_Q%matrix_struct)
CALL cp_fm_to_fm(fm_mat_Q, fm_mat_W(jquad))
CALL cp_fm_set_all(fm_mat_W(jquad), 0.0_dp)
END DO
NULLIFY (mat_W)
CALL dbcsr_init_p(mat_W)
CALL dbcsr_create(matrix=mat_W, &
template=matrix_s(1)%matrix, &
matrix_type=dbcsr_type_no_symmetry, &
row_blk_size=RI_blk_sizes, &
col_blk_size=RI_blk_sizes)
CALL timestop(handle)
END SUBROUTINE allocate_matrices_gw_im_time
! **************************************************************************************************
!> \brief ...
!> \param vec_Sigma_c_gw ...
!> \param color_rpa_group ...
!> \param dimen_nm_gw ...
!> \param gw_corr_lev_occ ...
!> \param gw_corr_lev_virt ...
!> \param homo ...
!> \param nmo ...
!> \param num_integ_group ...
!> \param num_integ_points ...
!> \param unit_nr ...
!> \param gw_corr_lev_tot ...
!> \param num_fit_points ...
!> \param omega_max_fit ...
!> \param do_minimax_quad ...
!> \param do_periodic ...
!> \param do_ri_Sigma_x ...
!> \param my_do_gw ...
!> \param first_cycle_periodic_correction ...
!> \param a_scaling ...
!> \param Eigenval ...
!> \param tj ...
!> \param vec_omega_fit_gw ...
!> \param vec_Sigma_x_gw ...
!> \param delta_corr ...
!> \param Eigenval_last ...
!> \param Eigenval_scf ...
!> \param vec_W_gw ...
!> \param fm_mat_S_gw ...
!> \param fm_mat_S_gw_work ...
!> \param para_env ...
!> \param mp2_env ...
!> \param kpoints ...
!> \param nkp ...
!> \param nkp_self_energy ...
!> \param do_kpoints_cubic_RPA ...
!> \param do_kpoints_from_Gamma ...
! **************************************************************************************************
SUBROUTINE allocate_matrices_gw(vec_Sigma_c_gw, color_rpa_group, dimen_nm_gw, &
gw_corr_lev_occ, gw_corr_lev_virt, homo, &
nmo, num_integ_group, num_integ_points, unit_nr, &
gw_corr_lev_tot, num_fit_points, omega_max_fit, &
do_minimax_quad, do_periodic, do_ri_Sigma_x, my_do_gw, &
first_cycle_periodic_correction, &
a_scaling, Eigenval, tj, vec_omega_fit_gw, vec_Sigma_x_gw, &
delta_corr, Eigenval_last, Eigenval_scf, vec_W_gw, &
fm_mat_S_gw, fm_mat_S_gw_work, &
para_env, mp2_env, kpoints, nkp, nkp_self_energy, &
do_kpoints_cubic_RPA, do_kpoints_from_Gamma)
COMPLEX(KIND=dp), ALLOCATABLE, &
DIMENSION(:, :, :, :), INTENT(OUT) :: vec_Sigma_c_gw
INTEGER, INTENT(IN) :: color_rpa_group, dimen_nm_gw
INTEGER, DIMENSION(:), INTENT(IN) :: gw_corr_lev_occ, gw_corr_lev_virt, homo
INTEGER, INTENT(IN) :: nmo, num_integ_group, num_integ_points, &
unit_nr
INTEGER, INTENT(INOUT) :: gw_corr_lev_tot, num_fit_points
REAL(KIND=dp) :: omega_max_fit
LOGICAL, INTENT(IN) :: do_minimax_quad, do_periodic, &
do_ri_Sigma_x, my_do_gw
LOGICAL, INTENT(OUT) :: first_cycle_periodic_correction
REAL(KIND=dp), INTENT(IN) :: a_scaling
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :), &
INTENT(INOUT) :: Eigenval
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:), &
INTENT(IN) :: tj
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:), &
INTENT(OUT) :: vec_omega_fit_gw
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :), &
INTENT(OUT) :: vec_Sigma_x_gw
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:), &
INTENT(INOUT) :: delta_corr
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :), &
INTENT(OUT) :: Eigenval_last, Eigenval_scf
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :), &
INTENT(OUT) :: vec_W_gw
TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: fm_mat_S_gw
TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:), &
INTENT(INOUT) :: fm_mat_S_gw_work
TYPE(mp_para_env_type), POINTER :: para_env
TYPE(mp2_type) :: mp2_env
TYPE(kpoint_type), POINTER :: kpoints
INTEGER, INTENT(OUT) :: nkp, nkp_self_energy
LOGICAL, INTENT(IN) :: do_kpoints_cubic_RPA, &
do_kpoints_from_Gamma
CHARACTER(LEN=*), PARAMETER :: routineN = 'allocate_matrices_gw'
INTEGER :: handle, iquad, ispin, jquad, nspins
LOGICAL :: my_open_shell
REAL(KIND=dp) :: omega
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: vec_omega_gw
CALL timeset(routineN, handle)
nspins = SIZE(Eigenval, 3)
my_open_shell = (nspins == 2)
gw_corr_lev_tot = gw_corr_lev_occ(1) + gw_corr_lev_virt(1)
! fill the omega_frequency vector
ALLOCATE (vec_omega_gw(num_integ_points))
vec_omega_gw = 0.0_dp
DO jquad = 1, num_integ_points
IF (do_minimax_quad) THEN
omega = tj(jquad)
ELSE
omega = a_scaling/TAN(tj(jquad))
END IF
vec_omega_gw(jquad) = omega
END DO
! determine number of fit points in the interval [0,w_max] for virt, or [-w_max,0] for occ
num_fit_points = 0
DO jquad = 1, num_integ_points
IF (vec_omega_gw(jquad) < omega_max_fit) THEN
num_fit_points = num_fit_points + 1
END IF
END DO
IF (mp2_env%ri_g0w0%analytic_continuation == gw_pade_approx) THEN
IF (mp2_env%ri_g0w0%nparam_pade > num_fit_points) THEN
IF (unit_nr > 0) WRITE (UNIT=unit_nr, FMT="(T3,A)") &
"Pade approximation: more parameters than data points. Reset # of parameters."
mp2_env%ri_g0w0%nparam_pade = num_fit_points
IF (unit_nr > 0) WRITE (UNIT=unit_nr, FMT="(T3,A,T74,I7)") &
"Number of pade parameters:", mp2_env%ri_g0w0%nparam_pade
END IF
END IF
! create new arrays containing omega values at which we calculate vec_Sigma_c_gw
ALLOCATE (vec_omega_fit_gw(num_fit_points))
! fill the omega vector with frequencies, where we calculate the self-energy
iquad = 0
DO jquad = 1, num_integ_points
IF (vec_omega_gw(jquad) < omega_max_fit) THEN
iquad = iquad + 1
vec_omega_fit_gw(iquad) = vec_omega_gw(jquad)
END IF
END DO
DEALLOCATE (vec_omega_gw)
IF (do_kpoints_cubic_RPA) THEN
CALL get_kpoint_info(kpoints, nkp=nkp)
IF (mp2_env%ri_g0w0%do_gamma_only_sigma) THEN
nkp_self_energy = 1
ELSE
nkp_self_energy = nkp
END IF
ELSE IF (do_kpoints_from_Gamma) THEN
CALL get_kpoint_info(kpoints, nkp=nkp)
IF (mp2_env%ri_g0w0%do_kpoints_Sigma) THEN
nkp_self_energy = mp2_env%ri_g0w0%nkp_self_energy
ELSE
nkp_self_energy = 1
END IF
ELSE
nkp = 1
nkp_self_energy = 1
END IF
ALLOCATE (vec_Sigma_c_gw(gw_corr_lev_tot, num_fit_points, nkp_self_energy, nspins))
vec_Sigma_c_gw = z_zero
ALLOCATE (Eigenval_scf(nmo, nkp_self_energy, nspins))
Eigenval_scf(:, :, :) = Eigenval(:, :, :)
ALLOCATE (Eigenval_last(nmo, nkp_self_energy, nspins))
Eigenval_last(:, :, :) = Eigenval(:, :, :)
IF (do_periodic) THEN
ALLOCATE (delta_corr(1 + homo(1) - gw_corr_lev_occ(1):homo(1) + gw_corr_lev_virt(1)))
delta_corr(:) = 0.0_dp
first_cycle_periodic_correction = .TRUE.
END IF
ALLOCATE (vec_Sigma_x_gw(nmo, nkp_self_energy, nspins))
vec_Sigma_x_gw = 0.0_dp
IF (my_do_gw) THEN
! minimax grids not implemented for O(N^4) GW
CPASSERT(.NOT. do_minimax_quad)
! create temporary matrix to store B*([1+Q(iw')]^-1-1), has the same size as B
ALLOCATE (fm_mat_S_gw_work(nspins))
DO ispin = 1, nspins
CALL cp_fm_create(fm_mat_S_gw_work(ispin), fm_mat_S_gw(ispin)%matrix_struct)
CALL cp_fm_set_all(matrix=fm_mat_S_gw_work(ispin), alpha=0.0_dp)
END DO
ALLOCATE (vec_W_gw(dimen_nm_gw, nspins))
vec_W_gw = 0.0_dp
! in case we do RI for Sigma_x, we calculate Sigma_x right here
IF (do_ri_Sigma_x) THEN
CALL get_vec_sigma_x(vec_Sigma_x_gw(:, :, 1), nmo, fm_mat_S_gw(1), para_env, num_integ_group, color_rpa_group, &
homo(1), gw_corr_lev_occ(1), mp2_env%ri_g0w0%vec_Sigma_x_minus_vxc_gw(:, 1, 1))
IF (my_open_shell) THEN
CALL get_vec_sigma_x(vec_Sigma_x_gw(:, :, 2), nmo, fm_mat_S_gw(2), para_env, num_integ_group, &
color_rpa_group, homo(2), gw_corr_lev_occ(2), &
mp2_env%ri_g0w0%vec_Sigma_x_minus_vxc_gw(:, 2, 1))
END IF
END IF
END IF
CALL timestop(handle)
END SUBROUTINE allocate_matrices_gw
! **************************************************************************************************
!> \brief ...
!> \param vec_Sigma_x_gw ...
!> \param nmo ...
!> \param fm_mat_S_gw ...
!> \param para_env ...
!> \param num_integ_group ...
!> \param color_rpa_group ...
!> \param homo ...
!> \param gw_corr_lev_occ ...
!> \param vec_Sigma_x_minus_vxc_gw11 ...
! **************************************************************************************************
SUBROUTINE get_vec_sigma_x(vec_Sigma_x_gw, nmo, fm_mat_S_gw, para_env, num_integ_group, color_rpa_group, homo, &
gw_corr_lev_occ, vec_Sigma_x_minus_vxc_gw11)
REAL(KIND=dp), DIMENSION(:, :), INTENT(INOUT) :: vec_Sigma_x_gw
INTEGER, INTENT(IN) :: nmo
TYPE(cp_fm_type), INTENT(IN) :: fm_mat_S_gw
TYPE(mp_para_env_type), POINTER :: para_env
INTEGER, INTENT(IN) :: num_integ_group, color_rpa_group, homo, &
gw_corr_lev_occ
REAL(KIND=dp), DIMENSION(:), INTENT(INOUT) :: vec_Sigma_x_minus_vxc_gw11
CHARACTER(LEN=*), PARAMETER :: routineN = 'get_vec_sigma_x'
INTEGER :: handle, iiB, m_global, n_global, &
ncol_local, nm_global, nrow_local
INTEGER, DIMENSION(:), POINTER :: col_indices
CALL timeset(routineN, handle)
CALL cp_fm_get_info(matrix=fm_mat_S_gw, &
nrow_local=nrow_local, &
ncol_local=ncol_local, &
col_indices=col_indices)
CALL para_env%sync()
! loop over (nm) index
DO iiB = 1, ncol_local
! this is needed for correct values within parallelization
IF (MODULO(1, num_integ_group) /= color_rpa_group) CYCLE
nm_global = col_indices(iiB)
! transform the index nm to n and m, formulae copied from Mauro's code
n_global = MAX(1, nm_global - 1)/nmo + 1
m_global = nm_global - (n_global - 1)*nmo
n_global = n_global + homo - gw_corr_lev_occ
IF (m_global <= homo) THEN
! Sigma_x_n = -sum_m^occ sum_P (B_(nm)^P)^2
vec_Sigma_x_gw(n_global, 1) = &
vec_Sigma_x_gw(n_global, 1) - &
DOT_PRODUCT(fm_mat_S_gw%local_data(:, iiB), fm_mat_S_gw%local_data(:, iiB))
END IF
END DO
CALL para_env%sync()
CALL para_env%sum(vec_Sigma_x_gw)
vec_Sigma_x_minus_vxc_gw11(:) = &
vec_Sigma_x_minus_vxc_gw11(:) + &
vec_Sigma_x_gw(:, 1)
CALL timestop(handle)
END SUBROUTINE get_vec_sigma_x
! **************************************************************************************************
!> \brief ...
!> \param fm_mat_S_gw_work ...
!> \param vec_W_gw ...
!> \param vec_Sigma_c_gw ...
!> \param vec_omega_fit_gw ...
!> \param vec_Sigma_x_minus_vxc_gw ...
!> \param Eigenval_last ...
!> \param Eigenval_scf ...
!> \param do_periodic ...
!> \param matrix_berry_re_mo_mo ...
!> \param matrix_berry_im_mo_mo ...
!> \param kpoints ...
!> \param vec_Sigma_x_gw ...
!> \param my_do_gw ...
! **************************************************************************************************
SUBROUTINE deallocate_matrices_gw(fm_mat_S_gw_work, vec_W_gw, vec_Sigma_c_gw, vec_omega_fit_gw, &
vec_Sigma_x_minus_vxc_gw, Eigenval_last, &
Eigenval_scf, do_periodic, matrix_berry_re_mo_mo, matrix_berry_im_mo_mo, kpoints, &
vec_Sigma_x_gw, my_do_gw)
TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:), &
INTENT(INOUT) :: fm_mat_S_gw_work
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :), &
INTENT(INOUT) :: vec_W_gw
COMPLEX(KIND=dp), ALLOCATABLE, &
DIMENSION(:, :, :, :), INTENT(INOUT) :: vec_Sigma_c_gw
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:), &
INTENT(INOUT) :: vec_omega_fit_gw
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :), &
INTENT(INOUT) :: vec_Sigma_x_minus_vxc_gw, Eigenval_last, &
Eigenval_scf
LOGICAL, INTENT(IN) :: do_periodic
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_berry_re_mo_mo, &
matrix_berry_im_mo_mo
TYPE(kpoint_type), POINTER :: kpoints
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :), &
INTENT(INOUT) :: vec_Sigma_x_gw
LOGICAL, INTENT(IN) :: my_do_gw
CHARACTER(LEN=*), PARAMETER :: routineN = 'deallocate_matrices_gw'
INTEGER :: handle, nspins
LOGICAL :: my_open_shell
CALL timeset(routineN, handle)
nspins = SIZE(Eigenval_last, 3)
my_open_shell = (nspins == 2)
IF (my_do_gw) THEN
CALL cp_fm_release(fm_mat_S_gw_work)
DEALLOCATE (vec_Sigma_x_minus_vxc_gw)
DEALLOCATE (vec_W_gw)
END IF
DEALLOCATE (vec_Sigma_c_gw)
DEALLOCATE (vec_Sigma_x_gw)
DEALLOCATE (vec_omega_fit_gw)
DEALLOCATE (Eigenval_last)
DEALLOCATE (Eigenval_scf)
IF (do_periodic) THEN
CALL dbcsr_deallocate_matrix_set(matrix_berry_re_mo_mo)
CALL dbcsr_deallocate_matrix_set(matrix_berry_im_mo_mo)
CALL kpoint_release(kpoints)
END IF
CALL timestop(handle)
END SUBROUTINE deallocate_matrices_gw
! **************************************************************************************************
!> \brief ...
!> \param weights_cos_tf_w_to_t ...
!> \param weights_sin_tf_t_to_w ...
!> \param do_ic_model ...
!> \param do_kpoints_cubic_RPA ...
!> \param fm_mat_W ...
!> \param t_3c_overl_int_ao_mo ...
!> \param t_3c_O_mo_compressed ...
!> \param t_3c_O_mo_ind ...
!> \param t_3c_overl_int_gw_RI ...
!> \param t_3c_overl_int_gw_AO ...
!> \param t_3c_overl_nnP_ic ...
!> \param t_3c_overl_nnP_ic_reflected ...
!> \param mat_W ...
!> \param qs_env ...
! **************************************************************************************************
SUBROUTINE deallocate_matrices_gw_im_time(weights_cos_tf_w_to_t, weights_sin_tf_t_to_w, do_ic_model, do_kpoints_cubic_RPA, &
fm_mat_W, &
t_3c_overl_int_ao_mo, t_3c_O_mo_compressed, t_3c_O_mo_ind, &
t_3c_overl_int_gw_RI, t_3c_overl_int_gw_AO, &
t_3c_overl_nnP_ic, t_3c_overl_nnP_ic_reflected, mat_W, &
qs_env)
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :), &
INTENT(INOUT) :: weights_cos_tf_w_to_t, &
weights_sin_tf_t_to_w
LOGICAL, INTENT(IN) :: do_ic_model, do_kpoints_cubic_RPA
TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:), &
INTENT(INOUT) :: fm_mat_W
TYPE(dbt_type), INTENT(INOUT) :: t_3c_overl_int_ao_mo
TYPE(hfx_compression_type), ALLOCATABLE, &
DIMENSION(:) :: t_3c_O_mo_compressed
TYPE(two_dim_int_array), ALLOCATABLE, DIMENSION(:) :: t_3c_O_mo_ind
TYPE(dbt_type), ALLOCATABLE, DIMENSION(:), &
INTENT(INOUT) :: t_3c_overl_int_gw_RI, &
t_3c_overl_int_gw_AO, &
t_3c_overl_nnP_ic, &
t_3c_overl_nnP_ic_reflected
TYPE(dbcsr_type), POINTER :: mat_W
TYPE(qs_environment_type), POINTER :: qs_env
CHARACTER(LEN=*), PARAMETER :: routineN = 'deallocate_matrices_gw_im_time'
INTEGER :: handle, ispin, nspins, unused
LOGICAL :: my_open_shell
CALL timeset(routineN, handle)
nspins = SIZE(t_3c_overl_int_gw_RI)
my_open_shell = (nspins == 2)
IF (ALLOCATED(weights_cos_tf_w_to_t)) DEALLOCATE (weights_cos_tf_w_to_t)
IF (ALLOCATED(weights_sin_tf_t_to_w)) DEALLOCATE (weights_sin_tf_t_to_w)
IF (.NOT. do_kpoints_cubic_RPA) THEN
CALL cp_fm_release(fm_mat_W)
CALL dbcsr_release_P(mat_W)
END IF
DO ispin = 1, nspins
CALL dbt_destroy(t_3c_overl_int_gw_RI(ispin))
CALL dbt_destroy(t_3c_overl_int_gw_AO(ispin))
END DO
DEALLOCATE (t_3c_overl_int_gw_AO, t_3c_overl_int_gw_RI)
IF (do_ic_model) THEN
DO ispin = 1, nspins
CALL dbt_destroy(t_3c_overl_nnP_ic(ispin))
CALL dbt_destroy(t_3c_overl_nnP_ic_reflected(ispin))
END DO
DEALLOCATE (t_3c_overl_nnP_ic, t_3c_overl_nnP_ic_reflected)
END IF
IF (.NOT. qs_env%mp2_env%ri_g0w0%do_kpoints_Sigma) THEN
DO ispin = 1, nspins
DEALLOCATE (t_3c_O_mo_ind(ispin)%array)
CALL dealloc_containers(t_3c_O_mo_compressed(ispin), unused)
END DO
DEALLOCATE (t_3c_O_mo_ind, t_3c_O_mo_compressed)
CALL dbt_destroy(t_3c_overl_int_ao_mo)
END IF
IF (qs_env%mp2_env%ri_g0w0%do_kpoints_Sigma) THEN
DO ispin = 1, nspins
CALL dbcsr_release(qs_env%mp2_env%ri_g0w0%matrix_sigma_x_minus_vxc(ispin)%matrix)
DEALLOCATE (qs_env%mp2_env%ri_g0w0%matrix_sigma_x_minus_vxc(ispin)%matrix)
CALL dbcsr_release(qs_env%mp2_env%ri_g0w0%matrix_ks(ispin)%matrix)
DEALLOCATE (qs_env%mp2_env%ri_g0w0%matrix_ks(ispin)%matrix)
END DO
DEALLOCATE (qs_env%mp2_env%ri_g0w0%matrix_sigma_x_minus_vxc)
DEALLOCATE (qs_env%mp2_env%ri_g0w0%matrix_ks)
END IF
CALL timestop(handle)
END SUBROUTINE deallocate_matrices_gw_im_time
! **************************************************************************************************
!> \brief ...
!> \param vec_Sigma_c_gw ...
!> \param dimen_nm_gw ...
!> \param dimen_RI ...
!> \param gw_corr_lev_occ ...
!> \param gw_corr_lev_virt ...
!> \param homo ...
!> \param jquad ...
!> \param nmo ...
!> \param num_fit_points ...
!> \param do_im_time ...
!> \param do_periodic ...
!> \param first_cycle_periodic_correction ...
!> \param fermi_level_offset ...
!> \param omega ...
!> \param Eigenval ...
!> \param delta_corr ...
!> \param vec_omega_fit_gw ...
!> \param vec_W_gw ...
!> \param wj ...
!> \param fm_mat_Q ...
!> \param fm_mat_R_gw ...
!> \param fm_mat_S_gw ...
!> \param fm_mat_S_gw_work ...
!> \param mo_coeff ...
!> \param para_env ...
!> \param para_env_RPA ...
!> \param matrix_berry_im_mo_mo ...
!> \param matrix_berry_re_mo_mo ...
!> \param kpoints ...
!> \param qs_env ...
!> \param mp2_env ...
! **************************************************************************************************
SUBROUTINE compute_GW_self_energy(vec_Sigma_c_gw, dimen_nm_gw, dimen_RI, gw_corr_lev_occ, &
gw_corr_lev_virt, homo, jquad, nmo, num_fit_points, &
do_im_time, do_periodic, &
first_cycle_periodic_correction, fermi_level_offset, &
omega, Eigenval, delta_corr, vec_omega_fit_gw, vec_W_gw, wj, &
fm_mat_Q, fm_mat_R_gw, fm_mat_S_gw, &
fm_mat_S_gw_work, mo_coeff, para_env, &
para_env_RPA, matrix_berry_im_mo_mo, matrix_berry_re_mo_mo, &
kpoints, qs_env, mp2_env)
COMPLEX(KIND=dp), ALLOCATABLE, &
DIMENSION(:, :, :, :), INTENT(INOUT) :: vec_Sigma_c_gw
INTEGER, INTENT(IN) :: dimen_nm_gw, dimen_RI
INTEGER, DIMENSION(:), INTENT(IN) :: gw_corr_lev_occ, gw_corr_lev_virt, homo
INTEGER, INTENT(IN) :: jquad, nmo, num_fit_points
LOGICAL, INTENT(IN) :: do_im_time, do_periodic
LOGICAL, INTENT(INOUT) :: first_cycle_periodic_correction
REAL(KIND=dp), INTENT(INOUT) :: fermi_level_offset, omega
REAL(KIND=dp), DIMENSION(:, :), INTENT(INOUT) :: Eigenval
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:), &
INTENT(INOUT) :: delta_corr
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:), &
INTENT(IN) :: vec_omega_fit_gw
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :), &
INTENT(INOUT) :: vec_W_gw
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:), &
INTENT(IN) :: wj
TYPE(cp_fm_type), INTENT(IN) :: fm_mat_Q, fm_mat_R_gw
TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: fm_mat_S_gw, fm_mat_S_gw_work
TYPE(cp_fm_type), INTENT(IN) :: mo_coeff
TYPE(mp_para_env_type), POINTER :: para_env, para_env_RPA
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_berry_im_mo_mo, &
matrix_berry_re_mo_mo
TYPE(kpoint_type), POINTER :: kpoints
TYPE(qs_environment_type), POINTER :: qs_env
TYPE(mp2_type) :: mp2_env
CHARACTER(LEN=*), PARAMETER :: routineN = 'compute_GW_self_energy'
INTEGER :: handle, i_global, iiB, ispin, j_global, &
jjB, ncol_local, nrow_local, nspins
INTEGER, DIMENSION(:), POINTER :: col_indices, row_indices
CALL timeset(routineN, handle)
nspins = SIZE(fm_mat_S_gw)
CALL cp_fm_get_info(matrix=fm_mat_Q, &
nrow_local=nrow_local, &
ncol_local=ncol_local, &
row_indices=row_indices, &
col_indices=col_indices)
IF (.NOT. do_im_time) THEN
! calculate [1+Q(iw')]^-1
CALL cp_fm_cholesky_invert(fm_mat_Q)
! symmetrize the result, fm_mat_R_gw is only temporary work matrix
CALL cp_fm_upper_to_full(fm_mat_Q, fm_mat_R_gw)
! periodic correction for GW (paper Phys. Rev. B 95, 235123 (2017))
IF (do_periodic) THEN
CALL calc_periodic_correction(delta_corr, qs_env, para_env, para_env_RPA, &
mp2_env%ri_g0w0%kp_grid, homo(1), nmo, gw_corr_lev_occ(1), &
gw_corr_lev_virt(1), omega, mo_coeff, Eigenval(:, 1), &
matrix_berry_re_mo_mo, matrix_berry_im_mo_mo, &
first_cycle_periodic_correction, kpoints, &
mp2_env%ri_g0w0%do_mo_coeff_gamma, &
mp2_env%ri_g0w0%num_kp_grids, mp2_env%ri_g0w0%eps_kpoint, &
mp2_env%ri_g0w0%do_extra_kpoints, &
mp2_env%ri_g0w0%do_aux_bas_gw, mp2_env%ri_g0w0%frac_aux_mos)
END IF
CALL para_env%sync()
! subtract 1 from the diagonal to get rid of exchange self-energy
!$OMP PARALLEL DO DEFAULT(NONE) PRIVATE(jjB,iiB,i_global,j_global) &
!$OMP SHARED(ncol_local,nrow_local,col_indices,row_indices,fm_mat_Q,dimen_RI)
DO jjB = 1, ncol_local
j_global = col_indices(jjB)
DO iiB = 1, nrow_local
i_global = row_indices(iiB)
IF (j_global == i_global .AND. i_global <= dimen_RI) THEN
fm_mat_Q%local_data(iiB, jjB) = fm_mat_Q%local_data(iiB, jjB) - 1.0_dp
END IF
END DO
END DO
CALL para_env%sync()
DO ispin = 1, nspins
CALL compute_GW_self_energy_deep(vec_Sigma_c_gw(:, :, :, ispin), dimen_nm_gw, dimen_RI, &
gw_corr_lev_occ(ispin), gw_corr_lev_virt(ispin), &
homo(ispin), jquad, nmo, &
num_fit_points, do_periodic, fermi_level_offset, omega, &
Eigenval(:, ispin), delta_corr, &
vec_omega_fit_gw, vec_W_gw(:, ispin), wj, fm_mat_Q, &
fm_mat_S_gw(ispin), fm_mat_S_gw_work(ispin))
END DO
END IF ! GW
CALL timestop(handle)
END SUBROUTINE compute_GW_self_energy
! **************************************************************************************************
!> \brief ...
!> \param fermi_level_offset ...
!> \param fermi_level_offset_input ...
!> \param Eigenval ...
!> \param homo ...
! **************************************************************************************************
SUBROUTINE get_fermi_level_offset(fermi_level_offset, fermi_level_offset_input, Eigenval, homo)
REAL(KIND=dp), INTENT(INOUT) :: fermi_level_offset
REAL(KIND=dp), INTENT(IN) :: fermi_level_offset_input
REAL(KIND=dp), DIMENSION(:, :), INTENT(INOUT) :: Eigenval
INTEGER, DIMENSION(:), INTENT(IN) :: homo
CHARACTER(LEN=*), PARAMETER :: routineN = 'get_fermi_level_offset'
INTEGER :: handle, ispin, nspins
CALL timeset(routineN, handle)
nspins = SIZE(Eigenval, 2)
! Fermi level offset should have a maximum such that the Fermi level of occupied orbitals
! is always closer to occupied orbitals than to virtual orbitals and vice versa
! that means, the Fermi level offset is at most as big as half the bandgap
fermi_level_offset = fermi_level_offset_input
DO ispin = 1, nspins
fermi_level_offset = MIN(fermi_level_offset, (Eigenval(homo(ispin) + 1, ispin) - Eigenval(homo(ispin), ispin))*0.5_dp)
END DO
CALL timestop(handle)
END SUBROUTINE get_fermi_level_offset
! **************************************************************************************************
!> \brief ...
!> \param fm_mat_W ...
!> \param fm_mat_Q ...
!> \param fm_mat_work ...
!> \param dimen_RI ...
!> \param fm_mat_L ...
!> \param num_integ_points ...
!> \param tj ...
!> \param tau_tj ...
!> \param weights_cos_tf_w_to_t ...
!> \param jquad ...
!> \param omega ...
! **************************************************************************************************
SUBROUTINE compute_W_cubic_GW(fm_mat_W, fm_mat_Q, fm_mat_work, dimen_RI, fm_mat_L, num_integ_points, &
tj, tau_tj, weights_cos_tf_w_to_t, jquad, omega)
TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: fm_mat_W
TYPE(cp_fm_type), INTENT(IN) :: fm_mat_Q, fm_mat_work
INTEGER, INTENT(IN) :: dimen_RI
TYPE(cp_fm_type), DIMENSION(:, :), INTENT(IN) :: fm_mat_L
INTEGER, INTENT(IN) :: num_integ_points
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:), &
INTENT(IN) :: tj, tau_tj
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :), &
INTENT(IN) :: weights_cos_tf_w_to_t
INTEGER, INTENT(IN) :: jquad
REAL(KIND=dp), INTENT(INOUT) :: omega
CHARACTER(LEN=*), PARAMETER :: routineN = 'compute_W_cubic_GW'
INTEGER :: handle, i_global, iiB, iquad, j_global, &
jjB, ncol_local, nrow_local
INTEGER, DIMENSION(:), POINTER :: col_indices, row_indices
REAL(KIND=dp) :: tau, weight
CALL timeset(routineN, handle)
CALL cp_fm_get_info(matrix=fm_mat_Q, &
nrow_local=nrow_local, &
ncol_local=ncol_local, &
row_indices=row_indices, &
col_indices=col_indices)
! calculate [1+Q(iw')]^-1
CALL cp_fm_cholesky_invert(fm_mat_Q)
! symmetrize the result
CALL cp_fm_upper_to_full(fm_mat_Q, fm_mat_work)
! subtract 1 from the diagonal to get rid of exchange self-energy
!$OMP PARALLEL DO DEFAULT(NONE) PRIVATE(jjB,iiB,i_global,j_global) &
!$OMP SHARED(ncol_local,nrow_local,col_indices,row_indices,fm_mat_Q,dimen_RI)
DO jjB = 1, ncol_local
j_global = col_indices(jjB)
DO iiB = 1, nrow_local
i_global = row_indices(iiB)
IF (j_global == i_global .AND. i_global <= dimen_RI) THEN
fm_mat_Q%local_data(iiB, jjB) = fm_mat_Q%local_data(iiB, jjB) - 1.0_dp
END IF
END DO
END DO
! multiply with L from the left and the right to get the screened Coulomb interaction
CALL parallel_gemm('T', 'N', dimen_RI, dimen_RI, dimen_RI, 1.0_dp, fm_mat_L(1, 1), fm_mat_Q, &