forked from alexei-matveev/paragauss-gpl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ls_calculate_dipole.f90
294 lines (253 loc) · 8.6 KB
/
ls_calculate_dipole.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
!
! 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 ls_calculate_dipole(na,nb,la_in,lb)
!
! Purpose: calculation of all primitive dipole integrals
! for a given set of indizes
! (unique_atom1,unique_atom2,l1,equal_atom2).
!
! Author: MS
! Date: 8/96
!
use unique_atom_module
use type_module
use solid_harmonics_module, only : solid_harmonics_calc,solid_harmonics_scalar
use int_data_dipole_module
use solhrules_module
use integralpar_module
use options_module, only: options_integral_expmax
implicit none
integer(kind=i4_kind),intent(in) :: na ! number of unique atom a
integer(kind=i4_kind),intent(in) :: nb ! number of unique atom b
integer(kind=i4_kind),intent(in) :: la_in ! angular momentum of unique atom a
integer(kind=i4_kind),intent(in) :: lb ! angular momentum of unique atom b
!===================================================================
! End of public interface of module
!===================================================================
! constants
real(kind=r8_kind),parameter :: pi=3.14159265358979324_r8_kind
real(kind=r8_kind),parameter :: gam=1.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
real(kind=r8_kind),parameter,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 /)
! variables
integer(kind=i4_kind) :: num,m,alloc_stat,i_xyz,i_l,i_m,i_lm,n_lm, &
nm_la,nm_lb,la_org,lb_org,la,naexps,nbexps
logical,allocatable :: cutoff(:,:)
real(kind=r8_kind),pointer,dimension(:) :: &
aexps,bexps
real(kind=r8_kind),allocatable,dimension(:,:) :: &
fact0_arr,fact1_arr,fact2_arr,overlap,solh,gamma_arg
real(kind=r8_kind),allocatable,dimension(:) :: &
fact0,fact1,fact2,fact4,fact6,tau,aexp_arr,clmamb_scalar
real(kind=r8_kind),allocatable,dimension(:,:,:) :: &
dipole,diff_rule_result
real(kind=r8_kind),dimension(3) :: xa,xb,xd
real(kind=r8_kind) :: arg
logical :: laltlb ! flag to decide if la is lower then lb or not
nm_la=2*la_in+1
nm_lb=2*lb+1
la_org=la_in
lb_org=lb
naexps = unique_atoms(na)%l_ob(la_in)%n_exponents
nbexps = unique_atoms(nb)%l_ob(lb)%n_exponents
if(lb>la_in) then
laltlb=.true.
la=lb
else
laltlb=.false.
la=la_in
end if
n_lm = (la+1)**2
allocate( &
fact0_arr(nbexps,naexps), &
fact1_arr(nbexps,naexps), &
fact2_arr(nbexps,naexps), &
cutoff(nbexps,naexps), &
stat=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("ls_calculate_dipole: allocation (1) failed")
xa = center1 ! from int_data_module
xb = center2 ! from int_data_module
xd =xa-xb
aexps => unique_atoms(na)%l_ob(la_in)%exponents(:)
bexps => unique_atoms(nb)%l_ob(lb)%exponents(:)
arg=sum(xd**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
! cutoff: where almost no overlap is present calculation is not necessary
where(fact2_arr*arg>=options_integral_expmax())
cutoff=.false.
elsewhere
cutoff=.true.
end where
num=count(cutoff)
if(num==0) then ! all integrals are equal zero
prim_int_2cob_dipole = 0.0_r8_kind
deallocate( &
fact0_arr, &
fact1_arr, &
fact2_arr, &
cutoff, &
stat=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("ls_calculate_dipole: deallocation (1/1) failed")
return
end if
allocate ( &
fact0(num), &
fact1(num), &
fact2(num), &
fact4(num), &
fact6(num), &
tau(num), &
overlap(num,n_lm), &
solh(num,n_lm), &
dipole(num,2*la+1,3), &
diff_rule_result(num,n_lm,3), &
gamma_arg(num,3), &
aexp_arr(num), &
clmamb_scalar((la+1)**2),&
stat=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("ls_calculate_dipole: allocation (2) 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)
if(.not.laltlb) then
aexp_arr=pack(spread(aexps,1,nbexps),cutoff)
else
aexp_arr=pack(spread(bexps,2,naexps),cutoff)
end if
deallocate( &
fact0_arr, &
fact1_arr, &
fact2_arr, &
stat=alloc_stat)
if (alloc_stat/=0) call error_handler &
("ls_calculate_dipole: deallocation (1/2a) failed")
! precalculation of solid harmonics
if(laltlb) then
xd=-xd
end if
clmamb_scalar=solid_harmonics_scalar(la,xd)
! calculate overlap * sqrt(aexp_arr**i_l*dfac(i_l))
tau = fact2 * arg
fact6 = exp(-tau) * (4.0_r8_kind*fact2/fact0)**0.75_r8_kind
fact4=1.0_r8_kind
i_lm=1
do i_l=0,la
do i_m=1,2*i_l+1
overlap(:,i_lm) = fact6 * fact4 * clmamb_scalar(i_lm)
i_lm=i_lm+1
enddo
fact4 = - fact4 * fact2 * 2.0_r8_kind
enddo
! calculate differential rule on C(1,m) and multiply all scaling factors
! gamma_arg = (a*vec_a + b*vec_b) / a
do i_xyz = 1, 3
gamma_arg(:,i_xyz)= &
pack( &
spread( aexps*xa(i_xyz), 1, nbexps ) + &
spread( bexps*xb(i_xyz), 2, naexps ), &
cutoff &
) / aexp_arr
enddo
solh = solid_harmonics_calc(la,gamma_arg)
! multiply scaling factor already here to save work:
! solh = solh * a / (a+b) / sqrt(a**la * dfac(la))
fact6 = aexp_arr / ( fact0 * sqrt(aexp_arr**la * dfac(la)) )
do i_lm = 1, n_lm
solh(:,i_lm) = &
solh(:,i_lm) * fact6
enddo
do i_xyz = 1, 3
diff_rule_result(:,:,i_xyz) = diff_rule( solh, 1, n_lm, i_xyz+1 )
enddo
! product rule with respect to a
do i_xyz = 1, 3
dipole(:,:,i_xyz) = &
prod_rule( &
diff_rule_result(:,:,i_xyz), &
overlap, &
la**2+1,la**2+2*la+1 &
)
enddo
! re-map to int_data_2cob_dipole
! Take into account special mapping of i_xyz to x,y,z
! determined by solidharmonics for l=1 and m=1,2,3
if(.not.laltlb) then
magnetic_number_map: do m=1,2*la+1
prim_int_2cob_dipole(:,:,1,m,1) = &
unpack(dipole(:,m,2),cutoff,zero)
prim_int_2cob_dipole(:,:,1,m,2) = &
unpack(dipole(:,m,3),cutoff,zero)
prim_int_2cob_dipole(:,:,1,m,3) = &
unpack(dipole(:,m,1),cutoff,zero)
end do magnetic_number_map
else
magnetic_number_map_2: do m=1,2*la+1
prim_int_2cob_dipole(:,:,m,1,1) = &
unpack(dipole(:,m,2),cutoff,zero)
prim_int_2cob_dipole(:,:,m,1,2) = &
unpack(dipole(:,m,3),cutoff,zero)
prim_int_2cob_dipole(:,:,m,1,3) = &
unpack(dipole(:,m,1),cutoff,zero)
end do magnetic_number_map_2
end if
deallocate ( &
fact0, &
fact1, &
fact2, &
fact4, &
fact6, &
tau, &
overlap, &
solh, &
dipole, &
diff_rule_result, &
gamma_arg, &
aexp_arr, &
clmamb_scalar,&
cutoff, &
stat=alloc_stat)
if (alloc_stat.ne.0) call error_handler &
("ls_calculate_dipole: deallocation (1/2b) (2) failed")
end subroutine ls_calculate_dipole