forked from alexei-matveev/paragauss-gpl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ss_calculate.f90
1484 lines (1265 loc) · 55.1 KB
/
ss_calculate.f90
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
!
! ParaGauss, a program package for high-performance computations of
! molecular systems
!
! Copyright (C) 2014 T. Belling, T. Grauschopf, S. Krüger,
! F. Nörtemann, M. Staufer, M. Mayer, V. A. Nasluzov, U. Birkenheuer,
! A. Hu, A. V. Matveev, A. V. Shor, M. S. K. Fuchs-Rohr, K. M. Neyman,
! D. I. Ganyushin, T. Kerdcharoen, A. Woiterski, A. B. Gordienko,
! S. Majumder, M. H. i Rotllant, R. Ramakrishnan, G. Dixit,
! A. Nikodem, T. Soini, M. Roderus, N. Rösch
!
! This program is free software; you can redistribute it and/or modify
! it under the terms of the GNU General Public License version 2 as
! published by the Free Software Foundation [1].
!
! This program is distributed in the hope that it will be useful, but
! WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
! General Public License for more details.
!
! [1] http://www.gnu.org/licenses/gpl-2.0.html
!
! Please see the accompanying LICENSE file for further information.
!
!=====================================================================
! Public interface of module
!=====================================================================
subroutine ss_calculate(na,nb,imode,many_3c)
!
! Purpose: calculation of all primitive 2 center orbital
! and 3 center integrals for a given set of indizes
! (unique_atom1,unique_atom2,l1,l2,equal_atom1,equal_atom2).
! For three center integrals, contraction and symmetry-
! adaption concerning fitfunctions is also performed.
!
!
! Author: FN
! Date: 7/96
!
!===================================================================
! End of public interface of module
!===================================================================
!-------------------------------------------------------------------
! Modifications
!-------------------------------------------------------------------
! letzter debug check am 17.7.96, nur stichprobenartig
! kontrolliert: co,h2,cuh
! FN
!
! Modification (Please copy before editing)
! Author: TB
! Date: 30.7.96
! Description: Restructuring of subroutine.
! Lots of missing deallocations added
! Steering variables from integralpar_module added
!
! Modification (Please copy before editing)
! Author: MM
! Date: 27.12.96
! Description: Relativistic pv scalar p matrix elements added
!
!
! Modification (Please copy before editing)
! Author: AH
! Date: 22.09.98
! Description: pseudopotential
!
!
! Modification (Please copy before editing)
! Author: AS
! Date: 11-12/99
! Description: integrals of electrostatic potential are added
!
! Modification (Please copy before editing)
! Author: AS
! Date: 03/00
! Description: integrals of electrostatic field are added
!
! Modification (Please copy before editing)
! Author: ...
! Date: ...
! Description: ...
!
!-------------------------------------------------------------------
! define FPP_TIMERS 2
# include "def.h"
use unique_atom_module, noname=>pseudopot_present
use gamma_module
use type_module
use datatype
use solid_harmonics_module, only : solid_harmonics_calc,&
solid_harmonics_scalar
use solhrules_module
use fitcontract_module, only: fitcontract
!!SB: should be only for resp, but...
use fitcontract_module, only: fitcontract_v2
use integralpar_module
use iounitadmin_module
use int_data_2cob3c_module, only : &
prim_int_2cob_ol, &
prim_int_2cob_kin, &
prim_int_2cob_poten, &
prim_int_2cob_nuc, &
prim_int_2cob_pvsp, &
prim_int_3c_co, &
prim_int_3c_xc, &
prim_int_2cob_nuc_pseudo, &
prim_int_2cob_field,&
center1, &
center2, &
n_m1, &
n_m2, &
ua1_basis, &
ua2_basis, &
OFF_STRIDE, OFF_V, OFF_PVSP, OFF_VFIN
use pointcharge_module
use options_module, only: options_integral_expmax
use potential_module
use elec_static_field_module
use operations_module, only: operations_core_density
use symmetry_data_module, only: symmetry_data_n_irreps, &
symmetry_data_n_partners, &
get_totalsymmetric_irrep
use calc3c_switches,only: old_potential,old_3c_co,old_elfield
use shgi_cntrl, only: IPSEU
implicit none
integer(kind=i4_kind), intent(in) :: na,nb
integer(kind=i8_kind), intent(in) :: imode ! control bitmask
real(r8_kind),optional,intent(out) :: many_3c(:,:,:,:,:)
! many_3c(nbexp,naexp,N_INTS*index3c,nlmb,nlma)
! Stored as illustrated by
! do ua=1,N_UA
! Int1[ua] stored at [3*(ua-1) + OFF_PVSP ] ! PVSP(ua)
! Int2[ua] stored at [3*(ua-1) + OFF_V ] ! V(ua)
! Int3[ua] stored at [3*(ua-1) + OFF_VFIN ] ! V_{fin}(ua)
! ...
! enddo
! offsets OFF_* defined in int_data_2cob3c_module
! *** end of interface ***
integer(kind=i4_kind) :: m1,m2
! real(kind=r8_kind),dimension(3,3),parameter :: unity_matrix=reshape&
real(kind=r8_kind),dimension(3,3) :: unity_matrix=reshape&
((/1.0_r8_kind,0.0_r8_kind,0.0_r8_kind,0.0_r8_kind,1.0_r8_kind,&
0.0_r8_kind,0.0_r8_kind,0.0_r8_kind,1.0_r8_kind/),(/3,3/))
integer(kind=i4_kind) :: naexps,nbexps,ncexps
real(kind=r8_kind),pointer :: aexps(:),bexps(:)
real(kind=r8_kind),pointer :: cexps(:)
real(kind=r8_kind),pointer :: rotmat(:,:) !!!!!!!!!!!!!!!!
real(kind=r8_kind) :: z ! charge
real(kind=r8_kind) :: zc ! core charge
! constants
real(kind=r8_kind),parameter :: pi=3.14159265358979324_r8_kind
real(kind=r8_kind),parameter :: two=2.0_r8_kind,three=3.0_r8_kind
real(kind=r8_kind),parameter :: four=4.0_r8_kind,six=6.0_r8_kind
real(kind=r8_kind),parameter :: very_small=1.0e-100_r8_kind
real(kind=r8_kind),parameter :: very_big=1.0e100_r8_kind
real(kind=r8_kind),parameter :: zero=0.0_r8_kind
!!! parameter-bug on sgi
! real(kind=r8_kind),parameter,dimension(0:8) :: dfac= &
real(kind=r8_kind), dimension(0:8) :: dfac= &
(/ 1.0_r8_kind, 1.0_r8_kind, 3.0_r8_kind, 15.0_r8_kind, 105.0_r8_kind, &
945.0_r8_kind, 10395.0_r8_kind, 135135.0_r8_kind, 2027025.0_r8_kind /)
! mapping of exponents to one dimension and cutoff of small integrals
logical,allocatable :: cutoff(:,:) ! (naexps,nbexps)
logical :: do_rotation !!!!!!!!!!!!!!!!!!!
integer(kind=i4_kind) :: num ! metaindex for (naexps,nbexps) > cutoff
! help factors
real(kind=r8_kind),allocatable,dimension(:,:):: fact0_arr, &
fact1_arr,fact2_arr ! (naexps,nbexps)
real(kind=r8_kind),allocatable,dimension(:) :: fact0,fact1, &
fact2,fact3 ! (num) metaindex for (naexps,nbexps) > cutoff
! help arrays for gamma-function
real(kind=r8_kind),allocatable,dimension(:,:) :: gamma_arg ! (num,3)
real(kind=r8_kind),allocatable,dimension(:) :: gamma_arg2 ! (num)
real(kind=r8_kind),allocatable,dimension(:,:) :: gamma_help ! (num,max_order(l)/1)
integer(kind=i4_kind) :: max_order,max_gamma
! help arrays for solid harmincs
real(kind=r8_kind),allocatable :: yl_arr(:,:,:) ! (num,(lmax_abs+1)**2,n_equals)
real(kind=r8_kind),allocatable :: yl_arg(:,:) ! (num,3)
! help variables
real(kind=r8_kind) :: arg,charge_c
real(kind=r8_kind),dimension(3) :: xa,xb,xc
integer(kind=i4_kind) :: i_l,k,i_ind,i_cont,i_exp,i_ua,i_ea,i,f_dim,j
integer(kind=i4_kind) :: lmax_ch,lmax_xc,lmax_abs,alloc_stat
integer(kind=i4_kind) :: memstat
integer(kind=i4_kind) :: n_equals,n_independent_fcts, &
n_contributing_fcts,independent_max
! pointing to arrays in unique_atom_symadapt_type
integer(kind=i4_kind),pointer :: eq_atom(:),magn(:)
real(kind=r8_kind),pointer :: coeff(:)
real(kind=r8_kind),allocatable :: sym_coeff(:,:,:,:)
! (num,n_equals,independent_max,lmax_abs)
! integrals
real(kind=r8_kind),allocatable,dimension(:) :: overlap,kinetic,nuclear ! (num)
real(kind=r8_kind),allocatable,dimension(:,:) :: potential !!!!!!!!!!!!!!!!!!
real(kind=r8_kind),allocatable,dimension(:,:) :: poten_grad !!!!!!!!!!!!!!!!!!
real(kind=r8_kind),allocatable,dimension(:,:) :: grad_poten !!!!!!!!!!!!!!!!!!
#if 0
real(kind=r8_kind),allocatable,dimension(:,:) :: field !!!!!!!!!!!!!!!!!!
#endif
real(kind=r8_kind),allocatable,dimension(:) :: intermed_3c !!!!!!!!!!!!!!!!!!
real(kind=r8_kind),allocatable,dimension(:) ::nuclear_pc_timps
real(kind=r8_kind),allocatable,dimension(:) :: nuc_pseudo
type(three_center_l) :: xc_int
! xx_int%l(-1:lmax_xx)%m(num,ncexps,n_independent_fcts,n_m1,n_m2)
real(kind=r8_kind) :: expmax
logical :: pseudopot_present ! same name as in UA module
! end of the variables for pseudopotentials
integer(kind=i4_kind) :: i4_zero = 0_i4_kind
logical :: split3c
real(r8_kind),allocatable :: this(:) ! (num)
!!$ real(r8_kind),allocatable :: this5d(:,:,:,:,:) ! (num,1,1,nlmB,nlmA)
real(r8_kind),allocatable :: this6d(:,:,:,:,:,:) ! (num,1,1,nlmB,nlmA,1)
real(r8_kind) :: zexps(1) ! for finite nuc only
logical :: with_timps
type(three_center_l_v2), allocatable :: coul_int(:)
integer(i4_kind) :: i_ir, i_pa, n_pa, n_ir
FPP_TIMER_DECL(pss)
intrinsic max,maxval
external error_handler
pseudopot_present = IAND(imode,IPSEU) .ne. 0
DPRINT 'ss_calculate: PP=',pseudopot_present,' imode=',imode
split3c = present(many_3c)
naexps = ua1_basis%n_exponents
nbexps = ua2_basis%n_exponents
allocate(fact0_arr(nbexps,naexps),STAT=alloc_stat)
if( alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation (1) failed")
allocate(fact1_arr(nbexps,naexps),STAT=alloc_stat)
if( alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation (2) failed")
allocate(fact2_arr(nbexps,naexps),STAT=alloc_stat)
if( alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation (3) failed")
allocate(cutoff(nbexps,naexps),STAT=alloc_stat)
if( alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation (4) failed")
xa = center1
xb = center2
m1=n_m1
m2=n_m2
ASSERT(m1==1)
ASSERT(m2==1)
aexps => ua1_basis%exponents(:)
bexps => ua2_basis%exponents(:)
arg=sum((xa-xb)**2)
fact0_arr=(spread(aexps,1,nbexps)+spread(bexps,2,naexps))
fact1_arr=(spread(aexps,1,nbexps)*spread(bexps,2,naexps))
where(fact0_arr>=very_small) ! prevent division by zero
fact2_arr=fact1_arr/fact0_arr
elsewhere
fact2_arr=very_big
end where
expmax = options_integral_expmax()
where(fact2_arr*arg>expmax) ! cutoff: where almost no overlap
cutoff=.false. ! is present calculation is not necessary
elsewhere
cutoff=.true.
end where
num=count(cutoff)
if(num==0) then ! all integrals are equal zero
if (integralpar_2cob_ol) then
prim_int_2cob_ol = 0.0_r8_kind
end if
if (integralpar_2cob_potential) then !!!!!!!!!!!!
prim_int_2cob_poten(:,:,:,:,:) = 0.0_r8_kind !!!!!!!!!!!!
end if
if (integralpar_2cob_field) then !!!!!!!!!!
prim_int_2cob_field(:,:,:,:,:) = 0.0_r8_kind !!!!!!!!!
end if
if (integralpar_2cob_kin) then
prim_int_2cob_kin= 0.0_r8_kind
end if
if (integralpar_2cob_nuc) then
prim_int_2cob_nuc(:,:,:,:)=0.0_r8_kind
end if
if (integralpar_relativistic) then
prim_int_2cob_pvsp(:,:,:,:)=0.0_r8_kind
end if
if(integralpar_3c_co) then
prim_int_3c_co=0.0_r8_kind
end if
if(integralpar_3c_xc) then
prim_int_3c_xc=0.0_r8_kind
end if
if( split3c )then
ASSERT(integralpar_relativistic)
many_3c = zero
endif
deallocate(fact0_arr,fact1_arr,&
fact2_arr,cutoff,stat=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE: deallocation fact0_arr ... failed")
return
end if
allocate (fact0(num),fact1(num),fact2(num),STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE: allocation of fact(i) failed")
! List of *facts* at the beginning
! fact0 = a + b
! fact1 = a * b
! fact2 = a*b/(a+b)
fact0=pack(fact0_arr,cutoff)
fact1=pack(fact1_arr,cutoff)
fact2=pack(fact2_arr,cutoff)
deallocate(fact0_arr,fact1_arr,fact2_arr,STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE: deallocation (1) failed")
if ( integralpar_2cob_nuc .or. &
integralpar_3c_xc .or. &
integralpar_3c_co .or. &
integralpar_2cob_potential .or. &
integralpar_2cob_field ) then
allocate(gamma_arg(num,3),STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE: allocation of gamma_arg failed")
allocate(gamma_arg2(num),STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE: allocation of gamma_arg2 failed")
! gamma_arg = (a*vec_a + b*vec_b)/(a + b)
gamma_arg(:,1)=(pack(spread(aexps*xa(1),1,nbexps) + &
spread(bexps*xb(1),2,naexps),cutoff))/fact0
gamma_arg(:,2)=(pack(spread(aexps*xa(2),1,nbexps) + &
spread(bexps*xb(2),2,naexps),cutoff))/fact0
gamma_arg(:,3)=(pack(spread(aexps*xa(3),1,nbexps) + &
spread(bexps*xb(3),2,naexps),cutoff))/fact0
endif
! first calculating 2-center integrals----------------
allocate(this(num),stat=memstat)
ASSERT(memstat==0)
if( split3c )then
allocate(this6d(num,1,1,1,1,1),stat=memstat)
ASSERT(memstat==0)
endif
! overlap ----------------------
allocate(overlap(num),STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE: allocation overlap failed")
overlap = (two*sqrt(fact1)/fact0)* &
sqrt((two*sqrt(fact1)/fact0))*exp(-fact2*arg)
! -----------------------------
! kinetic energy --------------
if (integralpar_2cob_kin) then
allocate(kinetic(num),STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE: allocation of kinetic failed")
kinetic=(three*fact2-two*fact2**two*arg)*overlap
endif
! ----------------------------
! nuclear attraction ---------
if (integralpar_2cob_nuc) then
allocate(nuclear(num),STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE: allocation of nuclear failed")
allocate(gamma_help(num,1),STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CACLULATE : allocation gamma_help (1) failed")
if (pseudopot_present)then
allocate(nuc_pseudo(num),STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE: allocation of nuc_pseudo failed")
nuc_pseudo=0.0_r8_kind
end if
with_timps = n_timps+pointcharge_N .gt. 0
if(with_timps .and. pseudopot_present &
.and.integralpar_relativistic) then
allocate(nuclear_pc_timps(num),STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE: allocation of nuclear_pc_timps failed")
nuclear_pc_timps=0.0_r8_kind
endif ! pointcharge_N+n_timps.ne.0
nuclear=0.0_r8_kind
unique_at: do i_ua=1,n_unique_atoms
charge_c=unique_atoms(i_ua)%Z
zc =unique_atoms(i_ua)%zc
! NUC and PP is handled by SHGI, skip the NUC:
DPRINT 'ss_calc: ua=',i_ua,', zero its charge!'
zc = zero
charge_c = zero
this = zero
do i_ea=1,unique_atoms(i_ua)%n_equal_atoms
xc=unique_atoms(i_ua)%position(:,i_ea) ! coordinates
gamma_arg2=((gamma_arg(:,1)-xc(1))**2+(gamma_arg(:,2)-xc(2))**2+&
(gamma_arg(:,3)-xc(3))**2)
gamma_help(:,1:1)=gamma(1,fact0*gamma_arg2)
this = this + (charge_c-zc) * gamma_help(:,1)
enddo
this = this * two*sqrt(fact0/pi)*overlap
if(zc.ne.zero.and.integralpar_relativistic) then
nuc_pseudo = nuc_pseudo + this
else
nuclear = nuclear + this ! this is contrib from atoms
endif
if( split3c )then
call unpack_many_3c(this,i_ua,OFF_V)
endif
enddo unique_at
! pseudopotential calculation
if(pseudopot_present.and. &
(.not.operations_core_density)) then
ABORT('not supported')
end if ! endif for pseudopot_present
! now add contributions from point charges and timps
do i_ua=1,pointcharge_N+n_timps
if(i_ua<=n_timps) then
charge_c=unique_timps(i_ua)%Z - unique_timps(i_ua)%ZC
n_equals=unique_timps(i_ua)%n_equal_atoms
else
cycle ! pointcharges go to SHGI !!!!!!!!!!!!!!AS
charge_c=pointcharge_array(i_ua-n_timps)%Z
n_equals=pointcharge_array(i_ua-n_timps)%n_equal_charges
end if
this = zero
do i_ea=1,n_equals
if(i_ua<=n_timps) then
xc=unique_timps(i_ua)%position(:,i_ea)
else
xc=pointcharge_array(i_ua-n_timps)%position(:,i_ea) ! coordinates
end if
gamma_arg2=((gamma_arg(:,1)-xc(1))**2+(gamma_arg(:,2)-xc(2))**2+&
(gamma_arg(:,3)-xc(3))**2)
gamma_help(:,1:1)=gamma(1,fact0*gamma_arg2)
this = this + charge_c * gamma_help(:,1)
enddo
this = this * two*sqrt(fact0/pi)*overlap
if(integralpar_relativistic &
.and.pseudopot_present) then
nuclear_pc_timps=nuclear_pc_timps+ this
else
nuclear = nuclear + this ! this is PC contrib
endif ! integralpar_relativistic
enddo
deallocate(gamma_help,STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CACLULATE : deallocation gamma_help (1) failed")
if (pseudopot_present.and.(.not.integralpar_relativistic)) then
nuclear = nuclear + nuc_pseudo
end if
endif
!calculate integrals of electrostatic potential
if (integralpar_2cob_potential.and.old_potential) then
allocate(potential(N_points,num),STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE: allocation of potential failed")
potential = 0.0_r8_kind
allocate(intermed_3c(num),STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE: allocation of intermed_3c failed")
allocate(gamma_help(num,1),STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation gamma_help (1) failed")
do i=1,N_points
n_equals=point_in_space(i)%N_equal_points
do i_ea=1,n_equals
xc=point_in_space(i)%position(:,i_ea) ! coordinates
gamma_arg2=((gamma_arg(:,1)-xc(1))**2+(gamma_arg(:,2)-xc(2))**2+&
(gamma_arg(:,3)-xc(3))**2)
gamma_help(:,1:1)=gamma(1,fact0*gamma_arg2)
potential(i,:) = potential(i,:) + gamma_help(:,1)
enddo
enddo
deallocate(gamma_help,STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CACLULATE : deallocation gamma_help (1) failed")
do i=1,N_points
potential(i,:) = potential(i,:)*two*sqrt(fact0/pi)*overlap
enddo
!!$print*,'pot',na,nb,sum(potential(:,1))
endif
#if 0
!calculate integrals of electrostatic field (projection)
if (integralpar_2cob_field .and. old_elfield) then
if(calc_normal) then
allocate(field(N_surface_points,num),stat=alloc_stat)
else
allocate(field(totsym_field_length,num),stat=alloc_stat)
end if
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE: allocation of field is failed")
field = 0.0_r8_kind
allocate(intermed_3c(num),stat=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE: allocation of indermed_3c for field is failed")
lmax_ch = maxval(unique_atoms(:)%lmax_ch)
max_order = max(lmax_ch+2,3)
max_gamma=2
!!$ if(integralpar_relativistic) then
!!$ max_gamma=4
!!$ max_order=max(max_order,4)
!!$ end if
allocate( grad_poten(num,3),STAT=alloc_stat )
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE: allocation grad_poten failed")
grad_poten = zero
allocate (gamma_help(num,max_order),STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation gamma_help(2) failed ")
i_nsp: do i=1,N_surface_points
n_equals=surface_points(i)%N_equal_points
f_dim=surf_points_grad_index(i+1)-surf_points_grad_index(i)
allocate(poten_grad(num,f_dim),stat=alloc_stat)
if (alloc_stat/=0) call error_handler &
("SS_CACLULATE : allocation failed poten_grad")
poten_grad=0.0_r8_kind
n_equals_i: do i_ea=1,n_equals
if(f_dim == 3) then
if(sum((surf_points_grad_info(i)%m(:,:,i_ea)-unity_matrix)**2)<&
1.0e-7_r8_kind) then
do_rotation=.false.
else
do_rotation=.true.
rotmat=>surf_points_grad_info(i)%m(:,:,i_ea)
endif
else
do_rotation=.true.
rotmat=>surf_points_grad_info(i)%m(:,:,i_ea)
endif
xc=surface_points(i)%position(:,i_ea)
gamma_arg2 = ((gamma_arg(:,1)-xc(1))**2 + &
(gamma_arg(:,2)-xc(2))**2 + &
(gamma_arg(:,3)-xc(3))**2)
gamma_help(:,1:max_gamma) = gamma(max_gamma,fact0*gamma_arg2)
do j=1,3
grad_poten(:,j) = four*sqrt(fact0/pi)*overlap*&
fact0*gamma_help(:,2)* &
(gamma_arg(:,j)-xc(j))
enddo
if(do_rotation) then
do j=1,f_dim
poten_grad(:,j)=poten_grad(:,j)+&
rotmat(j,1)*grad_poten(:,1)+&
rotmat(j,2)*grad_poten(:,2)+&
rotmat(j,3)*grad_poten(:,3)
enddo
else
do j=1,3
poten_grad(:,j)=poten_grad(:,j)+grad_poten(:,j)
enddo
end if
enddo n_equals_i
if(calc_normal) then
grad_poten=0.0_r8_kind
rotmat=>surf_points_grad_info(i)%m(:,:,1)
do j=1,f_dim
do k=1,3
grad_poten(:,k)= grad_poten(:,k)+rotmat(j,k)*poten_grad(:,j)
enddo
enddo
do k=1,3
field(i,:)=field(i,:)+grad_poten(:,k)*surface_points(i)%out_normal(k)
enddo
else
k=surf_points_grad_index(i)
do j=1,f_dim
field(k,:)=poten_grad(:,j)
k=k+1
end do
end if
deallocate(poten_grad,stat=alloc_stat)
if (alloc_stat/=0) call error_handler &
("SS_CACLULATE : deallocation failed poten_grad")
enddo i_nsp
deallocate( grad_poten,STAT=alloc_stat )
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE: deallocation grad_poten failed")
deallocate (gamma_help,STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : deallocation gamma_help(2) failed ")
endif
#endif
! re-map them to the int_data_2cob3c_stuff
if (integralpar_2cob_ol) then
prim_int_2cob_ol(:,:,m1,m2) = unpack(overlap,cutoff,zero)
endif
if (integralpar_2cob_kin) then
prim_int_2cob_kin(:,:,m1,m2)= unpack(kinetic,cutoff,zero)
deallocate(kinetic,STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CACLULATE : deallocation kinetic failed")
endif
if (integralpar_2cob_nuc) then
prim_int_2cob_nuc(:,:,m1,m2)= unpack(nuclear,cutoff,zero)
! 1-true nuclear, 2-pseudo,3-PC,4-EWPC
deallocate(nuclear,STAT=alloc_stat)
ASSERT(alloc_stat.eq.0)
if (pseudopot_present) then
if(integralpar_relativistic) then
with_timps = n_timps+pointcharge_N .gt. 0
if( with_timps ) then
prim_int_2cob_nuc_pseudo(:,:,m1,m2)= & !!! prim_int_2cob_nuc_pseudo(:,:,m1,m2)+ &
unpack(nuc_pseudo,cutoff,zero)+ &
unpack(nuclear_pc_timps,cutoff,zero)
else
prim_int_2cob_nuc_pseudo(:,:,m1,m2)= &
unpack(nuc_pseudo,cutoff,zero)
endif ! pointcharge_N+n_timps.ne.0
endif ! integralpar_relativistic
deallocate(nuc_pseudo,STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CACLULATE : deallocation nuc_pseudo failed")
end if
!!! call print_nuclear()
endif
if (integralpar_2cob_potential.and.old_potential) then
do i=1,N_points
intermed_3c(:)=potential(i,:)
prim_int_2cob_poten(:,:,i,m1,m2)= unpack(intermed_3c(:),cutoff,zero)
enddo
!!$print*,na,nb,sum(prim_int_2cob_poten(1,1,:,1,1)),m1,m2
deallocate(potential,STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CACLULATE : deallocation potential failed")
deallocate(intermed_3c,STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CACLULATE : deallocation intermed_3c failed")
endif
#if 0
if (integralpar_2cob_field .and. old_elfield) then !!!!!!!!!!!!!!!!1
if(calc_normal) then
do i=1,N_surface_points
intermed_3c(:)=field(i,:)
prim_int_2cob_field(:,:,i,m1,m2)= unpack(intermed_3c(:),cutoff,zero)
enddo
else
do i=1,totsym_field_length
intermed_3c(:)=field(i,:)
prim_int_2cob_field(:,:,i,m1,m2)= unpack(intermed_3c(:),cutoff,zero)
enddo
end if
deallocate(field,STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CACLULATE : deallocation field failed")
deallocate(intermed_3c,STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CACLULATE : deallocation intermed_3c for field failed")
endif
#endif
if (integralpar_relativistic) then
with_timps = n_timps+pointcharge_N .gt. 0
if( with_timps .and.pseudopot_present) then
deallocate(nuclear_pc_timps,STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CACLULATE : deallocation nuclear_pc_timps failed")
endif
endif
! ----------------------------------------------------
call integral_interrupt_2cob3c()
! now calculation of the 3-center integrals-----------
three_center_integrals: if (integralpar_3c_xc .or. integralpar_3c_co) then
allocate (fact3(num),STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE: allocation of fact3 failed")
unique_atom_loop: do i_ua = 1,n_unique_atoms ! loop over third center
lmax_ch= unique_atoms(i_ua)%lmax_ch ! maximum l for chargefit
lmax_xc= unique_atoms(i_ua)%lmax_xc ! maximum l for xcfit
! determine the maximal angular momentum
if (integralpar_3c_co .and. .not. integralpar_3c_xc) then
lmax_abs=lmax_ch
elseif (.not. integralpar_3c_co .and. integralpar_3c_xc) then
lmax_abs=lmax_xc
else
lmax_abs=max(lmax_ch,lmax_xc)
endif
z= unique_atoms(i_ua)%z ! charge
! --- further allocation ----------------------------------
! num : number of pairs(a,b) which are inside the cutoff
! for s-and r2-type there is only 1 indep. fct
max_order=max((lmax_abs+1),2)
allocate(gamma_help(num,max_order),STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation gamma_help (2) ")
if (integralpar_3c_co_resp) then
#ifdef WITH_RESPONSE
n_ir = symmetry_data_n_irreps()
allocate (coul_int(n_ir),STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation coul_int (2) failed")
i_ir_alloc_: DO i_ir=1,n_ir
n_pa = symmetry_data_n_partners(i_ir)
ncexps = unique_atoms(i_ua)%r2_ch%n_exponents
n_independent_fcts = &
unique_atoms(i_ua)%symadapt_partner(i_ir,0)%n_independent_fcts
allocate(coul_int(i_ir)%l(-1:lmax_ch),STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation coul_int (3) failed")
allocate(coul_int(i_ir)%l(-1)%m(num,ncexps,n_independent_fcts,&
n_m1,n_m2,n_pa),STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation coul_int (3) failed")
ncexps = unique_atoms(i_ua)%l_ch(0)%n_exponents
allocate(coul_int(i_ir)%l(0)%m(num,ncexps,n_independent_fcts,&
n_m1,n_m2,n_pa),STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation coul_int (4) failed")
do i_l=1,lmax_ch
ncexps = unique_atoms(i_ua)%l_ch(i_l)%n_exponents
n_independent_fcts = &
unique_atoms(i_ua)%symadapt_partner(i_ir,i_l)%n_independent_fcts
allocate(coul_int(i_ir)%l(i_l)%m(num,ncexps,n_independent_fcts,&
n_m1,n_m2,n_pa),STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation coul_int (4) failed")
end do
do i_l=-1,lmax_ch
coul_int(i_ir)%l(i_l)%m=zero
enddo
end do i_ir_alloc_
#else
ABORT('recompile w/ -DWITH_RESPONSE')
#endif
elseif(integralpar_3c_co) then
i_ir = get_totalsymmetric_irrep()
n_pa = 1
allocate (coul_int(i_ir),STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation coul_int (2) failed")
allocate(coul_int(i_ir)%l(-1:lmax_ch),STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation coul_int (3) failed")
ncexps = unique_atoms(i_ua)%r2_ch%n_exponents
allocate(coul_int(i_ir)%l(-1)%m(num,ncexps,1,n_m1,n_m2,n_pa),STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation coul_int (3) failed")
ncexps = unique_atoms(i_ua)%l_ch(0)%n_exponents
allocate(coul_int(i_ir)%l(0)%m(num,ncexps,1,n_m1,n_m2,n_pa),STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation coul_int (4) failed")
do i_l=-1,0
coul_int(i_ir)%l(i_l)%m=zero
enddo
do i_l=1,lmax_ch
ncexps = unique_atoms(i_ua)%l_ch(i_l)%n_exponents
n_independent_fcts = &
unique_atoms(i_ua)%symadapt_partner(i_ir,i_l)%n_independent_fcts
allocate(coul_int(i_ir)%l(i_l)%m(num,ncexps,n_independent_fcts,&
n_m1,n_m2,n_pa),STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation coul_int (4) failed")
coul_int(i_ir)%l(i_l)%m = zero
end do
endif
if(integralpar_3c_xc) then
allocate (xc_int%l(-1:lmax_xc),STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation xc_int (2) failed")
ncexps = unique_atoms(i_ua)%r2_xc%n_exponents
allocate(xc_int%l(-1)%m(num,ncexps,1,n_m1,n_m2),STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation xc_int (3) failed")
ncexps = unique_atoms(i_ua)%l_xc(0)%n_exponents
allocate(xc_int%l(0)%m(num,ncexps,1,n_m1,n_m2),STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation xc_int (4) failed")
do i_l=-1,0
xc_int%l(i_l)%m=zero
enddo
endif
n_equals=unique_atoms(i_ua)%n_equal_atoms
allocate(yl_arr(num,(lmax_abs+1)**2,n_equals),STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation yl_arr failed")
if( split3c )then
zexps(1) = (3.0_r8_kind/2.0_r8_kind) / unique_atoms(i_ua)%nuclear_radius**2
this6d = zero
endif
equal_atoms: do i_ea=1,n_equals
xc=unique_atoms(i_ua)%position(:,i_ea) ! coordinates
! gamma_arg2 = (gamma_arg**2 - vec_c**2)*(a+b)
gamma_arg2=((gamma_arg(:,1)-xc(1))**2+(gamma_arg(:,2)-xc(2))**2+&
(gamma_arg(:,3)-xc(3))**2)
! s-type and r2-type exchange fit integrals
if(integralpar_3c_xc) call s_r2_xc()
! do a pre-calculation of the solid harmonics --------
! calculate them for ALL equal_atoms and for l_max_abs
! it will cost more storage but will be faster
if (lmax_abs.gt.0) then
allocate(yl_arg(num,3),STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation yl_arg failed")
xc=unique_atoms(i_ua)%position(:,i_ea)
yl_arg(:,1) = gamma_arg(:,1) - xc(1)
yl_arg(:,2) = gamma_arg(:,2) - xc(2)
yl_arg(:,3) = gamma_arg(:,3) - xc(3)
yl_arr(:,:,i_ea) = solid_harmonics_calc(lmax_abs,yl_arg)
deallocate(yl_arg,STAT=alloc_stat) ! this is not needed anymore
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : deallocation yl_arg failed")
endif
enddo equal_atoms
independent_max = maxval(unique_atoms(i_ua)%symadapt_partner(1,:)%n_independent_fcts)
lmax_gt_zero: if (lmax_abs.gt.0) then
allocate(sym_coeff(num,n_equals,independent_max,lmax_abs),STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation sym_coeff failed")
! precalculate symmetry adaption coefficient sym_coeff
call l_fit_symmetry_adapt()
! l-type exchange fit integrals
if(integralpar_3c_xc) call l_xc()
deallocate(sym_coeff,STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE: deallocation sym_coeff failed ")
endif lmax_gt_zero
!
! - CO calculation
!
if (integralpar_3c_co_resp) then
#ifdef WITH_RESPONSE
i_ir_: DO i_ir=1,symmetry_data_n_irreps()
i_pa_: DO i_pa=1,symmetry_data_n_partners(i_ir)
ea_: do i_ea=1,n_equals
xc=unique_atoms(i_ua)%position(:,i_ea) ! coordinates
! gamma_arg2 = (gamma_arg**2 - vec_c**2)*(a+b)
gamma_arg2=((gamma_arg(:,1)-xc(1))**2+(gamma_arg(:,2)-xc(2))**2+&
(gamma_arg(:,3)-xc(3))**2)
i_l=0
n_independent_fcts = &
unique_atoms(i_ua)%symadapt_partner(i_ir,i_l)%n_independent_fcts
if (n_independent_fcts .ne. 0) then
! s-type and r2-type coulomb fit integrals
call s_coulomb( &
unique_atoms(i_ua)%l_ch(0)%exponents(:), &
coul_int(i_ir)%l(0)%m)
call r2_coulomb()
if( split3c )then
! adds this EA only:
call s_coulomb( zexps, this6d )
endif
allocate(yl_arg(num,3),STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation yl_arg failed")
xc=unique_atoms(i_ua)%position(:,i_ea)
yl_arg(:,1) = gamma_arg(:,1) - xc(1)
yl_arg(:,2) = gamma_arg(:,2) - xc(2)
yl_arg(:,3) = gamma_arg(:,3) - xc(3)
yl_arr(:,:,i_ea) = solid_harmonics_calc(lmax_abs,yl_arg)
deallocate(yl_arg,STAT=alloc_stat) ! this is not needed anymore
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : deallocation yl_arg failed")
end if
end do ea_
do i_l=1,lmax_ch
n_independent_fcts = &
unique_atoms(i_ua)%symadapt_partner(i_ir,i_l)%n_independent_fcts
if (n_independent_fcts .ne. 0) then
allocate(sym_coeff(num,n_equals,n_independent_fcts,i_l),&
STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation sym_coeff failed")
! precalculate symmetry adaption coefficient sym_coeff
call l_fit_symmetry_adapt_v2(i_l,i_ir)
! l-type coulomb fit integrals
call l_coulomb()
deallocate(sym_coeff,STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE: deallocation sym_coeff failed ")
end if
end do
end do i_pa_
end do i_ir_
#else
ABORT('recompile w/ -DWITH_RESPONSE')
#endif
elseif (integralpar_3c_co) then
i_ir = get_totalsymmetric_irrep()
i_pa = 1
ea2_: do i_ea=1,n_equals
xc=unique_atoms(i_ua)%position(:,i_ea) ! coordinates
! gamma_arg2 = (gamma_arg**2 - vec_c**2)*(a+b)
gamma_arg2=((gamma_arg(:,1)-xc(1))**2+(gamma_arg(:,2)-xc(2))**2+&
(gamma_arg(:,3)-xc(3))**2)
i_l=0
n_independent_fcts = &
unique_atoms(i_ua)%symadapt_partner(i_ir,i_l)%n_independent_fcts