-
Notifications
You must be signed in to change notification settings - Fork 1
/
mp2_ri_libint.F
1297 lines (1111 loc) · 58.3 KB
/
mp2_ri_libint.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 to calculate the 3 and 2 center ERI's needed in the RI
!> approximation using libint
!> \par History
!> 08.2013 created [Mauro Del Ben]
!> \author Mauro Del Ben
! **************************************************************************************************
MODULE mp2_ri_libint
USE atomic_kind_types, ONLY: atomic_kind_type,&
get_atomic_kind_set
USE basis_set_types, ONLY: get_gto_basis_set,&
gto_basis_set_type,&
init_aux_basis_set
USE cell_types, ONLY: cell_type
USE cp_blacs_env, ONLY: cp_blacs_env_create,&
cp_blacs_env_release,&
cp_blacs_env_type
USE cp_control_types, ONLY: dft_control_type
USE cp_files, ONLY: close_file,&
open_file
USE cp_fm_basic_linalg, ONLY: cp_fm_triangular_invert
USE cp_fm_cholesky, ONLY: cp_fm_cholesky_decompose
USE cp_fm_struct, ONLY: cp_fm_struct_create,&
cp_fm_struct_release,&
cp_fm_struct_type
USE cp_fm_types, ONLY: cp_fm_create,&
cp_fm_get_submatrix,&
cp_fm_release,&
cp_fm_set_submatrix,&
cp_fm_type
USE gamma, ONLY: init_md_ftable
USE hfx_energy_potential, ONLY: coulomb4
USE hfx_pair_list_methods, ONLY: build_pair_list_mp2
USE hfx_screening_methods, ONLY: calc_pair_dist_radii,&
calc_screening_functions
USE hfx_types, ONLY: &
hfx_basis_info_type, hfx_basis_type, hfx_create_neighbor_cells, hfx_pgf_list, &
hfx_pgf_product_list, hfx_potential_type, hfx_screen_coeff_type, hfx_type, log_zero, &
pair_set_list_type
USE input_constants, ONLY: do_potential_TShPSC,&
do_potential_long
USE kinds, ONLY: dp,&
int_8
USE libint_wrapper, ONLY: cp_libint_t
USE message_passing, ONLY: mp_para_env_type
USE mp2_types, ONLY: init_TShPSC_lmax,&
mp2_biel_type,&
mp2_type,&
pair_list_type_mp2
USE orbital_pointers, ONLY: nco,&
ncoset,&
nso
USE particle_types, ONLY: particle_type
USE qs_environment_types, ONLY: get_qs_env,&
qs_environment_type
USE qs_kind_types, ONLY: get_qs_kind,&
get_qs_kind_set,&
qs_kind_type
USE t_sh_p_s_c, ONLY: free_C0,&
init
#include "./base/base_uses.f90"
IMPLICIT NONE
PRIVATE
PUBLIC :: libint_ri_mp2, read_RI_basis_set, release_RI_basis_set, prepare_integral_calc
CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'mp2_ri_libint'
!***
CONTAINS
! **************************************************************************************************
!> \brief ...
!> \param dimen ...
!> \param RI_dimen ...
!> \param occupied ...
!> \param natom ...
!> \param mp2_biel ...
!> \param mp2_env ...
!> \param C ...
!> \param kind_of ...
!> \param RI_basis_parameter ...
!> \param RI_basis_info ...
!> \param basis_S0 ...
!> \param RI_index_table ...
!> \param qs_env ...
!> \param para_env ...
!> \param Lai ...
! **************************************************************************************************
SUBROUTINE libint_ri_mp2(dimen, RI_dimen, occupied, natom, mp2_biel, mp2_env, C, &
kind_of, &
RI_basis_parameter, RI_basis_info, basis_S0, RI_index_table, &
qs_env, para_env, &
Lai)
INTEGER :: dimen, RI_dimen, occupied, natom
TYPE(mp2_biel_type) :: mp2_biel
TYPE(mp2_type) :: mp2_env
REAL(KIND=dp), DIMENSION(dimen, dimen) :: C
INTEGER, DIMENSION(:) :: kind_of
TYPE(hfx_basis_type), DIMENSION(:), POINTER :: RI_basis_parameter
TYPE(hfx_basis_info_type) :: RI_basis_info
TYPE(hfx_basis_type), DIMENSION(:), POINTER :: basis_S0
INTEGER, ALLOCATABLE, DIMENSION(:, :) :: RI_index_table
TYPE(qs_environment_type), POINTER :: qs_env
TYPE(mp_para_env_type), POINTER :: para_env
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :) :: Lai
CHARACTER(LEN=*), PARAMETER :: routineN = 'libint_ri_mp2'
INTEGER :: handle, nkind
CALL timeset(routineN, handle)
! Get the RI basis set and store in to a nice form
IF (.NOT. (ASSOCIATED(RI_basis_parameter))) THEN
IF (ALLOCATED(RI_index_table)) DEALLOCATE (RI_index_table)
IF (ASSOCIATED(basis_S0)) DEALLOCATE (basis_S0)
CALL read_RI_basis_set(qs_env, RI_basis_parameter, RI_basis_info, &
natom, nkind, kind_of, RI_index_table, RI_dimen, &
basis_S0)
END IF
CALL calc_lai_libint(mp2_env, qs_env, para_env, &
mp2_biel, dimen, C, occupied, &
RI_basis_parameter, RI_basis_info, RI_index_table, RI_dimen, basis_S0, &
Lai)
CALL timestop(handle)
END SUBROUTINE libint_ri_mp2
! **************************************************************************************************
!> \brief Read the auxiliary basis set for RI approxiamtion
!> \param qs_env ...
!> \param RI_basis_parameter ...
!> \param RI_basis_info ...
!> \param natom ...
!> \param nkind ...
!> \param kind_of ...
!> \param RI_index_table ...
!> \param RI_dimen ...
!> \param basis_S0 ...
!> \par History
!> 08.2013 created [Mauro Del Ben]
!> \author Mauro Del Ben
! **************************************************************************************************
SUBROUTINE read_RI_basis_set(qs_env, RI_basis_parameter, RI_basis_info, &
natom, nkind, kind_of, RI_index_table, RI_dimen, &
basis_S0)
TYPE(qs_environment_type), POINTER :: qs_env
TYPE(hfx_basis_type), DIMENSION(:), POINTER :: RI_basis_parameter
TYPE(hfx_basis_info_type) :: RI_basis_info
INTEGER :: natom, nkind
INTEGER, DIMENSION(:) :: kind_of
INTEGER, ALLOCATABLE, DIMENSION(:, :) :: RI_index_table
INTEGER :: RI_dimen
TYPE(hfx_basis_type), DIMENSION(:), POINTER :: basis_S0
INTEGER :: co_counter, counter, i, iatom, ikind, ipgf, iset, j, k, la, max_am_kind, &
max_coeff, max_nsgfl, max_pgf, max_pgf_kind, max_set, nl_count, nset, nseta, offset_a, &
offset_a1, s_offset_nl_a, sgfa, so_counter
INTEGER, DIMENSION(:), POINTER :: la_max, la_min, npgfa, nshell
INTEGER, DIMENSION(:, :), POINTER :: first_sgfa, nl_a
REAL(dp), DIMENSION(:, :), POINTER :: sphi_a
TYPE(gto_basis_set_type), POINTER :: orb_basis_a
TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
TYPE(qs_kind_type), POINTER :: atom_kind
NULLIFY (RI_basis_parameter)
NULLIFY (qs_kind_set)
CALL get_qs_env(qs_env=qs_env, qs_kind_set=qs_kind_set)
nkind = SIZE(qs_kind_set, 1)
ALLOCATE (RI_basis_parameter(nkind))
ALLOCATE (basis_S0(nkind))
max_set = 0
DO ikind = 1, nkind
NULLIFY (atom_kind)
atom_kind => qs_kind_set(ikind)
! here we reset the initial RI basis such that we can
! work with non-normalized auxiliary basis functions
CALL get_qs_kind(qs_kind=atom_kind, &
basis_set=orb_basis_a, basis_type="RI_AUX")
IF (.NOT. (ASSOCIATED(orb_basis_a))) THEN
CPABORT("Initial RI auxiliary basis not specified.")
END IF
orb_basis_a%gcc = 1.0_dp
orb_basis_a%norm_type = 1
CALL init_aux_basis_set(orb_basis_a)
CALL get_qs_kind_set(qs_kind_set=qs_kind_set, &
maxsgf=RI_basis_info%max_sgf, &
maxnset=RI_basis_info%max_set, &
maxlgto=RI_basis_info%max_am, &
basis_type="RI_AUX")
CALL get_gto_basis_set(gto_basis_set=orb_basis_a, &
lmax=RI_basis_parameter(ikind)%lmax, &
lmin=RI_basis_parameter(ikind)%lmin, &
npgf=RI_basis_parameter(ikind)%npgf, &
nset=RI_basis_parameter(ikind)%nset, &
zet=RI_basis_parameter(ikind)%zet, &
nsgf_set=RI_basis_parameter(ikind)%nsgf, &
first_sgf=RI_basis_parameter(ikind)%first_sgf, &
sphi=RI_basis_parameter(ikind)%sphi, &
nsgf=RI_basis_parameter(ikind)%nsgf_total, &
l=RI_basis_parameter(ikind)%nl, &
nshell=RI_basis_parameter(ikind)%nshell, &
set_radius=RI_basis_parameter(ikind)%set_radius, &
pgf_radius=RI_basis_parameter(ikind)%pgf_radius, &
kind_radius=RI_basis_parameter(ikind)%kind_radius)
max_set = MAX(max_set, RI_basis_parameter(ikind)%nset)
basis_S0(ikind)%kind_radius = RI_basis_parameter(ikind)%kind_radius
basis_S0(ikind)%nset = 1
basis_S0(ikind)%nsgf_total = 1
ALLOCATE (basis_S0(ikind)%set_radius(1))
basis_S0(ikind)%set_radius(1) = RI_basis_parameter(ikind)%kind_radius
ALLOCATE (basis_S0(ikind)%lmax(1))
basis_S0(ikind)%lmax(1) = 0
ALLOCATE (basis_S0(ikind)%lmin(1))
basis_S0(ikind)%lmin(1) = 0
ALLOCATE (basis_S0(ikind)%npgf(1))
basis_S0(ikind)%npgf(1) = 1
ALLOCATE (basis_S0(ikind)%nsgf(1))
basis_S0(ikind)%nsgf(1) = 1
ALLOCATE (basis_S0(ikind)%nshell(1))
basis_S0(ikind)%nshell(1) = 1
ALLOCATE (basis_S0(ikind)%pgf_radius(1, 1))
basis_S0(ikind)%pgf_radius(1, 1) = RI_basis_parameter(ikind)%kind_radius
ALLOCATE (basis_S0(ikind)%sphi(1, 1))
basis_S0(ikind)%sphi(1, 1) = 1.0_dp
ALLOCATE (basis_S0(ikind)%zet(1, 1))
basis_S0(ikind)%zet(1, 1) = 0.0_dp
ALLOCATE (basis_S0(ikind)%first_sgf(1, 1))
basis_S0(ikind)%first_sgf(1, 1) = 1
ALLOCATE (basis_S0(ikind)%nl(1, 1))
basis_S0(ikind)%nl(1, 1) = 0
ALLOCATE (basis_S0(ikind)%nsgfl(0:0, 1))
basis_S0(ikind)%nsgfl = 1
ALLOCATE (basis_S0(ikind)%sphi_ext(1, 0:0, 1, 1))
basis_S0(ikind)%sphi_ext(1, 0, 1, 1) = 1.0_dp
END DO
RI_basis_info%max_set = max_set
DO ikind = 1, nkind
ALLOCATE (RI_basis_parameter(ikind)%nsgfl(0:RI_basis_info%max_am, max_set))
RI_basis_parameter(ikind)%nsgfl = 0
nset = RI_basis_parameter(ikind)%nset
nshell => RI_basis_parameter(ikind)%nshell
DO iset = 1, nset
DO i = 0, RI_basis_info%max_am
nl_count = 0
DO j = 1, nshell(iset)
IF (RI_basis_parameter(ikind)%nl(j, iset) == i) nl_count = nl_count + 1
END DO
RI_basis_parameter(ikind)%nsgfl(i, iset) = nl_count
END DO
END DO
END DO
max_nsgfl = 0
max_pgf = 0
DO ikind = 1, nkind
max_coeff = 0
max_am_kind = 0
max_pgf_kind = 0
npgfa => RI_basis_parameter(ikind)%npgf
nseta = RI_basis_parameter(ikind)%nset
nl_a => RI_basis_parameter(ikind)%nsgfl
la_max => RI_basis_parameter(ikind)%lmax
la_min => RI_basis_parameter(ikind)%lmin
DO iset = 1, nseta
max_pgf_kind = MAX(max_pgf_kind, npgfa(iset))
max_pgf = MAX(max_pgf, npgfa(iset))
DO la = la_min(iset), la_max(iset)
max_nsgfl = MAX(max_nsgfl, nl_a(la, iset))
max_coeff = MAX(max_coeff, nso(la)*nl_a(la, iset)*nco(la))
max_am_kind = MAX(max_am_kind, la)
END DO
END DO
ALLOCATE (RI_basis_parameter(ikind)%sphi_ext(max_coeff, 0:max_am_kind, max_pgf_kind, nseta))
RI_basis_parameter(ikind)%sphi_ext = 0.0_dp
END DO
DO ikind = 1, nkind
sphi_a => RI_basis_parameter(ikind)%sphi
nseta = RI_basis_parameter(ikind)%nset
la_max => RI_basis_parameter(ikind)%lmax
la_min => RI_basis_parameter(ikind)%lmin
npgfa => RI_basis_parameter(ikind)%npgf
first_sgfa => RI_basis_parameter(ikind)%first_sgf
nl_a => RI_basis_parameter(ikind)%nsgfl
DO iset = 1, nseta
sgfa = first_sgfa(1, iset)
DO ipgf = 1, npgfa(iset)
offset_a1 = (ipgf - 1)*ncoset(la_max(iset))
s_offset_nl_a = 0
DO la = la_min(iset), la_max(iset)
offset_a = offset_a1 + ncoset(la - 1)
co_counter = 0
co_counter = co_counter + 1
so_counter = 0
DO k = sgfa + s_offset_nl_a, sgfa + s_offset_nl_a + nso(la)*nl_a(la, iset) - 1
DO i = offset_a + 1, offset_a + nco(la)
so_counter = so_counter + 1
RI_basis_parameter(ikind)%sphi_ext(so_counter, la, ipgf, iset) = sphi_a(i, k)
END DO
END DO
s_offset_nl_a = s_offset_nl_a + nso(la)*(nl_a(la, iset))
END DO
END DO
END DO
END DO
ALLOCATE (RI_index_table(natom, max_set))
RI_index_table = -HUGE(0)
counter = 0
RI_dimen = 0
DO iatom = 1, natom
ikind = kind_of(iatom)
nset = RI_basis_parameter(ikind)%nset
DO iset = 1, nset
RI_index_table(iatom, iset) = counter + 1
counter = counter + RI_basis_parameter(ikind)%nsgf(iset)
RI_dimen = RI_dimen + RI_basis_parameter(ikind)%nsgf(iset)
END DO
END DO
END SUBROUTINE read_RI_basis_set
! **************************************************************************************************
!> \brief Release the auxiliary basis set for RI approxiamtion (to be used
!> only in the case of basis optimization)
!> \param RI_basis_parameter ...
!> \param basis_S0 ...
!> \par History
!> 08.2013 created [Mauro Del Ben]
!> \author Mauro Del Ben
! **************************************************************************************************
SUBROUTINE release_RI_basis_set(RI_basis_parameter, basis_S0)
TYPE(hfx_basis_type), DIMENSION(:), POINTER :: RI_basis_parameter, basis_S0
INTEGER :: i
! RI basis
DO i = 1, SIZE(RI_basis_parameter)
DEALLOCATE (RI_basis_parameter(i)%nsgfl)
DEALLOCATE (RI_basis_parameter(i)%sphi_ext)
END DO
DEALLOCATE (RI_basis_parameter)
! S0 basis
DO i = 1, SIZE(basis_S0)
DEALLOCATE (basis_S0(i)%set_radius)
DEALLOCATE (basis_S0(i)%lmax)
DEALLOCATE (basis_S0(i)%lmin)
DEALLOCATE (basis_S0(i)%npgf)
DEALLOCATE (basis_S0(i)%nsgf)
DEALLOCATE (basis_S0(i)%nshell)
DEALLOCATE (basis_S0(i)%pgf_radius)
DEALLOCATE (basis_S0(i)%sphi)
DEALLOCATE (basis_S0(i)%zet)
DEALLOCATE (basis_S0(i)%first_sgf)
DEALLOCATE (basis_S0(i)%nl)
DEALLOCATE (basis_S0(i)%nsgfl)
DEALLOCATE (basis_S0(i)%sphi_ext)
END DO
DEALLOCATE (basis_S0)
END SUBROUTINE release_RI_basis_set
! **************************************************************************************************
!> \brief ...
!> \param mp2_env ...
!> \param qs_env ...
!> \param para_env ...
!> \param mp2_biel ...
!> \param dimen ...
!> \param C ...
!> \param occupied ...
!> \param RI_basis_parameter ...
!> \param RI_basis_info ...
!> \param RI_index_table ...
!> \param RI_dimen ...
!> \param basis_S0 ...
!> \param Lai ...
!> \par History
!> 08.2013 created [Mauro Del Ben]
!> \author Mauro Del Ben
! **************************************************************************************************
SUBROUTINE calc_lai_libint(mp2_env, qs_env, para_env, &
mp2_biel, dimen, C, occupied, &
RI_basis_parameter, RI_basis_info, RI_index_table, RI_dimen, basis_S0, &
Lai)
TYPE(mp2_type) :: mp2_env
TYPE(qs_environment_type), POINTER :: qs_env
TYPE(mp_para_env_type), POINTER :: para_env
TYPE(mp2_biel_type) :: mp2_biel
INTEGER :: dimen
REAL(KIND=dp), DIMENSION(dimen, dimen) :: C
INTEGER :: occupied
TYPE(hfx_basis_type), DIMENSION(:), POINTER :: RI_basis_parameter
TYPE(hfx_basis_info_type) :: RI_basis_info
INTEGER, ALLOCATABLE, DIMENSION(:, :) :: RI_index_table
INTEGER :: RI_dimen
TYPE(hfx_basis_type), DIMENSION(:), POINTER :: basis_S0
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :) :: Lai
CHARACTER(LEN=*), PARAMETER :: routineN = 'calc_lai_libint'
INTEGER :: counter_L_blocks, handle, i, i_list_kl, i_set_list_kl, i_set_list_kl_start, &
i_set_list_kl_stop, iatom, iatom_end, iatom_start, iiB, ikind, info_chol, iset, jatom, &
jatom_end, jatom_start, jjB, jkind, jset, katom, katom_end, katom_start, kkB, kkind, &
kset, kset_start, L_B_i_end, L_B_i_start, L_B_k_end, L_B_k_start, latom, latom_end, &
latom_start, lkind, llB, lset, max_pgf, max_set, natom, ncob, nints, nseta, nsetb, nsetc, &
nsetd, nsgf_max, nspins, orb_k_end, orb_k_start, orb_l_end, orb_l_start, &
primitive_counter, sphi_a_u1, sphi_a_u2, sphi_a_u3, sphi_b_u1, sphi_b_u2, sphi_b_u3
INTEGER :: sphi_c_u1, sphi_c_u2, sphi_c_u3, sphi_d_u1, sphi_d_u2, sphi_d_u3, virtual
INTEGER(int_8) :: estimate_to_store_int, neris_tmp, &
neris_total, nprim_ints
INTEGER, ALLOCATABLE, DIMENSION(:) :: kind_of, nimages
INTEGER, DIMENSION(:), POINTER :: la_max, la_min, lb_max, lb_min, lc_max, &
lc_min, ld_max, ld_min, npgfa, npgfb, &
npgfc, npgfd, nsgfa, nsgfb, nsgfc, &
nsgfd
INTEGER, DIMENSION(:, :), POINTER :: nsgfl_a, nsgfl_b, nsgfl_c, nsgfl_d
LOGICAL :: do_periodic
LOGICAL, DIMENSION(:, :), POINTER :: shm_atomic_pair_list
REAL(KIND=dp) :: cartesian_estimate, coeffs_kind_max0, eps_schwarz, ln_10, &
log10_eps_schwarz, log10_pmax, max_contraction_val, pmax_atom, pmax_entry, ra(3), rb(3), &
rc(3), rd(3)
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: ee_buffer1, ee_buffer2, &
ee_primitives_tmp, ee_work, ee_work2, &
primitive_integrals
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: L_block, L_full_matrix, max_contraction
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :) :: BI1, MNRS
REAL(KIND=dp), DIMENSION(:), POINTER :: p_work
REAL(KIND=dp), DIMENSION(:, :), POINTER :: shm_pmax_block, zeta, zetb, zetc, zetd
REAL(KIND=dp), DIMENSION(:, :, :), POINTER :: sphi_a_ext_set, sphi_b_ext_set, &
sphi_c_ext_set, sphi_d_ext_set
REAL(KIND=dp), DIMENSION(:, :, :, :), POINTER :: sphi_a_ext, sphi_b_ext, sphi_c_ext, &
sphi_d_ext
TYPE(cell_type), POINTER :: cell
TYPE(cp_blacs_env_type), POINTER :: blacs_env
TYPE(cp_fm_struct_type), POINTER :: fm_struct_L
TYPE(cp_fm_type) :: fm_matrix_L
TYPE(cp_libint_t) :: private_lib
TYPE(hfx_basis_type), DIMENSION(:), POINTER :: basis_parameter
TYPE(hfx_pgf_list), ALLOCATABLE, DIMENSION(:) :: pgf_list_ij, pgf_list_kl
TYPE(hfx_pgf_product_list), ALLOCATABLE, &
DIMENSION(:) :: pgf_product_list
TYPE(hfx_potential_type) :: mp2_potential_parameter
TYPE(hfx_screen_coeff_type), ALLOCATABLE, &
DIMENSION(:, :), TARGET :: radii_pgf_large, screen_coeffs_pgf_large
TYPE(hfx_screen_coeff_type), DIMENSION(:, :), &
POINTER :: screen_coeffs_kind, tmp_R_1, tmp_R_2, &
tmp_screen_pgf1, tmp_screen_pgf2
TYPE(hfx_screen_coeff_type), &
DIMENSION(:, :, :, :), POINTER :: screen_coeffs_set
TYPE(hfx_screen_coeff_type), &
DIMENSION(:, :, :, :, :, :), POINTER :: radii_pgf, screen_coeffs_pgf
TYPE(hfx_type), POINTER :: actual_x_data
TYPE(pair_list_type_mp2) :: list_kl
TYPE(pair_set_list_type), ALLOCATABLE, &
DIMENSION(:) :: set_list_kl
TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
CALL timeset(routineN, handle)
ln_10 = LOG(10.0_dp)
!! initialize some counters
neris_tmp = 0_int_8
neris_total = 0_int_8
nprim_ints = 0_int_8
CALL prepare_integral_calc(cell, qs_env, mp2_env, para_env, mp2_potential_parameter, actual_x_data, &
do_periodic, basis_parameter, max_set, particle_set, natom, kind_of, &
nsgf_max, primitive_integrals, ee_work, ee_work2, ee_buffer1, ee_buffer2, &
ee_primitives_tmp, nspins, max_contraction, max_pgf, pgf_list_ij, &
pgf_list_kl, pgf_product_list, nimages, eps_schwarz, log10_eps_schwarz, &
private_lib, p_work, screen_coeffs_set, screen_coeffs_kind, screen_coeffs_pgf, &
radii_pgf, RI_basis_parameter, RI_basis_info)
ALLOCATE (radii_pgf_large(SIZE(radii_pgf, 1), SIZE(radii_pgf, 2)))
ALLOCATE (screen_coeffs_pgf_large(SIZE(screen_coeffs_pgf, 1), SIZE(screen_coeffs_pgf, 2)))
DO iiB = 1, SIZE(radii_pgf, 1)
DO jjB = 1, SIZE(radii_pgf, 2)
radii_pgf_large(iiB, jjB)%x = 100_dp
END DO
END DO
DO iiB = 1, SIZE(screen_coeffs_pgf, 1)
DO jjB = 1, SIZE(screen_coeffs_pgf, 2)
screen_coeffs_pgf_large(iiB, jjB)%x = 5000_dp
END DO
END DO
tmp_R_1 => radii_pgf_large(:, :)
tmp_R_2 => radii_pgf_large(:, :)
tmp_screen_pgf1 => screen_coeffs_pgf_large(:, :)
tmp_screen_pgf2 => screen_coeffs_pgf_large(:, :)
! start computing the L matrix
ALLOCATE (L_full_matrix(RI_dimen, RI_dimen))
L_full_matrix = 0.0_dp
counter_L_blocks = 0
DO iatom = 1, natom
jatom = iatom
ikind = kind_of(iatom)
jkind = kind_of(jatom)
ra = particle_set(iatom)%r(:)
rb = particle_set(jatom)%r(:)
la_max => RI_basis_parameter(ikind)%lmax
la_min => RI_basis_parameter(ikind)%lmin
npgfa => RI_basis_parameter(ikind)%npgf
nseta = RI_basis_parameter(ikind)%nset
zeta => RI_basis_parameter(ikind)%zet
nsgfa => RI_basis_parameter(ikind)%nsgf
sphi_a_ext => RI_basis_parameter(ikind)%sphi_ext(:, :, :, :)
nsgfl_a => RI_basis_parameter(ikind)%nsgfl
sphi_a_u1 = UBOUND(sphi_a_ext, 1)
sphi_a_u2 = UBOUND(sphi_a_ext, 2)
sphi_a_u3 = UBOUND(sphi_a_ext, 3)
lb_max => basis_S0(jkind)%lmax
lb_min => basis_S0(jkind)%lmin
npgfb => basis_S0(jkind)%npgf
nsetb = basis_S0(jkind)%nset
zetb => basis_S0(jkind)%zet
nsgfb => basis_S0(jkind)%nsgf
sphi_b_ext => basis_S0(jkind)%sphi_ext(:, :, :, :)
nsgfl_b => basis_S0(jkind)%nsgfl
sphi_b_u1 = UBOUND(sphi_b_ext, 1)
sphi_b_u2 = UBOUND(sphi_b_ext, 2)
sphi_b_u3 = UBOUND(sphi_b_ext, 3)
DO katom = iatom, natom
latom = katom
kkind = kind_of(katom)
lkind = kind_of(latom)
rc = particle_set(katom)%r(:)
rd = particle_set(latom)%r(:)
lc_max => RI_basis_parameter(kkind)%lmax
lc_min => RI_basis_parameter(kkind)%lmin
npgfc => RI_basis_parameter(kkind)%npgf
nsetc = RI_basis_parameter(kkind)%nset
zetc => RI_basis_parameter(kkind)%zet
nsgfc => RI_basis_parameter(kkind)%nsgf
sphi_c_ext => RI_basis_parameter(kkind)%sphi_ext(:, :, :, :)
nsgfl_c => RI_basis_parameter(kkind)%nsgfl
sphi_c_u1 = UBOUND(sphi_c_ext, 1)
sphi_c_u2 = UBOUND(sphi_c_ext, 2)
sphi_c_u3 = UBOUND(sphi_c_ext, 3)
ld_max => basis_S0(lkind)%lmax
ld_min => basis_S0(lkind)%lmin
npgfd => basis_S0(lkind)%npgf
nsetd = RI_basis_parameter(lkind)%nset
zetd => basis_S0(lkind)%zet
nsgfd => basis_S0(lkind)%nsgf
sphi_d_ext => basis_S0(lkind)%sphi_ext(:, :, :, :)
nsgfl_d => basis_S0(lkind)%nsgfl
sphi_d_u1 = UBOUND(sphi_d_ext, 1)
sphi_d_u2 = UBOUND(sphi_d_ext, 2)
sphi_d_u3 = UBOUND(sphi_d_ext, 3)
jset = 1
lset = 1
DO iset = 1, nseta
ncob = npgfb(jset)*ncoset(lb_max(jset))
sphi_a_ext_set => sphi_a_ext(:, :, :, iset)
sphi_b_ext_set => sphi_b_ext(:, :, :, jset)
L_B_i_start = RI_index_table(iatom, iset)
L_B_i_end = RI_index_table(iatom, iset) + nsgfa(iset) - 1
kset_start = 1
IF (iatom == katom) kset_start = iset
DO kset = kset_start, nsetc
counter_L_blocks = counter_L_blocks + 1
IF (MOD(counter_L_blocks, para_env%num_pe) /= para_env%mepos) CYCLE
sphi_c_ext_set => sphi_c_ext(:, :, :, kset)
sphi_d_ext_set => sphi_d_ext(:, :, :, lset)
L_B_k_start = RI_index_table(katom, kset)
L_B_k_end = RI_index_table(katom, kset) + nsgfc(kset) - 1
pmax_entry = 0.0_dp
log10_pmax = pmax_entry
log10_eps_schwarz = log_zero
max_contraction_val = 1.0000_dp
ALLOCATE (L_block(nsgfa(iset), nsgfc(kset)))
CALL coulomb4(private_lib, ra, rb, rc, rd, npgfa(iset), npgfb(jset), npgfc(kset), npgfd(lset), &
la_min(iset), la_max(iset), lb_min(jset), lb_max(jset), &
lc_min(kset), lc_max(kset), ld_min(lset), ld_max(lset), &
nsgfa(iset), nsgfb(jset), nsgfc(kset), nsgfd(lset), &
sphi_a_u1, sphi_a_u2, sphi_a_u3, &
sphi_b_u1, sphi_b_u2, sphi_b_u3, &
sphi_c_u1, sphi_c_u2, sphi_c_u3, &
sphi_d_u1, sphi_d_u2, sphi_d_u3, &
zeta(1:npgfa(iset), iset), zetb(1:npgfb(jset), jset), &
zetc(1:npgfc(kset), kset), zetd(1:npgfd(lset), lset), &
primitive_integrals, &
mp2_potential_parameter, &
actual_x_data%neighbor_cells, screen_coeffs_set(1, 1, 1, 1)%x, &
screen_coeffs_set(1, 1, 1, 1)%x, eps_schwarz, &
max_contraction_val, cartesian_estimate, cell, neris_tmp, &
log10_pmax, log10_eps_schwarz, &
tmp_R_1, tmp_R_2, tmp_screen_pgf1, tmp_screen_pgf2, &
pgf_list_ij, pgf_list_kl, pgf_product_list, &
nsgfl_a(:, iset), nsgfl_b(:, jset), &
nsgfl_c(:, kset), nsgfl_d(:, lset), &
sphi_a_ext_set, &
sphi_b_ext_set, &
sphi_c_ext_set, &
sphi_d_ext_set, &
ee_work, ee_work2, ee_buffer1, ee_buffer2, ee_primitives_tmp, &
nimages, do_periodic, p_work)
primitive_counter = 0
DO llB = 1, nsgfd(lset)
DO kkB = 1, nsgfc(kset)
DO jjB = 1, nsgfb(jset)
DO iiB = 1, nsgfa(iset)
primitive_counter = primitive_counter + 1
L_block(iiB, kkB) = primitive_integrals(primitive_counter)
END DO
END DO
END DO
END DO
L_full_matrix(L_B_i_start:L_B_i_end, L_B_k_start:L_B_k_end) = L_block
L_full_matrix(L_B_k_start:L_B_k_end, L_B_i_start:L_B_i_end) = TRANSPOSE(L_block)
DEALLOCATE (L_block)
END DO ! kset
END DO ! iset
END DO !katom
END DO !iatom
! now create a fm_matrix for the L matrix
CALL para_env%sum(L_full_matrix)
! create a sub blacs_env
NULLIFY (blacs_env)
CALL cp_blacs_env_create(blacs_env=blacs_env, para_env=para_env)
NULLIFY (fm_struct_L)
CALL cp_fm_struct_create(fm_struct_L, context=blacs_env, nrow_global=RI_dimen, &
ncol_global=RI_dimen, para_env=para_env)
CALL cp_fm_create(fm_matrix_L, fm_struct_L, name="fm_matrix_L")
CALL cp_fm_struct_release(fm_struct_L)
CALL cp_blacs_env_release(blacs_env)
CALL cp_fm_set_submatrix(fm=fm_matrix_L, new_values=L_full_matrix, start_row=1, start_col=1, &
n_rows=RI_dimen, n_cols=RI_dimen)
info_chol = 0
CALL cp_fm_cholesky_decompose(matrix=fm_matrix_L, n=RI_dimen, info_out=info_chol)
CPASSERT(info_chol == 0)
! triangual invert
CALL cp_fm_triangular_invert(matrix_a=fm_matrix_L, uplo_tr='U')
! replicate L matrix to each proc
L_full_matrix = 0.0_dp
CALL cp_fm_get_submatrix(fm_matrix_L, L_full_matrix, 1, 1, RI_dimen, RI_dimen, .FALSE.)
CALL cp_fm_release(fm_matrix_L)
! clean lower part
DO iiB = 1, RI_dimen
L_full_matrix(iiB + 1:RI_dimen, iiB) = 0.0_dp
END DO
ALLOCATE (list_kl%elements(natom**2))
coeffs_kind_max0 = MAXVAL(screen_coeffs_kind(:, :)%x(2))
ALLOCATE (set_list_kl((max_set*natom)**2))
!! precalculate maximum density matrix elements in blocks
actual_x_data%pmax_block = 0.0_dp
shm_pmax_block => actual_x_data%pmax_block
shm_atomic_pair_list => actual_x_data%atomic_pair_list
iatom_start = 1
iatom_end = natom
jatom_start = 1
jatom_end = natom
katom_start = 1
katom_end = natom
latom_start = 1
latom_end = natom
CALL build_pair_list_mp2(natom, list_kl, set_list_kl, katom_start, katom_end, &
latom_start, latom_end, &
kind_of, basis_parameter, particle_set, &
do_periodic, screen_coeffs_set, screen_coeffs_kind, &
coeffs_kind_max0, log10_eps_schwarz, cell, 0.D+00, &
shm_atomic_pair_list)
virtual = dimen - occupied
ALLOCATE (Lai(RI_dimen, virtual, occupied))
Lai = 0.0_dp
DO iatom = 1, natom
jatom = iatom
ikind = kind_of(iatom)
jkind = kind_of(jatom)
ra = particle_set(iatom)%r(:)
rb = particle_set(jatom)%r(:)
la_max => RI_basis_parameter(ikind)%lmax
la_min => RI_basis_parameter(ikind)%lmin
npgfa => RI_basis_parameter(ikind)%npgf
nseta = RI_basis_parameter(ikind)%nset
zeta => RI_basis_parameter(ikind)%zet
nsgfa => RI_basis_parameter(ikind)%nsgf
sphi_a_ext => RI_basis_parameter(ikind)%sphi_ext(:, :, :, :)
nsgfl_a => RI_basis_parameter(ikind)%nsgfl
sphi_a_u1 = UBOUND(sphi_a_ext, 1)
sphi_a_u2 = UBOUND(sphi_a_ext, 2)
sphi_a_u3 = UBOUND(sphi_a_ext, 3)
lb_max => basis_S0(jkind)%lmax
lb_min => basis_S0(jkind)%lmin
npgfb => basis_S0(jkind)%npgf
nsetb = basis_S0(jkind)%nset
zetb => basis_S0(jkind)%zet
nsgfb => basis_S0(jkind)%nsgf
sphi_b_ext => basis_S0(jkind)%sphi_ext(:, :, :, :)
nsgfl_b => basis_S0(jkind)%nsgfl
sphi_b_u1 = UBOUND(sphi_b_ext, 1)
sphi_b_u2 = UBOUND(sphi_b_ext, 2)
sphi_b_u3 = UBOUND(sphi_b_ext, 3)
jset = 1
DO iset = 1, nseta
counter_L_blocks = counter_L_blocks + 1
IF (MOD(counter_L_blocks, para_env%num_pe) /= para_env%mepos) CYCLE
ncob = npgfb(jset)*ncoset(lb_max(jset))
sphi_a_ext_set => sphi_a_ext(:, :, :, iset)
sphi_b_ext_set => sphi_b_ext(:, :, :, jset)
L_B_i_start = RI_index_table(iatom, iset)
L_B_i_end = RI_index_table(iatom, iset) + nsgfa(iset) - 1
ALLOCATE (BI1(dimen, dimen, nsgfa(iset)))
BI1 = 0.0_dp
DO i_list_kl = 1, list_kl%n_element
katom = list_kl%elements(i_list_kl)%pair(1)
latom = list_kl%elements(i_list_kl)%pair(2)
i_set_list_kl_start = list_kl%elements(i_list_kl)%set_bounds(1)
i_set_list_kl_stop = list_kl%elements(i_list_kl)%set_bounds(2)
kkind = list_kl%elements(i_list_kl)%kind_pair(1)
lkind = list_kl%elements(i_list_kl)%kind_pair(2)
rc = list_kl%elements(i_list_kl)%r1
rd = list_kl%elements(i_list_kl)%r2
pmax_atom = 0.0_dp
lc_max => basis_parameter(kkind)%lmax
lc_min => basis_parameter(kkind)%lmin
npgfc => basis_parameter(kkind)%npgf
zetc => basis_parameter(kkind)%zet
nsgfc => basis_parameter(kkind)%nsgf
sphi_c_ext => basis_parameter(kkind)%sphi_ext(:, :, :, :)
nsgfl_c => basis_parameter(kkind)%nsgfl
sphi_c_u1 = UBOUND(sphi_c_ext, 1)
sphi_c_u2 = UBOUND(sphi_c_ext, 2)
sphi_c_u3 = UBOUND(sphi_c_ext, 3)
ld_max => basis_parameter(lkind)%lmax
ld_min => basis_parameter(lkind)%lmin
npgfd => basis_parameter(lkind)%npgf
zetd => basis_parameter(lkind)%zet
nsgfd => basis_parameter(lkind)%nsgf
sphi_d_ext => basis_parameter(lkind)%sphi_ext(:, :, :, :)
nsgfl_d => basis_parameter(lkind)%nsgfl
sphi_d_u1 = UBOUND(sphi_d_ext, 1)
sphi_d_u2 = UBOUND(sphi_d_ext, 2)
sphi_d_u3 = UBOUND(sphi_d_ext, 3)
DO i_set_list_kl = i_set_list_kl_start, i_set_list_kl_stop
kset = set_list_kl(i_set_list_kl)%pair(1)
lset = set_list_kl(i_set_list_kl)%pair(2)
IF (katom == latom .AND. lset < kset) CYCLE
orb_k_start = mp2_biel%index_table(katom, kset)
orb_k_end = orb_k_start + nsgfc(kset) - 1
orb_l_start = mp2_biel%index_table(latom, lset)
orb_l_end = orb_l_start + nsgfd(lset) - 1
!! get max_vals if we screen on initial density
pmax_entry = 0.0_dp
sphi_c_ext_set => sphi_c_ext(:, :, :, kset)
sphi_d_ext_set => sphi_d_ext(:, :, :, lset)
log10_pmax = pmax_entry
log10_eps_schwarz = log_zero
IF (ALLOCATED(MNRS)) DEALLOCATE (MNRS)
ALLOCATE (MNRS(nsgfd(lset), nsgfc(kset), nsgfa(iset)))
MNRS = 0.0_dp
max_contraction_val = max_contraction(kset, katom)*max_contraction(lset, latom)
CALL coulomb4(private_lib, ra, rb, rc, rd, npgfa(iset), npgfb(jset), npgfc(kset), npgfd(lset), &
la_min(iset), la_max(iset), lb_min(jset), lb_max(jset), &
lc_min(kset), lc_max(kset), ld_min(lset), ld_max(lset), &
nsgfa(iset), nsgfb(jset), nsgfc(kset), nsgfd(lset), &
sphi_a_u1, sphi_a_u2, sphi_a_u3, &
sphi_b_u1, sphi_b_u2, sphi_b_u3, &
sphi_c_u1, sphi_c_u2, sphi_c_u3, &
sphi_d_u1, sphi_d_u2, sphi_d_u3, &
zeta(1:npgfa(iset), iset), zetb(1:npgfb(jset), jset), &
zetc(1:npgfc(kset), kset), zetd(1:npgfd(lset), lset), &
primitive_integrals, &
mp2_potential_parameter, &
actual_x_data%neighbor_cells, screen_coeffs_set(kset, kset, kkind, kkind)%x, &
screen_coeffs_set(kset, kset, kkind, kkind)%x, eps_schwarz, &
max_contraction_val, cartesian_estimate, cell, neris_tmp, &
log10_pmax, log10_eps_schwarz, &
tmp_R_1, tmp_R_2, tmp_screen_pgf1, tmp_screen_pgf2, &
pgf_list_ij, pgf_list_kl, pgf_product_list, &
nsgfl_a(:, iset), nsgfl_b(:, jset), &
nsgfl_c(:, kset), nsgfl_d(:, lset), &
sphi_a_ext_set, &
sphi_b_ext_set, &
sphi_c_ext_set, &
sphi_d_ext_set, &
ee_work, ee_work2, ee_buffer1, ee_buffer2, ee_primitives_tmp, &
nimages, do_periodic, p_work)
nints = nsgfa(iset)*nsgfb(jset)*nsgfc(kset)*nsgfd(lset)
neris_total = neris_total + nints
nprim_ints = nprim_ints + neris_tmp
IF (cartesian_estimate == 0.0_dp) cartesian_estimate = TINY(cartesian_estimate)
estimate_to_store_int = EXPONENT(cartesian_estimate)
estimate_to_store_int = MAX(estimate_to_store_int, -15_int_8)
cartesian_estimate = SET_EXPONENT(1.0_dp, estimate_to_store_int + 1)
primitive_counter = 0
DO llB = 1, nsgfd(lset)
DO kkB = 1, nsgfc(kset)
DO jjB = 1, nsgfb(jset)
DO iiB = 1, nsgfa(iset)
primitive_counter = primitive_counter + 1
MNRS(llB, kkB, iiB) = primitive_integrals(primitive_counter)
END DO
END DO
END DO
END DO
DO iiB = 1, nsgfa(iset)
BI1(orb_l_start:orb_l_end, orb_k_start:orb_k_end, iiB) = MNRS(:, :, iiB)
BI1(orb_k_start:orb_k_end, orb_l_start:orb_l_end, iiB) = TRANSPOSE(MNRS(:, :, iiB))
END DO
END DO ! i_set_list_kl
END DO ! i_list_kl
DO iiB = 1, nsgfa(iset)
BI1(1:virtual, 1:occupied, iiB) = MATMUL(TRANSPOSE(C(1:dimen, occupied + 1:dimen)), &
MATMUL(BI1(1:dimen, 1:dimen, iiB), C(1:dimen, 1:occupied)))
Lai(L_B_i_start + iiB - 1, 1:virtual, 1:occupied) = BI1(1:virtual, 1:occupied, iiB)
END DO
DEALLOCATE (BI1)
END DO
END DO
CALL para_env%sum(Lai)
DO iiB = 1, occupied
IF (MOD(iiB, para_env%num_pe) == para_env%mepos) THEN
Lai(1:RI_dimen, 1:virtual, iiB) = MATMUL(TRANSPOSE(L_full_matrix), Lai(1:RI_dimen, 1:virtual, iiB))
ELSE
Lai(:, :, iiB) = 0.0_dp
END IF
END DO
CALL para_env%sum(Lai)
DEALLOCATE (set_list_kl)
DO i = 1, max_pgf**2
DEALLOCATE (pgf_list_ij(i)%image_list)
DEALLOCATE (pgf_list_kl(i)%image_list)
END DO
DEALLOCATE (pgf_list_ij)
DEALLOCATE (pgf_list_kl)
DEALLOCATE (pgf_product_list)
DEALLOCATE (max_contraction, kind_of)
DEALLOCATE (ee_work, ee_work2, ee_buffer1, ee_buffer2, ee_primitives_tmp)
DEALLOCATE (nimages)
IF (mp2_env%potential_parameter%potential_type == do_potential_TShPSC) THEN
init_TShPSC_lmax = -1
CALL free_C0()
END IF
CALL timestop(handle)
END SUBROUTINE calc_lai_libint
! **************************************************************************************************
!> \brief ...
!> \param cell ...
!> \param qs_env ...
!> \param mp2_env ...
!> \param para_env ...
!> \param mp2_potential_parameter ...
!> \param actual_x_data ...
!> \param do_periodic ...
!> \param basis_parameter ...
!> \param max_set ...
!> \param particle_set ...
!> \param natom ...
!> \param kind_of ...
!> \param nsgf_max ...
!> \param primitive_integrals ...
!> \param ee_work ...
!> \param ee_work2 ...
!> \param ee_buffer1 ...
!> \param ee_buffer2 ...
!> \param ee_primitives_tmp ...
!> \param nspins ...
!> \param max_contraction ...
!> \param max_pgf ...
!> \param pgf_list_ij ...
!> \param pgf_list_kl ...
!> \param pgf_product_list ...
!> \param nimages ...
!> \param eps_schwarz ...
!> \param log10_eps_schwarz ...
!> \param private_lib ...
!> \param p_work ...
!> \param screen_coeffs_set ...
!> \param screen_coeffs_kind ...
!> \param screen_coeffs_pgf ...
!> \param radii_pgf ...
!> \param RI_basis_parameter ...
!> \param RI_basis_info ...
! **************************************************************************************************
SUBROUTINE prepare_integral_calc(cell, qs_env, mp2_env, para_env, mp2_potential_parameter, actual_x_data, &
do_periodic, basis_parameter, max_set, particle_set, natom, kind_of, &
nsgf_max, primitive_integrals, ee_work, ee_work2, ee_buffer1, ee_buffer2, &
ee_primitives_tmp, nspins, max_contraction, max_pgf, pgf_list_ij, &
pgf_list_kl, pgf_product_list, nimages, eps_schwarz, log10_eps_schwarz, &
private_lib, p_work, screen_coeffs_set, screen_coeffs_kind, screen_coeffs_pgf, &
radii_pgf, RI_basis_parameter, RI_basis_info)
TYPE(cell_type), POINTER :: cell
TYPE(qs_environment_type), INTENT(IN), POINTER :: qs_env
TYPE(mp2_type), INTENT(INOUT) :: mp2_env
TYPE(mp_para_env_type), INTENT(IN) :: para_env
TYPE(hfx_potential_type), INTENT(OUT) :: mp2_potential_parameter