ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/UseTheForce/DarkSide/electrostatic.F90
(Generate patch)

Comparing trunk/OOPSE-4/src/UseTheForce/DarkSide/electrostatic.F90 (file contents):
Revision 2302 by chrisfen, Fri Sep 16 16:07:39 2005 UTC vs.
Revision 2722 by gezelter, Thu Apr 20 18:24:24 2006 UTC

# Line 47 | Line 47 | module electrostatic_module
47    use vector_class
48    use simulation
49    use status
50 +  use interpolation
51   #ifdef IS_MPI
52    use mpiSimulation
53   #endif
# Line 54 | Line 55 | module electrostatic_module
55  
56    PRIVATE
57  
58 +
59   #define __FORTRAN90
60 + #include "UseTheForce/DarkSide/fInteractionMap.h"
61   #include "UseTheForce/DarkSide/fElectrostaticSummationMethod.h"
62 + #include "UseTheForce/DarkSide/fElectrostaticScreeningMethod.h"
63  
64 +
65    !! these prefactors convert the multipole interactions into kcal / mol
66    !! all were computed assuming distances are measured in angstroms
67    !! Charge-Charge, assuming charges are measured in electrons
68 <  real(kind=dp), parameter :: pre11 = 332.0637778_dp
68 >  real(kind=dp), parameter :: pre11 = 332.0637778d0
69    !! Charge-Dipole, assuming charges are measured in electrons, and
70    !! dipoles are measured in debyes
71 <  real(kind=dp), parameter :: pre12 = 69.13373_dp
71 >  real(kind=dp), parameter :: pre12 = 69.13373d0
72    !! Dipole-Dipole, assuming dipoles are measured in debyes
73 <  real(kind=dp), parameter :: pre22 = 14.39325_dp
73 >  real(kind=dp), parameter :: pre22 = 14.39325d0
74    !! Charge-Quadrupole, assuming charges are measured in electrons, and
75    !! quadrupoles are measured in 10^-26 esu cm^2
76    !! This unit is also known affectionately as an esu centi-barn.
77 <  real(kind=dp), parameter :: pre14 = 69.13373_dp
77 >  real(kind=dp), parameter :: pre14 = 69.13373d0
78  
79 <  !! variables to handle different summation methods for long-range electrostatics:
79 >  real(kind=dp), parameter :: zero = 0.0d0
80 >
81 >  !! variables to handle different summation methods for long-range
82 >  !! electrostatics:
83    integer, save :: summationMethod = NONE
84 +  integer, save :: screeningMethod = UNDAMPED
85    logical, save :: summationMethodChecked = .false.
86    real(kind=DP), save :: defaultCutoff = 0.0_DP
87 +  real(kind=DP), save :: defaultCutoff2 = 0.0_DP
88    logical, save :: haveDefaultCutoff = .false.
89    real(kind=DP), save :: dampingAlpha = 0.0_DP
90 +  real(kind=DP), save :: alpha2 = 0.0_DP
91    logical, save :: haveDampingAlpha = .false.
92 <  real(kind=DP), save :: dielectric = 0.0_DP
92 >  real(kind=DP), save :: dielectric = 1.0_DP
93    logical, save :: haveDielectric = .false.
83  real(kind=DP), save :: constERFC = 0.0_DP
94    real(kind=DP), save :: constEXP = 0.0_DP
95 <  logical, save :: haveDWAconstants = .false.
95 >  real(kind=dp), save :: rcuti = 0.0_DP
96 >  real(kind=dp), save :: rcuti2 = 0.0_DP
97 >  real(kind=dp), save :: rcuti3 = 0.0_DP
98 >  real(kind=dp), save :: rcuti4 = 0.0_DP
99 >  real(kind=dp), save :: alphaPi = 0.0_DP
100 >  real(kind=dp), save :: invRootPi = 0.0_DP
101 >  real(kind=dp), save :: rrf = 1.0_DP
102 >  real(kind=dp), save :: rt = 1.0_DP
103 >  real(kind=dp), save :: rrfsq = 1.0_DP
104 >  real(kind=dp), save :: preRF = 0.0_DP
105 >  real(kind=dp), save :: preRF2 = 0.0_DP
106 >  real(kind=dp), save :: f0 = 1.0_DP
107 >  real(kind=dp), save :: f1 = 1.0_DP
108 >  real(kind=dp), save :: f2 = 0.0_DP
109 >  real(kind=dp), save :: f3 = 0.0_DP
110 >  real(kind=dp), save :: f4 = 0.0_DP
111 >  real(kind=dp), save :: f0c = 1.0_DP
112 >  real(kind=dp), save :: f1c = 1.0_DP
113 >  real(kind=dp), save :: f2c = 0.0_DP
114 >  real(kind=dp), save :: f3c = 0.0_DP
115 >  real(kind=dp), save :: f4c = 0.0_DP
116  
117 <
117 > #if defined(__IFC) || defined(__PGI)
118 > ! error function for ifc version > 7.
119 >  double precision, external :: derfc
120 > #endif
121 >  
122    public :: setElectrostaticSummationMethod
123 +  public :: setScreeningMethod
124    public :: setElectrostaticCutoffRadius
125 <  public :: setDampedWolfAlpha
125 >  public :: setDampingAlpha
126    public :: setReactionFieldDielectric
127 +  public :: buildElectroSplines
128    public :: newElectrostaticType
129    public :: setCharge
130    public :: setDipoleMoment
# Line 97 | Line 133 | module electrostatic_module
133    public :: doElectrostaticPair
134    public :: getCharge
135    public :: getDipoleMoment
100  public :: pre22
136    public :: destroyElectrostaticTypes
137 +  public :: self_self
138 +  public :: rf_self_excludes
139  
140 +
141    type :: Electrostatic
142       integer :: c_ident
143       logical :: is_Charge = .false.
# Line 115 | Line 153 | contains
153  
154    type(Electrostatic), dimension(:), allocatable :: ElectrostaticMap
155  
156 +  logical, save :: hasElectrostaticMap
157 +
158   contains
159  
160    subroutine setElectrostaticSummationMethod(the_ESM)
121
161      integer, intent(in) :: the_ESM    
162  
163      if ((the_ESM .le. 0) .or. (the_ESM .gt. REACTION_FIELD)) then
164         call handleError("setElectrostaticSummationMethod", "Unsupported Summation Method")
165      endif
166  
167 +    summationMethod = the_ESM
168 +
169    end subroutine setElectrostaticSummationMethod
170  
171 <  subroutine setElectrostaticCutoffRadius(thisRcut)
171 >  subroutine setScreeningMethod(the_SM)
172 >    integer, intent(in) :: the_SM    
173 >    screeningMethod = the_SM
174 >  end subroutine setScreeningMethod
175 >
176 >  subroutine setElectrostaticCutoffRadius(thisRcut, thisRsw)
177      real(kind=dp), intent(in) :: thisRcut
178 +    real(kind=dp), intent(in) :: thisRsw
179      defaultCutoff = thisRcut
180 +    defaultCutoff2 = defaultCutoff*defaultCutoff
181 +    rrf = defaultCutoff
182 +    rt = thisRsw
183      haveDefaultCutoff = .true.
184    end subroutine setElectrostaticCutoffRadius
185  
186 <  subroutine setDampedWolfAlpha(thisAlpha)
186 >  subroutine setDampingAlpha(thisAlpha)
187      real(kind=dp), intent(in) :: thisAlpha
188      dampingAlpha = thisAlpha
189 +    alpha2 = dampingAlpha*dampingAlpha
190      haveDampingAlpha = .true.
191 <  end subroutine setDampedWolfAlpha
191 >  end subroutine setDampingAlpha
192    
193    subroutine setReactionFieldDielectric(thisDielectric)
194      real(kind=dp), intent(in) :: thisDielectric
# Line 145 | Line 196 | contains
196      haveDielectric = .true.
197    end subroutine setReactionFieldDielectric
198  
199 +  subroutine buildElectroSplines()
200 +  end subroutine buildElectroSplines
201 +
202    subroutine newElectrostaticType(c_ident, is_Charge, is_Dipole, &
203         is_SplitDipole, is_Quadrupole, is_Tap, status)
204  
# Line 172 | Line 226 | contains
226            return
227         end if
228  
229 <       if (.not. allocated(ElectrostaticMap)) then
176 <          allocate(ElectrostaticMap(nAtypes))
177 <       endif
229 >       allocate(ElectrostaticMap(nAtypes))
230  
231      end if
232  
# Line 192 | Line 244 | contains
244      ElectrostaticMap(myATID)%is_Quadrupole = is_Quadrupole
245      ElectrostaticMap(myATID)%is_Tap = is_Tap
246  
247 +    hasElectrostaticMap = .true.
248 +
249    end subroutine newElectrostaticType
250  
251    subroutine setCharge(c_ident, charge, status)
# Line 203 | Line 257 | contains
257      status = 0
258      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
259  
260 <    if (.not.allocated(ElectrostaticMap)) then
260 >    if (.not.hasElectrostaticMap) then
261         call handleError("electrostatic", "no ElectrostaticMap was present before first call of setCharge!")
262         status = -1
263         return
# Line 233 | Line 287 | contains
287      status = 0
288      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
289  
290 <    if (.not.allocated(ElectrostaticMap)) then
290 >    if (.not.hasElectrostaticMap) then
291         call handleError("electrostatic", "no ElectrostaticMap was present before first call of setDipoleMoment!")
292         status = -1
293         return
# Line 263 | Line 317 | contains
317      status = 0
318      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
319  
320 <    if (.not.allocated(ElectrostaticMap)) then
320 >    if (.not.hasElectrostaticMap) then
321         call handleError("electrostatic", "no ElectrostaticMap was present before first call of setSplitDipoleDistance!")
322         status = -1
323         return
# Line 293 | Line 347 | contains
347      status = 0
348      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
349  
350 <    if (.not.allocated(ElectrostaticMap)) then
350 >    if (.not.hasElectrostaticMap) then
351         call handleError("electrostatic", "no ElectrostaticMap was present before first call of setQuadrupoleMoments!")
352         status = -1
353         return
# Line 324 | Line 378 | contains
378      integer :: localError
379      real(kind=dp) :: c
380  
381 <    if (.not.allocated(ElectrostaticMap)) then
381 >    if (.not.hasElectrostaticMap) then
382         call handleError("electrostatic", "no ElectrostaticMap was present before first call of getCharge!")
383         return
384      end if
# Line 342 | Line 396 | contains
396      integer :: localError
397      real(kind=dp) :: dm
398  
399 <    if (.not.allocated(ElectrostaticMap)) then
399 >    if (.not.hasElectrostaticMap) then
400         call handleError("electrostatic", "no ElectrostaticMap was present before first call of getDipoleMoment!")
401         return
402      end if
# Line 357 | Line 411 | contains
411  
412    subroutine checkSummationMethod()
413  
414 <    if (summationMethod .eq. DAMPED_WOLF) then
415 <       if (.not.haveDWAconstants) then
416 <          
363 <          if (.not.haveDampingAlpha) then
364 <             call handleError("checkSummationMethod", "no Damping Alpha set!")
365 <          endif
366 <          
367 <          if (.not.haveDefaultCutoff) then
368 <             call handleError("checkSummationMethod", "no Default Cutoff set!")
369 <          endif
414 >    if (.not.haveDefaultCutoff) then
415 >       call handleError("checkSummationMethod", "no Default Cutoff set!")
416 >    endif
417  
418 <          constEXP = exp(-dampingAlpha*dampingAlpha*defaultCutoff*defaultCutoff)
419 <          constERFC = erfc(dampingAlpha*defaultCutoff)
420 <          
421 <          haveDWAconstants = .true.
418 >    rcuti = 1.0d0 / defaultCutoff
419 >    rcuti2 = rcuti*rcuti
420 >    rcuti3 = rcuti2*rcuti
421 >    rcuti4 = rcuti2*rcuti2
422 >
423 >    if (screeningMethod .eq. DAMPED) then
424 >       if (.not.haveDampingAlpha) then
425 >          call handleError("checkSummationMethod", "no Damping Alpha set!")
426         endif
427 +      
428 +       if (.not.haveDefaultCutoff) then
429 +          call handleError("checkSummationMethod", "no Default Cutoff set!")
430 +       endif
431 +
432 +       constEXP = exp(-alpha2*defaultCutoff2)
433 +       invRootPi = 0.56418958354775628695d0
434 +       alphaPi = 2.0d0*dampingAlpha*invRootPi
435 +       f0c = derfc(dampingAlpha*defaultCutoff)
436 +       f1c = alphaPi*defaultCutoff*constEXP + f0c
437 +       f2c = alphaPi*2.0d0*alpha2*constEXP
438 +       f3c = alphaPi*2.0d0*alpha2*constEXP*defaultCutoff2*defaultCutoff
439      endif
440  
441      if (summationMethod .eq. REACTION_FIELD) then
442 <       if (.not.haveDielectric) then
443 <          call handleError("checkSummationMethod", "no reaction field Dielectric set!")
442 >       if (haveDielectric) then
443 >          defaultCutoff2 = defaultCutoff*defaultCutoff
444 >          preRF = (dielectric-1.0d0) / &
445 >               ((2.0d0*dielectric+1.0d0)*defaultCutoff2*defaultCutoff)
446 >          preRF2 = 2.0d0*preRF
447 >       else
448 >          call handleError("checkSummationMethod", "Dielectric not set")
449         endif
450 +      
451      endif
452  
453      summationMethodChecked = .true.
454    end subroutine checkSummationMethod
455  
456  
457 +  subroutine doElectrostaticPair(atom1, atom2, d, rij, r2, rcut, sw, &
458 +       vpair, fpair, pot, eFrame, f, t, do_pot)
459  
389  subroutine doElectrostaticPair(atom1, atom2, d, rij, r2, sw, &
390       vpair, fpair, pot, eFrame, f, t, do_pot, corrMethod, rcuti)
391
460      logical, intent(in) :: do_pot
461  
462      integer, intent(in) :: atom1, atom2
463      integer :: localError
396    integer, intent(in) :: corrMethod
464  
465 <    real(kind=dp), intent(in) :: rij, r2, sw, rcuti
465 >    real(kind=dp), intent(in) :: rij, r2, sw, rcut
466      real(kind=dp), intent(in), dimension(3) :: d
467      real(kind=dp), intent(inout) :: vpair
468 <    real(kind=dp), intent(inout), dimension(3) :: fpair
468 >    real(kind=dp), intent(inout), dimension(3) :: fpair    
469  
470 <    real( kind = dp ) :: pot, swi
470 >    real( kind = dp ) :: pot
471      real( kind = dp ), dimension(9,nLocal) :: eFrame
472      real( kind = dp ), dimension(3,nLocal) :: f
473 +    real( kind = dp ), dimension(3,nLocal) :: felec
474      real( kind = dp ), dimension(3,nLocal) :: t
475  
476      real (kind = dp), dimension(3) :: ux_i, uy_i, uz_i
# Line 420 | Line 488 | contains
488      real (kind=dp) :: cx_i, cy_i, cz_i
489      real (kind=dp) :: cx_j, cy_j, cz_j
490      real (kind=dp) :: cx2, cy2, cz2
491 <    real (kind=dp) :: ct_i, ct_j, ct_ij, a1
491 >    real (kind=dp) :: ct_i, ct_j, ct_ij, a0, a1
492      real (kind=dp) :: riji, ri, ri2, ri3, ri4
493      real (kind=dp) :: pref, vterm, epot, dudr, vterm1, vterm2
494      real (kind=dp) :: xhat, yhat, zhat
495      real (kind=dp) :: dudx, dudy, dudz
496 <    real (kind=dp) :: scale, sc2, bigR, switcher, dswitcher
497 <    real (kind=dp) :: rcuti2, rcuti3, rcuti4
496 >    real (kind=dp) :: scale, sc2, bigR
497 >    real (kind=dp) :: varEXP
498 >    real (kind=dp) :: pot_term
499 >    real (kind=dp) :: preVal, rfVal
500 >    real (kind=dp) :: f13, f134
501  
431    if (.not.allocated(ElectrostaticMap)) then
432       call handleError("electrostatic", "no ElectrostaticMap was present before first call of do_electrostatic_pair!")
433       return
434    end if
435
502      if (.not.summationMethodChecked) then
503         call checkSummationMethod()
504      endif
505  
440
506   #ifdef IS_MPI
507      me1 = atid_Row(atom1)
508      me2 = atid_Col(atom2)
# Line 449 | Line 514 | contains
514      !! some variables we'll need independent of electrostatic type:
515  
516      riji = 1.0d0 / rij
517 <
517 >  
518      xhat = d(1) * riji
519      yhat = d(2) * riji
520      zhat = d(3) * riji
521  
457    rcuti2 = rcuti*rcuti
458    rcuti3 = rcuti2*rcuti
459    rcuti4 = rcuti2*rcuti2
460
461    swi = 1.0d0 / sw
462
522      !! logicals
523      i_is_Charge = ElectrostaticMap(me1)%is_Charge
524      i_is_Dipole = ElectrostaticMap(me1)%is_Dipole
# Line 493 | Line 552 | contains
552         if (i_is_SplitDipole) then
553            d_i = ElectrostaticMap(me1)%split_dipole_distance
554         endif
555 <
555 >       duduz_i = zero
556      endif
557  
558      if (i_is_Quadrupole) then
# Line 524 | Line 583 | contains
583         cx_i = ux_i(1)*xhat + ux_i(2)*yhat + ux_i(3)*zhat
584         cy_i = uy_i(1)*xhat + uy_i(2)*yhat + uy_i(3)*zhat
585         cz_i = uz_i(1)*xhat + uz_i(2)*yhat + uz_i(3)*zhat
586 +       dudux_i = zero
587 +       duduy_i = zero
588 +       duduz_i = zero
589      endif
590  
591      if (j_is_Charge) then
# Line 546 | Line 608 | contains
608         if (j_is_SplitDipole) then
609            d_j = ElectrostaticMap(me2)%split_dipole_distance
610         endif
611 +       duduz_j = zero
612      endif
613  
614      if (j_is_Quadrupole) then
# Line 576 | Line 639 | contains
639         cx_j = ux_j(1)*xhat + ux_j(2)*yhat + ux_j(3)*zhat
640         cy_j = uy_j(1)*xhat + uy_j(2)*yhat + uy_j(3)*zhat
641         cz_j = uz_j(1)*xhat + uz_j(2)*yhat + uz_j(3)*zhat
642 +       dudux_j = zero
643 +       duduy_j = zero
644 +       duduz_j = zero
645      endif
646    
647 < !!$    switcher = 1.0d0
648 < !!$    dswitcher = 0.0d0
649 < !!$    ebalance = 0.0d0
650 < !!$    ! weaken the dipole interaction at close range for TAP water
585 < !!$    if (j_is_Tap .and. i_is_Tap) then
586 < !!$      call calc_switch(rij, mu_i, switcher, dswitcher)
587 < !!$    endif
647 >    epot = zero
648 >    dudx = zero
649 >    dudy = zero
650 >    dudz = zero  
651  
589    epot = 0.0_dp
590    dudx = 0.0_dp
591    dudy = 0.0_dp
592    dudz = 0.0_dp
593
594    dudux_i = 0.0_dp
595    duduy_i = 0.0_dp
596    duduz_i = 0.0_dp
597
598    dudux_j = 0.0_dp
599    duduy_j = 0.0_dp
600    duduz_j = 0.0_dp
601
652      if (i_is_Charge) then
653  
654         if (j_is_Charge) then
655 +          if (screeningMethod .eq. DAMPED) then
656 +             f0 = derfc(dampingAlpha*rij)
657 +             varEXP = exp(-alpha2*rij*rij)
658 +             f1 = alphaPi*rij*varEXP + f0
659 +          endif
660  
661 <          if (corrMethod .eq. 1) then
607 <             vterm = pre11 * q_i * q_j * (riji - rcuti)
661 >          preVal = pre11 * q_i * q_j
662  
663 <             vpair = vpair + vterm
664 <             epot = epot + sw * vterm
663 >          if (summationMethod .eq. SHIFTED_POTENTIAL) then
664 >             vterm = preVal * (riji*f0 - rcuti*f0c)
665              
666 <             dudr  = - sw * pre11 * q_i * q_j * (riji*riji*riji - rcuti2*rcuti)
666 >             dudr  = -sw * preVal * riji * riji * f1
667 >  
668 >          elseif (summationMethod .eq. SHIFTED_FORCE) then
669 >             vterm = preVal * ( riji*f0 - rcuti*f0c + &
670 >                  f1c*rcuti2*(rij-defaultCutoff) )
671              
672 <             dudx = dudx + dudr * d(1)
673 <             dudy = dudy + dudr * d(2)
674 <             dudz = dudz + dudr * d(3)
675 <
672 >             dudr  = -sw*preVal * (riji*riji*f1 - rcuti2*f1c)
673 >  
674 >          elseif (summationMethod .eq. REACTION_FIELD) then
675 >             rfVal = preRF*rij*rij
676 >             vterm = preVal * ( riji + rfVal )
677 >            
678 >             dudr  = sw * preVal * ( 2.0d0*rfVal - riji )*riji
679 >  
680            else
681 <             vterm = pre11 * q_i * q_j * riji
620 <
621 <             vpair = vpair + vterm
622 <             epot = epot + sw * vterm
681 >             vterm = preVal * riji*f0
682              
683 <             dudr  = - sw * vterm * riji
684 <            
626 <             dudx = dudx + dudr * xhat
627 <             dudy = dudy + dudr * yhat
628 <             dudz = dudz + dudr * zhat
629 <
683 >             dudr  = - sw * preVal * riji*riji*f1
684 >  
685            endif
686  
687 +          vpair = vpair + vterm
688 +          epot = epot + sw*vterm
689 +
690 +          dudx = dudx + dudr * xhat
691 +          dudy = dudy + dudr * yhat
692 +          dudz = dudz + dudr * zhat
693 +
694         endif
695  
696         if (j_is_Dipole) then
697 +          if (screeningMethod .eq. DAMPED) then
698 +             f0 = derfc(dampingAlpha*rij)
699 +             varEXP = exp(-alpha2*rij*rij)
700 +             f1 = alphaPi*rij*varEXP + f0
701 +             f3 = alphaPi*2.0d0*alpha2*varEXP*rij*rij*rij
702 +          endif
703  
704 <          pref = sw * pre12 * q_i * mu_j
704 >          pref = pre12 * q_i * mu_j
705  
706 <          if (corrMethod .eq. 1) then
706 >          if (summationMethod .eq. REACTION_FIELD) then
707               ri2 = riji * riji
708               ri3 = ri2 * riji
709 <
710 <             vterm = - pref * ct_j * (ri2 - rcuti2)
711 <             vpair = vpair + swi*vterm
712 <             epot = epot + vterm
709 >    
710 >             vterm = - pref * ct_j * ( ri2 - preRF2*rij )
711 >             vpair = vpair + vterm
712 >             epot = epot + sw*vterm
713              
714               !! this has a + sign in the () because the rij vector is
715               !! r_j - r_i and the charge-dipole potential takes the origin
716               !! as the point dipole, which is atom j in this case.
717              
718 <             dudx = dudx - pref * ( ri3*( uz_j(1) - 3.0d0*ct_j*xhat) &
719 <                  - rcuti3*( uz_j(1) - 3.0d0*ct_j*d(1)*rcuti ) )
720 <             dudy = dudy - pref * ( ri3*( uz_j(2) - 3.0d0*ct_j*yhat) &
721 <                  - rcuti3*( uz_j(2) - 3.0d0*ct_j*d(2)*rcuti ) )
722 <             dudz = dudz - pref * ( ri3*( uz_j(3) - 3.0d0*ct_j*zhat) &
723 <                  - rcuti3*( uz_j(3) - 3.0d0*ct_j*d(3)*rcuti ) )
724 <            
725 <             duduz_j(1) = duduz_j(1) - pref*( ri2*xhat - d(1)*rcuti3 )
726 <             duduz_j(2) = duduz_j(2) - pref*( ri2*yhat - d(2)*rcuti3 )
659 <             duduz_j(3) = duduz_j(3) - pref*( ri2*zhat - d(3)*rcuti3 )
718 >             dudx = dudx - sw*pref*( ri3*(uz_j(1) - 3.0d0*ct_j*xhat) - &
719 >                                     preRF2*uz_j(1) )
720 >             dudy = dudy - sw*pref*( ri3*(uz_j(2) - 3.0d0*ct_j*yhat) - &
721 >                                     preRF2*uz_j(2) )
722 >             dudz = dudz - sw*pref*( ri3*(uz_j(3) - 3.0d0*ct_j*zhat) - &
723 >                                     preRF2*uz_j(3) )        
724 >             duduz_j(1) = duduz_j(1) - sw*pref * xhat * ( ri2 - preRF2*rij )
725 >             duduz_j(2) = duduz_j(2) - sw*pref * yhat * ( ri2 - preRF2*rij )
726 >             duduz_j(3) = duduz_j(3) - sw*pref * zhat * ( ri2 - preRF2*rij )
727  
728            else
729               if (j_is_SplitDipole) then
730 <                BigR = sqrt(r2 + 0.25_dp * d_j * d_j)
731 <                ri = 1.0_dp / BigR
730 >                BigR = sqrt(r2 + 0.25d0 * d_j * d_j)
731 >                ri = 1.0d0 / BigR
732                  scale = rij * ri
733               else
734                  ri = riji
735 <                scale = 1.0_dp
735 >                scale = 1.0d0
736               endif
737              
738               ri2 = ri * ri
739               ri3 = ri2 * ri
740               sc2 = scale * scale
741 +
742 +             pot_term =  ri2 * scale * f1
743 +             vterm = - pref * ct_j * pot_term
744 +             vpair = vpair + vterm
745 +             epot = epot + sw*vterm
746              
675             vterm = - pref * ct_j * ri2 * scale
676             vpair = vpair + swi * vterm
677             epot = epot + vterm
678            
747               !! this has a + sign in the () because the rij vector is
748               !! r_j - r_i and the charge-dipole potential takes the origin
749               !! as the point dipole, which is atom j in this case.
750              
751 <             dudx = dudx - pref * ri3 * ( uz_j(1) - 3.0d0*ct_j*xhat*sc2)
752 <             dudy = dudy - pref * ri3 * ( uz_j(2) - 3.0d0*ct_j*yhat*sc2)
753 <             dudz = dudz - pref * ri3 * ( uz_j(3) - 3.0d0*ct_j*zhat*sc2)
754 <            
755 <             duduz_j(1) = duduz_j(1) - pref * ri2 * xhat * scale
756 <             duduz_j(2) = duduz_j(2) - pref * ri2 * yhat * scale
757 <             duduz_j(3) = duduz_j(3) - pref * ri2 * zhat * scale
751 >             dudx = dudx - sw*pref * ri3 * ( uz_j(1)*f1 - &
752 >                  ct_j*xhat*sc2*( 3.0d0*f1 + f3 ) )
753 >             dudy = dudy - sw*pref * ri3 * ( uz_j(2)*f1 - &
754 >                  ct_j*yhat*sc2*( 3.0d0*f1 + f3 ) )
755 >             dudz = dudz - sw*pref * ri3 * ( uz_j(3)*f1 - &
756 >                  ct_j*zhat*sc2*( 3.0d0*f1 + f3 ) )
757 >                          
758 >             duduz_j(1) = duduz_j(1) - sw*pref * pot_term * xhat
759 >             duduz_j(2) = duduz_j(2) - sw*pref * pot_term * yhat
760 >             duduz_j(3) = duduz_j(3) - sw*pref * pot_term * zhat
761  
762            endif
763         endif
764  
765         if (j_is_Quadrupole) then
766 +          if (screeningMethod .eq. DAMPED) then
767 +             f0 = derfc(dampingAlpha*rij)
768 +             varEXP = exp(-alpha2*rij*rij)
769 +             f1 = alphaPi*rij*varEXP + f0
770 +             f2 = alphaPi*2.0d0*alpha2*varEXP
771 +             f3 = f2*rij*rij*rij
772 +             f4 = 2.0d0*alpha2*f2*rij
773 +          endif
774 +
775            ri2 = riji * riji
776            ri3 = ri2 * riji
777            ri4 = ri2 * ri2
# Line 699 | Line 779 | contains
779            cy2 = cy_j * cy_j
780            cz2 = cz_j * cz_j
781  
782 <
783 <          pref =  sw * pre14 * q_i / 3.0_dp
784 <
785 <          if (corrMethod .eq. 1) then
786 <             vterm1 = pref * ri3*( qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
787 <                  qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
788 <                  qzz_j * (3.0_dp*cz2 - 1.0_dp) )
709 <             vterm2 = pref * rcuti3*( qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
710 <                  qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
711 <                  qzz_j * (3.0_dp*cz2 - 1.0_dp) )
712 <             vpair = vpair + swi*( vterm1 - vterm2 )
713 <             epot = epot + ( vterm1 - vterm2 )
714 <            
715 <             dudx = dudx - (5.0_dp * &
716 <                  (vterm1*riji*xhat - vterm2*rcuti2*d(1))) + pref * ( &
717 <                  (ri4 - rcuti4)*(qxx_j*(6.0_dp*cx_j*ux_j(1)) - &
718 <                  qxx_j*2.0_dp*(xhat - rcuti*d(1))) + &
719 <                  (ri4 - rcuti4)*(qyy_j*(6.0_dp*cy_j*uy_j(1)) - &
720 <                  qyy_j*2.0_dp*(xhat - rcuti*d(1))) + &
721 <                  (ri4 - rcuti4)*(qzz_j*(6.0_dp*cz_j*uz_j(1)) - &
722 <                  qzz_j*2.0_dp*(xhat - rcuti*d(1))) )
723 <             dudy = dudy - (5.0_dp * &
724 <                  (vterm1*riji*yhat - vterm2*rcuti2*d(2))) + pref * ( &
725 <                  (ri4 - rcuti4)*(qxx_j*(6.0_dp*cx_j*ux_j(2)) - &
726 <                  qxx_j*2.0_dp*(yhat - rcuti*d(2))) + &
727 <                  (ri4 - rcuti4)*(qyy_j*(6.0_dp*cy_j*uy_j(2)) - &
728 <                  qyy_j*2.0_dp*(yhat - rcuti*d(2))) + &
729 <                  (ri4 - rcuti4)*(qzz_j*(6.0_dp*cz_j*uz_j(2)) - &
730 <                  qzz_j*2.0_dp*(yhat - rcuti*d(2))) )
731 <             dudz = dudz - (5.0_dp * &
732 <                  (vterm1*riji*zhat - vterm2*rcuti2*d(3))) + pref * ( &
733 <                  (ri4 - rcuti4)*(qxx_j*(6.0_dp*cx_j*ux_j(3)) - &
734 <                  qxx_j*2.0_dp*(zhat - rcuti*d(3))) + &
735 <                  (ri4 - rcuti4)*(qyy_j*(6.0_dp*cy_j*uy_j(3)) - &
736 <                  qyy_j*2.0_dp*(zhat - rcuti*d(3))) + &
737 <                  (ri4 - rcuti4)*(qzz_j*(6.0_dp*cz_j*uz_j(3)) - &
738 <                  qzz_j*2.0_dp*(zhat - rcuti*d(3))) )
739 <            
740 <             dudux_j(1) = dudux_j(1) + pref * (ri3*(qxx_j*6.0_dp*cx_j*xhat) - &
741 <                  rcuti4*(qxx_j*6.0_dp*cx_j*d(1)))
742 <             dudux_j(2) = dudux_j(2) + pref * (ri3*(qxx_j*6.0_dp*cx_j*yhat) - &
743 <                  rcuti4*(qxx_j*6.0_dp*cx_j*d(2)))
744 <             dudux_j(3) = dudux_j(3) + pref * (ri3*(qxx_j*6.0_dp*cx_j*zhat) - &
745 <                  rcuti4*(qxx_j*6.0_dp*cx_j*d(3)))
746 <            
747 <             duduy_j(1) = duduy_j(1) + pref * (ri3*(qyy_j*6.0_dp*cy_j*xhat) - &
748 <                  rcuti4*(qyy_j*6.0_dp*cx_j*d(1)))
749 <             duduy_j(2) = duduy_j(2) + pref * (ri3*(qyy_j*6.0_dp*cy_j*yhat) - &
750 <                  rcuti4*(qyy_j*6.0_dp*cx_j*d(2)))
751 <             duduy_j(3) = duduy_j(3) + pref * (ri3*(qyy_j*6.0_dp*cy_j*zhat) - &
752 <                  rcuti4*(qyy_j*6.0_dp*cx_j*d(3)))
753 <            
754 <             duduz_j(1) = duduz_j(1) + pref * (ri3*(qzz_j*6.0_dp*cz_j*xhat) - &
755 <                  rcuti4*(qzz_j*6.0_dp*cx_j*d(1)))
756 <             duduz_j(2) = duduz_j(2) + pref * (ri3*(qzz_j*6.0_dp*cz_j*yhat) - &
757 <                  rcuti4*(qzz_j*6.0_dp*cx_j*d(2)))
758 <             duduz_j(3) = duduz_j(3) + pref * (ri3*(qzz_j*6.0_dp*cz_j*zhat) - &
759 <                  rcuti4*(qzz_j*6.0_dp*cx_j*d(3)))
760 <        
761 <          else
762 <             vterm = pref * ri3 * (qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
763 <                  qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
764 <                  qzz_j * (3.0_dp*cz2 - 1.0_dp))
765 <             vpair = vpair + swi * vterm
766 <             epot = epot + vterm
767 <            
768 <             dudx = dudx - 5.0_dp*vterm*riji*xhat + pref * ri4 * ( &
769 <                  qxx_j*(6.0_dp*cx_j*ux_j(1) - 2.0_dp*xhat) + &
770 <                  qyy_j*(6.0_dp*cy_j*uy_j(1) - 2.0_dp*xhat) + &
771 <                  qzz_j*(6.0_dp*cz_j*uz_j(1) - 2.0_dp*xhat) )
772 <             dudy = dudy - 5.0_dp*vterm*riji*yhat + pref * ri4 * ( &
773 <                  qxx_j*(6.0_dp*cx_j*ux_j(2) - 2.0_dp*yhat) + &
774 <                  qyy_j*(6.0_dp*cy_j*uy_j(2) - 2.0_dp*yhat) + &
775 <                  qzz_j*(6.0_dp*cz_j*uz_j(2) - 2.0_dp*yhat) )
776 <             dudz = dudz - 5.0_dp*vterm*riji*zhat + pref * ri4 * ( &
777 <                  qxx_j*(6.0_dp*cx_j*ux_j(3) - 2.0_dp*zhat) + &
778 <                  qyy_j*(6.0_dp*cy_j*uy_j(3) - 2.0_dp*zhat) + &
779 <                  qzz_j*(6.0_dp*cz_j*uz_j(3) - 2.0_dp*zhat) )
780 <            
781 <             dudux_j(1) = dudux_j(1) + pref * ri3*(qxx_j*6.0_dp*cx_j*xhat)
782 <             dudux_j(2) = dudux_j(2) + pref * ri3*(qxx_j*6.0_dp*cx_j*yhat)
783 <             dudux_j(3) = dudux_j(3) + pref * ri3*(qxx_j*6.0_dp*cx_j*zhat)
784 <            
785 <             duduy_j(1) = duduy_j(1) + pref * ri3*(qyy_j*6.0_dp*cy_j*xhat)
786 <             duduy_j(2) = duduy_j(2) + pref * ri3*(qyy_j*6.0_dp*cy_j*yhat)
787 <             duduy_j(3) = duduy_j(3) + pref * ri3*(qyy_j*6.0_dp*cy_j*zhat)
788 <            
789 <             duduz_j(1) = duduz_j(1) + pref * ri3*(qzz_j*6.0_dp*cz_j*xhat)
790 <             duduz_j(2) = duduz_j(2) + pref * ri3*(qzz_j*6.0_dp*cz_j*yhat)
791 <             duduz_j(3) = duduz_j(3) + pref * ri3*(qzz_j*6.0_dp*cz_j*zhat)
782 >          pref =  pre14 * q_i / 3.0d0
783 >          pot_term = ri3*(qxx_j * (3.0d0*cx2 - 1.0d0) + &
784 >               qyy_j * (3.0d0*cy2 - 1.0d0) + &
785 >               qzz_j * (3.0d0*cz2 - 1.0d0))
786 >          vterm = pref * (pot_term*f1 + (qxx_j*cx2 + qyy_j*cy2 + qzz_j*cz2)*f2)
787 >          vpair = vpair + vterm
788 >          epot = epot + sw*vterm
789            
790 <          endif
790 >          dudx = dudx - sw*pref*pot_term*riji*xhat*(5.0d0*f1 + f3) + &
791 >               sw*pref*ri4 * ( &
792 >               qxx_j*(2.0d0*cx_j*ux_j(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) + &
793 >               qyy_j*(2.0d0*cy_j*uy_j(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) + &
794 >               qzz_j*(2.0d0*cz_j*uz_j(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) ) &
795 >               + (qxx_j*cx2 + qyy_j*cy2 + qzz_j*cz2)*f4
796 >          dudy = dudy - sw*pref*pot_term*riji*yhat*(5.0d0*f1 + f3) + &
797 >               sw*pref*ri4 * ( &
798 >               qxx_j*(2.0d0*cx_j*ux_j(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) + &
799 >               qyy_j*(2.0d0*cy_j*uy_j(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) + &
800 >               qzz_j*(2.0d0*cz_j*uz_j(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) ) &
801 >               + (qxx_j*cx2 + qyy_j*cy2 + qzz_j*cz2)*f4
802 >          dudz = dudz - sw*pref*pot_term*riji*zhat*(5.0d0*f1 + f3) + &
803 >               sw*pref*ri4 * ( &
804 >               qxx_j*(2.0d0*cx_j*ux_j(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) + &
805 >               qyy_j*(2.0d0*cy_j*uy_j(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) + &
806 >               qzz_j*(2.0d0*cz_j*uz_j(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) ) &
807 >               + (qxx_j*cx2 + qyy_j*cy2 + qzz_j*cz2)*f4
808 >          
809 >          dudux_j(1) = dudux_j(1) + sw*pref*ri3*( (qxx_j*2.0d0*cx_j*xhat) &
810 >               * (3.0d0*f1 + f3) )
811 >          dudux_j(2) = dudux_j(2) + sw*pref*ri3*( (qxx_j*2.0d0*cx_j*yhat) &
812 >               * (3.0d0*f1 + f3) )
813 >          dudux_j(3) = dudux_j(3) + sw*pref*ri3*( (qxx_j*2.0d0*cx_j*zhat) &
814 >               * (3.0d0*f1 + f3) )
815 >          
816 >          duduy_j(1) = duduy_j(1) + sw*pref*ri3*( (qyy_j*2.0d0*cy_j*xhat) &
817 >               * (3.0d0*f1 + f3) )
818 >          duduy_j(2) = duduy_j(2) + sw*pref*ri3*( (qyy_j*2.0d0*cy_j*yhat) &
819 >               * (3.0d0*f1 + f3) )
820 >          duduy_j(3) = duduy_j(3) + sw*pref*ri3*( (qyy_j*2.0d0*cy_j*zhat) &
821 >               * (3.0d0*f1 + f3) )
822 >          
823 >          duduz_j(1) = duduz_j(1) + sw*pref*ri3*( (qzz_j*2.0d0*cz_j*xhat) &
824 >               * (3.0d0*f1 + f3) )
825 >          duduz_j(2) = duduz_j(2) + sw*pref*ri3*( (qzz_j*2.0d0*cz_j*yhat) &
826 >               * (3.0d0*f1 + f3) )
827 >          duduz_j(3) = duduz_j(3) + sw*pref*ri3*( (qzz_j*2.0d0*cz_j*zhat) &
828 >               * (3.0d0*f1 + f3) )
829 >          
830         endif
831      endif
832 <
832 >    
833      if (i_is_Dipole) then
834  
835         if (j_is_Charge) then
836 +          if (screeningMethod .eq. DAMPED) then
837 +             f0 = derfc(dampingAlpha*rij)
838 +             varEXP = exp(-alpha2*rij*rij)
839 +             f1 = alphaPi*rij*varEXP + f0
840 +             f3 = alphaPi*2.0d0*alpha2*varEXP*rij*rij*rij
841 +          endif
842 +          
843 +          pref = pre12 * q_j * mu_i
844 +          
845 +          if (summationMethod .eq. SHIFTED_POTENTIAL) then
846 +             ri2 = riji * riji
847 +             ri3 = ri2 * riji
848 +            
849 +             pot_term = ri2*f1 - rcuti2*f1c
850 +             vterm = pref * ct_i * pot_term
851 +             vpair = vpair + vterm
852 +             epot = epot + sw*vterm
853 +            
854 +             dudx = dudx + sw*pref*( ri3*(uz_i(1)*f1-ct_i*xhat*(3.0d0*f1+f3)) )
855 +             dudy = dudy + sw*pref*( ri3*(uz_i(2)*f1-ct_i*yhat*(3.0d0*f1+f3)) )
856 +             dudz = dudz + sw*pref*( ri3*(uz_i(3)*f1-ct_i*zhat*(3.0d0*f1+f3)) )
857 +            
858 +             duduz_i(1) = duduz_i(1) + sw*pref * xhat * pot_term
859 +             duduz_i(2) = duduz_i(2) + sw*pref * yhat * pot_term
860 +             duduz_i(3) = duduz_i(3) + sw*pref * zhat * pot_term
861  
862 <          pref = sw * pre12 * q_j * mu_i
802 <
803 <          if (corrMethod .eq. 1) then
862 >          elseif (summationMethod .eq. SHIFTED_FORCE) then
863               ri2 = riji * riji
864               ri3 = ri2 * riji
865  
866 <             vterm = pref * ct_i * (ri2 - rcuti2)
867 <             vpair = vpair + swi * vterm
868 <             epot = epot + vterm
866 >             !! might need a -(f1c-f0c) or dct_i/dr in the derivative term...
867 >             pot_term = ri2*f1 - rcuti2*f1c + &
868 >                  (2.0d0*rcuti3*f1c + f2c)*( rij - defaultCutoff )
869 >             vterm = pref * ct_i * pot_term
870 >             vpair = vpair + vterm
871 >             epot = epot + sw*vterm
872              
873 <             !! this has a + sign in the () because the rij vector is
874 <             !! r_j - r_i and the charge-dipole potential takes the origin
875 <             !! as the point dipole, which is atom j in this case.
873 >             dudx = dudx + sw*pref*( ri3*(uz_i(1)*f1-ct_i*xhat*(3.0d0*f1+f3)) &
874 >                  - rcuti3*(uz_i(1)*f1c-ct_i*xhat*(3.0d0*f1c+f3c)) )
875 >             dudy = dudy + sw*pref*( ri3*(uz_i(2)*f1-ct_i*yhat*(3.0d0*f1+f3)) &
876 >                  - rcuti3*(uz_i(1)*f1c-ct_i*xhat*(3.0d0*f1c+f3c)) )
877 >             dudz = dudz + sw*pref*( ri3*(uz_i(3)*f1-ct_i*zhat*(3.0d0*f1+f3)) &
878 >                  - rcuti3*(uz_i(1)*f1c-ct_i*xhat*(3.0d0*f1c+f3c)) )
879              
880 <             dudx = dudx + pref * ( ri3*( uz_i(1) - 3.0d0*ct_i*xhat) &
881 <                  - rcuti3*( uz_i(1) - 3.0d0*ct_i*d(1)*rcuti ) )
882 <             dudy = dudy + pref * ( ri3*( uz_i(2) - 3.0d0*ct_i*yhat) &
883 <                  - rcuti3*( uz_i(2) - 3.0d0*ct_i*d(2)*rcuti ) )
884 <             dudz = dudz + pref * ( ri3*( uz_i(3) - 3.0d0*ct_i*zhat) &
885 <                  - rcuti3*( uz_i(3) - 3.0d0*ct_i*d(3)*rcuti ) )
880 >             duduz_i(1) = duduz_i(1) + sw*pref * xhat * pot_term
881 >             duduz_i(2) = duduz_i(2) + sw*pref * yhat * pot_term
882 >             duduz_i(3) = duduz_i(3) + sw*pref * zhat * pot_term
883 >
884 >          elseif (summationMethod .eq. REACTION_FIELD) then
885 >             ri2 = riji * riji
886 >             ri3 = ri2 * riji
887 >
888 >             vterm = pref * ct_i * ( ri2 - preRF2*rij )
889 >             vpair = vpair + vterm
890 >             epot = epot + sw*vterm
891              
892 <             duduz_i(1) = duduz_i(1) - pref*( ri2*xhat - d(1)*rcuti3 )
893 <             duduz_i(2) = duduz_i(2) - pref*( ri2*yhat - d(2)*rcuti3 )
894 <             duduz_i(3) = duduz_i(3) - pref*( ri2*zhat - d(3)*rcuti3 )
892 >             dudx = dudx + sw*pref * ( ri3*(uz_i(1) - 3.0d0*ct_i*xhat) - &
893 >                  preRF2*uz_i(1) )
894 >             dudy = dudy + sw*pref * ( ri3*(uz_i(2) - 3.0d0*ct_i*yhat) - &
895 >                  preRF2*uz_i(2) )
896 >             dudz = dudz + sw*pref * ( ri3*(uz_i(3) - 3.0d0*ct_i*zhat) - &
897 >                  preRF2*uz_i(3) )
898 >            
899 >             duduz_i(1) = duduz_i(1) + sw*pref * xhat * ( ri2 - preRF2*rij )
900 >             duduz_i(2) = duduz_i(2) + sw*pref * yhat * ( ri2 - preRF2*rij )
901 >             duduz_i(3) = duduz_i(3) + sw*pref * zhat * ( ri2 - preRF2*rij )
902  
903            else
904               if (i_is_SplitDipole) then
905 <                BigR = sqrt(r2 + 0.25_dp * d_i * d_i)
906 <                ri = 1.0_dp / BigR
905 >                BigR = sqrt(r2 + 0.25d0 * d_i * d_i)
906 >                ri = 1.0d0 / BigR
907                  scale = rij * ri
908               else
909                  ri = riji
910 <                scale = 1.0_dp
910 >                scale = 1.0d0
911               endif
912              
913               ri2 = ri * ri
914               ri3 = ri2 * ri
915               sc2 = scale * scale
916 +
917 +             pot_term = ri2 * f1 * scale
918 +             vterm = pref * ct_i * pot_term
919 +             vpair = vpair + vterm
920 +             epot = epot + sw*vterm
921              
922 <             vterm = pref * ct_i * ri2 * scale
923 <             vpair = vpair + swi * vterm
924 <             epot = epot + vterm
922 >             dudx = dudx + sw*pref * ri3 * ( uz_i(1)*f1 - &
923 >                  ct_i*xhat*sc2*( 3.0d0*f1 + f3 ) )
924 >             dudy = dudy + sw*pref * ri3 * ( uz_i(2)*f1 - &
925 >                  ct_i*yhat*sc2*( 3.0d0*f1 + f3 ) )
926 >             dudz = dudz + sw*pref * ri3 * ( uz_i(3)*f1 - &
927 >                  ct_i*zhat*sc2*( 3.0d0*f1 + f3 ) )
928              
929 <             dudx = dudx + pref * ri3 * ( uz_i(1) - 3.0d0 * ct_i * xhat*sc2)
930 <             dudy = dudy + pref * ri3 * ( uz_i(2) - 3.0d0 * ct_i * yhat*sc2)
931 <             dudz = dudz + pref * ri3 * ( uz_i(3) - 3.0d0 * ct_i * zhat*sc2)
847 <            
848 <             duduz_i(1) = duduz_i(1) + pref * ri2 * xhat * scale
849 <             duduz_i(2) = duduz_i(2) + pref * ri2 * yhat * scale
850 <             duduz_i(3) = duduz_i(3) + pref * ri2 * zhat * scale
929 >             duduz_i(1) = duduz_i(1) + sw*pref * pot_term * xhat
930 >             duduz_i(2) = duduz_i(2) + sw*pref * pot_term * yhat
931 >             duduz_i(3) = duduz_i(3) + sw*pref * pot_term * zhat
932            endif
933         endif
934 <
934 >      
935         if (j_is_Dipole) then
936 +          if (screeningMethod .eq. DAMPED) then
937 +             f0 = derfc(dampingAlpha*rij)
938 +             varEXP = exp(-alpha2*rij*rij)
939 +             f1 = alphaPi*rij*varEXP + f0
940 +             f2 = alphaPi*2.0d0*alpha2*varEXP
941 +             f3 = f2*rij*rij*rij
942 +             f4 = 2.0d0*alpha2*f3*rij*rij
943 +          endif
944  
945 <          pref = sw * pre22 * mu_i * mu_j
945 >          ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
946 >          
947 >          ri2 = riji * riji
948 >          ri3 = ri2 * riji
949 >          ri4 = ri2 * ri2
950 >          
951 >          pref = pre22 * mu_i * mu_j
952  
953 <          if (corrMethod .eq. 1) then
954 <             ri2 = riji * riji
955 <             ri3 = ri2 * riji
956 <             ri4 = ri2 * ri2
957 <
863 <             vterm = pref * (ri3 - rcuti3) * (ct_ij - 3.0d0 * ct_i * ct_j)
864 <             vpair = vpair + swi * vterm
865 <             epot = epot + vterm
953 >          if (summationMethod .eq. REACTION_FIELD) then
954 >             vterm = pref*( ri3*(ct_ij - 3.0d0 * ct_i * ct_j) - &
955 >                  preRF2*ct_ij )
956 >             vpair = vpair + vterm
957 >             epot = epot + sw*vterm
958              
959               a1 = 5.0d0 * ct_i * ct_j - ct_ij
960              
961 <             dudx = dudx + pref*3.0d0*ri4 &
962 <                  *(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1)) - &
963 <                  pref*3.0d0*rcuti4*(a1*rcuti*d(1)-ct_i*uz_j(1)-ct_j*uz_i(1))
964 <             dudy = dudy + pref*3.0d0*ri4 &
965 <                  *(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2)) - &
966 <                  pref*3.0d0*rcuti4*(a1*rcuti*d(2)-ct_i*uz_j(2)-ct_j*uz_i(2))
875 <             dudz = dudz + pref*3.0d0*ri4 &
876 <                  *(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3)) - &
877 <                  pref*3.0d0*rcuti4*(a1*rcuti*d(3)-ct_i*uz_j(3)-ct_j*uz_i(3))
961 >             dudx = dudx + sw*pref*3.0d0*ri4 &
962 >                             * (a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
963 >             dudy = dudy + sw*pref*3.0d0*ri4 &
964 >                             * (a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
965 >             dudz = dudz + sw*pref*3.0d0*ri4 &
966 >                             * (a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
967              
968 <             duduz_i(1) = duduz_i(1) + pref*(ri3*(uz_j(1) - 3.0d0*ct_j*xhat) &
969 <                  - rcuti3*(uz_j(1) - 3.0d0*ct_j*d(1)*rcuti))
970 <             duduz_i(2) = duduz_i(2) + pref*(ri3*(uz_j(2) - 3.0d0*ct_j*yhat) &
971 <                  - rcuti3*(uz_j(2) - 3.0d0*ct_j*d(2)*rcuti))
972 <             duduz_i(3) = duduz_i(3) + pref*(ri3*(uz_j(3) - 3.0d0*ct_j*zhat) &
973 <                  - rcuti3*(uz_j(3) - 3.0d0*ct_j*d(3)*rcuti))
974 <             duduz_j(1) = duduz_j(1) + pref*(ri3*(uz_i(1) - 3.0d0*ct_i*xhat) &
975 <                  - rcuti3*(uz_i(1) - 3.0d0*ct_i*d(1)*rcuti))
976 <             duduz_j(2) = duduz_j(2) + pref*(ri3*(uz_i(2) - 3.0d0*ct_i*yhat) &
977 <                  - rcuti3*(uz_i(2) - 3.0d0*ct_i*d(2)*rcuti))
978 <             duduz_j(3) = duduz_j(3) + pref*(ri3*(uz_i(3) - 3.0d0*ct_i*zhat) &
979 <                  - rcuti3*(uz_i(3) - 3.0d0*ct_i*d(3)*rcuti))
968 >             duduz_i(1) = duduz_i(1) + sw*pref*(ri3*(uz_j(1)-3.0d0*ct_j*xhat) &
969 >                  - preRF2*uz_j(1))
970 >             duduz_i(2) = duduz_i(2) + sw*pref*(ri3*(uz_j(2)-3.0d0*ct_j*yhat) &
971 >                  - preRF2*uz_j(2))
972 >             duduz_i(3) = duduz_i(3) + sw*pref*(ri3*(uz_j(3)-3.0d0*ct_j*zhat) &
973 >                  - preRF2*uz_j(3))
974 >             duduz_j(1) = duduz_j(1) + sw*pref*(ri3*(uz_i(1)-3.0d0*ct_i*xhat) &
975 >                  - preRF2*uz_i(1))
976 >             duduz_j(2) = duduz_j(2) + sw*pref*(ri3*(uz_i(2)-3.0d0*ct_i*yhat) &
977 >                  - preRF2*uz_i(2))
978 >             duduz_j(3) = duduz_j(3) + sw*pref*(ri3*(uz_i(3)-3.0d0*ct_i*zhat) &
979 >                  - preRF2*uz_i(3))
980 >
981            else
892            
982               if (i_is_SplitDipole) then
983                  if (j_is_SplitDipole) then
984 <                   BigR = sqrt(r2 + 0.25_dp * d_i * d_i + 0.25_dp * d_j * d_j)
984 >                   BigR = sqrt(r2 + 0.25d0 * d_i * d_i + 0.25d0 * d_j * d_j)
985                  else
986 <                   BigR = sqrt(r2 + 0.25_dp * d_i * d_i)
986 >                   BigR = sqrt(r2 + 0.25d0 * d_i * d_i)
987                  endif
988 <                ri = 1.0_dp / BigR
988 >                ri = 1.0d0 / BigR
989                  scale = rij * ri                
990               else
991                  if (j_is_SplitDipole) then
992 <                   BigR = sqrt(r2 + 0.25_dp * d_j * d_j)
993 <                   ri = 1.0_dp / BigR
992 >                   BigR = sqrt(r2 + 0.25d0 * d_j * d_j)
993 >                   ri = 1.0d0 / BigR
994                     scale = rij * ri                            
995                  else                
996                     ri = riji
997 <                   scale = 1.0_dp
997 >                   scale = 1.0d0
998                  endif
999               endif
1000              
912             ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
913            
914             ri2 = ri * ri
915             ri3 = ri2 * ri
916             ri4 = ri2 * ri2
1001               sc2 = scale * scale
1002 +
1003 +             pot_term = (ct_ij - 3.0d0 * ct_i * ct_j * sc2)
1004 +             vterm = pref * ( ri3*pot_term*f1 + (ct_i * ct_j)*f2 )
1005 +             vpair = vpair + vterm
1006 +             epot = epot + sw*vterm
1007              
1008 <             vterm = pref * ri3 * (ct_ij - 3.0d0 * ct_i * ct_j * sc2)
1009 <             vpair = vpair + swi * vterm
921 <             epot = epot + vterm
1008 >             f13 = f1+f3
1009 >             f134 = f13 + f4
1010              
1011 <             a1 = 5.0d0 * ct_i * ct_j * sc2 - ct_ij
1011 > !!$             dudx = dudx + sw*pref * ( ri4*scale*( &
1012 > !!$                  3.0d0*(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))*f1 &
1013 > !!$                  - pot_term*f3) &
1014 > !!$                  + 2.0d0*ct_i*ct_j*xhat*(ct_i*uz_j(1)+ct_j*uz_i(1))*f3 &
1015 > !!$                  + (ct_i * ct_j)*f4 )
1016 > !!$             dudy = dudy + sw*pref * ( ri4*scale*( &
1017 > !!$                  3.0d0*(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))*f1 &
1018 > !!$                  - pot_term*f3) &
1019 > !!$                  + 2.0d0*ct_i*ct_j*yhat*(ct_i*uz_j(2)+ct_j*uz_i(2))*f3 &
1020 > !!$                  + (ct_i * ct_j)*f4 )
1021 > !!$             dudz = dudz + sw*pref * ( ri4*scale*( &
1022 > !!$                  3.0d0*(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))*f1 &
1023 > !!$                  - pot_term*f3) &
1024 > !!$                  + 2.0d0*ct_i*ct_j*zhat*(ct_i*uz_j(3)+ct_j*uz_i(3))*f3 &
1025 > !!$                  + (ct_i * ct_j)*f4 )
1026 >
1027 >             dudx = dudx + sw*pref * ( ri4*scale*( &
1028 >                  15.0d0*(ct_i * ct_j * sc2)*xhat*f134 - &
1029 >                  3.0d0*(ct_i*uz_j(1) + ct_j*uz_i(1) + ct_ij*xhat)*f134) )
1030 >             dudy = dudy + sw*pref * ( ri4*scale*( &
1031 >                  15.0d0*(ct_i * ct_j * sc2)*yhat*f134 - &
1032 >                  3.0d0*(ct_i*uz_j(2) + ct_j*uz_i(2) + ct_ij*yhat)*f134) )
1033 >             dudz = dudz + sw*pref * ( ri4*scale*( &
1034 >                  15.0d0*(ct_i * ct_j * sc2)*zhat*f134 - &
1035 >                  3.0d0*(ct_i*uz_j(3) + ct_j*uz_i(3) + ct_ij*zhat)*f134) )
1036              
1037 <             dudx = dudx + pref*3.0d0*ri4*scale &
1038 <                  *(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
1039 <             dudy = dudy + pref*3.0d0*ri4*scale &
1040 <                  *(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
1041 <             dudz = dudz + pref*3.0d0*ri4*scale &
1042 <                  *(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
1037 >             duduz_i(1) = duduz_i(1) + sw*pref * &
1038 >                  ( ri3*(uz_j(1) - 3.0d0*ct_j*xhat*sc2)*f1 + (ct_j*xhat)*f2 )
1039 >             duduz_i(2) = duduz_i(2) + sw*pref * &
1040 >                  ( ri3*(uz_j(2) - 3.0d0*ct_j*yhat*sc2)*f1 + (ct_j*yhat)*f2 )
1041 >             duduz_i(3) = duduz_i(3) + sw*pref * &
1042 >                  ( ri3*(uz_j(3) - 3.0d0*ct_j*zhat*sc2)*f1 + (ct_j*zhat)*f2 )
1043              
1044 <             duduz_i(1) = duduz_i(1) + pref*ri3 &
1045 <                  *(uz_j(1) - 3.0d0*ct_j*xhat*sc2)
1046 <             duduz_i(2) = duduz_i(2) + pref*ri3 &
1047 <                  *(uz_j(2) - 3.0d0*ct_j*yhat*sc2)
1048 <             duduz_i(3) = duduz_i(3) + pref*ri3 &
1049 <                  *(uz_j(3) - 3.0d0*ct_j*zhat*sc2)
938 <            
939 <             duduz_j(1) = duduz_j(1) + pref*ri3 &
940 <                  *(uz_i(1) - 3.0d0*ct_i*xhat*sc2)
941 <             duduz_j(2) = duduz_j(2) + pref*ri3 &
942 <                  *(uz_i(2) - 3.0d0*ct_i*yhat*sc2)
943 <             duduz_j(3) = duduz_j(3) + pref*ri3 &
944 <                  *(uz_i(3) - 3.0d0*ct_i*zhat*sc2)
1044 >             duduz_j(1) = duduz_j(1) + sw*pref * &
1045 >                  ( ri3*(uz_i(1) - 3.0d0*ct_i*xhat*sc2)*f1 + (ct_i*xhat)*f2 )
1046 >             duduz_j(2) = duduz_j(2) + sw*pref * &
1047 >                  ( ri3*(uz_i(2) - 3.0d0*ct_i*yhat*sc2)*f1 + (ct_i*yhat)*f2 )
1048 >             duduz_j(3) = duduz_j(3) + sw*pref * &
1049 >                  ( ri3*(uz_i(3) - 3.0d0*ct_i*zhat*sc2)*f1 + (ct_i*zhat)*f2 )
1050            endif
1051         endif
1052      endif
1053  
1054      if (i_is_Quadrupole) then
1055         if (j_is_Charge) then
1056 +          if (screeningMethod .eq. DAMPED) then
1057 +             f0 = derfc(dampingAlpha*rij)
1058 +             varEXP = exp(-alpha2*rij*rij)
1059 +             f1 = alphaPi*rij*varEXP + f0
1060 +             f2 = alphaPi*2.0d0*alpha2*varEXP
1061 +             f3 = f2*rij*rij*rij
1062 +             f4 = 2.0d0*alpha2*f2*rij
1063 +          endif
1064  
1065            ri2 = riji * riji
1066            ri3 = ri2 * riji
# Line 956 | Line 1069 | contains
1069            cy2 = cy_i * cy_i
1070            cz2 = cz_i * cz_i
1071  
1072 <          pref = sw * pre14 * q_j / 3.0_dp
1073 <
1074 <          if (corrMethod .eq. 1) then
1075 <             vterm1 = pref * ri3*( qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1076 <                  qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1077 <                  qzz_i * (3.0_dp*cz2 - 1.0_dp) )
1078 <             vterm2 = pref * rcuti3*( qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1079 <                  qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1080 <                  qzz_i * (3.0_dp*cz2 - 1.0_dp) )
1081 <             vpair = vpair + swi * ( vterm1 - vterm2 )
1082 <             epot = epot + ( vterm1 - vterm2 )
1083 <            
1084 <             dudx = dudx - (5.0_dp*(vterm1*riji*xhat - vterm2*rcuti2*d(1))) + &
1085 <                  pref * ( (ri4 - rcuti4)*(qxx_i*(6.0_dp*cx_i*ux_i(1)) - &
1086 <                  qxx_i*2.0_dp*(xhat - rcuti*d(1))) + &
1087 <                  (ri4 - rcuti4)*(qyy_i*(6.0_dp*cy_i*uy_i(1)) - &
1088 <                  qyy_i*2.0_dp*(xhat - rcuti*d(1))) + &
1089 <                  (ri4 - rcuti4)*(qzz_i*(6.0_dp*cz_i*uz_i(1)) - &
1090 <                  qzz_i*2.0_dp*(xhat - rcuti*d(1))) )
1091 <             dudy = dudy - (5.0_dp*(vterm1*riji*yhat - vterm2*rcuti2*d(2))) + &
1092 <                  pref * ( (ri4 - rcuti4)*(qxx_i*(6.0_dp*cx_i*ux_i(2)) - &
1093 <                  qxx_i*2.0_dp*(yhat - rcuti*d(2))) + &
1094 <                  (ri4 - rcuti4)*(qyy_i*(6.0_dp*cy_i*uy_i(2)) - &
1095 <                  qyy_i*2.0_dp*(yhat - rcuti*d(2))) + &
1096 <                  (ri4 - rcuti4)*(qzz_i*(6.0_dp*cz_i*uz_i(2)) - &
1097 <                  qzz_i*2.0_dp*(yhat - rcuti*d(2))) )
1098 <             dudz = dudz - (5.0_dp*(vterm1*riji*zhat - vterm2*rcuti2*d(3))) + &
1099 <                  pref * ( (ri4 - rcuti4)*(qxx_i*(6.0_dp*cx_i*ux_i(3)) - &
1100 <                  qxx_i*2.0_dp*(zhat - rcuti*d(3))) + &
1101 <                  (ri4 - rcuti4)*(qyy_i*(6.0_dp*cy_i*uy_i(3)) - &
1102 <                  qyy_i*2.0_dp*(zhat - rcuti*d(3))) + &
1103 <                  (ri4 - rcuti4)*(qzz_i*(6.0_dp*cz_i*uz_i(3)) - &
1104 <                  qzz_i*2.0_dp*(zhat - rcuti*d(3))) )
1105 <            
1106 <             dudux_i(1) = dudux_i(1) + pref * (ri3*(qxx_i*6.0_dp*cx_i*xhat) - &
1107 <                  rcuti4*(qxx_i*6.0_dp*cx_i*d(1)))
1108 <             dudux_i(2) = dudux_i(2) + pref * (ri3*(qxx_i*6.0_dp*cx_i*yhat) - &
1109 <                  rcuti4*(qxx_i*6.0_dp*cx_i*d(2)))
1110 <             dudux_i(3) = dudux_i(3) + pref * (ri3*(qxx_i*6.0_dp*cx_i*zhat) - &
1111 <                  rcuti4*(qxx_i*6.0_dp*cx_i*d(3)))
1112 <            
1113 <             duduy_i(1) = duduy_i(1) + pref * (ri3*(qyy_i*6.0_dp*cy_i*xhat) - &
1114 <                  rcuti4*(qyy_i*6.0_dp*cx_i*d(1)))
1115 <             duduy_i(2) = duduy_i(2) + pref * (ri3*(qyy_i*6.0_dp*cy_i*yhat) - &
1116 <                  rcuti4*(qyy_i*6.0_dp*cx_i*d(2)))
1117 <             duduy_i(3) = duduy_i(3) + pref * (ri3*(qyy_i*6.0_dp*cy_i*zhat) - &
1118 <                  rcuti4*(qyy_i*6.0_dp*cx_i*d(3)))
1006 <            
1007 <             duduz_i(1) = duduz_i(1) + pref * (ri3*(qzz_i*6.0_dp*cz_i*xhat) - &
1008 <                  rcuti4*(qzz_i*6.0_dp*cx_i*d(1)))
1009 <             duduz_i(2) = duduz_i(2) + pref * (ri3*(qzz_i*6.0_dp*cz_i*yhat) - &
1010 <                  rcuti4*(qzz_i*6.0_dp*cx_i*d(2)))
1011 <             duduz_i(3) = duduz_i(3) + pref * (ri3*(qzz_i*6.0_dp*cz_i*zhat) - &
1012 <                  rcuti4*(qzz_i*6.0_dp*cx_i*d(3)))
1072 >          pref = pre14 * q_j / 3.0d0
1073 >          pot_term = ri3 * (qxx_i * (3.0d0*cx2 - 1.0d0) + &
1074 >                            qyy_i * (3.0d0*cy2 - 1.0d0) + &
1075 >                            qzz_i * (3.0d0*cz2 - 1.0d0))
1076 >          vterm = pref * (pot_term*f1 + (qxx_i*cx2 + qyy_i*cy2 + qzz_i*cz2)*f2)
1077 >          vpair = vpair + vterm
1078 >          epot = epot + sw*vterm
1079 >          
1080 >          dudx = dudx - sw*pref*pot_term*riji*xhat*(5.0d0*f1 + f3) + &
1081 >               sw*pref*ri4 * ( &
1082 >               qxx_i*(2.0d0*cx_i*ux_i(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) + &
1083 >               qyy_i*(2.0d0*cy_i*uy_i(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) + &
1084 >               qzz_i*(2.0d0*cz_i*uz_i(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) ) &
1085 >               + (qxx_i*cx2 + qyy_i*cy2 + qzz_i*cz2)*f4
1086 >          dudy = dudy - sw*pref*pot_term*riji*yhat*(5.0d0*f1 + f3) + &
1087 >               sw*pref*ri4 * ( &
1088 >               qxx_i*(2.0d0*cx_i*ux_i(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) + &
1089 >               qyy_i*(2.0d0*cy_i*uy_i(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) + &
1090 >               qzz_i*(2.0d0*cz_i*uz_i(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) ) &
1091 >               + (qxx_i*cx2 + qyy_i*cy2 + qzz_i*cz2)*f4
1092 >          dudz = dudz - sw*pref*pot_term*riji*zhat*(5.0d0*f1 + f3) + &
1093 >               sw*pref*ri4 * ( &
1094 >               qxx_i*(2.0d0*cx_i*ux_i(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) + &
1095 >               qyy_i*(2.0d0*cy_i*uy_i(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) + &
1096 >               qzz_i*(2.0d0*cz_i*uz_i(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) ) &
1097 >               + (qxx_i*cx2 + qyy_i*cy2 + qzz_i*cz2)*f4
1098 >          
1099 >          dudux_i(1) = dudux_i(1) + sw*pref*( ri3*(qxx_i*2.0d0*cx_i*xhat) &
1100 >               * (3.0d0*f1 + f3) )
1101 >          dudux_i(2) = dudux_i(2) + sw*pref*( ri3*(qxx_i*2.0d0*cx_i*yhat) &
1102 >               * (3.0d0*f1 + f3) )
1103 >          dudux_i(3) = dudux_i(3) + sw*pref*( ri3*(qxx_i*2.0d0*cx_i*zhat) &
1104 >               * (3.0d0*f1 + f3) )
1105 >          
1106 >          duduy_i(1) = duduy_i(1) + sw*pref*( ri3*(qyy_i*2.0d0*cy_i*xhat) &
1107 >               * (3.0d0*f1 + f3) )
1108 >          duduy_i(2) = duduy_i(2) + sw*pref*( ri3*(qyy_i*2.0d0*cy_i*yhat) &
1109 >               * (3.0d0*f1 + f3) )
1110 >          duduy_i(3) = duduy_i(3) + sw*pref*( ri3*(qyy_i*2.0d0*cy_i*zhat) &
1111 >               * (3.0d0*f1 + f3) )
1112 >          
1113 >          duduz_i(1) = duduz_i(1) + sw*pref*( ri3*(qzz_i*2.0d0*cz_i*xhat) &
1114 >               * (3.0d0*f1 + f3) )
1115 >          duduz_i(2) = duduz_i(2) + sw*pref*( ri3*(qzz_i*2.0d0*cz_i*yhat) &
1116 >               * (3.0d0*f1 + f3) )
1117 >          duduz_i(3) = duduz_i(3) + sw*pref*( ri3*(qzz_i*2.0d0*cz_i*zhat) &
1118 >               * (3.0d0*f1 + f3) )
1119  
1014          else
1015             vterm = pref * ri3 * (qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1016                  qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1017                  qzz_i * (3.0_dp*cz2 - 1.0_dp))
1018             vpair = vpair + swi * vterm
1019             epot = epot + vterm
1020            
1021             dudx = dudx - 5.0_dp*vterm*riji*xhat + pref * ri4 * ( &
1022                  qxx_i*(6.0_dp*cx_i*ux_i(1) - 2.0_dp*xhat) + &
1023                  qyy_i*(6.0_dp*cy_i*uy_i(1) - 2.0_dp*xhat) + &
1024                  qzz_i*(6.0_dp*cz_i*uz_i(1) - 2.0_dp*xhat) )
1025             dudy = dudy - 5.0_dp*vterm*riji*yhat + pref * ri4 * ( &
1026                  qxx_i*(6.0_dp*cx_i*ux_i(2) - 2.0_dp*yhat) + &
1027                  qyy_i*(6.0_dp*cy_i*uy_i(2) - 2.0_dp*yhat) + &
1028                  qzz_i*(6.0_dp*cz_i*uz_i(2) - 2.0_dp*yhat) )
1029             dudz = dudz - 5.0_dp*vterm*riji*zhat + pref * ri4 * ( &
1030                  qxx_i*(6.0_dp*cx_i*ux_i(3) - 2.0_dp*zhat) + &
1031                  qyy_i*(6.0_dp*cy_i*uy_i(3) - 2.0_dp*zhat) + &
1032                  qzz_i*(6.0_dp*cz_i*uz_i(3) - 2.0_dp*zhat) )
1033            
1034             dudux_i(1) = dudux_i(1) + pref * ri3*(qxx_i*6.0_dp*cx_i*xhat)
1035             dudux_i(2) = dudux_i(2) + pref * ri3*(qxx_i*6.0_dp*cx_i*yhat)
1036             dudux_i(3) = dudux_i(3) + pref * ri3*(qxx_i*6.0_dp*cx_i*zhat)
1037            
1038             duduy_i(1) = duduy_i(1) + pref * ri3*(qyy_i*6.0_dp*cy_i*xhat)
1039             duduy_i(2) = duduy_i(2) + pref * ri3*(qyy_i*6.0_dp*cy_i*yhat)
1040             duduy_i(3) = duduy_i(3) + pref * ri3*(qyy_i*6.0_dp*cy_i*zhat)
1041            
1042             duduz_i(1) = duduz_i(1) + pref * ri3*(qzz_i*6.0_dp*cz_i*xhat)
1043             duduz_i(2) = duduz_i(2) + pref * ri3*(qzz_i*6.0_dp*cz_i*yhat)
1044             duduz_i(3) = duduz_i(3) + pref * ri3*(qzz_i*6.0_dp*cz_i*zhat)
1045          endif
1120         endif
1121      endif
1122  
1123  
1124      if (do_pot) then
1125   #ifdef IS_MPI
1126 <       pot_row(atom1) = pot_row(atom1) + 0.5d0*epot
1127 <       pot_col(atom2) = pot_col(atom2) + 0.5d0*epot
1126 >       pot_row(ELECTROSTATIC_POT,atom1) = pot_row(ELECTROSTATIC_POT,atom1) + 0.5d0*epot
1127 >       pot_col(ELECTROSTATIC_POT,atom2) = pot_col(ELECTROSTATIC_POT,atom2) + 0.5d0*epot
1128   #else
1129         pot = pot + epot
1130   #endif
# Line 1155 | Line 1229 | contains
1229      return
1230    end subroutine doElectrostaticPair
1231  
1232 <  !! calculates the switching functions and their derivatives for a given
1159 <  subroutine calc_switch(r, mu, scale, dscale)
1232 >  subroutine destroyElectrostaticTypes()
1233  
1234 <    real (kind=dp), intent(in) :: r, mu
1162 <    real (kind=dp), intent(inout) :: scale, dscale
1163 <    real (kind=dp) :: rl, ru, mulow, minRatio, temp, scaleVal
1234 >    if(allocated(ElectrostaticMap)) deallocate(ElectrostaticMap)
1235  
1236 <    ! distances must be in angstroms
1237 <    rl = 2.75d0
1238 <    ru = 3.75d0
1239 <    mulow = 0.0d0 !3.3856d0 ! 1.84 * 1.84
1240 <    minRatio = mulow / (mu*mu)
1241 <    scaleVal = 1.0d0 - minRatio
1236 >  end subroutine destroyElectrostaticTypes
1237 >
1238 >  subroutine self_self(atom1, eFrame, mypot, t, do_pot)
1239 >    logical, intent(in) :: do_pot
1240 >    integer, intent(in) :: atom1
1241 >    integer :: atid1
1242 >    real(kind=dp), dimension(9,nLocal) :: eFrame
1243 >    real(kind=dp), dimension(3,nLocal) :: t
1244 >    real(kind=dp) :: mu1, c1
1245 >    real(kind=dp) :: preVal, epot, mypot
1246 >    real(kind=dp) :: eix, eiy, eiz
1247 >
1248 >    ! this is a local only array, so we use the local atom type id's:
1249 >    atid1 = atid(atom1)
1250 >
1251 >    if (.not.summationMethodChecked) then
1252 >       call checkSummationMethod()
1253 >    endif
1254      
1255 <    if (r.lt.rl) then
1256 <       scale = minRatio
1257 <       dscale = 0.0d0
1258 <    elseif (r.gt.ru) then
1259 <       scale = 1.0d0
1260 <       dscale = 0.0d0
1261 <    else
1262 <       scale = 1.0d0 - scaleVal*((ru + 2.0d0*r - 3.0d0*rl) * (ru-r)**2) &
1263 <                        / ((ru - rl)**3)
1264 <       dscale = -scaleVal * 6.0d0 * (r-ru)*(r-rl)/((ru - rl)**3)    
1255 >    if (summationMethod .eq. REACTION_FIELD) then
1256 >       if (ElectrostaticMap(atid1)%is_Dipole) then
1257 >          mu1 = getDipoleMoment(atid1)
1258 >          
1259 >          preVal = pre22 * preRF2 * mu1*mu1
1260 >          mypot = mypot - 0.5d0*preVal
1261 >          
1262 >          ! The self-correction term adds into the reaction field vector
1263 >          
1264 >          eix = preVal * eFrame(3,atom1)
1265 >          eiy = preVal * eFrame(6,atom1)
1266 >          eiz = preVal * eFrame(9,atom1)
1267 >          
1268 >          ! once again, this is self-self, so only the local arrays are needed
1269 >          ! even for MPI jobs:
1270 >          
1271 >          t(1,atom1)=t(1,atom1) - eFrame(6,atom1)*eiz + &
1272 >               eFrame(9,atom1)*eiy
1273 >          t(2,atom1)=t(2,atom1) - eFrame(9,atom1)*eix + &
1274 >               eFrame(3,atom1)*eiz
1275 >          t(3,atom1)=t(3,atom1) - eFrame(3,atom1)*eiy + &
1276 >               eFrame(6,atom1)*eix
1277 >          
1278 >       endif
1279 >
1280 >    elseif ( (summationMethod .eq. SHIFTED_FORCE) .or. &
1281 >         (summationMethod .eq. SHIFTED_POTENTIAL) ) then
1282 >       if (ElectrostaticMap(atid1)%is_Charge) then
1283 >          c1 = getCharge(atid1)
1284 >          
1285 >          if (screeningMethod .eq. DAMPED) then
1286 >             mypot = mypot - (f0c * rcuti * 0.5d0 + &
1287 >                  dampingAlpha*invRootPi) * c1 * c1    
1288 >            
1289 >          else            
1290 >             mypot = mypot - (rcuti * 0.5d0 * c1 * c1)
1291 >            
1292 >          endif
1293 >       endif
1294      endif
1295 <        
1295 >    
1296      return
1297 <  end subroutine calc_switch
1297 >  end subroutine self_self
1298  
1299 <  subroutine destroyElectrostaticTypes()
1300 <
1301 <    if(allocated(ElectrostaticMap)) deallocate(ElectrostaticMap)
1299 >  subroutine rf_self_excludes(atom1, atom2, sw, eFrame, d, rij, vpair, myPot, &
1300 >       f, t, do_pot)
1301 >    logical, intent(in) :: do_pot
1302 >    integer, intent(in) :: atom1
1303 >    integer, intent(in) :: atom2
1304 >    logical :: i_is_Charge, j_is_Charge
1305 >    logical :: i_is_Dipole, j_is_Dipole
1306 >    integer :: atid1
1307 >    integer :: atid2
1308 >    real(kind=dp), intent(in) :: rij
1309 >    real(kind=dp), intent(in) :: sw
1310 >    real(kind=dp), intent(in), dimension(3) :: d
1311 >    real(kind=dp), intent(inout) :: vpair
1312 >    real(kind=dp), dimension(9,nLocal) :: eFrame
1313 >    real(kind=dp), dimension(3,nLocal) :: f
1314 >    real(kind=dp), dimension(3,nLocal) :: t
1315 >    real (kind = dp), dimension(3) :: duduz_i
1316 >    real (kind = dp), dimension(3) :: duduz_j
1317 >    real (kind = dp), dimension(3) :: uz_i
1318 >    real (kind = dp), dimension(3) :: uz_j
1319 >    real(kind=dp) :: q_i, q_j, mu_i, mu_j
1320 >    real(kind=dp) :: xhat, yhat, zhat
1321 >    real(kind=dp) :: ct_i, ct_j
1322 >    real(kind=dp) :: ri2, ri3, riji, vterm
1323 >    real(kind=dp) :: pref, preVal, rfVal, myPot
1324 >    real(kind=dp) :: dudx, dudy, dudz, dudr
1325  
1326 <  end subroutine destroyElectrostaticTypes
1326 >    if (.not.summationMethodChecked) then
1327 >       call checkSummationMethod()
1328 >    endif
1329  
1330 +    dudx = zero
1331 +    dudy = zero
1332 +    dudz = zero
1333 +
1334 +    riji = 1.0d0/rij
1335 +
1336 +    xhat = d(1) * riji
1337 +    yhat = d(2) * riji
1338 +    zhat = d(3) * riji
1339 +
1340 +    ! this is a local only array, so we use the local atom type id's:
1341 +    atid1 = atid(atom1)
1342 +    atid2 = atid(atom2)
1343 +    i_is_Charge = ElectrostaticMap(atid1)%is_Charge
1344 +    j_is_Charge = ElectrostaticMap(atid2)%is_Charge
1345 +    i_is_Dipole = ElectrostaticMap(atid1)%is_Dipole
1346 +    j_is_Dipole = ElectrostaticMap(atid2)%is_Dipole
1347 +
1348 +    if (i_is_Charge.and.j_is_Charge) then
1349 +       q_i = ElectrostaticMap(atid1)%charge
1350 +       q_j = ElectrostaticMap(atid2)%charge
1351 +      
1352 +       preVal = pre11 * q_i * q_j
1353 +       rfVal = preRF*rij*rij
1354 +       vterm = preVal * rfVal
1355 +      
1356 +       myPot = myPot + sw*vterm
1357 +      
1358 +       dudr  = sw*preVal * 2.0d0*rfVal*riji
1359 +      
1360 +       dudx = dudx + dudr * xhat
1361 +       dudy = dudy + dudr * yhat
1362 +       dudz = dudz + dudr * zhat
1363 +      
1364 +    elseif (i_is_Charge.and.j_is_Dipole) then
1365 +       q_i = ElectrostaticMap(atid1)%charge
1366 +       mu_j = ElectrostaticMap(atid2)%dipole_moment
1367 +       uz_j(1) = eFrame(3,atom2)
1368 +       uz_j(2) = eFrame(6,atom2)
1369 +       uz_j(3) = eFrame(9,atom2)
1370 +       ct_j = uz_j(1)*xhat + uz_j(2)*yhat + uz_j(3)*zhat
1371 +      
1372 +       ri2 = riji * riji
1373 +       ri3 = ri2 * riji
1374 +      
1375 +       pref = pre12 * q_i * mu_j
1376 +       vterm = - pref * ct_j * ( ri2 - preRF2*rij )
1377 +       myPot = myPot + sw*vterm
1378 +      
1379 +       dudx = dudx - sw*pref*( ri3*(uz_j(1)-3.0d0*ct_j*xhat) &
1380 +            - preRF2*uz_j(1) )
1381 +       dudy = dudy - sw*pref*( ri3*(uz_j(2)-3.0d0*ct_j*yhat) &
1382 +            - preRF2*uz_j(2) )
1383 +       dudz = dudz - sw*pref*( ri3*(uz_j(3)-3.0d0*ct_j*zhat) &
1384 +            - preRF2*uz_j(3) )
1385 +      
1386 +       duduz_j(1) = duduz_j(1) - sw * pref * xhat * ( ri2 - preRF2*rij )
1387 +       duduz_j(2) = duduz_j(2) - sw * pref * yhat * ( ri2 - preRF2*rij )
1388 +       duduz_j(3) = duduz_j(3) - sw * pref * zhat * ( ri2 - preRF2*rij )
1389 +      
1390 +    elseif (i_is_Dipole.and.j_is_Charge) then
1391 +       mu_i = ElectrostaticMap(atid1)%dipole_moment
1392 +       q_j = ElectrostaticMap(atid2)%charge
1393 +       uz_i(1) = eFrame(3,atom1)
1394 +       uz_i(2) = eFrame(6,atom1)
1395 +       uz_i(3) = eFrame(9,atom1)
1396 +       ct_i = uz_i(1)*xhat + uz_i(2)*yhat + uz_i(3)*zhat
1397 +      
1398 +       ri2 = riji * riji
1399 +       ri3 = ri2 * riji
1400 +      
1401 +       pref = pre12 * q_j * mu_i
1402 +       vterm = pref * ct_i * ( ri2 - preRF2*rij )
1403 +       myPot = myPot + sw*vterm
1404 +      
1405 +       dudx = dudx + sw*pref*( ri3*(uz_i(1)-3.0d0*ct_i*xhat) &
1406 +            - preRF2*uz_i(1) )
1407 +       dudy = dudy + sw*pref*( ri3*(uz_i(2)-3.0d0*ct_i*yhat) &
1408 +            - preRF2*uz_i(2) )
1409 +       dudz = dudz + sw*pref*( ri3*(uz_i(3)-3.0d0*ct_i*zhat) &
1410 +            - preRF2*uz_i(3) )
1411 +      
1412 +       duduz_i(1) = duduz_i(1) + sw * pref * xhat * ( ri2 - preRF2*rij )
1413 +       duduz_i(2) = duduz_i(2) + sw * pref * yhat * ( ri2 - preRF2*rij )
1414 +       duduz_i(3) = duduz_i(3) + sw * pref * zhat * ( ri2 - preRF2*rij )
1415 +      
1416 +    endif
1417 +      
1418 +
1419 +    ! accumulate the forces and torques resulting from the self term
1420 +    f(1,atom1) = f(1,atom1) + dudx
1421 +    f(2,atom1) = f(2,atom1) + dudy
1422 +    f(3,atom1) = f(3,atom1) + dudz
1423 +    
1424 +    f(1,atom2) = f(1,atom2) - dudx
1425 +    f(2,atom2) = f(2,atom2) - dudy
1426 +    f(3,atom2) = f(3,atom2) - dudz
1427 +    
1428 +    if (i_is_Dipole) then
1429 +       t(1,atom1)=t(1,atom1) - uz_i(2)*duduz_i(3) + uz_i(3)*duduz_i(2)
1430 +       t(2,atom1)=t(2,atom1) - uz_i(3)*duduz_i(1) + uz_i(1)*duduz_i(3)
1431 +       t(3,atom1)=t(3,atom1) - uz_i(1)*duduz_i(2) + uz_i(2)*duduz_i(1)
1432 +    elseif (j_is_Dipole) then
1433 +       t(1,atom2)=t(1,atom2) - uz_j(2)*duduz_j(3) + uz_j(3)*duduz_j(2)
1434 +       t(2,atom2)=t(2,atom2) - uz_j(3)*duduz_j(1) + uz_j(1)*duduz_j(3)
1435 +       t(3,atom2)=t(3,atom2) - uz_j(1)*duduz_j(2) + uz_j(2)*duduz_j(1)
1436 +    endif
1437 +
1438 +    return
1439 +  end subroutine rf_self_excludes
1440 +
1441   end module electrostatic_module

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines