forked from TinkerTools/tinker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathegauss.f
1026 lines (1026 loc) · 28.4 KB
/
egauss.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
c
c
c ###################################################
c ## COPYRIGHT (C) 1994 by Jay William Ponder ##
c ## All Rights Reserved ##
c ###################################################
c
c ############################################################
c ## ##
c ## subroutine egauss -- Gaussian van der Waals energy ##
c ## ##
c ############################################################
c
c
c "egauss" calculates the Gaussian expansion van der Waals energy
c
c
subroutine egauss
use limits
use warp
implicit none
c
c
c choose the method for summing over pairwise interactions
c
if (use_smooth) then
call egauss0d
else if (use_vlist) then
call egauss0c
else if (use_lights) then
call egauss0b
else
call egauss0a
end if
return
end
c
c
c ################################################################
c ## ##
c ## subroutine egauss0a -- double loop Gaussian vdw energy ##
c ## ##
c ################################################################
c
c
c "egauss0a" calculates the Gaussian expansion van der Waals
c energy using a pairwise double loop
c
c
subroutine egauss0a
use atomid
use atoms
use bound
use cell
use couple
use energi
use group
use shunt
use usage
use vdw
use vdwpot
implicit none
integer i,j,k,m
integer ii,iv,it
integer kk,kv,kt
integer, allocatable :: iv14(:)
real*8 e,eps,rdn
real*8 rad2,fgrp
real*8 xi,yi,zi
real*8 xr,yr,zr
real*8 rik,rik2,rik3
real*8 rik4,rik5,taper
real*8 expcut,expterm
real*8 a(maxgauss)
real*8 b(maxgauss)
real*8, allocatable :: vscale(:)
logical proceed,usei
character*6 mode
c
c
c zero out the van der Waals energy contribution
c
ev = 0.0d0
if (nvdw .eq. 0) return
c
c perform dynamic allocation of some local arrays
c
allocate (iv14(n))
allocate (vscale(n))
c
c set arrays needed to scale connected atom interactions
c
do i = 1, n
iv14(i) = 0
vscale(i) = 1.0d0
end do
c
c set cutoff distances and switching function coefficients
c
mode = 'VDW'
call switch (mode)
expcut = -50.0d0
c
c apply any reduction factor to the atomic coordinates
c
do k = 1, nvdw
i = ivdw(k)
iv = ired(i)
rdn = kred(i)
xred(i) = rdn*(x(i)-x(iv)) + x(iv)
yred(i) = rdn*(y(i)-y(iv)) + y(iv)
zred(i) = rdn*(z(i)-z(iv)) + z(iv)
end do
c
c find the van der Waals energy via double loop search
c
do ii = 1, nvdw-1
i = ivdw(ii)
iv = ired(i)
it = jvdw(i)
xi = xred(i)
yi = yred(i)
zi = zred(i)
usei = (use(i) .or. use(iv))
c
c set exclusion coefficients for connected atoms
c
do j = 1, n12(i)
vscale(i12(j,i)) = v2scale
end do
do j = 1, n13(i)
vscale(i13(j,i)) = v3scale
end do
do j = 1, n14(i)
vscale(i14(j,i)) = v4scale
iv14(i14(j,i)) = i
end do
do j = 1, n15(i)
vscale(i15(j,i)) = v5scale
end do
c
c decide whether to compute the current interaction
c
do kk = ii+1, nvdw
k = ivdw(kk)
kv = ired(k)
proceed = .true.
if (use_group) call groups (proceed,fgrp,i,k,0,0,0,0)
if (proceed) proceed = (usei .or. use(k) .or. use(kv))
c
c compute the energy contribution for this interaction
c
if (proceed) then
kt = jvdw(k)
xr = xi - xred(k)
yr = yi - yred(k)
zr = zi - zred(k)
call image (xr,yr,zr)
rik2 = xr*xr + yr*yr + zr*zr
c
c check for an interaction distance less than the cutoff
c
if (rik2 .le. off2) then
rad2 = radmin(kt,it)**2
eps = epsilon(kt,it)
if (iv14(k) .eq. i) then
rad2 = radmin4(kt,it)**2
eps = epsilon4(kt,it)
end if
eps = eps * vscale(k)
do j = 1, ngauss
a(j) = igauss(1,j) * eps
b(j) = igauss(2,j) / rad2
end do
e = 0.0d0
do j = 1, ngauss
expterm = -b(j) * rik2
if (expterm .gt. expcut)
& e = e + a(j)*exp(expterm)
end do
c
c use energy switching if near the cutoff distance
c
if (rik2 .gt. cut2) then
rik = sqrt(rik2)
rik3 = rik2 * rik
rik4 = rik2 * rik2
rik5 = rik2 * rik3
taper = c5*rik5 + c4*rik4 + c3*rik3
& + c2*rik2 + c1*rik + c0
e = e * taper
end if
c
c scale the interaction based on its group membership
c
if (use_group) e = e * fgrp
c
c increment the overall van der Waals energy components
c
ev = ev + e
end if
end if
end do
c
c reset exclusion coefficients for connected atoms
c
do j = 1, n12(i)
vscale(i12(j,i)) = 1.0d0
end do
do j = 1, n13(i)
vscale(i13(j,i)) = 1.0d0
end do
do j = 1, n14(i)
vscale(i14(j,i)) = 1.0d0
end do
do j = 1, n15(i)
vscale(i15(j,i)) = 1.0d0
end do
end do
c
c for periodic boundary conditions with large cutoffs
c neighbors must be found by the replicates method
c
if (.not. use_replica) return
c
c calculate interaction energy with other unit cells
c
do ii = 1, nvdw
i = ivdw(ii)
iv = ired(i)
it = jvdw(i)
xi = xred(i)
yi = yred(i)
zi = zred(i)
usei = (use(i) .or. use(iv))
c
c set exclusion coefficients for connected atoms
c
do j = 1, n12(i)
vscale(i12(j,i)) = v2scale
end do
do j = 1, n13(i)
vscale(i13(j,i)) = v3scale
end do
do j = 1, n14(i)
vscale(i14(j,i)) = v4scale
iv14(i14(j,i)) = i
end do
do j = 1, n15(i)
vscale(i15(j,i)) = v5scale
end do
c
c decide whether to compute the current interaction
c
do kk = ii, nvdw
k = ivdw(kk)
kv = ired(k)
proceed = .true.
if (use_group) call groups (proceed,fgrp,i,k,0,0,0,0)
if (proceed) proceed = (usei .or. use(k) .or. use(kv))
c
c compute the energy contribution for this interaction
c
if (proceed) then
kt = jvdw(k)
do m = 2, ncell
xr = xi - xred(k)
yr = yi - yred(k)
zr = zi - zred(k)
call imager (xr,yr,zr,m)
rik2 = xr*xr + yr*yr + zr*zr
c
c check for an interaction distance less than the cutoff
c
if (rik2 .le. off2) then
rad2 = radmin(kt,it)**2
eps = epsilon(kt,it)
if (use_polymer) then
if (rik2 .le. polycut2) then
if (iv14(k) .eq. i) then
rad2 = radmin4(kt,it)**2
eps = epsilon4(kt,it)
end if
eps = eps * vscale(k)
end if
end if
do j = 1, ngauss
a(j) = igauss(1,j) * eps
b(j) = igauss(2,j) / rad2
end do
e = 0.0d0
do j = 1, ngauss
expterm = -b(j) * rik2
if (expterm .gt. expcut)
& e = e + a(j)*exp(expterm)
end do
c
c use energy switching if near the cutoff distance
c
if (rik2 .gt. cut2) then
rik = sqrt(rik2)
rik3 = rik2 * rik
rik4 = rik2 * rik2
rik5 = rik2 * rik3
taper = c5*rik5 + c4*rik4 + c3*rik3
& + c2*rik2 + c1*rik + c0
e = e * taper
end if
c
c scale the interaction based on its group membership
c
if (use_group) e = e * fgrp
c
c increment the overall van der Waals energy component;
c interaction of an atom with its own image counts half
c
if (i .eq. k) e = 0.5d0 * e
ev = ev + e
end if
end do
end if
end do
c
c reset exclusion coefficients for connected atoms
c
do j = 1, n12(i)
vscale(i12(j,i)) = 1.0d0
end do
do j = 1, n13(i)
vscale(i13(j,i)) = 1.0d0
end do
do j = 1, n14(i)
vscale(i14(j,i)) = 1.0d0
end do
do j = 1, n15(i)
vscale(i15(j,i)) = 1.0d0
end do
end do
c
c perform deallocation of some local arrays
c
deallocate (iv14)
deallocate (vscale)
return
end
c
c
c ###############################################################
c ## ##
c ## subroutine egauss0b -- Gaussian vdw energy via lights ##
c ## ##
c ###############################################################
c
c
c "egauss0b" calculates the Gaussian expansion van der Waals energy
c using the method of lights
c
c
subroutine egauss0b
use atomid
use atoms
use bound
use boxes
use cell
use couple
use energi
use group
use light
use shunt
use usage
use vdw
use vdwpot
implicit none
integer i,j,k,m
integer ii,iv,it
integer kk,kv,kt
integer kgy,kgz
integer start,stop
integer, allocatable :: iv14(:)
real*8 e,eps,rdn
real*8 rad2,fgrp
real*8 xi,yi,zi
real*8 xr,yr,zr
real*8 rik,rik2,rik3
real*8 rik4,rik5,taper
real*8 expcut,expterm
real*8 a(maxgauss)
real*8 b(maxgauss)
real*8, allocatable :: vscale(:)
real*8, allocatable :: xsort(:)
real*8, allocatable :: ysort(:)
real*8, allocatable :: zsort(:)
logical proceed,usei,prime
logical unique,repeat
character*6 mode
c
c
c zero out the van der Waals energy contribution
c
ev = 0.0d0
if (nvdw .eq. 0) return
c
c perform dynamic allocation of some local arrays
c
allocate (iv14(n))
allocate (vscale(n))
allocate (xsort(8*n))
allocate (ysort(8*n))
allocate (zsort(8*n))
c
c set arrays needed to scale connected atom interactions
c
do i = 1, n
iv14(i) = 0
vscale(i) = 1.0d0
end do
c
c set cutoff distances and switching function coefficients
c
mode = 'VDW'
call switch (mode)
expcut = -50.0d0
c
c apply any reduction factor to the atomic coordinates
c
do j = 1, nvdw
i = ivdw(j)
iv = ired(i)
rdn = kred(i)
xred(j) = rdn*(x(i)-x(iv)) + x(iv)
yred(j) = rdn*(y(i)-y(iv)) + y(iv)
zred(j) = rdn*(z(i)-z(iv)) + z(iv)
end do
c
c transfer the interaction site coordinates to sorting arrays
c
do i = 1, nvdw
xsort(i) = xred(i)
ysort(i) = yred(i)
zsort(i) = zred(i)
end do
c
c use the method of lights to generate neighbors
c
unique = .true.
call lights (off,nvdw,xsort,ysort,zsort,unique)
c
c loop over all atoms computing the interactions
c
do ii = 1, nvdw
i = ivdw(ii)
iv = ired(i)
it = jvdw(i)
xi = xsort(rgx(ii))
yi = ysort(rgy(ii))
zi = zsort(rgz(ii))
usei = (use(i) .or. use(iv))
c
c set exclusion coefficients for connected atoms
c
do j = 1, n12(i)
vscale(i12(j,i)) = v2scale
end do
do j = 1, n13(i)
vscale(i13(j,i)) = v3scale
end do
do j = 1, n14(i)
vscale(i14(j,i)) = v4scale
iv14(i14(j,i)) = i
end do
do j = 1, n15(i)
vscale(i15(j,i)) = v5scale
end do
c
c loop over method of lights neighbors of current atom
c
if (kbx(ii) .le. kex(ii)) then
repeat = .false.
start = kbx(ii) + 1
stop = kex(ii)
else
repeat = .true.
start = 1
stop = kex(ii)
end if
10 continue
do m = start, stop
kk = locx(m)
kgy = rgy(kk)
if (kby(ii) .le. key(ii)) then
if (kgy.lt.kby(ii) .or. kgy.gt.key(ii)) goto 20
else
if (kgy.lt.kby(ii) .and. kgy.gt.key(ii)) goto 20
end if
kgz = rgz(kk)
if (kbz(ii) .le. kez(ii)) then
if (kgz.lt.kbz(ii) .or. kgz.gt.kez(ii)) goto 20
else
if (kgz.lt.kbz(ii) .and. kgz.gt.kez(ii)) goto 20
end if
k = ivdw(kk-((kk-1)/nvdw)*nvdw)
kv = ired(k)
prime = (kk .le. nvdw)
c
c decide whether to compute the current interaction
c
proceed = .true.
if (use_group) call groups (proceed,fgrp,i,k,0,0,0,0)
if (proceed) proceed = (usei .or. use(k) .or. use(kv))
c
c compute the energy contribution for this interaction
c
if (proceed) then
kt = jvdw(k)
xr = xi - xsort(m)
yr = yi - ysort(kgy)
zr = zi - zsort(kgz)
if (use_bounds) then
if (abs(xr) .gt. xcell2) xr = xr - sign(xcell,xr)
if (abs(yr) .gt. ycell2) yr = yr - sign(ycell,yr)
if (abs(zr) .gt. zcell2) zr = zr - sign(zcell,zr)
if (monoclinic) then
xr = xr + zr*beta_cos
zr = zr * beta_sin
else if (triclinic) then
xr = xr + yr*gamma_cos + zr*beta_cos
yr = yr*gamma_sin + zr*beta_term
zr = zr * gamma_term
end if
end if
rik2 = xr*xr + yr*yr + zr*zr
c
c check for an interaction distance less than the cutoff
c
if (rik2 .le. off2) then
rad2 = radmin(kt,it)**2
eps = epsilon(kt,it)
if (prime) then
if (iv14(k) .eq. i) then
rad2 = radmin4(kt,it)**2
eps = epsilon4(kt,it)
end if
eps = eps * vscale(k)
end if
do j = 1, ngauss
a(j) = igauss(1,j) * eps
b(j) = igauss(2,j) / rad2
end do
e = 0.0d0
do j = 1, ngauss
expterm = -b(j) * rik2
if (expterm .gt. expcut)
& e = e + a(j)*exp(expterm)
end do
c
c use energy switching if near the cutoff distance
c
if (rik2 .gt. cut2) then
rik = sqrt(rik2)
rik3 = rik2 * rik
rik4 = rik2 * rik2
rik5 = rik2 * rik3
taper = c5*rik5 + c4*rik4 + c3*rik3
& + c2*rik2 + c1*rik + c0
e = e * taper
end if
c
c scale the interaction based on its group membership
c
if (use_group) e = e * fgrp
c
c increment the overall van der Waals energy component
c
ev = ev + e
end if
end if
20 continue
end do
if (repeat) then
repeat = .false.
start = kbx(ii) + 1
stop = nlight
goto 10
end if
c
c reset exclusion coefficients for connected atoms
c
do j = 1, n12(i)
vscale(i12(j,i)) = 1.0d0
end do
do j = 1, n13(i)
vscale(i13(j,i)) = 1.0d0
end do
do j = 1, n14(i)
vscale(i14(j,i)) = 1.0d0
end do
do j = 1, n15(i)
vscale(i15(j,i)) = 1.0d0
end do
end do
c
c perform deallocation of some local arrays
c
deallocate (iv14)
deallocate (vscale)
deallocate (xsort)
deallocate (ysort)
deallocate (zsort)
return
end
c
c
c #############################################################
c ## ##
c ## subroutine egauss0c -- Gaussian vdw energy via list ##
c ## ##
c #############################################################
c
c
c "egauss0c" calculates the Gaussian expansion van der Waals
c energy using a pairwise neighbor list
c
c
subroutine egauss0c
use atomid
use atoms
use bound
use couple
use energi
use group
use neigh
use shunt
use usage
use vdw
use vdwpot
implicit none
integer i,j,k
integer ii,iv,it
integer kk,kv,kt
integer, allocatable :: iv14(:)
real*8 e,eps,rdn
real*8 rad2,fgrp
real*8 xi,yi,zi
real*8 xr,yr,zr
real*8 rik,rik2,rik3
real*8 rik4,rik5,taper
real*8 expcut,expterm
real*8 a(maxgauss)
real*8 b(maxgauss)
real*8, allocatable :: vscale(:)
logical proceed,usei
character*6 mode
c
c
c zero out the van der Waals energy contribution
c
ev = 0.0d0
if (nvdw .eq. 0) return
c
c perform dynamic allocation of some local arrays
c
allocate (iv14(n))
allocate (vscale(n))
c
c set arrays needed to scale connected atom interactions
c
do i = 1, n
iv14(i) = 0
vscale(i) = 1.0d0
end do
c
c set cutoff distances and switching function coefficients
c
mode = 'VDW'
call switch (mode)
expcut = -50.0d0
c
c apply any reduction factor to the atomic coordinates
c
do k = 1, nvdw
i = ivdw(k)
iv = ired(i)
rdn = kred(i)
xred(i) = rdn*(x(i)-x(iv)) + x(iv)
yred(i) = rdn*(y(i)-y(iv)) + y(iv)
zred(i) = rdn*(z(i)-z(iv)) + z(iv)
end do
c
c OpenMP directives for the major loop structure
c
!$OMP PARALLEL default(private) shared(nvdw,ivdw,jvdw,ired,
!$OMP& kred,xred,yred,zred,use,nvlst,vlst,n12,n13,n14,n15,
!$OMP& i12,i13,i14,i15,v2scale,v3scale,v4scale,v5scale,
!$OMP& use_group,off2,radmin,epsilon,radmin4,epsilon4,ngauss,
!$OMP& igauss,expcut,cut2,c0,c1,c2,c3,c4,c5)
!$OMP& firstprivate(vscale,iv14) shared(ev)
!$OMP DO reduction(+:ev) schedule(guided)
c
c find the van der Waals energy via neighbor list search
c
do ii = 1, nvdw
i = ivdw(ii)
iv = ired(i)
it = jvdw(i)
xi = xred(i)
yi = yred(i)
zi = zred(i)
usei = (use(i) .or. use(iv))
c
c set exclusion coefficients for connected atoms
c
do j = 1, n12(i)
vscale(i12(j,i)) = v2scale
end do
do j = 1, n13(i)
vscale(i13(j,i)) = v3scale
end do
do j = 1, n14(i)
vscale(i14(j,i)) = v4scale
iv14(i14(j,i)) = i
end do
do j = 1, n15(i)
vscale(i15(j,i)) = v5scale
end do
c
c decide whether to compute the current interaction
c
do kk = 1, nvlst(ii)
k = ivdw(vlst(kk,ii))
kv = ired(k)
proceed = .true.
if (use_group) call groups (proceed,fgrp,i,k,0,0,0,0)
if (proceed) proceed = (usei .or. use(k) .or. use(kv))
c
c compute the energy contribution for this interaction
c
if (proceed) then
kt = jvdw(k)
xr = xi - xred(k)
yr = yi - yred(k)
zr = zi - zred(k)
call image (xr,yr,zr)
rik2 = xr*xr + yr*yr + zr*zr
c
c check for an interaction distance less than the cutoff
c
if (rik2 .le. off2) then
rad2 = radmin(kt,it)**2
eps = epsilon(kt,it)
if (iv14(k) .eq. i) then
rad2 = radmin4(kt,it)**2
eps = epsilon4(kt,it)
end if
eps = eps * vscale(k)
do j = 1, ngauss
a(j) = igauss(1,j) * eps
b(j) = igauss(2,j) / rad2
end do
e = 0.0d0
do j = 1, ngauss
expterm = -b(j) * rik2
if (expterm .gt. expcut)
& e = e + a(j)*exp(expterm)
end do
c
c use energy switching if near the cutoff distance
c
if (rik2 .gt. cut2) then
rik = sqrt(rik2)
rik3 = rik2 * rik
rik4 = rik2 * rik2
rik5 = rik2 * rik3
taper = c5*rik5 + c4*rik4 + c3*rik3
& + c2*rik2 + c1*rik + c0
e = e * taper
end if
c
c scale the interaction based on its group membership
c
if (use_group) e = e * fgrp
c
c increment the overall van der Waals energy components
c
ev = ev + e
end if
end if
end do
c
c reset exclusion coefficients for connected atoms
c
do j = 1, n12(i)
vscale(i12(j,i)) = 1.0d0
end do
do j = 1, n13(i)
vscale(i13(j,i)) = 1.0d0
end do
do j = 1, n14(i)
vscale(i14(j,i)) = 1.0d0
end do
do j = 1, n15(i)
vscale(i15(j,i)) = 1.0d0
end do
end do
c
c OpenMP directives for the major loop structure
c
!$OMP END DO
!$OMP END PARALLEL
c
c perform deallocation of some local arrays
c
deallocate (iv14)
deallocate (vscale)
return
end
c
c
c ##################################################################
c ## ##
c ## subroutine egauss0d -- Gaussian vdw energy for smoothing ##
c ## ##
c ##################################################################
c
c
c "egauss0d" calculates the Gaussian expansion van der Waals
c energy for use with potential energy smoothing
c
c
subroutine egauss0d
use atomid
use atoms
use couple
use energi
use group
use math
use usage
use vdw
use vdwpot
use warp
implicit none
integer i,j,k,ii,kk
integer iv,kv,it,kt
integer, allocatable :: iv14(:)
real*8 e,rik,rik2,rdn
real*8 eps,rad2,fgrp
real*8 xi,yi,zi
real*8 xr,yr,zr
real*8 erf,expcut,broot
real*8 expterm,expterm2
real*8 width,wterm
real*8 t1,t2,term
real*8 a(maxgauss)
real*8 b(maxgauss)
real*8, allocatable :: vscale(:)
logical proceed,usei
external erf
c
c
c zero out the van der Waals energy contribution
c
ev = 0.0d0
if (nvdw .eq. 0) return
c
c perform dynamic allocation of some local arrays
c
allocate (iv14(n))
allocate (vscale(n))
c
c set arrays needed to scale connected atom interactions
c
do i = 1, n
iv14(i) = 0
vscale(i) = 1.0d0
end do
c
c set the extent of smoothing to be performed
c
expcut = -50.0d0
width = 0.0d0
if (use_dem) then
width = 4.0d0 * diffv * deform
else if (use_gda) then
wterm = (2.0d0/3.0d0) * diffv
else if (use_tophat) then
width = max(diffv*deform,0.0001d0)
end if
c
c apply any reduction factor to the atomic coordinates
c
do k = 1, nvdw
i = ivdw(k)
iv = ired(i)
rdn = kred(i)
xred(i) = rdn*(x(i)-x(iv)) + x(iv)
yred(i) = rdn*(y(i)-y(iv)) + y(iv)
zred(i) = rdn*(z(i)-z(iv)) + z(iv)
end do
c
c find the van der Waals energy via double loop search
c
do ii = 1, nvdw-1
i = ivdw(ii)
iv = ired(i)
it = jvdw(i)
xi = xred(i)
yi = yred(i)
zi = zred(i)
usei = (use(i) .or. use(iv))
c
c set exclusion coefficients for connected atoms
c
do j = 1, n12(i)
vscale(i12(j,i)) = v2scale
end do
do j = 1, n13(i)
vscale(i13(j,i)) = v3scale
end do
do j = 1, n14(i)
vscale(i14(j,i)) = v4scale
iv14(i14(j,i)) = i
end do
do j = 1, n15(i)
vscale(i15(j,i)) = v5scale
end do
c
c decide whether to compute the current interaction
c
do kk = ii+1, nvdw
k = ivdw(kk)
kv = ired(k)
proceed = .true.
if (use_group) call groups (proceed,fgrp,i,k,0,0,0,0)
if (proceed) proceed = (usei .or. use(k) .or. use(kv))
c
c compute the energy contribution for this interaction
c
if (proceed) then
kt = jvdw(k)
xr = xi - xred(k)
yr = yi - yred(k)
zr = zi - zred(k)
rik2 = xr*xr + yr*yr + zr*zr
c
c check for an interaction distance less than the cutoff
c
rad2 = radmin(kt,it)**2
eps = epsilon(kt,it)
if (iv14(k) .eq. i) then
rad2 = radmin4(kt,it)**2
eps = epsilon4(kt,it)
end if
eps = eps * vscale(k)
do j = 1, ngauss
a(j) = igauss(1,j) * eps
b(j) = igauss(2,j) / rad2
end do
e = 0.0d0
c
c transform the potential function via smoothing
c
if (use_tophat) then
rik = sqrt(rik2)
do j = 1, ngauss
broot = sqrt(b(j))
expterm = -b(j) * (rik+width)**2
if (expterm .gt. expcut) then
expterm = exp(expterm)
else
expterm = 0.0d0
end if
expterm2 = -b(j) * (width-rik)**2
if (expterm2 .gt. expcut) then
expterm2 = exp(expterm2)
else
expterm2 = 0.0d0
end if
term = broot * (expterm-expterm2)
term = term + rootpi*b(j)*rik
& * (erf(broot*(rik+width))
& +erf(broot*(width-rik)))
e = e + term*a(j)/(b(j)*b(j)*broot)
end do
e = e * 3.0d0/(8.0d0*rik*width**3)
else
if (use_gda) width = wterm * (m2(i)+m2(k))
do j = 1, ngauss
t1 = 1.0d0 + b(j)*width
t2 = sqrt(t1**3)
expterm = -b(j) * rik2 / t1
if (expterm .gt. expcut)
& e = e + (a(j)/t2)*exp(expterm)
end do
end if
c
c scale the interaction based on its group membership
c
if (use_group) e = e * fgrp
c
c increment the overall van der Waals energy components
c