-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathss_calculate_grads.f90
2200 lines (1973 loc) · 88.2 KB
/
ss_calculate_grads.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.
!
subroutine ss_calculate_grads(i_ea1,i_ea2,imode)
!-------------------------------------------------------------------
!
! Purpose: calculate integrals for gradients for
! orbitals with both angular momenta = 0.
! Symmetry adaption for fitfunctions
! is included.
! This routines calculates gradients for
! a given pair of uniques AND a given
! pair of atomic centers
!
! Subroutine called by: ...
!
! References: ...
!
! Author: FN
! Date: ...
!
!-------------------------------------------------------------------
!== Interrupt of public interface of module ========================
!-------------------------------------------------------------------
! Modifications
!-------------------------------------------------------------------
! Author: AH
! Date: 4/99
! Description: gradients for pseudopotentials has
! been added
!-------------------------------------------------------------------
! Modification (Please copy before editing)
! Author: ...
! Date: ...
! Description: ...
!------------ Modules used -----------------------------------------
#include "def.h"
use type_module ! type specification parameters
use unique_atom_module, noname=>pseudopot_present
use gamma_module
use operations_module, only: operations_core_density
use type_module
use datatype
use solid_harmonics_module, only : solid_harmonics_calc
use solhrules_module, only: solhrules_differential,&
diff_rule
use fitcontract_module, only: fitcontract
use integralpar_module
use iounitadmin_module
use gradient_data_module
use integralpar_module
use options_module, only: options_integral_expmax, options_split_gradients, &
options_xcmode, xcmode_model_density, &
options_spin_restricted
use int_data_2cob3c_module, only: &
ua1,ua2,& ! indices of unique atoms of quadrupel
ua1_basis,ua2_basis, & ! => uai%l_ob(0)
center1,center2,& ! coordinates of centers
quadrupel,&
prim_int_2cob_ol_grad,&
prim_int_3cob_grad,&
prim_int_3cob_nuc_grad,&
prim_int_3cob_epe,&
prim_int_3cob_coul_grad,&
prim_int_2cob_ks_grad,&
prim_int_2cob_kin_grad,&
prim_int_2cob_nuc_grad,&
prim_int_2cob_pvsp_grad, &
prim_int_3cob_solv_grad, &
prim_int_3cob_solv_grad_pc, &
prim_int_2cob_pseudo_grad, &
prim_int_coul_dervs, &
prim_int_2cob_ol_dervs
use pointcharge_module
#ifdef WITH_EPE
use ewaldpc_module
#endif
use solv_cavity_module, only: to_calc_grads, with_pc, fixed_pc
use elec_static_field_module, only: totsym_field_length,surf_points_grad_index
use calc3c_switches, only: old_3c_co,old_3c_fc,old_solv_grad,integralpar_dervs,new_3c_co_grad
use shgi_cntrl, only: IPSEU
implicit none
!== Interrupt end of public interface of module ====================
!------------ Declaration of formal parameters ---------------------
integer(kind=i4_kind),intent(in) :: i_ea1,i_ea2
integer(kind=i8_kind),intent(in) :: imode ! for control
!===================================================================
! End of public interface of module
!===================================================================
!..............................................................................
! << OUTPUT ARRAYS >>
! ===================
! prim_int_2cob_ol_grad ( 1:N) : dsym/dRa < xi_i | 1 | xi_j >
! prim_int_2cob_ol_grad (N+1:M) : dsym/dRb < xi_i | 1 | xi_j >
! << relativistic calculation >>
! prim_int_2cob_kin_grad ( 1:N) : dsym/dRa < xi_i | T | xi_j >
! prim_int_2cob_kin_grad (N+1:M) : dsym/dRb < xi_i | T | xi_j >
! prim_int_2cob_nuc_grad ( ia: ) : dsym/dRa < xi_i | V_nuc | xi_j >
! prim_int_2cob_nuc_grad ( ib: ) : dsym/dRb < xi_i | V_nuc | xi_j >
! prim_int_2cob_nuc_grad ( ic: ) : dsym/dRc < xi_i | V_nuc | xi_j >
! prim_int_2cob_pvsp_grad( ia: ) : dsym/dRa < xi_i | V_pvsp | xi_j >
! prim_int_2cob_pvsp_grad( ib: ) : dsym/dRb < xi_i | V_pvsp | xi_j >
! prim_int_2cob_pvsp_grad( ic: ) : dsym/dRc < xi_i | V_pvsp | xi_j >
! prim_int_3cob_grad ( ia: ) : dsym/dRa < xi_i | V_H | xi_j >
! prim_int_3cob_grad ( ib: ) : dsym/dRb < xi_i | V_H | xi_j >
! prim_int_3cob_grad ( ic: ) : dsym/dRc < xi_i | V_H | xi_j >
! << non-relativistic calculation with total gradients >>
! prim_int_3cob_grad ( ia: ) : dsym/dRa < xi_i | T + V_nuc + V_H | xi_j >
! prim_int_3cob_grad ( ib: ) : dsym/dRb < xi_i | T + V_nuc + V_H | xi_j >
! prim_int_3cob_grad ( ic: ) : dsym/dRc < xi_i | V_nuc + V_H | xi_j >
! << non-relativistic calculation with split gradients >>
! prim_int_2cob_ks_grad ( 1:N) : dsym/dRa < xi_i | T + V_nuc + V_H | xi_j >
! prim_int_2cob_ks_grad (N+1:M) : dsym/dRb < xi_i | T + V_nuc + V_H | xi_j >
! prim_int_3cob_nuc_grad ( ic: ) : dsym/dRc < xi_i | V_nuc | xi_j >
! prim_int_3cob_grad ( ic: ) : dsym/dRc < xi_i | V_H | xi_j >
!
! Model_Density_Approach
! ~~~~~~~~~~~~~~~~~~~~~~
! << relativistic calculation >>
! prim_int_3cob_grad ( toff+ia: ) : dsym/dRa <xi_i| V_H+V_X,t|xi_j>
! prim_int_3cob_grad ( toff+ib: ) : dsym/dRb <xi_i| V_H+V_X,t|xi_j>
! prim_int_3cob_grad ( toff+ic: ) : dsym/dRc <xi_i| V_H+V_X,t|xi_j>
! << non-relativistic calculation with total gradients >>
! prim_int_3cob_grad ( toff+ia: ) : dsym/dRa <xi_i|T+V_nuc+V_H+V_X,t|xi_j>
! prim_int_3cob_grad ( toff+ib: ) : dsym/dRb <xi_i|T+V_nuc+V_H+V_X,t|xi_j>
! prim_int_3cob_grad ( toff+ic: ) : dsym/dRc <xi_i| V_nuc+V_H+V_X,t|xi_j>
! << non-relativistic calculation with split gradients >>
! prim_int_2cob_ks_grad (toff+ 1:N) : dsym/dRa <xi_i|T+V_nuc+V_H+V_X,t|xi_j>
! prim_int_2cob_ks_grad (toff+N+1:M) : dsym/dRb <xi_i|T+V_nuc+V_H+V_X,t|xi_j>
! prim_int_3cob_nuc_grad ( ic: ) : dsym/dRc <xi_i| V_nuc |xi_j>
! prim_int_3cob_coul_grad( ic: ) : dsym/dRc <xi_i| V_H |xi_j>
! prim_int_3cob_grad ( toff+ic: ) : dsym/dRc <xi_i| V_X,t|xi_j>
!
! << WORKING ARRAYS >>
! ====================
! grad_overlap_a(:,1:3 ) : d/dRa < xi_i | 1 | xi_j >
! grad_kinetic (:,1:3 ) : d/dRa < xi_i | T | xi_j >
! grad_nuclear_a(:,1:3 ) : d/dRa < xi_i | V_nuc | xi_j >
! grad_nuclear_b(:,1:3 ) : d/dRb < xi_i | V_nuc | xi_j >
! grad_nuclear_c(:,1:3 ) : d/dRc < xi_i | V_nuc | xi_j >
! nuc_grad (:,1:grad_dim) : dsym/dRc < xi_i | V_nuc | xi_j >
! grad_pvsp_a (:,1:3 ) : d/dRa < xi_i | V_pvsp | xi_j >
! grad_pvsp_b (:,1:3 ) : d/dRb < xi_i | V_pvsp | xi_j >
! help_arr_c (:,1:3 ) : d/dRc < xi_i | V_pvsp | xi_j >
! pvsp_grad (:,1:grad_dim) : dsym/dRc < xi_i | V_pvsp | xi_j >
! coul_int_a ( 1:3 ) : d/dRa [ xi_i | f_k | xi_j ]
! coul_int_b ( 1:3 ) : d/dRb [ xi_i | f_k | xi_j ]
! help_arr (:,1:3 ) : d/dRb [ xi_i | f_k | xi_j ]
! coul_int_c ( 1:grad_dim) : dsym/dRb [ xi_i | f_k | xi_j ]
!
! grad_mat_[xyz]a (:,:,:,:) : d/dRa < xi_i | ... | xi_j >
! grad_mat_[xyz]b (:,:,:,:) : d/dRb < xi_i | ... | xi_j >
! grad_spmat_[xyz]a(:,:,:,:) : d/dRa < xi_i | ... | xi_j >
! grad_spmat_[xyz]b(:,:,:,:) : d/dRb < xi_i | ... | xi_j >
!..............................................................................
!------------ Declaration of subroutines ------------------------
external error_handler
intrinsic max,maxval
!------------ Declaration of local constants --------------------
real(kind=r8_kind),parameter :: pi=3.14159265358979324_r8_kind
real(kind=r8_kind),parameter :: one=1.0_r8_kind,&
two=2.0_r8_kind,&
three=3.0_r8_kind, &
four=4.0_r8_kind
! 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/))
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
!------------ Declaration of local variables --------------------
integer(kind=i4_kind) :: naexps,nbexps,ncexps,grad_dim
real(kind=r8_kind),pointer :: aexps(:),bexps(:)
real(kind=r8_kind),pointer :: cexps(:)
! mapping of exponents to one dimension and cutoff of small integrals
logical,allocatable :: cutoff(:,:) ! (naexps,nbexps)
integer(kind=i4_kind) :: num ! metaindex for (naexps,nbexps) > cutoff
! help factors
integer(kind=i4_kind) :: na,nb, &! number of unique atoms
i_grad,index,counter
integer(kind=i4_kind) :: ima, imb, imc, spin_index
logical :: moving_a, moving_b, moving_c, &
split_gradients, model_density, &
spin_polarized
logical :: iam_ppot
real(kind=r8_kind),allocatable,dimension(:,:):: fact0_arr, &
fact1_arr,fact2_arr ! (naexps,nbexps)
real(kind=r8_kind),allocatable,dimension(:) :: fact0,fact1, &
fact2,fact3,fac,aexp_arr,bexp_arr ! (num) metaindex for (naexps,nbexps) > cutoff
real(kind=r8_kind),dimension(3) :: dist
! xa - xb
! help factors for gamma-function
real(kind=r8_kind),allocatable,dimension(:,:):: gamma_arg, &
gamma_help
real(kind=r8_kind),allocatable,dimension(:) :: gamma_arg2
! help arrays for solid harmonics
real(kind=r8_kind),allocatable,dimension(:,:) :: yl_arg
real(kind=r8_kind),allocatable,dimension(:,:,:) :: yl_arr
real(kind=r8_kind),allocatable,dimension(:,:,:,:) :: yl_arr_grad
! help arrays for symmetry adaption
real(kind=r8_kind),allocatable,dimension(:,:,:,:) :: sym_coef1
real(kind=r8_kind),allocatable,dimension(:,:,:,:,:) :: sym_coef2
! integrals
real(kind=r8_kind),allocatable,dimension(:) :: overlap1
type(unique_atom_type), pointer :: ua_pointer
real(kind=r8_kind),allocatable,dimension(:,:) :: &
grad_overlap_a, &
grad_kinetic, &
grad_nuclear_a, &
grad_nuclear_b, &
grad_nuclear_c, &
grad_nuc_pseudo_a, &
grad_nuc_pseudo_b, &
grad_nuc_pseudo_c, &
grad_solv_a, &
grad_solv_b, &
grad_solv_c, &
grad_solv_c_help
real(kind=r8_kind),allocatable,dimension(:,:) :: &
grad_pseudo_a, &
grad_pseudo_b, &
grad_pseudo_c
logical :: pseudopot_present ! same name as in UA module
type(arrmat4),pointer :: pointer_prim_int(:) ! help pointer to point on primitive integrals
! ! 3-center integrals
! type(three_center_l_grad) :: grad_coul_1, grad_coul_2
type(three_center_l),allocatable :: coul_int_a(:),coul_int_b(:),coul_int_c(:)
! help pointers to unique atoms module data
integer(kind=i4_kind),pointer :: eq_atom(:),magn(:)
real(kind=r8_kind),pointer :: coef(:),rotmat(:,:)
real(kind=r8_kind),allocatable :: nuc_grad(:,:),help_arr(:,:)
real(kind=r8_kind),pointer :: &
grad_mat_xa(:,:,:,:),grad_mat_ya(:,:,:,:),grad_mat_za(:,:,:,:),&
grad_mat_xb(:,:,:,:),grad_mat_yb(:,:,:,:),grad_mat_zb(:,:,:,:)
real(kind=r8_kind),pointer :: &
grad_spmat_xa(:,:,:,:),grad_spmat_ya(:,:,:,:),grad_spmat_za(:,:,:,:),&
grad_spmat_xb(:,:,:,:),grad_spmat_yb(:,:,:,:),grad_spmat_zb(:,:,:,:)
integer(kind=i4_kind) :: alloc_stat,i,ua3,max_order,&
max_gamma,lmax_ch,k,m1,m2, &
n_equal_c,lm,n_indep_max,n_indep,i_l,i_sum, &
n_indep_fcts,n_contributing_fcts,i_ind,i_cont,i_ea3
integer(kind=i4_kind) :: allocstat(7),i_alo
integer(kind=i4_kind) :: k2dr
real(kind=r8_kind),dimension(3) :: xa,xb,xc
real(kind=r8_kind) :: arg,zc
real(kind=r8_kind) :: zcc ! core charge
logical :: check_ab,check_bc,check_ac,do_rotation
!-------------------------------------------------------------------
!------------ Executable code -----------------------------------
pseudopot_present = IAND(imode,IPSEU) .ne. 0
DPRINT 'ss_grads: PP=',pseudopot_present,' imode=',imode
allocstat=0
na=quadrupel%ua1
nb=quadrupel%ua2
ima = unique_atoms(na)%moving_atom
imb = unique_atoms(nb)%moving_atom
moving_a = ima > 0
moving_b = imb > 0
split_gradients = options_split_gradients()
model_density = options_xcmode() == xcmode_model_density
spin_polarized = .not. options_spin_restricted()
! first get the exponent data ------------------------
!write(*,'(A22,4I5)') 'ss_calculate_grads:',na,nb,1,1
naexps = ua1_basis%n_exponents
nbexps = ua2_basis%n_exponents
allocate(fact0_arr(nbexps,naexps),fact1_arr(nbexps,naexps), &
fact2_arr(nbexps,naexps),cutoff(nbexps,naexps), &
STAT=allocstat(1))
ASSERT(allocstat(1).eq.0)
allocstat(1)=1 ! fact0_arr fact1_arr fact2_arr
allocstat(2)=1 ! cutoff
xa = center1
xb = center2
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
where(fact2_arr*arg>=options_integral_expmax()) ! cutoff: where almost no overlap
cutoff=.false. ! is present calculation is not necessary
elsewhere
cutoff=.true.
end where
num=count(cutoff)
all_zero: if(num==0) then ! all integrals are equal zero
if (integralpar_2cob_ol_grad) then
do i_grad=1,size(prim_int_2cob_ol_grad)
prim_int_2cob_ol_grad(i_grad)%m = 0.0_r8_kind
if(integralpar_dervs) then
! FIXME: init prim_int_2cob_ol_dervs elsewhere:
do k2dr=1,size(prim_int_2cob_ol_grad)
prim_int_2cob_ol_dervs(i_grad,k2dr)%m = 0.0_r8_kind
enddo
endif
end do
end if
if (integralpar_solv_grad) then !!!!!!!!!!!
do i_grad=1,gradient_data_n_spin_gradients !!!!!!!!!!!
prim_int_3cob_solv_grad(i_grad)%m = 0.0_r8_kind !!!!!!!!!!!
enddo !!!!!!!!!!!
if (with_pc .and. .not.fixed_pc) then
do i_grad=1,totsym_field_length !!!!!!!!!!!
prim_int_3cob_solv_grad_pc(i_grad)%m = 0.0_r8_kind !!!!!!!!!!!
enddo !!!!!!!!!!!
end if
endif
if (integralpar_3cob_grad) then
do i_grad=1,gradient_data_n_spin_gradients
prim_int_3cob_grad(i_grad)%m = 0.0_r8_kind
if(integralpar_dervs) then
! FIXME: init prim_int_coul_dervs elsewhere:
do k2dr=1,gradient_data_n_spin_gradients
prim_int_coul_dervs(i_grad,k2dr)%m = 0.0_r8_kind
enddo
endif
enddo
end if
if (split_gradients) then
do i_grad=1,size(prim_int_2cob_ks_grad)
prim_int_2cob_ks_grad(i_grad)%m = 0.0_r8_kind
end do
do i_grad=1,gradient_data_n_gradients
prim_int_3cob_nuc_grad(i_grad)%m = 0.0_r8_kind
end do
if (model_density) then
do i_grad=1,gradient_data_n_gradients
prim_int_3cob_coul_grad(i_grad)%m = 0.0_r8_kind
end do
endif
endif
deallocate(fact0_arr,fact1_arr,fact2_arr,cutoff,stat=allocstat(1))
if (allocstat(1).ne.0) call error_handler &
("SS_CALCULATE: deallocation failed")
allocstat(2)=0 ! cutoff
return
end if all_zero
allocate (fact0(num),fact1(num),fact2(num),&
fact3(num),fac(num),help_arr(num,3),&
aexp_arr(num),bexp_arr(num), STAT=allocstat(3))
ASSERT(allocstat(3).eq.0)
allocstat(3)=1
! 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)
aexp_arr=pack(spread(aexps,1,nbexps),cutoff)
bexp_arr=pack(spread(bexps,2,naexps),cutoff)
help_arr=zero
deallocate(fact0_arr,fact1_arr,fact2_arr,STAT=allocstat(1))
ASSERT(allocstat(1).eq.0)
allocate(grad_mat_xa(nbexps,naexps,1,1),&
grad_mat_ya(nbexps,naexps,1,1),&
grad_mat_za(nbexps,naexps,1,1),&
grad_mat_xb(nbexps,naexps,1,1),&
grad_mat_yb(nbexps,naexps,1,1),&
grad_mat_zb(nbexps,naexps,1,1),stat=alloc_stat)
ASSERT(alloc_stat.eq.0)
grad_mat_xa=0.0_r8_kind
grad_mat_ya=0.0_r8_kind
grad_mat_za=0.0_r8_kind
grad_mat_xb=0.0_r8_kind
grad_mat_yb=0.0_r8_kind
grad_mat_zb=0.0_r8_kind
if (model_density .and. spin_polarized) then
allocate(grad_spmat_xa(nbexps,naexps,1,1),&
grad_spmat_ya(nbexps,naexps,1,1),&
grad_spmat_za(nbexps,naexps,1,1),&
grad_spmat_xb(nbexps,naexps,1,1),&
grad_spmat_yb(nbexps,naexps,1,1),&
grad_spmat_zb(nbexps,naexps,1,1),stat=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE: allocation failed grad_spmat")
grad_spmat_xa=0.0_r8_kind
grad_spmat_ya=0.0_r8_kind
grad_spmat_za=0.0_r8_kind
grad_spmat_xb=0.0_r8_kind
grad_spmat_yb=0.0_r8_kind
grad_spmat_zb=0.0_r8_kind
endif
! now prepare arguments for incomplete Gamma-Fct.
! gamma_arg = (a*vec_a + b*vec_b)/(a + b)
! allocation: num*max_order + num*3 + num
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 (gamma_help(num,max_order), gamma_arg(num,3), &
gamma_arg2(num), &
STAT=allocstat(4))
if(allocstat(4).ne.0) call error_handler &
("SS_CALCULATE_GRAD : allocation gamma_help failed ")
allocstat(4)=1
do i=1,3
gamma_arg(:,i) = pack( spread(aexps,1,nbexps)*xa(i) + &
spread(bexps,2,naexps)*xb(i),cutoff )/fact0
enddo
! ---------------------------------------------------
m1=1
m2=1
! first calculating 2-center integrals----------------
! PROCESS <xi_i|xi_j> and <xi_i|T|xi_j>
call calculate_ol_and_kin
notsolv0: if( .not. integralpar_solv_grad) then
allocate( grad_nuclear_a(num,3),STAT=alloc_stat )
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE_GRAD: allocation grad_nuclear_a failed")
grad_nuclear_a = zero
allocate( grad_nuclear_b(num,3),STAT=alloc_stat )
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE_GRAD: allocation grad_nuclear_b failed")
grad_nuclear_b = zero
allocate( grad_nuclear_c(num,3),STAT=allocstat(6) )
if (allocstat(6).ne.0) call error_handler &
("SS_CALCULATE_GRAD: allocation grad_nuclear_c failed")
allocstat(6)=1
grad_nuclear_c = zero
if (pseudopot_present) then
allocate( grad_pseudo_a(num,3),STAT=alloc_stat )
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE_GRAD: allocation grad_nuc_pseudo_a failed")
grad_pseudo_a = zero
allocate( grad_pseudo_b(num,3),STAT=alloc_stat )
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE_GRAD: allocation grad_nuc_pseudo_b failed")
grad_pseudo_b = zero
allocate( grad_pseudo_c(num,3),STAT=alloc_stat )
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE_GRAD: allocation grad_nuc_pseudo_c failed")
grad_pseudo_c = zero
endif
if (pseudopot_present.and.integralpar_relativistic) then
allocate( grad_nuc_pseudo_a(num,3),STAT=alloc_stat )
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE_GRAD: allocation grad_nuc_pseudo_a failed")
grad_nuc_pseudo_a = zero
allocate( grad_nuc_pseudo_b(num,3),STAT=alloc_stat )
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE_GRAD: allocation grad_nuc_pseudo_b failed")
grad_nuc_pseudo_b = zero
allocate( grad_nuc_pseudo_c(num,3),STAT=alloc_stat )
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE_GRAD: allocation grad_nuc_pseudo_c failed")
grad_nuc_pseudo_c = zero
endif
endif notsolv0
fac = sqrt(fact0/pi)
! prim_int_3cob_grad(2)%m(:,:,1,1)=unpack(overlap1,cutoff,zero) !no nuc
notsolv1 : if( .not. integralpar_solv_grad) then
! prim_int_3cob_grad(2)%m(:,:,1,1)=unpack(overlap1,cutoff,zero) !no nuc
! loop over atomic centers
! PROCESS <xi_i|V_nuc|xi_j>, <xi_i|V_pvsp|xi_j>, and <xi_i|V_H|xi_j>
! prim_int_3cob_grad(2)%m(:,:,1,1)=unpack(overlap1,cutoff,zero) !no nuc
unique_3: do ua3 = 1,N_unique_atoms+n_timps
if(ua3<=n_unique_atoms) then
ua_pointer=>unique_atoms(ua3)
zc = ua_pointer%Z
zcc= ua_pointer%ZC
! NUC and PP is handled by SHGI, skip the NUC:
DPRINT 'ss_grads: ua=',ua3,', zero its charge!'
zcc = zero
zc = zero
n_equal_c = unique_atoms(ua3)%N_equal_atoms
imc = unique_atoms(ua3)%moving_atom
moving_c = imc > 0
if (moving_c) then
grad_dim = gradient_index(imc+1) - gradient_index(imc)
else
grad_dim = 0
endif
! ** allocate calculate and deallocate nuc_grad intermediate
allocate(nuc_grad(num,grad_dim),stat=alloc_stat)
ASSERT(alloc_stat.eq.0)
nuc_grad=zero
! PROCESS <xi_i|Zc/|r-Rc||xi_j> and <xi_i|V_pvsp[c]|xi_j>
iam_ppot=zcc/=0.0_r8_kind &
.and.(.not.operations_core_density).and. &
pseudopot_present
call calculate_nuc() ! requires iam_ppot
else ! it is TIMP
ua_pointer=> unique_timps(ua3-n_unique_atoms)
zcc= ua_pointer%ZC
!!$ moving_c=.false. !!!! not false for EPE calculations
imc = ua_pointer%moving_atom !!!+N_moving_unique_atoms
moving_c = imc > 0
if (moving_c) then
grad_dim = gradient_index(N_moving_unique_atoms+imc+1) &
- gradient_index(N_moving_unique_atoms+imc)
allocate(nuc_grad(num,grad_dim),stat=alloc_stat)
if (alloc_stat/=0) call error_handler &
("SS_CACLULATE : allocation failed nuc_grad")
nuc_grad=zero
else
grad_dim = 0
endif
n_equal_c=ua_pointer%n_equal_atoms
end if !atom/timp
! PROCESS pseudopotentials
iam_ppot=zcc/=0.0_r8_kind.and. &
(.not.operations_core_density).and. &
pseudopot_present
if (iam_ppot) then
ABORT('not supported')
endif
! result is in grad_nuc_pseudo_a, grad_nuc_pseudo_b and nuc_grad for c
if(ua3<=n_unique_atoms) then
! ADD dsym/dRc <xi_i|V_nuc[c]|xi_j>, dsym/dRc <xi_i|V_pvsp[c]|xi_j>
if (moving_c) index = gradient_index(imc) - 1 ! may be shifted up ???
do i_grad=1,grad_dim ! only if moving_c
if(.not.integralpar_relativistic) then
if (split_gradients) then
prim_int_3cob_nuc_grad(index+i_grad)%m(:,:,1,1) = &
prim_int_3cob_nuc_grad(index+i_grad)%m(:,:,1,1) - &
unpack(nuc_grad(:,i_grad),cutoff,zero)
else
! if(.not.cpks_energies) then
prim_int_3cob_grad(index+i_grad)%m(:,:,1,1)=& ! no nuc grad if commented
prim_int_3cob_grad(index+i_grad)%m(:,:,1,1) &
-unpack(nuc_grad(:,i_grad),cutoff,zero)
! endif
endif
else ! integralpar_relativistic and regular PP
ppot: if(iam_ppot) then
prim_int_2cob_pseudo_grad(index+i_grad)%m(:,:,1,1)=&
prim_int_2cob_pseudo_grad(index+i_grad)%m(:,:,1,1) &
-unpack(nuc_grad(:,i_grad),cutoff,zero)
else
prim_int_2cob_nuc_grad(index+i_grad)%m(:,:,1,1)=&
prim_int_2cob_nuc_grad(index+i_grad)%m&
(:,:,1,1)-unpack(nuc_grad(:,i_grad),cutoff,zero)
end if ppot
end if
end do
deallocate(nuc_grad,stat=alloc_stat)
if (alloc_stat/=0) call error_handler &
("SS_CACLULATE : deallocation failed nuc_grad")
! now fitfunctions
! Orbital gradients:
lmax_ch = int(unique_atoms(ua3)%lmax_ch,kind=i4_kind)
max_order = max(3,lmax_ch+2)
if(.not.new_3c_co_grad) then
allocate(coul_int_a(3),coul_int_b(3),coul_int_c(grad_dim),STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation coul_int_a")
allocate(coul_int_a(1)%l(-1:lmax_ch),coul_int_a(2)%l(-1:lmax_ch),&
coul_int_a(3)%l(-1:lmax_ch),STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation coul_int_a (1) ")
allocate(coul_int_b(1)%l(-1:lmax_ch),&
coul_int_b(2)%l(-1:lmax_ch),&
coul_int_b(3)%l(-1:lmax_ch),&
STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation coul_int_b (1) ")
ncexps = unique_atoms(ua3)%r2_ch%n_exponents
allocate(coul_int_a(1)%l(-1)%m(num,ncexps,1,1,1),&
coul_int_a(2)%l(-1)%m(num,ncexps,1,1,1),&
coul_int_a(3)%l(-1)%m(num,ncexps,1,1,1),STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation coul_int_a ")
coul_int_a(1)%l(-1)%m = zero
coul_int_a(2)%l(-1)%m = zero
coul_int_a(3)%l(-1)%m = zero
allocate(coul_int_b(1)%l(-1)%m(num,ncexps,1,1,1),&
coul_int_b(2)%l(-1)%m(num,ncexps,1,1,1),&
coul_int_b(3)%l(-1)%m(num,ncexps,1,1,1),STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation coul_int_b ")
coul_int_b(1)%l(-1)%m = zero
coul_int_b(2)%l(-1)%m = zero
coul_int_b(3)%l(-1)%m = zero
ncexps = unique_atoms(ua3)%l_ch(0)%n_exponents
allocate(coul_int_a(1)%l(0)%m(num,ncexps,1,1,1),&
coul_int_a(2)%l(0)%m(num,ncexps,1,1,1),&
coul_int_a(3)%l(0)%m(num,ncexps,1,1,1),STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation coul_int_a ")
coul_int_a(1)%l(0)%m = zero
coul_int_a(2)%l(0)%m = zero
coul_int_a(3)%l(0)%m = zero
allocate(coul_int_b(1)%l(0)%m(num,ncexps,1,1,1),&
coul_int_b(2)%l(0)%m(num,ncexps,1,1,1),&
coul_int_b(3)%l(0)%m(num,ncexps,1,1,1),STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : allocation coul_int_b ")
coul_int_b(1)%l(0)%m = zero
coul_int_b(2)%l(0)%m = zero
coul_int_b(3)%l(0)%m = zero
do i_grad=1,grad_dim ! only if moving_c
allocate(coul_int_c(i_grad)%l(-1:lmax_ch),&
stat=alloc_stat)
if (alloc_stat/=0) call error_handler &
("SS_CACLULATE : allocation failed &
&coul_int_c(i_grads)%l(-1:lmax_ch")
ncexps = unique_atoms(ua3)%r2_ch%n_exponents
allocate(coul_int_c(i_grad)%l(-1)%m&
(num,ncexps,1,1,1),stat=alloc_stat)
if (alloc_stat/=0) call error_handler &
("SS_CACLULATE : allocation failed &
&coul_int_c(i_grad)%l(-1)%m")
ncexps = unique_atoms(ua3)%l_ch(0)%n_exponents
allocate(coul_int_c(i_grad)%l(0)%m&
(num,ncexps,1,1,1),stat=alloc_stat)
if (alloc_stat/=0) call error_handler &
("SS_CACLULATE : allocation failed &
&coul_int_c(i_grad)%l(0)%m")
coul_int_c(i_grad)%l(0)%m=0.0_r8_kind
coul_int_c(i_grad)%l(-1)%m=0.0_r8_kind
end do
endif
if (lmax_ch.gt.0) then
allocate(yl_arr(num,(lmax_ch+1)**2,n_equal_c),STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE_GRAD: allocation yl_arr failed")
yl_arr = zero
allocate(yl_arr_grad(num,n_equal_c,(lmax_ch+1)**2,3)&
,STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE_GRAD: allocation yl_arr_grad failed")
yl_arr_grad = zero
n_indep_max = maxval(unique_atoms(ua3)%symadapt_partner&
(1,:)%n_independent_fcts)
allocate(sym_coef1(num,n_equal_c,n_indep_max,lmax_ch),&
STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE_GRAD: allocation sym_coef1 failed")
sym_coef1 = zero
allocate(sym_coef2(num,n_equal_c,n_indep_max,lmax_ch,3),&
STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE_GRAD: allocation sym_coef2 failed")
sym_coef2 = zero
if(.not.new_3c_co_grad) then
do i_l = 1,lmax_ch
ncexps = unique_atoms(ua3)%l_ch(i_l)%n_exponents
n_indep = &
unique_atoms(ua3)%symadapt_partner(1,i_l)%n_independent_fcts
allocate( coul_int_a(1)%l(i_l)%m(num,ncexps,n_indep,1,1),&
coul_int_a(2)%l(i_l)%m(num,ncexps,n_indep,1,1),&
coul_int_a(3)%l(i_l)%m(num,ncexps,n_indep,1,1),&
STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE_GRAD: allocation coul_int_a, ang. mom. failed")
coul_int_a(1)%l(i_l)%m = zero
coul_int_a(2)%l(i_l)%m = zero
coul_int_a(3)%l(i_l)%m = zero
allocate (coul_int_b(1)%l(i_l)%m(num,ncexps,n_indep,1,1),&
coul_int_b(2)%l(i_l)%m(num,ncexps,n_indep,1,1),&
coul_int_b(3)%l(i_l)%m(num,ncexps,n_indep,1,1),&
STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE_GRAD: allocation coul_int_b, ang. mom. failed")
coul_int_b(1)%l(i_l)%m = zero
coul_int_b(2)%l(i_l)%m = zero
coul_int_b(3)%l(i_l)%m = zero
do i_grad=1,grad_dim ! only if moving_c
allocate (coul_int_c(i_grad)%l(i_l)%m(num,ncexps,n_indep,1,1),&
STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE_GRAD: allocation coul_int_c, ang. mom. failed")
coul_int_c(i_grad)%l(i_l)%m = zero
end do
enddo
endif
endif
equal_3_coul: do i_ea3 = 1,n_equal_c
if (moving_c) then
if(grad_dim==3) then
if(sum((unique_atom_grad_info(imc)%m(:,:,i_ea3)-unity_matrix)**2)<&
1.0e-7_r8_kind) then
do_rotation=.false.
else
do_rotation=.true.
rotmat=>unique_atom_grad_info(imc)%m(:,:,i_ea3)
endif
else
do_rotation=.true.
rotmat=>unique_atom_grad_info(imc)%m(:,:,i_ea3)
end if
endif
xc = unique_atoms(ua3)%position(:,i_ea3)
check_ab =( (quadrupel%ua1.eq.quadrupel%ua2).and. &
(i_ea1.eq.i_ea2))
check_ac =( (quadrupel%ua1.eq.ua3).and. &
(i_ea1.eq.i_ea3))
check_bc =( (quadrupel%ua2.eq.ua3).and. &
(i_ea2.eq.i_ea3))
! now do a precalculation of solid harmonics
if (lmax_ch.gt.0) then
allocate(yl_arg(num,3),STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE_grad : allocation yl_arg failed")
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_ea3) = solid_harmonics_calc(lmax_ch,yl_arg)
deallocate(yl_arg,STAT=alloc_stat) ! this is not needed anymore
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE_grad : deallocation yl_arg failed")
do lm=1,(lmax_ch+1)**2
do i_sum=1,solhrules_differential(3,lm)%n_summands
yl_arr_grad(:,i_ea3,lm,1) = &
yl_arr_grad(:,i_ea3,lm,1) + &
solhrules_differential(3,lm)%coef(i_sum)* &
yl_arr(:,solhrules_differential(3,lm)%lm_sh(i_sum),i_ea3)
enddo
do i_sum=1,solhrules_differential(4,lm)%n_summands
yl_arr_grad(:,i_ea3,lm,2) = &
yl_arr_grad(:,i_ea3,lm,2) + &
solhrules_differential(4,lm)%coef(i_sum)* &
yl_arr(:,solhrules_differential(4,lm)%lm_sh(i_sum),i_ea3)
enddo
do i_sum=1,solhrules_differential(2,lm)%n_summands
yl_arr_grad(:,i_ea3,lm,3) = &
yl_arr_grad(:,i_ea3,lm,3) + &
solhrules_differential(2,lm)%coef(i_sum)* &
yl_arr(:,solhrules_differential(2,lm)%lm_sh(i_sum),i_ea3)
enddo
enddo
endif
! if all three centers are the same, the integrals are zero
if ( check_ab.and.check_bc ) then
cycle equal_3_coul
endif
! PROCESS [xi_i|f_k|xi_j]
! first evaluate s-type coulomb integrals
if(old_3c_co) call s_coulomb()
! now treating r2-type coloumb integrals
if(old_3c_co) call r2_coulomb()
enddo equal_3_coul
if (lmax_ch.gt.0) then
call calc_sym_coef()
! finally calculate l-type coulomb integrals
if(old_3c_co) call l_coulomb()
endif
! now let`s call fitcontract
if(integralpar_3cob_grad) then
! coulombic contributions of derivatives with respect
! to center a and b
! CONTRACT d/dRa [xi_i|f_k|xi_j] and d/dRb [xi_i|f_k|xi_j]
if (model_density .and. spin_polarized) then
if(old_3c_fc.and.old_3c_co) then
if (moving_a) then
call fitcontract('grad',num,ua3,cutoff,coul_int_a(1), &
grad_mat_xa,grad_spmat_xa)
call fitcontract('grad',num,ua3,cutoff,coul_int_a(2), &
grad_mat_ya,grad_spmat_ya)
call fitcontract('grad',num,ua3,cutoff,coul_int_a(3), &
grad_mat_za,grad_spmat_za)
endif
if (moving_b) then
call fitcontract('grad',num,ua3,cutoff,coul_int_b(1), &
grad_mat_xb,grad_spmat_xb)
call fitcontract('grad',num,ua3,cutoff,coul_int_b(2), &
grad_mat_yb,grad_spmat_yb)
call fitcontract('grad',num,ua3,cutoff,coul_int_b(3), &
grad_mat_zb,grad_spmat_zb)
endif
endif
else ! standard SCF
if(old_3c_co) then
if (moving_a) then
! do i_l=-1,lmax_ch
! if(old_3c_co.and.associated(coul_int_a(3)%l(i_l)%m)) &
! print*,sum(coul_int_a(3)%l(i_l)%m),i_l,' ga'
! enddo
if(old_3c_fc) then
call fitcontract('grad',num,ua3,cutoff,coul_int_a(1),&
grad_mat_xa)
call fitcontract('grad',num,ua3,cutoff,coul_int_a(2),&
grad_mat_ya)
call fitcontract('grad',num,ua3,cutoff,coul_int_a(3),&
grad_mat_za)
endif
endif
if (moving_b) then
if(old_3c_fc) then
call fitcontract('grad',num,ua3,cutoff,coul_int_b(1),&
grad_mat_xb)
call fitcontract('grad',num,ua3,cutoff,coul_int_b(2),&
grad_mat_yb)
call fitcontract('grad',num,ua3,cutoff,coul_int_b(3),&
grad_mat_zb)
endif
endif
endif
endif
! CONTRACT dsym/dRc [xi_i|f_k|xi_j]
do i_grad=1,grad_dim ! only if noving_c
index = gradient_index(imc) + i_grad - 1
if (model_density) then
if (spin_polarized) then
spin_index = index + gradient_data_n_gradients
if (split_gradients) then
if(old_3c_fc.and.old_3c_co) &
call fitcontract('grad',num,ua3,cutoff, &
coul_int_c(i_grad), &
prim_int_3cob_coul_grad(index)%m, & ! V_H
prim_int_3cob_grad(spin_index)%m, & ! V_X,spin
prim_int_3cob_grad(index)%m ) ! V_X,tot
else ! total gradients only
if(old_3c_fc.and.old_3c_co) &
call fitcontract('grad',num,ua3,cutoff, &
coul_int_c(i_grad), &
prim_int_3cob_grad(index)%m, & ! V_H+V_x,tot
prim_int_3cob_grad(spin_index)%m ) ! V_X,spin
endif
else ! spin_restricted
if (split_gradients) then
if(old_3c_fc.and.old_3c_co) &
call fitcontract('grad',num,ua3,cutoff, &
coul_int_c(i_grad), &
prim_int_3cob_coul_grad(index)%m, & ! V_H
mda_xcpot_gradients = &
prim_int_3cob_grad(index)%m ) ! V_X,tot
else ! total gradients only
if(old_3c_fc.and.old_3c_co) &
call fitcontract('grad',num,ua3,cutoff, &
coul_int_c(i_grad), &
prim_int_3cob_grad(index)%m ) ! V_H+V_X,tot
endif
end if
else ! standard SCF
if(old_3c_fc.and.old_3c_co) then
! do i_l=-1,lmax_ch
! if(old_3c_co.and.associated(coul_int_c(i_grad)%l(i_l)%m)) &
! print*,'c ',i_l,i_grad,sum(coul_int_c(i_grad)%l(i_l)%m)
! enddo
call fitcontract('grad',num,ua3,cutoff,coul_int_c(i_grad),&
prim_int_3cob_grad(index)%m)
endif
endif
if(.not.new_3c_co_grad) then
do i_l = -1, lmax_ch
deallocate(coul_int_c(i_grad)%l(i_l)%m,&
STAT=alloc_stat)
if(alloc_stat/=0) call error_handler &
("SS_CALCULATE : deallocation coul_int_c&
&%l%m failed")
enddo
deallocate (coul_int_c(i_grad)%l,STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : deallocation coul_int_c&
&(i_grad)%l failed")
endif
end do
if(.not.new_3c_co_grad) then
deallocate (coul_int_c,STAT=alloc_stat)
if(alloc_stat.ne.0) call error_handler &
("SS_CALCULATE : deallocation coul_int_c failed")
endif
if(.not.new_3c_co_grad) then
do i_l=-1,lmax_ch
deallocate(coul_int_a(1)%l(i_l)%m,&
coul_int_a(2)%l(i_l)%m,&
coul_int_a(3)%l(i_l)%m,&
STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE_GRAD: deallocation coul_int_a (1) failed")
deallocate(coul_int_b(1)%l(i_l)%m,&
coul_int_b(2)%l(i_l)%m,&
coul_int_b(3)%l(i_l)%m,&
STAT=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("SS_CALCULATE_GRAD: deallocation coul_int_b (1) failed")
enddo