-
Notifications
You must be signed in to change notification settings - Fork 1
/
gw_large_cell_gamma.F
2423 lines (1848 loc) · 105 KB
/
gw_large_cell_gamma.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 from paper [Graml2024]
!> \author Jan Wilhelm
!> \date 07.2023
! **************************************************************************************************
MODULE gw_large_cell_gamma
USE atomic_kind_types, ONLY: atomic_kind_type
USE cell_types, ONLY: cell_type,&
get_cell,&
pbc
USE constants_operator, ONLY: operator_coulomb
USE cp_cfm_basic_linalg, ONLY: cp_cfm_upper_to_full
USE cp_cfm_cholesky, ONLY: cp_cfm_cholesky_decompose,&
cp_cfm_cholesky_invert
USE cp_cfm_diag, ONLY: cp_cfm_geeig
USE cp_cfm_types, ONLY: cp_cfm_create,&
cp_cfm_get_info,&
cp_cfm_release,&
cp_cfm_to_cfm,&
cp_cfm_to_fm,&
cp_cfm_type,&
cp_fm_to_cfm
USE cp_dbcsr_api, ONLY: &
dbcsr_add, dbcsr_copy, dbcsr_create, dbcsr_deallocate_matrix, dbcsr_get_block_p, &
dbcsr_iterator_blocks_left, dbcsr_iterator_next_block, dbcsr_iterator_start, &
dbcsr_iterator_stop, dbcsr_iterator_type, dbcsr_p_type, dbcsr_release, &
dbcsr_reserve_all_blocks, dbcsr_set, dbcsr_type
USE cp_dbcsr_operations, ONLY: copy_dbcsr_to_fm,&
copy_fm_to_dbcsr,&
dbcsr_deallocate_matrix_set
USE cp_files, ONLY: close_file,&
open_file
USE cp_fm_basic_linalg, ONLY: cp_fm_scale_and_add
USE cp_fm_diag, ONLY: cp_fm_power
USE cp_fm_types, ONLY: &
cp_fm_create, cp_fm_get_diag, cp_fm_get_info, cp_fm_read_unformatted, cp_fm_release, &
cp_fm_set_all, cp_fm_to_fm, cp_fm_type, cp_fm_write_unformatted
USE cp_log_handling, ONLY: cp_get_default_logger,&
cp_logger_type
USE cp_output_handling, ONLY: cp_p_file,&
cp_print_key_should_output,&
cp_print_key_unit_nr
USE dbt_api, ONLY: dbt_clear,&
dbt_contract,&
dbt_copy,&
dbt_create,&
dbt_destroy,&
dbt_type
USE gw_communication, ONLY: fm_to_local_tensor,&
local_dbt_to_global_mat
USE gw_utils, ONLY: analyt_conti_and_print,&
de_init_bs_env,&
time_to_freq
USE input_constants, ONLY: rtp_method_bse
USE input_section_types, ONLY: section_vals_type
USE kinds, ONLY: default_string_length,&
dp,&
int_8
USE kpoint_coulomb_2c, ONLY: build_2c_coulomb_matrix_kp
USE kpoint_types, ONLY: kpoint_type
USE machine, ONLY: m_walltime
USE mathconstants, ONLY: twopi,&
z_one,&
z_zero
USE message_passing, ONLY: mp_file_delete
USE mp2_ri_2c, ONLY: RI_2c_integral_mat
USE parallel_gemm_api, ONLY: parallel_gemm
USE particle_types, ONLY: particle_type
USE post_scf_bandstructure_types, ONLY: post_scf_bandstructure_type
USE post_scf_bandstructure_utils, ONLY: MIC_contribution_from_ikp,&
cfm_ikp_from_fm_Gamma,&
get_all_VBM_CBM_bandgaps
USE qs_environment_types, ONLY: get_qs_env,&
qs_environment_type
USE qs_kind_types, ONLY: qs_kind_type
USE qs_tensors, ONLY: build_3c_integrals
USE rpa_gw_kpoints_util, ONLY: cp_cfm_power
#include "./base/base_uses.f90"
IMPLICIT NONE
PRIVATE
CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'gw_large_cell_gamma'
PUBLIC :: gw_calc_large_cell_Gamma, &
compute_3c_integrals
CONTAINS
! **************************************************************************************************
!> \brief Perform GW band structure calculation
!> \param qs_env ...
!> \param bs_env ...
!> \par History
!> * 07.2023 created [Jan Wilhelm]
! **************************************************************************************************
SUBROUTINE gw_calc_large_cell_Gamma(qs_env, bs_env)
TYPE(qs_environment_type), POINTER :: qs_env
TYPE(post_scf_bandstructure_type), POINTER :: bs_env
CHARACTER(LEN=*), PARAMETER :: routineN = 'gw_calc_large_cell_Gamma'
INTEGER :: handle
TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: fm_Sigma_x_Gamma, fm_W_MIC_time
TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :, :) :: fm_Sigma_c_Gamma_time
CALL timeset(routineN, handle)
! G^occ_µλ(i|τ|,k=0) = sum_n^occ C_µn(k=0) e^(-|(ϵ_nk=0-ϵ_F)τ|) C_λn(k=0)
! G^vir_µλ(i|τ|,k=0) = sum_n^vir C_µn(k=0) e^(-|(ϵ_nk=0-ϵ_F)τ|) C_λn(k=0)
! χ_PQ(iτ,k=0) = sum_λν [sum_µ (µν|P) G^occ_µλ(i|τ|)] [sum_σ (σλ|Q) G^vir_σν(i|τ|)]
CALL get_mat_chi_Gamma_tau(bs_env, qs_env, bs_env%mat_chi_Gamma_tau)
! χ_PQ(iτ,k=0) -> χ_PQ(iω,k) -> ε_PQ(iω,k) -> W_PQ(iω,k) -> W^MIC_PQ(iτ) -> M^-1*W^MIC*M^-1
CALL get_W_MIC(bs_env, qs_env, bs_env%mat_chi_Gamma_tau, fm_W_MIC_time)
! D_µν = sum_n^occ C_µn(k=0) C_νn(k=0), V^trunc_PQ = sum_cell_R <phi_P,0|V^trunc|phi_Q,R>
! Σ^x_λσ(k=0) = sum_νQ [sum_P (νσ|P) V^trunc_PQ] [sum_µ (λµ|Q) D_µν)]
CALL get_Sigma_x(bs_env, qs_env, fm_Sigma_x_Gamma)
! Σ^c_λσ(iτ,k=0) = sum_νQ [sum_P (νσ|P) W^MIC_PQ(iτ)] [sum_µ (λµ|Q) G^occ_µν(i|τ|)], τ < 0
! Σ^c_λσ(iτ,k=0) = sum_νQ [sum_P (νσ|P) W^MIC_PQ(iτ)] [sum_µ (λµ|Q) G^vir_µν(i|τ|)], τ > 0
CALL get_Sigma_c(bs_env, qs_env, fm_W_MIC_time, fm_Sigma_c_Gamma_time)
! Σ^c_λσ(iτ,k=0) -> Σ^c_nn(ϵ,k); ϵ_nk^GW = ϵ_nk^DFT + Σ^c_nn(ϵ,k) + Σ^x_nn(k) - v^xc_nn(k)
CALL compute_QP_energies(bs_env, qs_env, fm_Sigma_x_Gamma, fm_Sigma_c_Gamma_time)
CALL de_init_bs_env(bs_env)
CALL timestop(handle)
END SUBROUTINE gw_calc_large_cell_Gamma
! **************************************************************************************************
!> \brief ...
!> \param bs_env ...
!> \param qs_env ...
!> \param mat_chi_Gamma_tau ...
! **************************************************************************************************
SUBROUTINE get_mat_chi_Gamma_tau(bs_env, qs_env, mat_chi_Gamma_tau)
TYPE(post_scf_bandstructure_type), POINTER :: bs_env
TYPE(qs_environment_type), POINTER :: qs_env
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: mat_chi_Gamma_tau
CHARACTER(LEN=*), PARAMETER :: routineN = 'get_mat_chi_Gamma_tau'
INTEGER :: handle, i_intval_idx, i_t, inner_loop_atoms_interval_index, ispin, j_intval_idx
INTEGER, DIMENSION(2) :: i_atoms, IL_atoms, j_atoms
LOGICAL :: dist_too_long_i, dist_too_long_j
REAL(KIND=dp) :: t1, tau
TYPE(dbt_type) :: t_2c_Gocc, t_2c_Gvir, t_3c_for_Gocc, &
t_3c_for_Gvir, t_3c_x_Gocc, &
t_3c_x_Gocc_2, t_3c_x_Gvir, &
t_3c_x_Gvir_2
CALL timeset(routineN, handle)
DO i_t = 1, bs_env%num_time_freq_points
t1 = m_walltime()
IF (bs_env%read_chi(i_t)) THEN
CALL fm_read(bs_env%fm_RI_RI, bs_env, bs_env%chi_name, i_t)
CALL copy_fm_to_dbcsr(bs_env%fm_RI_RI, mat_chi_Gamma_tau(i_t)%matrix, &
keep_sparsity=.FALSE.)
IF (bs_env%unit_nr > 0) THEN
WRITE (bs_env%unit_nr, '(T2,A,I5,A,I3,A,F7.1,A)') &
'Read χ(iτ,k=0) from file for time point ', i_t, ' /', &
bs_env%num_time_freq_points, &
', Execution time', m_walltime() - t1, ' s'
END IF
CYCLE
END IF
IF (.NOT. bs_env%calc_chi(i_t)) CYCLE
CALL create_tensors_chi(t_2c_Gocc, t_2c_Gvir, t_3c_for_Gocc, t_3c_for_Gvir, &
t_3c_x_Gocc, t_3c_x_Gvir, t_3c_x_Gocc_2, t_3c_x_Gvir_2, bs_env)
! 1. compute G^occ and G^vir
! Background: G^σ(iτ) = G^occ,σ(iτ) * Θ(-τ) + G^vir,σ(iτ) * Θ(τ), σ ∈ {↑,↓}
! G^occ,σ_µλ(i|τ|,k=0) = sum_n^occ C^σ_µn(k=0) e^(-|(ϵ^σ_nk=0-ϵ_F)τ|) C^σ_λn(k=0)
! G^vir,σ_µλ(i|τ|,k=0) = sum_n^vir C^σ_µn(k=0) e^(-|(ϵ^σ_nk=0-ϵ_F)τ|) C^σ_λn(k=0)
tau = bs_env%imag_time_points(i_t)
DO ispin = 1, bs_env%n_spin
CALL G_occ_vir(bs_env, tau, bs_env%fm_Gocc, ispin, occ=.TRUE., vir=.FALSE.)
CALL G_occ_vir(bs_env, tau, bs_env%fm_Gvir, ispin, occ=.FALSE., vir=.TRUE.)
CALL fm_to_local_tensor(bs_env%fm_Gocc, bs_env%mat_ao_ao%matrix, &
bs_env%mat_ao_ao_tensor%matrix, t_2c_Gocc, bs_env, &
bs_env%atoms_j_t_group)
CALL fm_to_local_tensor(bs_env%fm_Gvir, bs_env%mat_ao_ao%matrix, &
bs_env%mat_ao_ao_tensor%matrix, t_2c_Gvir, bs_env, &
bs_env%atoms_i_t_group)
! every group has its own range of i_atoms and j_atoms; only deal with a
! limited number of i_atom-j_atom pairs simultaneously in a group to save memory
DO i_intval_idx = 1, bs_env%n_intervals_i
DO j_intval_idx = 1, bs_env%n_intervals_j
i_atoms = bs_env%i_atom_intervals(1:2, i_intval_idx)
j_atoms = bs_env%j_atom_intervals(1:2, j_intval_idx)
DO inner_loop_atoms_interval_index = 1, bs_env%n_intervals_inner_loop_atoms
IL_atoms = bs_env%inner_loop_atom_intervals(1:2, inner_loop_atoms_interval_index)
CALL check_dist(i_atoms, IL_atoms, qs_env, bs_env, dist_too_long_i)
CALL check_dist(j_atoms, IL_atoms, qs_env, bs_env, dist_too_long_j)
IF (dist_too_long_i .OR. dist_too_long_j) CYCLE
! 2. compute 3-center integrals (µν|P) ("|": truncated Coulomb operator)
CALL compute_3c_integrals(qs_env, bs_env, t_3c_for_Gocc, i_atoms, IL_atoms)
! 3. tensor operation M_λνP(iτ) = sum_µ (µν|P) G^occ_µλ(i|τ|,k=0)
CALL G_times_3c(t_3c_for_Gocc, t_2c_Gocc, t_3c_x_Gocc, bs_env, &
j_atoms, i_atoms, IL_atoms)
! 4. compute 3-center integrals (σλ|Q) ("|": truncated Coulomb operator)
CALL compute_3c_integrals(qs_env, bs_env, t_3c_for_Gvir, j_atoms, IL_atoms)
! 5. tensor operation N_νλQ(iτ) = sum_σ (σλ|Q) G^vir_σν(i|τ|,k=0)
CALL G_times_3c(t_3c_for_Gvir, t_2c_Gvir, t_3c_x_Gvir, bs_env, &
i_atoms, j_atoms, IL_atoms)
END DO ! IL_atoms
! 6. reorder tensors
CALL dbt_copy(t_3c_x_Gocc, t_3c_x_Gocc_2, move_data=.TRUE., order=[1, 3, 2])
CALL dbt_copy(t_3c_x_Gvir, t_3c_x_Gvir_2, move_data=.TRUE.)
! 7. tensor operation χ_PQ(iτ,k=0) = sum_λν M_λνP(iτ) N_νλQ(iτ),
CALL dbt_contract(alpha=bs_env%spin_degeneracy, &
tensor_1=t_3c_x_Gocc_2, tensor_2=t_3c_x_Gvir_2, &
beta=1.0_dp, tensor_3=bs_env%t_chi, &
contract_1=[2, 3], notcontract_1=[1], map_1=[1], &
contract_2=[2, 3], notcontract_2=[1], map_2=[2], &
filter_eps=bs_env%eps_filter, move_data=.TRUE.)
END DO ! j_atoms
END DO ! i_atoms
END DO ! ispin
! 8. communicate data of χ_PQ(iτ,k=0) in tensor bs_env%t_chi (which local in the
! subgroup) to the global dbcsr matrix mat_chi_Gamma_tau (which stores
! χ_PQ(iτ,k=0) for all time points)
CALL local_dbt_to_global_mat(bs_env%t_chi, bs_env%mat_RI_RI_tensor%matrix, &
mat_chi_Gamma_tau(i_t)%matrix, bs_env%para_env)
CALL write_matrix(mat_chi_Gamma_tau(i_t)%matrix, i_t, bs_env%chi_name, &
bs_env%fm_RI_RI, qs_env)
CALL destroy_tensors_chi(t_2c_Gocc, t_2c_Gvir, t_3c_for_Gocc, t_3c_for_Gvir, &
t_3c_x_Gocc, t_3c_x_Gvir, t_3c_x_Gocc_2, t_3c_x_Gvir_2)
IF (bs_env%unit_nr > 0) THEN
WRITE (bs_env%unit_nr, '(T2,A,I13,A,I3,A,F7.1,A)') &
'Computed χ(iτ,k=0) for time point', i_t, ' /', bs_env%num_time_freq_points, &
', Execution time', m_walltime() - t1, ' s'
END IF
END DO ! i_t
IF (bs_env%unit_nr > 0) WRITE (bs_env%unit_nr, '(A)') ' '
CALL timestop(handle)
END SUBROUTINE get_mat_chi_Gamma_tau
! **************************************************************************************************
!> \brief ...
!> \param fm ...
!> \param bs_env ...
!> \param mat_name ...
!> \param idx ...
! **************************************************************************************************
SUBROUTINE fm_read(fm, bs_env, mat_name, idx)
TYPE(cp_fm_type) :: fm
TYPE(post_scf_bandstructure_type), POINTER :: bs_env
CHARACTER(LEN=*) :: mat_name
INTEGER :: idx
CHARACTER(LEN=*), PARAMETER :: routineN = 'fm_read'
CHARACTER(LEN=default_string_length) :: f_chi
INTEGER :: handle, unit_nr
CALL timeset(routineN, handle)
unit_nr = -1
IF (bs_env%para_env%is_source()) THEN
IF (idx < 10) THEN
WRITE (f_chi, '(3A,I1,A)') TRIM(bs_env%prefix), TRIM(mat_name), "_0", idx, ".matrix"
ELSE IF (idx < 100) THEN
WRITE (f_chi, '(3A,I2,A)') TRIM(bs_env%prefix), TRIM(mat_name), "_", idx, ".matrix"
ELSE
CPABORT('Please implement more than 99 time/frequency points.')
END IF
CALL open_file(file_name=TRIM(f_chi), file_action="READ", file_form="UNFORMATTED", &
file_position="REWIND", file_status="OLD", unit_number=unit_nr)
END IF
CALL cp_fm_read_unformatted(fm, unit_nr)
IF (bs_env%para_env%is_source()) CALL close_file(unit_number=unit_nr)
CALL timestop(handle)
END SUBROUTINE fm_read
! **************************************************************************************************
!> \brief ...
!> \param t_2c_Gocc ...
!> \param t_2c_Gvir ...
!> \param t_3c_for_Gocc ...
!> \param t_3c_for_Gvir ...
!> \param t_3c_x_Gocc ...
!> \param t_3c_x_Gvir ...
!> \param t_3c_x_Gocc_2 ...
!> \param t_3c_x_Gvir_2 ...
!> \param bs_env ...
! **************************************************************************************************
SUBROUTINE create_tensors_chi(t_2c_Gocc, t_2c_Gvir, t_3c_for_Gocc, t_3c_for_Gvir, &
t_3c_x_Gocc, t_3c_x_Gvir, t_3c_x_Gocc_2, t_3c_x_Gvir_2, bs_env)
TYPE(dbt_type) :: t_2c_Gocc, t_2c_Gvir, t_3c_for_Gocc, &
t_3c_for_Gvir, t_3c_x_Gocc, &
t_3c_x_Gvir, t_3c_x_Gocc_2, &
t_3c_x_Gvir_2
TYPE(post_scf_bandstructure_type), POINTER :: bs_env
CHARACTER(LEN=*), PARAMETER :: routineN = 'create_tensors_chi'
INTEGER :: handle
CALL timeset(routineN, handle)
CALL dbt_create(bs_env%t_G, t_2c_Gocc)
CALL dbt_create(bs_env%t_G, t_2c_Gvir)
CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_for_Gocc)
CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_for_Gvir)
CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_x_Gocc)
CALL dbt_create(bs_env%t_RI_AO__AO, t_3c_x_Gvir)
CALL dbt_create(bs_env%t_RI__AO_AO, t_3c_x_Gocc_2)
CALL dbt_create(bs_env%t_RI__AO_AO, t_3c_x_Gvir_2)
CALL timestop(handle)
END SUBROUTINE create_tensors_chi
! **************************************************************************************************
!> \brief ...
!> \param t_2c_Gocc ...
!> \param t_2c_Gvir ...
!> \param t_3c_for_Gocc ...
!> \param t_3c_for_Gvir ...
!> \param t_3c_x_Gocc ...
!> \param t_3c_x_Gvir ...
!> \param t_3c_x_Gocc_2 ...
!> \param t_3c_x_Gvir_2 ...
! **************************************************************************************************
SUBROUTINE destroy_tensors_chi(t_2c_Gocc, t_2c_Gvir, t_3c_for_Gocc, t_3c_for_Gvir, &
t_3c_x_Gocc, t_3c_x_Gvir, t_3c_x_Gocc_2, t_3c_x_Gvir_2)
TYPE(dbt_type) :: t_2c_Gocc, t_2c_Gvir, t_3c_for_Gocc, &
t_3c_for_Gvir, t_3c_x_Gocc, &
t_3c_x_Gvir, t_3c_x_Gocc_2, &
t_3c_x_Gvir_2
CHARACTER(LEN=*), PARAMETER :: routineN = 'destroy_tensors_chi'
INTEGER :: handle
CALL timeset(routineN, handle)
CALL dbt_destroy(t_2c_Gocc)
CALL dbt_destroy(t_2c_Gvir)
CALL dbt_destroy(t_3c_for_Gocc)
CALL dbt_destroy(t_3c_for_Gvir)
CALL dbt_destroy(t_3c_x_Gocc)
CALL dbt_destroy(t_3c_x_Gvir)
CALL dbt_destroy(t_3c_x_Gocc_2)
CALL dbt_destroy(t_3c_x_Gvir_2)
CALL timestop(handle)
END SUBROUTINE destroy_tensors_chi
! **************************************************************************************************
!> \brief ...
!> \param matrix ...
!> \param matrix_index ...
!> \param matrix_name ...
!> \param fm ...
!> \param qs_env ...
! **************************************************************************************************
SUBROUTINE write_matrix(matrix, matrix_index, matrix_name, fm, qs_env)
TYPE(dbcsr_type) :: matrix
INTEGER :: matrix_index
CHARACTER(LEN=*) :: matrix_name
TYPE(cp_fm_type), INTENT(IN), POINTER :: fm
TYPE(qs_environment_type), POINTER :: qs_env
CHARACTER(LEN=*), PARAMETER :: routineN = 'write_matrix'
INTEGER :: handle
CALL timeset(routineN, handle)
CALL cp_fm_set_all(fm, 0.0_dp)
CALL copy_dbcsr_to_fm(matrix, fm)
CALL fm_write(fm, matrix_index, matrix_name, qs_env)
CALL timestop(handle)
END SUBROUTINE write_matrix
! **************************************************************************************************
!> \brief ...
!> \param fm ...
!> \param matrix_index ...
!> \param matrix_name ...
!> \param qs_env ...
! **************************************************************************************************
SUBROUTINE fm_write(fm, matrix_index, matrix_name, qs_env)
TYPE(cp_fm_type) :: fm
INTEGER :: matrix_index
CHARACTER(LEN=*) :: matrix_name
TYPE(qs_environment_type), POINTER :: qs_env
CHARACTER(LEN=*), PARAMETER :: key = 'PROPERTIES%BANDSTRUCTURE%GW%PRINT%RESTART', &
routineN = 'fm_write'
CHARACTER(LEN=default_string_length) :: filename
INTEGER :: handle, unit_nr
TYPE(cp_logger_type), POINTER :: logger
TYPE(section_vals_type), POINTER :: input
CALL timeset(routineN, handle)
CALL get_qs_env(qs_env, input=input)
logger => cp_get_default_logger()
IF (BTEST(cp_print_key_should_output(logger%iter_info, input, key), cp_p_file)) THEN
IF (matrix_index < 10) THEN
WRITE (filename, '(3A,I1)') "RESTART_", matrix_name, "_0", matrix_index
ELSE IF (matrix_index < 100) THEN
WRITE (filename, '(3A,I2)') "RESTART_", matrix_name, "_", matrix_index
ELSE
CPABORT('Please implement more than 99 time/frequency points.')
END IF
unit_nr = cp_print_key_unit_nr(logger, input, key, extension=".matrix", &
file_form="UNFORMATTED", middle_name=TRIM(filename), &
file_position="REWIND", file_action="WRITE")
CALL cp_fm_write_unformatted(fm, unit_nr)
IF (unit_nr > 0) THEN
CALL close_file(unit_nr)
END IF
END IF
CALL timestop(handle)
END SUBROUTINE fm_write
! **************************************************************************************************
!> \brief ...
!> \param bs_env ...
!> \param tau ...
!> \param fm_G_Gamma ...
!> \param ispin ...
!> \param occ ...
!> \param vir ...
! **************************************************************************************************
SUBROUTINE G_occ_vir(bs_env, tau, fm_G_Gamma, ispin, occ, vir)
TYPE(post_scf_bandstructure_type), POINTER :: bs_env
REAL(KIND=dp) :: tau
TYPE(cp_fm_type) :: fm_G_Gamma
INTEGER :: ispin
LOGICAL :: occ, vir
CHARACTER(LEN=*), PARAMETER :: routineN = 'G_occ_vir'
INTEGER :: handle, homo, i_row_local, j_col, &
j_col_local, n_mo, ncol_local, &
nrow_local
INTEGER, DIMENSION(:), POINTER :: col_indices
REAL(KIND=dp) :: tau_E
CALL timeset(routineN, handle)
CPASSERT(occ .NEQV. vir)
CALL cp_fm_get_info(matrix=bs_env%fm_work_mo(1), &
nrow_local=nrow_local, &
ncol_local=ncol_local, &
col_indices=col_indices)
n_mo = bs_env%n_ao
homo = bs_env%n_occ(ispin)
CALL cp_fm_to_fm(bs_env%fm_mo_coeff_Gamma(ispin), bs_env%fm_work_mo(1))
DO i_row_local = 1, nrow_local
DO j_col_local = 1, ncol_local
j_col = col_indices(j_col_local)
tau_E = ABS(tau*0.5_dp*(bs_env%eigenval_scf_Gamma(j_col, ispin) - bs_env%e_fermi(ispin)))
IF (tau_E < bs_env%stabilize_exp) THEN
bs_env%fm_work_mo(1)%local_data(i_row_local, j_col_local) = &
bs_env%fm_work_mo(1)%local_data(i_row_local, j_col_local)*EXP(-tau_E)
ELSE
bs_env%fm_work_mo(1)%local_data(i_row_local, j_col_local) = 0.0_dp
END IF
IF ((occ .AND. j_col > homo) .OR. (vir .AND. j_col <= homo)) THEN
bs_env%fm_work_mo(1)%local_data(i_row_local, j_col_local) = 0.0_dp
END IF
END DO
END DO
CALL parallel_gemm(transa="N", transb="T", m=n_mo, n=n_mo, k=n_mo, alpha=1.0_dp, &
matrix_a=bs_env%fm_work_mo(1), matrix_b=bs_env%fm_work_mo(1), &
beta=0.0_dp, matrix_c=fm_G_Gamma)
CALL timestop(handle)
END SUBROUTINE G_occ_vir
! **************************************************************************************************
!> \brief ...
!> \param qs_env ...
!> \param bs_env ...
!> \param t_3c ...
!> \param atoms_AO_1 ...
!> \param atoms_AO_2 ...
!> \param atoms_RI ...
! **************************************************************************************************
SUBROUTINE compute_3c_integrals(qs_env, bs_env, t_3c, atoms_AO_1, atoms_AO_2, atoms_RI)
TYPE(qs_environment_type), POINTER :: qs_env
TYPE(post_scf_bandstructure_type), POINTER :: bs_env
TYPE(dbt_type) :: t_3c
INTEGER, DIMENSION(2), OPTIONAL :: atoms_AO_1, atoms_AO_2, atoms_RI
CHARACTER(LEN=*), PARAMETER :: routineN = 'compute_3c_integrals'
INTEGER :: handle
INTEGER, DIMENSION(2) :: my_atoms_AO_1, my_atoms_AO_2, my_atoms_RI
TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :) :: t_3c_array
CALL timeset(routineN, handle)
! free memory (not clear whether memory has been freed previously)
CALL dbt_clear(t_3c)
ALLOCATE (t_3c_array(1, 1))
CALL dbt_create(t_3c, t_3c_array(1, 1))
IF (PRESENT(atoms_AO_1)) THEN
my_atoms_AO_1 = atoms_AO_1
ELSE
my_atoms_AO_1 = [1, bs_env%n_atom]
END IF
IF (PRESENT(atoms_AO_2)) THEN
my_atoms_AO_2 = atoms_AO_2
ELSE
my_atoms_AO_2 = [1, bs_env%n_atom]
END IF
IF (PRESENT(atoms_RI)) THEN
my_atoms_RI = atoms_RI
ELSE
my_atoms_RI = [1, bs_env%n_atom]
END IF
CALL build_3c_integrals(t_3c_array, &
bs_env%eps_filter, &
qs_env, &
bs_env%nl_3c, &
int_eps=bs_env%eps_filter, &
basis_i=bs_env%basis_set_RI, &
basis_j=bs_env%basis_set_AO, &
basis_k=bs_env%basis_set_AO, &
potential_parameter=bs_env%ri_metric, &
bounds_i=atoms_RI, &
bounds_j=atoms_AO_1, &
bounds_k=atoms_AO_2, &
desymmetrize=.FALSE.)
CALL dbt_copy(t_3c_array(1, 1), t_3c, move_data=.TRUE.)
CALL dbt_destroy(t_3c_array(1, 1))
DEALLOCATE (t_3c_array)
CALL timestop(handle)
END SUBROUTINE compute_3c_integrals
! **************************************************************************************************
!> \brief ...
!> \param t_3c_for_G ...
!> \param t_G ...
!> \param t_M ...
!> \param bs_env ...
!> \param atoms_AO_1 ...
!> \param atoms_AO_2 ...
!> \param atoms_IL ...
! **************************************************************************************************
SUBROUTINE G_times_3c(t_3c_for_G, t_G, t_M, bs_env, atoms_AO_1, atoms_AO_2, atoms_IL)
TYPE(dbt_type) :: t_3c_for_G, t_G, t_M
TYPE(post_scf_bandstructure_type), POINTER :: bs_env
INTEGER, DIMENSION(2) :: atoms_AO_1, atoms_AO_2, atoms_IL
CHARACTER(LEN=*), PARAMETER :: routineN = 'G_times_3c'
INTEGER :: handle
INTEGER, DIMENSION(2) :: bounds_IL, bounds_l
INTEGER, DIMENSION(2, 2) :: bounds_k
CALL timeset(routineN, handle)
! JW bounds_IL and bounds_k do not safe any operations, but maybe communication
! maybe remove "bounds_1=bounds_IL, &" and "bounds_2=bounds_k, &" later and
! check whether performance improves
bounds_IL(1:2) = [bs_env%i_ao_start_from_atom(atoms_IL(1)), &
bs_env%i_ao_end_from_atom(atoms_IL(2))]
bounds_k(1:2, 1) = [1, bs_env%n_RI]
bounds_k(1:2, 2) = [bs_env%i_ao_start_from_atom(atoms_AO_2(1)), &
bs_env%i_ao_end_from_atom(atoms_AO_2(2))]
bounds_l(1:2) = [bs_env%i_ao_start_from_atom(atoms_AO_1(1)), &
bs_env%i_ao_end_from_atom(atoms_AO_1(2))]
CALL dbt_contract(alpha=1.0_dp, &
tensor_1=t_3c_for_G, &
tensor_2=t_G, &
beta=1.0_dp, &
tensor_3=t_M, &
contract_1=[3], notcontract_1=[1, 2], map_1=[1, 2], &
contract_2=[2], notcontract_2=[1], map_2=[3], &
bounds_1=bounds_IL, &
bounds_2=bounds_k, &
bounds_3=bounds_l, &
filter_eps=bs_env%eps_filter)
CALL dbt_clear(t_3c_for_G)
CALL timestop(handle)
END SUBROUTINE G_times_3c
! **************************************************************************************************
!> \brief ...
!> \param atoms_1 ...
!> \param atoms_2 ...
!> \param qs_env ...
!> \param bs_env ...
!> \param dist_too_long ...
! **************************************************************************************************
SUBROUTINE check_dist(atoms_1, atoms_2, qs_env, bs_env, dist_too_long)
INTEGER, DIMENSION(2) :: atoms_1, atoms_2
TYPE(qs_environment_type), POINTER :: qs_env
TYPE(post_scf_bandstructure_type), POINTER :: bs_env
LOGICAL :: dist_too_long
CHARACTER(LEN=*), PARAMETER :: routineN = 'check_dist'
INTEGER :: atom_1, atom_2, handle
REAL(dp) :: abs_rab, min_dist_AO_atoms
REAL(KIND=dp), DIMENSION(3) :: rab
TYPE(cell_type), POINTER :: cell
TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
CALL timeset(routineN, handle)
CALL get_qs_env(qs_env, cell=cell, particle_set=particle_set)
min_dist_AO_atoms = 1.0E5_dp
DO atom_1 = atoms_1(1), atoms_1(2)
DO atom_2 = atoms_2(1), atoms_2(2)
rab = pbc(particle_set(atom_1)%r(1:3), particle_set(atom_2)%r(1:3), cell)
abs_rab = SQRT(rab(1)**2 + rab(2)**2 + rab(3)**2)
min_dist_AO_atoms = MIN(min_dist_AO_atoms, abs_rab)
END DO
END DO
dist_too_long = (min_dist_AO_atoms > bs_env%max_dist_AO_atoms)
CALL timestop(handle)
END SUBROUTINE check_dist
! **************************************************************************************************
!> \brief ...
!> \param bs_env ...
!> \param qs_env ...
!> \param mat_chi_Gamma_tau ...
!> \param fm_W_MIC_time ...
! **************************************************************************************************
SUBROUTINE get_W_MIC(bs_env, qs_env, mat_chi_Gamma_tau, fm_W_MIC_time)
TYPE(post_scf_bandstructure_type), POINTER :: bs_env
TYPE(qs_environment_type), POINTER :: qs_env
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: mat_chi_Gamma_tau
TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: fm_W_MIC_time
CHARACTER(LEN=*), PARAMETER :: routineN = 'get_W_MIC'
INTEGER :: handle
CALL timeset(routineN, handle)
IF (bs_env%all_W_exist) THEN
CALL read_W_MIC_time(bs_env, mat_chi_Gamma_tau, fm_W_MIC_time)
ELSE
CALL compute_W_MIC(bs_env, qs_env, mat_chi_Gamma_tau, fm_W_MIC_time)
END IF
CALL timestop(handle)
END SUBROUTINE get_W_MIC
! **************************************************************************************************
!> \brief ...
!> \param bs_env ...
!> \param qs_env ...
!> \param fm_V_kp ...
!> \param ikp_batch ...
! **************************************************************************************************
SUBROUTINE compute_V_k_by_lattice_sum(bs_env, qs_env, fm_V_kp, ikp_batch)
TYPE(post_scf_bandstructure_type), POINTER :: bs_env
TYPE(qs_environment_type), POINTER :: qs_env
TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: fm_V_kp
INTEGER :: ikp_batch
CHARACTER(LEN=*), PARAMETER :: routineN = 'compute_V_k_by_lattice_sum'
INTEGER :: handle, ikp, ikp_end, ikp_start, &
nkp_chi_eps_W_batch, re_im
TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
TYPE(cell_type), POINTER :: cell
TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: mat_V_kp
TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
CALL timeset(routineN, handle)
nkp_chi_eps_W_batch = bs_env%nkp_chi_eps_W_batch
ikp_start = (ikp_batch - 1)*bs_env%nkp_chi_eps_W_batch + 1
ikp_end = MIN(ikp_batch*bs_env%nkp_chi_eps_W_batch, bs_env%kpoints_chi_eps_W%nkp)
NULLIFY (mat_V_kp)
ALLOCATE (mat_V_kp(ikp_start:ikp_end, 2))
DO ikp = ikp_start, ikp_end
DO re_im = 1, 2
NULLIFY (mat_V_kp(ikp, re_im)%matrix)
ALLOCATE (mat_V_kp(ikp, re_im)%matrix)
CALL dbcsr_create(mat_V_kp(ikp, re_im)%matrix, template=bs_env%mat_RI_RI%matrix)
CALL dbcsr_reserve_all_blocks(mat_V_kp(ikp, re_im)%matrix)
CALL dbcsr_set(mat_V_kp(ikp, re_im)%matrix, 0.0_dp)
END DO ! re_im
END DO ! ikp
CALL get_qs_env(qs_env=qs_env, &
particle_set=particle_set, &
cell=cell, &
qs_kind_set=qs_kind_set, &
atomic_kind_set=atomic_kind_set)
IF (ikp_end .LE. bs_env%nkp_chi_eps_W_orig) THEN
! 1. 2c Coulomb integrals for the first "original" k-point grid
bs_env%kpoints_chi_eps_W%nkp_grid = bs_env%nkp_grid_chi_eps_W_orig
ELSE IF (ikp_start > bs_env%nkp_chi_eps_W_orig .AND. &
ikp_end .LE. bs_env%nkp_chi_eps_W_orig_plus_extra) THEN
! 2. 2c Coulomb integrals for the second "extrapolation" k-point grid
bs_env%kpoints_chi_eps_W%nkp_grid = bs_env%nkp_grid_chi_eps_W_extra
ELSE
CPABORT("Error with k-point parallelization.")
END IF
CALL build_2c_coulomb_matrix_kp(mat_V_kp, &
bs_env%kpoints_chi_eps_W, &
basis_type="RI_AUX", &
cell=cell, &
particle_set=particle_set, &
qs_kind_set=qs_kind_set, &
atomic_kind_set=atomic_kind_set, &
size_lattice_sum=bs_env%size_lattice_sum_V, &
operator_type=operator_coulomb, &
ikp_start=ikp_start, &
ikp_end=ikp_end)
bs_env%kpoints_chi_eps_W%nkp_grid = bs_env%nkp_grid_chi_eps_W_orig
ALLOCATE (fm_V_kp(ikp_start:ikp_end, 2))
DO ikp = ikp_start, ikp_end
DO re_im = 1, 2
CALL cp_fm_create(fm_V_kp(ikp, re_im), bs_env%fm_RI_RI%matrix_struct)
CALL copy_dbcsr_to_fm(mat_V_kp(ikp, re_im)%matrix, fm_V_kp(ikp, re_im))
CALL dbcsr_deallocate_matrix(mat_V_kp(ikp, re_im)%matrix)
END DO
END DO
DEALLOCATE (mat_V_kp)
CALL timestop(handle)
END SUBROUTINE compute_V_k_by_lattice_sum
! **************************************************************************************************
!> \brief ...
!> \param bs_env ...
!> \param qs_env ...
!> \param fm_V_kp ...
!> \param cfm_V_sqrt_ikp ...
!> \param cfm_M_inv_V_sqrt_ikp ...
!> \param ikp ...
! **************************************************************************************************
SUBROUTINE compute_MinvVsqrt_Vsqrt(bs_env, qs_env, fm_V_kp, cfm_V_sqrt_ikp, &
cfm_M_inv_V_sqrt_ikp, ikp)
TYPE(post_scf_bandstructure_type), POINTER :: bs_env
TYPE(qs_environment_type), POINTER :: qs_env
TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: fm_V_kp
TYPE(cp_cfm_type) :: cfm_V_sqrt_ikp, cfm_M_inv_V_sqrt_ikp
INTEGER :: ikp
CHARACTER(LEN=*), PARAMETER :: routineN = 'compute_MinvVsqrt_Vsqrt'
INTEGER :: handle, info, n_RI
TYPE(cp_cfm_type) :: cfm_M_inv_ikp, cfm_work
TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: fm_M_ikp
CALL timeset(routineN, handle)
n_RI = bs_env%n_RI
! get here M(k) and write it to fm_M_ikp
CALL RI_2c_integral_mat(qs_env, fm_M_ikp, fm_V_kp(ikp, 1), &
n_RI, bs_env%ri_metric, do_kpoints=.TRUE., &
kpoints=bs_env%kpoints_chi_eps_W, &
regularization_RI=bs_env%regularization_RI, ikp_ext=ikp, &
do_build_cell_index=(ikp == 1))
IF (ikp == 1) THEN
CALL cp_cfm_create(cfm_V_sqrt_ikp, fm_V_kp(ikp, 1)%matrix_struct)
CALL cp_cfm_create(cfm_M_inv_V_sqrt_ikp, fm_V_kp(ikp, 1)%matrix_struct)
END IF
CALL cp_cfm_create(cfm_M_inv_ikp, fm_V_kp(ikp, 1)%matrix_struct)
CALL cp_fm_to_cfm(fm_M_ikp(1, 1), fm_M_ikp(1, 2), cfm_M_inv_ikp)
CALL cp_fm_to_cfm(fm_V_kp(ikp, 1), fm_V_kp(ikp, 2), cfm_V_sqrt_ikp)
CALL cp_fm_release(fm_M_ikp)
CALL cp_cfm_create(cfm_work, fm_V_kp(ikp, 1)%matrix_struct)
! M(k) -> M^-1(k)
CALL cp_cfm_to_cfm(cfm_M_inv_ikp, cfm_work)
CALL cp_cfm_cholesky_decompose(matrix=cfm_M_inv_ikp, n=n_RI, info_out=info)
IF (info == 0) THEN
! successful Cholesky decomposition
CALL cp_cfm_cholesky_invert(cfm_M_inv_ikp)
! symmetrize the result
CALL cp_cfm_upper_to_full(cfm_M_inv_ikp)
ELSE
! Cholesky decomposition not successful: use expensive diagonalization
CALL cp_cfm_power(cfm_work, threshold=bs_env%eps_eigval_mat_RI, exponent=-1.0_dp)
CALL cp_cfm_to_cfm(cfm_work, cfm_M_inv_ikp)
END IF
! V(k) -> L(k) with L^H(k)*L(k) = V(k) [L(k) can be just considered to be V^0.5(k)]
CALL cp_cfm_to_cfm(cfm_V_sqrt_ikp, cfm_work)
CALL cp_cfm_cholesky_decompose(matrix=cfm_V_sqrt_ikp, n=n_RI, info_out=info)
IF (info == 0) THEN
! successful Cholesky decomposition
CALL clean_lower_part(cfm_V_sqrt_ikp)
ELSE
! Cholesky decomposition not successful: use expensive diagonalization
CALL cp_cfm_power(cfm_work, threshold=0.0_dp, exponent=0.5_dp)
CALL cp_cfm_to_cfm(cfm_work, cfm_V_sqrt_ikp)
END IF
CALL cp_cfm_release(cfm_work)
! get M^-1(k)*V^0.5(k)
CALL parallel_gemm("N", "C", n_RI, n_RI, n_RI, z_one, cfm_M_inv_ikp, cfm_V_sqrt_ikp, &
z_zero, cfm_M_inv_V_sqrt_ikp)
CALL cp_cfm_release(cfm_M_inv_ikp)
CALL timestop(handle)
END SUBROUTINE compute_MinvVsqrt_Vsqrt
! **************************************************************************************************
!> \brief ...
!> \param bs_env ...
!> \param mat_chi_Gamma_tau ...
!> \param fm_W_MIC_time ...
! **************************************************************************************************
SUBROUTINE read_W_MIC_time(bs_env, mat_chi_Gamma_tau, fm_W_MIC_time)
TYPE(post_scf_bandstructure_type), POINTER :: bs_env
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: mat_chi_Gamma_tau
TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: fm_W_MIC_time
CHARACTER(LEN=*), PARAMETER :: routineN = 'read_W_MIC_time'
INTEGER :: handle, i_t
REAL(KIND=dp) :: t1
CALL timeset(routineN, handle)
CALL dbcsr_deallocate_matrix_set(mat_chi_Gamma_tau)
CALL create_fm_W_MIC_time(bs_env, fm_W_MIC_time)
DO i_t = 1, bs_env%num_time_freq_points
t1 = m_walltime()
CALL fm_read(fm_W_MIC_time(i_t), bs_env, bs_env%W_time_name, i_t)
IF (bs_env%unit_nr > 0) THEN
WRITE (bs_env%unit_nr, '(T2,A,I5,A,I3,A,F7.1,A)') &
'Read W^MIC(iτ) from file for time point ', i_t, ' /', bs_env%num_time_freq_points, &
', Execution time', m_walltime() - t1, ' s'
END IF
END DO
IF (bs_env%unit_nr > 0) WRITE (bs_env%unit_nr, '(A)') ' '
! Marek : Reading of the W(w=0) potential for RTP
! TODO : is the condition bs_env%all_W_exist sufficient for reading?
IF (bs_env%rtp_method == rtp_method_bse) THEN
CALL cp_fm_create(bs_env%fm_W_MIC_freq_zero, bs_env%fm_W_MIC_freq%matrix_struct)
t1 = m_walltime()
CALL fm_read(bs_env%fm_W_MIC_freq_zero, bs_env, "W_freq_rtp", 0)
IF (bs_env%unit_nr > 0) THEN
WRITE (bs_env%unit_nr, '(T2,A,I5,A,I3,A,F7.1,A)') &
'Read W^MIC(w=0) from file for frequency point ', 1, ' /', 1, &
', Execution time', m_walltime() - t1, ' s'
END IF
END IF
CALL timestop(handle)
END SUBROUTINE read_W_MIC_time
! **************************************************************************************************
!> \brief ...
!> \param bs_env ...
!> \param qs_env ...
!> \param mat_chi_Gamma_tau ...
!> \param fm_W_MIC_time ...
! **************************************************************************************************
SUBROUTINE compute_W_MIC(bs_env, qs_env, mat_chi_Gamma_tau, fm_W_MIC_time)
TYPE(post_scf_bandstructure_type), POINTER :: bs_env
TYPE(qs_environment_type), POINTER :: qs_env
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: mat_chi_Gamma_tau
TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: fm_W_MIC_time
CHARACTER(LEN=*), PARAMETER :: routineN = 'compute_W_MIC'
INTEGER :: handle, i_t, ikp, ikp_batch, &
ikp_in_batch, j_w
REAL(KIND=dp) :: t1
TYPE(cp_cfm_type) :: cfm_M_inv_V_sqrt_ikp, cfm_V_sqrt_ikp
TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: fm_V_kp