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 2381 by chrisfen, Tue Oct 18 15:01:42 2005 UTC vs.
Revision 2717 by gezelter, Mon Apr 17 21:49:12 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 58 | Line 59 | module electrostatic_module
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 >  !! variables to handle different summation methods for long-range
80 >  !! electrostatics:
81    integer, save :: summationMethod = NONE
82 +  integer, save :: screeningMethod = UNDAMPED
83    logical, save :: summationMethodChecked = .false.
84    real(kind=DP), save :: defaultCutoff = 0.0_DP
85    real(kind=DP), save :: defaultCutoff2 = 0.0_DP
86    logical, save :: haveDefaultCutoff = .false.
87    real(kind=DP), save :: dampingAlpha = 0.0_DP
88 +  real(kind=DP), save :: alpha2 = 0.0_DP
89    logical, save :: haveDampingAlpha = .false.
90    real(kind=DP), save :: dielectric = 1.0_DP
91    logical, save :: haveDielectric = .false.
87  real(kind=DP), save :: constERFC = 0.0_DP
92    real(kind=DP), save :: constEXP = 0.0_DP
89  logical, save :: haveDWAconstants = .false.
93    real(kind=dp), save :: rcuti = 0.0_DP
94    real(kind=dp), save :: rcuti2 = 0.0_DP
95    real(kind=dp), save :: rcuti3 = 0.0_DP
# Line 97 | Line 100 | module electrostatic_module
100    real(kind=dp), save :: rt = 1.0_DP
101    real(kind=dp), save :: rrfsq = 1.0_DP
102    real(kind=dp), save :: preRF = 0.0_DP
103 <  logical, save :: preRFCalculated = .false.
104 <
105 < #ifdef __IFC
103 >  real(kind=dp), save :: preRF2 = 0.0_DP
104 >  real(kind=dp), save :: f0 = 1.0_DP
105 >  real(kind=dp), save :: f1 = 1.0_DP
106 >  real(kind=dp), save :: f2 = 0.0_DP
107 >  real(kind=dp), save :: f3 = 0.0_DP
108 >  real(kind=dp), save :: f4 = 0.0_DP
109 >  real(kind=dp), save :: f0c = 1.0_DP
110 >  real(kind=dp), save :: f1c = 1.0_DP
111 >  real(kind=dp), save :: f2c = 0.0_DP
112 >  real(kind=dp), save :: f3c = 0.0_DP
113 >  real(kind=dp), save :: f4c = 0.0_DP
114 >
115 > #if defined(__IFC) || defined(__PGI)
116   ! error function for ifc version > 7.
117    double precision, external :: derfc
118   #endif
119    
120    public :: setElectrostaticSummationMethod
121 +  public :: setScreeningMethod
122    public :: setElectrostaticCutoffRadius
123 <  public :: setDampedWolfAlpha
123 >  public :: setDampingAlpha
124    public :: setReactionFieldDielectric
125 <  public :: setReactionFieldPrefactor
125 >  public :: buildElectroSplines
126    public :: newElectrostaticType
127    public :: setCharge
128    public :: setDipoleMoment
# Line 117 | Line 131 | module electrostatic_module
131    public :: doElectrostaticPair
132    public :: getCharge
133    public :: getDipoleMoment
120  public :: pre22
134    public :: destroyElectrostaticTypes
135 <  public :: accumulate_rf
136 <  public :: accumulate_self_rf
124 <  public :: reaction_field_final
125 <  public :: rf_correct_forces
135 >  public :: self_self
136 >  public :: rf_self_excludes
137  
138 +
139    type :: Electrostatic
140       integer :: c_ident
141       logical :: is_Charge = .false.
# Line 139 | Line 151 | contains
151  
152    type(Electrostatic), dimension(:), allocatable :: ElectrostaticMap
153  
154 +  logical, save :: hasElectrostaticMap
155 +
156   contains
157  
158    subroutine setElectrostaticSummationMethod(the_ESM)
# Line 152 | Line 166 | contains
166  
167    end subroutine setElectrostaticSummationMethod
168  
169 +  subroutine setScreeningMethod(the_SM)
170 +    integer, intent(in) :: the_SM    
171 +    screeningMethod = the_SM
172 +  end subroutine setScreeningMethod
173 +
174    subroutine setElectrostaticCutoffRadius(thisRcut, thisRsw)
175      real(kind=dp), intent(in) :: thisRcut
176      real(kind=dp), intent(in) :: thisRsw
177      defaultCutoff = thisRcut
178 +    defaultCutoff2 = defaultCutoff*defaultCutoff
179      rrf = defaultCutoff
180      rt = thisRsw
181      haveDefaultCutoff = .true.
182    end subroutine setElectrostaticCutoffRadius
183  
184 <  subroutine setDampedWolfAlpha(thisAlpha)
184 >  subroutine setDampingAlpha(thisAlpha)
185      real(kind=dp), intent(in) :: thisAlpha
186      dampingAlpha = thisAlpha
187 +    alpha2 = dampingAlpha*dampingAlpha
188      haveDampingAlpha = .true.
189 <  end subroutine setDampedWolfAlpha
189 >  end subroutine setDampingAlpha
190    
191    subroutine setReactionFieldDielectric(thisDielectric)
192      real(kind=dp), intent(in) :: thisDielectric
# Line 173 | Line 194 | contains
194      haveDielectric = .true.
195    end subroutine setReactionFieldDielectric
196  
197 <  subroutine setReactionFieldPrefactor
198 <    if (haveDefaultCutoff .and. haveDielectric) then
178 <       defaultCutoff2 = defaultCutoff*defaultCutoff
179 <       preRF = pre22 * 2.0d0*(dielectric-1.0d0) / &
180 <            ((2.0d0*dielectric+1.0d0)*defaultCutoff2*defaultCutoff)
181 <       preRFCalculated = .true.
182 <    else if (.not.haveDefaultCutoff) then
183 <       call handleError("setReactionFieldPrefactor", "Default cutoff not set")
184 <    else
185 <       call handleError("setReactionFieldPrefactor", "Dielectric not set")
186 <    endif
187 <  end subroutine setReactionFieldPrefactor
197 >  subroutine buildElectroSplines()
198 >  end subroutine buildElectroSplines
199  
200    subroutine newElectrostaticType(c_ident, is_Charge, is_Dipole, &
201         is_SplitDipole, is_Quadrupole, is_Tap, status)
# Line 213 | Line 224 | contains
224            return
225         end if
226  
227 <       if (.not. allocated(ElectrostaticMap)) then
217 <          allocate(ElectrostaticMap(nAtypes))
218 <       endif
227 >       allocate(ElectrostaticMap(nAtypes))
228  
229      end if
230  
# Line 233 | Line 242 | contains
242      ElectrostaticMap(myATID)%is_Quadrupole = is_Quadrupole
243      ElectrostaticMap(myATID)%is_Tap = is_Tap
244  
245 +    hasElectrostaticMap = .true.
246 +
247    end subroutine newElectrostaticType
248  
249    subroutine setCharge(c_ident, charge, status)
# Line 244 | Line 255 | contains
255      status = 0
256      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
257  
258 <    if (.not.allocated(ElectrostaticMap)) then
258 >    if (.not.hasElectrostaticMap) then
259         call handleError("electrostatic", "no ElectrostaticMap was present before first call of setCharge!")
260         status = -1
261         return
# Line 274 | Line 285 | contains
285      status = 0
286      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
287  
288 <    if (.not.allocated(ElectrostaticMap)) then
288 >    if (.not.hasElectrostaticMap) then
289         call handleError("electrostatic", "no ElectrostaticMap was present before first call of setDipoleMoment!")
290         status = -1
291         return
# Line 304 | Line 315 | contains
315      status = 0
316      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
317  
318 <    if (.not.allocated(ElectrostaticMap)) then
318 >    if (.not.hasElectrostaticMap) then
319         call handleError("electrostatic", "no ElectrostaticMap was present before first call of setSplitDipoleDistance!")
320         status = -1
321         return
# Line 334 | Line 345 | contains
345      status = 0
346      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
347  
348 <    if (.not.allocated(ElectrostaticMap)) then
348 >    if (.not.hasElectrostaticMap) then
349         call handleError("electrostatic", "no ElectrostaticMap was present before first call of setQuadrupoleMoments!")
350         status = -1
351         return
# Line 365 | Line 376 | contains
376      integer :: localError
377      real(kind=dp) :: c
378  
379 <    if (.not.allocated(ElectrostaticMap)) then
379 >    if (.not.hasElectrostaticMap) then
380         call handleError("electrostatic", "no ElectrostaticMap was present before first call of getCharge!")
381         return
382      end if
# Line 383 | Line 394 | contains
394      integer :: localError
395      real(kind=dp) :: dm
396  
397 <    if (.not.allocated(ElectrostaticMap)) then
397 >    if (.not.hasElectrostaticMap) then
398         call handleError("electrostatic", "no ElectrostaticMap was present before first call of getDipoleMoment!")
399         return
400      end if
# Line 407 | Line 418 | contains
418      rcuti3 = rcuti2*rcuti
419      rcuti4 = rcuti2*rcuti2
420  
421 <    if (summationMethod .eq. DAMPED_WOLF) then
422 <       if (.not.haveDWAconstants) then
423 <          
413 <          if (.not.haveDampingAlpha) then
414 <             call handleError("checkSummationMethod", "no Damping Alpha set!")
415 <          endif
416 <          
417 <          if (.not.haveDefaultCutoff) then
418 <             call handleError("checkSummationMethod", "no Default Cutoff set!")
419 <          endif
420 <
421 <          constEXP = exp(-dampingAlpha*dampingAlpha*defaultCutoff*defaultCutoff)
422 <          constERFC = derfc(dampingAlpha*defaultCutoff)
423 <          invRootPi = 0.56418958354775628695d0
424 <          alphaPi = 2*dampingAlpha*invRootPi
425 <  
426 <          haveDWAconstants = .true.
421 >    if (screeningMethod .eq. DAMPED) then
422 >       if (.not.haveDampingAlpha) then
423 >          call handleError("checkSummationMethod", "no Damping Alpha set!")
424         endif
425 +      
426 +       if (.not.haveDefaultCutoff) then
427 +          call handleError("checkSummationMethod", "no Default Cutoff set!")
428 +       endif
429 +
430 +       constEXP = exp(-alpha2*defaultCutoff2)
431 +       invRootPi = 0.56418958354775628695d0
432 +       alphaPi = 2.0d0*dampingAlpha*invRootPi
433 +       f0c = derfc(dampingAlpha*defaultCutoff)
434 +       f1c = alphaPi*defaultCutoff*constEXP + f0c
435 +       f2c = alphaPi*2.0d0*alpha2*constEXP
436 +       f3c = alphaPi*2.0d0*alpha2*constEXP*defaultCutoff2*defaultCutoff
437      endif
438  
439      if (summationMethod .eq. REACTION_FIELD) then
440 <       if (.not.haveDielectric) then
441 <          call handleError("checkSummationMethod", "no reaction field Dielectric set!")
440 >       if (haveDielectric) then
441 >          defaultCutoff2 = defaultCutoff*defaultCutoff
442 >          preRF = (dielectric-1.0d0) / &
443 >               ((2.0d0*dielectric+1.0d0)*defaultCutoff2*defaultCutoff)
444 >          preRF2 = 2.0d0*preRF
445 >       else
446 >          call handleError("checkSummationMethod", "Dielectric not set")
447         endif
448 +      
449      endif
450  
451      summationMethodChecked = .true.
452    end subroutine checkSummationMethod
453  
454  
455 <
441 <  subroutine doElectrostaticPair(atom1, atom2, d, rij, r2, sw, &
455 >  subroutine doElectrostaticPair(atom1, atom2, d, rij, r2, rcut, sw, &
456         vpair, fpair, pot, eFrame, f, t, do_pot)
457  
458      logical, intent(in) :: do_pot
# Line 446 | Line 460 | contains
460      integer, intent(in) :: atom1, atom2
461      integer :: localError
462  
463 <    real(kind=dp), intent(in) :: rij, r2, sw
463 >    real(kind=dp), intent(in) :: rij, r2, sw, rcut
464      real(kind=dp), intent(in), dimension(3) :: d
465      real(kind=dp), intent(inout) :: vpair
466 <    real(kind=dp), intent(inout), dimension(3) :: fpair
466 >    real(kind=dp), intent(inout), dimension(3) :: fpair    
467  
468      real( kind = dp ) :: pot
469      real( kind = dp ), dimension(9,nLocal) :: eFrame
470      real( kind = dp ), dimension(3,nLocal) :: f
471 +    real( kind = dp ), dimension(3,nLocal) :: felec
472      real( kind = dp ), dimension(3,nLocal) :: t
473  
474      real (kind = dp), dimension(3) :: ux_i, uy_i, uz_i
# Line 471 | Line 486 | contains
486      real (kind=dp) :: cx_i, cy_i, cz_i
487      real (kind=dp) :: cx_j, cy_j, cz_j
488      real (kind=dp) :: cx2, cy2, cz2
489 <    real (kind=dp) :: ct_i, ct_j, ct_ij, a1
489 >    real (kind=dp) :: ct_i, ct_j, ct_ij, a0, a1
490      real (kind=dp) :: riji, ri, ri2, ri3, ri4
491      real (kind=dp) :: pref, vterm, epot, dudr, vterm1, vterm2
492      real (kind=dp) :: xhat, yhat, zhat
493      real (kind=dp) :: dudx, dudy, dudz
494      real (kind=dp) :: scale, sc2, bigR
495 <    real (kind=dp) :: varERFC, varEXP
496 <    real (kind=dp) :: limScale
495 >    real (kind=dp) :: varEXP
496 >    real (kind=dp) :: pot_term
497 >    real (kind=dp) :: preVal, rfVal
498 >    real (kind=dp) :: f13, f134
499  
483    if (.not.allocated(ElectrostaticMap)) then
484       call handleError("electrostatic", "no ElectrostaticMap was present before first call of do_electrostatic_pair!")
485       return
486    end if
487
500      if (.not.summationMethodChecked) then
501         call checkSummationMethod()
490      
502      endif
503  
493
504   #ifdef IS_MPI
505      me1 = atid_Row(atom1)
506      me2 = atid_Col(atom2)
# Line 625 | Line 635 | contains
635         cz_j = uz_j(1)*xhat + uz_j(2)*yhat + uz_j(3)*zhat
636      endif
637    
638 <    epot = 0.0_dp
639 <    dudx = 0.0_dp
640 <    dudy = 0.0_dp
641 <    dudz = 0.0_dp
638 >    epot = 0.0d0
639 >    dudx = 0.0d0
640 >    dudy = 0.0d0
641 >    dudz = 0.0d0
642  
643 <    dudux_i = 0.0_dp
644 <    duduy_i = 0.0_dp
645 <    duduz_i = 0.0_dp
643 >    dudux_i = 0.0d0
644 >    duduy_i = 0.0d0
645 >    duduz_i = 0.0d0
646  
647 <    dudux_j = 0.0_dp
648 <    duduy_j = 0.0_dp
649 <    duduz_j = 0.0_dp
647 >    dudux_j = 0.0d0
648 >    duduy_j = 0.0d0
649 >    duduz_j = 0.0d0
650  
651      if (i_is_Charge) then
652  
653         if (j_is_Charge) then
654 +          if (screeningMethod .eq. DAMPED) then
655 +             f0 = derfc(dampingAlpha*rij)
656 +             varEXP = exp(-alpha2*rij*rij)
657 +             f1 = alphaPi*rij*varEXP + f0
658 +          endif
659  
660 <          if (summationMethod .eq. UNDAMPED_WOLF) then
660 >          preVal = pre11 * q_i * q_j
661  
662 <             vterm = pre11 * q_i * q_j * (riji - rcuti)
663 <             vpair = vpair + vterm
649 <             epot = epot + sw*vterm
662 >          if (summationMethod .eq. SHIFTED_POTENTIAL) then
663 >             vterm = preVal * (riji*f0 - rcuti*f0c)
664              
665 <             dudr  = -sw*pre11*q_i*q_j * (riji*riji-rcuti2)*riji
665 >             dudr  = -sw * preVal * riji * riji * f1
666 >  
667 >          elseif (summationMethod .eq. SHIFTED_FORCE) then
668 >             vterm = preVal * ( riji*f0 - rcuti*f0c + &
669 >                  f1c*rcuti2*(rij-defaultCutoff) )
670              
671 <             dudx = dudx + dudr * d(1)
672 <             dudy = dudy + dudr * d(2)
673 <             dudz = dudz + dudr * d(3)
674 <
675 <          elseif (summationMethod .eq. DAMPED_WOLF) then
658 <
659 <             varERFC = derfc(dampingAlpha*rij)
660 <             varEXP = exp(-dampingAlpha*dampingAlpha*rij*rij)
661 <             vterm = pre11 * q_i * q_j * (varERFC*riji - constERFC*rcuti)
662 <             vpair = vpair + vterm
663 <             epot = epot + sw*vterm
671 >             dudr  = -sw*preVal * (riji*riji*f1 - rcuti2*f1c)
672 >  
673 >          elseif (summationMethod .eq. REACTION_FIELD) then
674 >             rfVal = preRF*rij*rij
675 >             vterm = preVal * ( riji + rfVal )
676              
677 <             dudr  = -sw*pre11*q_i*q_j * ( riji*((varERFC*riji*riji &
678 <                                                  + alphaPi*varEXP) &
667 <                                                 - (constERFC*rcuti2 &
668 <                                                    + alphaPi*constEXP)) )
669 <            
670 <             dudx = dudx + dudr * d(1)
671 <             dudy = dudy + dudr * d(2)
672 <             dudz = dudz + dudr * d(3)
673 <
677 >             dudr  = sw * preVal * ( 2.0d0*rfVal - riji )*riji
678 >  
679            else
680 <
676 <             vterm = pre11 * q_i * q_j * riji
677 <             vpair = vpair + vterm
678 <             epot = epot + sw*vterm
680 >             vterm = preVal * riji*f0
681              
682 <             dudr  = - sw * vterm * riji
683 <            
682 <             dudx = dudx + dudr * xhat
683 <             dudy = dudy + dudr * yhat
684 <             dudz = dudz + dudr * zhat
685 <
682 >             dudr  = - sw * preVal * riji*riji*f1
683 >  
684            endif
685  
686 +          vpair = vpair + vterm
687 +          epot = epot + sw*vterm
688 +
689 +          dudx = dudx + dudr * xhat
690 +          dudy = dudy + dudr * yhat
691 +          dudz = dudz + dudr * zhat
692 +
693         endif
694  
695         if (j_is_Dipole) then
696 +          if (screeningMethod .eq. DAMPED) then
697 +             f0 = derfc(dampingAlpha*rij)
698 +             varEXP = exp(-alpha2*rij*rij)
699 +             f1 = alphaPi*rij*varEXP + f0
700 +             f3 = alphaPi*2.0d0*alpha2*varEXP*rij*rij*rij
701 +          endif
702  
703            pref = pre12 * q_i * mu_j
704  
705 <          if (summationMethod .eq. UNDAMPED_WOLF) then
705 >          if (summationMethod .eq. REACTION_FIELD) then
706               ri2 = riji * riji
707               ri3 = ri2 * riji
708 <
709 <             pref = pre12 * q_i * mu_j
699 <             vterm = - pref * ct_j * (ri2 - rcuti2)
708 >    
709 >             vterm = - pref * ct_j * ( ri2 - preRF2*rij )
710               vpair = vpair + vterm
711               epot = epot + sw*vterm
712              
# Line 704 | Line 714 | contains
714               !! r_j - r_i and the charge-dipole potential takes the origin
715               !! as the point dipole, which is atom j in this case.
716              
717 <             dudx = dudx - sw*pref * ( ri3*( uz_j(1) - 3.0d0*ct_j*xhat) &
718 <                  - rcuti3*( uz_j(1) - 3.0d0*ct_j*d(1)*rcuti ) )
719 <             dudy = dudy - sw*pref * ( ri3*( uz_j(2) - 3.0d0*ct_j*yhat) &
720 <                  - rcuti3*( uz_j(2) - 3.0d0*ct_j*d(2)*rcuti ) )
721 <             dudz = dudz - sw*pref * ( ri3*( uz_j(3) - 3.0d0*ct_j*zhat) &
722 <                  - rcuti3*( uz_j(3) - 3.0d0*ct_j*d(3)*rcuti ) )
723 <            
724 <             duduz_j(1) = duduz_j(1) - sw*pref*( ri2*xhat - d(1)*rcuti3 )
725 <             duduz_j(2) = duduz_j(2) - sw*pref*( ri2*yhat - d(2)*rcuti3 )
716 <             duduz_j(3) = duduz_j(3) - sw*pref*( ri2*zhat - d(3)*rcuti3 )
717 >             dudx = dudx - sw*pref*( ri3*(uz_j(1) - 3.0d0*ct_j*xhat) - &
718 >                                     preRF2*uz_j(1) )
719 >             dudy = dudy - sw*pref*( ri3*(uz_j(2) - 3.0d0*ct_j*yhat) - &
720 >                                     preRF2*uz_j(2) )
721 >             dudz = dudz - sw*pref*( ri3*(uz_j(3) - 3.0d0*ct_j*zhat) - &
722 >                                     preRF2*uz_j(3) )        
723 >             duduz_j(1) = duduz_j(1) - sw*pref * xhat * ( ri2 - preRF2*rij )
724 >             duduz_j(2) = duduz_j(2) - sw*pref * yhat * ( ri2 - preRF2*rij )
725 >             duduz_j(3) = duduz_j(3) - sw*pref * zhat * ( ri2 - preRF2*rij )
726  
727            else
728               if (j_is_SplitDipole) then
729 <                BigR = sqrt(r2 + 0.25_dp * d_j * d_j)
730 <                ri = 1.0_dp / BigR
729 >                BigR = sqrt(r2 + 0.25d0 * d_j * d_j)
730 >                ri = 1.0d0 / BigR
731                  scale = rij * ri
732               else
733                  ri = riji
734 <                scale = 1.0_dp
734 >                scale = 1.0d0
735               endif
736              
737               ri2 = ri * ri
738               ri3 = ri2 * ri
739               sc2 = scale * scale
740  
741 <             pref = pre12 * q_i * mu_j
742 <             vterm = - pref * ct_j * ri2 * scale
741 >             pot_term =  ri2 * scale * f1
742 >             vterm = - pref * ct_j * pot_term
743               vpair = vpair + vterm
744               epot = epot + sw*vterm
745              
# Line 738 | Line 747 | contains
747               !! r_j - r_i and the charge-dipole potential takes the origin
748               !! as the point dipole, which is atom j in this case.
749              
750 <             dudx = dudx - sw*pref * ri3 * ( uz_j(1) - 3.0d0*ct_j*xhat*sc2)
751 <             dudy = dudy - sw*pref * ri3 * ( uz_j(2) - 3.0d0*ct_j*yhat*sc2)
752 <             dudz = dudz - sw*pref * ri3 * ( uz_j(3) - 3.0d0*ct_j*zhat*sc2)
753 <            
754 <             duduz_j(1) = duduz_j(1) - sw*pref * ri2 * xhat * scale
755 <             duduz_j(2) = duduz_j(2) - sw*pref * ri2 * yhat * scale
756 <             duduz_j(3) = duduz_j(3) - sw*pref * ri2 * zhat * scale
750 >             dudx = dudx - sw*pref * ri3 * ( uz_j(1)*f1 - &
751 >                  ct_j*xhat*sc2*( 3.0d0*f1 + f3 ) )
752 >             dudy = dudy - sw*pref * ri3 * ( uz_j(2)*f1 - &
753 >                  ct_j*yhat*sc2*( 3.0d0*f1 + f3 ) )
754 >             dudz = dudz - sw*pref * ri3 * ( uz_j(3)*f1 - &
755 >                  ct_j*zhat*sc2*( 3.0d0*f1 + f3 ) )
756 >                          
757 >             duduz_j(1) = duduz_j(1) - sw*pref * pot_term * xhat
758 >             duduz_j(2) = duduz_j(2) - sw*pref * pot_term * yhat
759 >             duduz_j(3) = duduz_j(3) - sw*pref * pot_term * zhat
760  
761            endif
762         endif
763  
764         if (j_is_Quadrupole) then
765 +          if (screeningMethod .eq. DAMPED) then
766 +             f0 = derfc(dampingAlpha*rij)
767 +             varEXP = exp(-alpha2*rij*rij)
768 +             f1 = alphaPi*rij*varEXP + f0
769 +             f2 = alphaPi*2.0d0*alpha2*varEXP
770 +             f3 = f2*rij*rij*rij
771 +             f4 = 2.0d0*alpha2*f2*rij
772 +          endif
773 +
774            ri2 = riji * riji
775            ri3 = ri2 * riji
776            ri4 = ri2 * ri2
# Line 757 | Line 778 | contains
778            cy2 = cy_j * cy_j
779            cz2 = cz_j * cz_j
780  
781 <          if (summationMethod .eq. UNDAMPED_WOLF) then
782 <             pref =  pre14 * q_i / 3.0_dp
783 <             vterm1 = pref * ri3*( qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
784 <                  qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
785 <                  qzz_j * (3.0_dp*cz2 - 1.0_dp) )
786 <             vterm2 = pref * rcuti3*( qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
787 <                  qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
767 <                  qzz_j * (3.0_dp*cz2 - 1.0_dp) )
768 <             vpair = vpair + ( vterm1 - vterm2 )
769 <             epot = epot + sw*( vterm1 - vterm2 )
770 <            
771 <             dudx = dudx - (5.0_dp * &
772 <                  (vterm1*riji*xhat - vterm2*rcuti2*d(1))) + sw*pref * ( &
773 <                  (ri4 - rcuti4)*(qxx_j*(6.0_dp*cx_j*ux_j(1)) - &
774 <                  qxx_j*2.0_dp*(xhat - rcuti*d(1))) + &
775 <                  (ri4 - rcuti4)*(qyy_j*(6.0_dp*cy_j*uy_j(1)) - &
776 <                  qyy_j*2.0_dp*(xhat - rcuti*d(1))) + &
777 <                  (ri4 - rcuti4)*(qzz_j*(6.0_dp*cz_j*uz_j(1)) - &
778 <                  qzz_j*2.0_dp*(xhat - rcuti*d(1))) )
779 <             dudy = dudy - (5.0_dp * &
780 <                  (vterm1*riji*yhat - vterm2*rcuti2*d(2))) + sw*pref * ( &
781 <                  (ri4 - rcuti4)*(qxx_j*(6.0_dp*cx_j*ux_j(2)) - &
782 <                  qxx_j*2.0_dp*(yhat - rcuti*d(2))) + &
783 <                  (ri4 - rcuti4)*(qyy_j*(6.0_dp*cy_j*uy_j(2)) - &
784 <                  qyy_j*2.0_dp*(yhat - rcuti*d(2))) + &
785 <                  (ri4 - rcuti4)*(qzz_j*(6.0_dp*cz_j*uz_j(2)) - &
786 <                  qzz_j*2.0_dp*(yhat - rcuti*d(2))) )
787 <             dudz = dudz - (5.0_dp * &
788 <                  (vterm1*riji*zhat - vterm2*rcuti2*d(3))) + sw*pref * ( &
789 <                  (ri4 - rcuti4)*(qxx_j*(6.0_dp*cx_j*ux_j(3)) - &
790 <                  qxx_j*2.0_dp*(zhat - rcuti*d(3))) + &
791 <                  (ri4 - rcuti4)*(qyy_j*(6.0_dp*cy_j*uy_j(3)) - &
792 <                  qyy_j*2.0_dp*(zhat - rcuti*d(3))) + &
793 <                  (ri4 - rcuti4)*(qzz_j*(6.0_dp*cz_j*uz_j(3)) - &
794 <                  qzz_j*2.0_dp*(zhat - rcuti*d(3))) )
795 <            
796 <             dudux_j(1) = dudux_j(1) + sw*pref*(ri3*(qxx_j*6.0_dp*cx_j*xhat) -&
797 <                  rcuti4*(qxx_j*6.0_dp*cx_j*d(1)))
798 <             dudux_j(2) = dudux_j(2) + sw*pref*(ri3*(qxx_j*6.0_dp*cx_j*yhat) -&
799 <                  rcuti4*(qxx_j*6.0_dp*cx_j*d(2)))
800 <             dudux_j(3) = dudux_j(3) + sw*pref*(ri3*(qxx_j*6.0_dp*cx_j*zhat) -&
801 <                  rcuti4*(qxx_j*6.0_dp*cx_j*d(3)))
802 <            
803 <             duduy_j(1) = duduy_j(1) + sw*pref*(ri3*(qyy_j*6.0_dp*cy_j*xhat) -&
804 <                  rcuti4*(qyy_j*6.0_dp*cx_j*d(1)))
805 <             duduy_j(2) = duduy_j(2) + sw*pref*(ri3*(qyy_j*6.0_dp*cy_j*yhat) -&
806 <                  rcuti4*(qyy_j*6.0_dp*cx_j*d(2)))
807 <             duduy_j(3) = duduy_j(3) + sw*pref*(ri3*(qyy_j*6.0_dp*cy_j*zhat) -&
808 <                  rcuti4*(qyy_j*6.0_dp*cx_j*d(3)))
809 <            
810 <             duduz_j(1) = duduz_j(1) + sw*pref*(ri3*(qzz_j*6.0_dp*cz_j*xhat) -&
811 <                  rcuti4*(qzz_j*6.0_dp*cx_j*d(1)))
812 <             duduz_j(2) = duduz_j(2) + sw*pref*(ri3*(qzz_j*6.0_dp*cz_j*yhat) -&
813 <                  rcuti4*(qzz_j*6.0_dp*cx_j*d(2)))
814 <             duduz_j(3) = duduz_j(3) + sw*pref*(ri3*(qzz_j*6.0_dp*cz_j*zhat) -&
815 <                  rcuti4*(qzz_j*6.0_dp*cx_j*d(3)))
816 <        
817 <          else
818 <             pref =  pre14 * q_i / 3.0_dp
819 <             vterm = pref * ri3 * (qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
820 <                  qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
821 <                  qzz_j * (3.0_dp*cz2 - 1.0_dp))
822 <             vpair = vpair + vterm
823 <             epot = epot + sw*vterm
824 <            
825 <             dudx = dudx - 5.0_dp*sw*vterm*riji*xhat + sw*pref * ri4 * ( &
826 <                  qxx_j*(6.0_dp*cx_j*ux_j(1) - 2.0_dp*xhat) + &
827 <                  qyy_j*(6.0_dp*cy_j*uy_j(1) - 2.0_dp*xhat) + &
828 <                  qzz_j*(6.0_dp*cz_j*uz_j(1) - 2.0_dp*xhat) )
829 <             dudy = dudy - 5.0_dp*sw*vterm*riji*yhat + sw*pref * ri4 * ( &
830 <                  qxx_j*(6.0_dp*cx_j*ux_j(2) - 2.0_dp*yhat) + &
831 <                  qyy_j*(6.0_dp*cy_j*uy_j(2) - 2.0_dp*yhat) + &
832 <                  qzz_j*(6.0_dp*cz_j*uz_j(2) - 2.0_dp*yhat) )
833 <             dudz = dudz - 5.0_dp*sw*vterm*riji*zhat + sw*pref * ri4 * ( &
834 <                  qxx_j*(6.0_dp*cx_j*ux_j(3) - 2.0_dp*zhat) + &
835 <                  qyy_j*(6.0_dp*cy_j*uy_j(3) - 2.0_dp*zhat) + &
836 <                  qzz_j*(6.0_dp*cz_j*uz_j(3) - 2.0_dp*zhat) )
837 <            
838 <             dudux_j(1) = dudux_j(1) + sw*pref * ri3*(qxx_j*6.0_dp*cx_j*xhat)
839 <             dudux_j(2) = dudux_j(2) + sw*pref * ri3*(qxx_j*6.0_dp*cx_j*yhat)
840 <             dudux_j(3) = dudux_j(3) + sw*pref * ri3*(qxx_j*6.0_dp*cx_j*zhat)
841 <            
842 <             duduy_j(1) = duduy_j(1) + sw*pref * ri3*(qyy_j*6.0_dp*cy_j*xhat)
843 <             duduy_j(2) = duduy_j(2) + sw*pref * ri3*(qyy_j*6.0_dp*cy_j*yhat)
844 <             duduy_j(3) = duduy_j(3) + sw*pref * ri3*(qyy_j*6.0_dp*cy_j*zhat)
845 <            
846 <             duduz_j(1) = duduz_j(1) + sw*pref * ri3*(qzz_j*6.0_dp*cz_j*xhat)
847 <             duduz_j(2) = duduz_j(2) + sw*pref * ri3*(qzz_j*6.0_dp*cz_j*yhat)
848 <             duduz_j(3) = duduz_j(3) + sw*pref * ri3*(qzz_j*6.0_dp*cz_j*zhat)
781 >          pref =  pre14 * q_i / 3.0d0
782 >          pot_term = ri3*(qxx_j * (3.0d0*cx2 - 1.0d0) + &
783 >               qyy_j * (3.0d0*cy2 - 1.0d0) + &
784 >               qzz_j * (3.0d0*cz2 - 1.0d0))
785 >          vterm = pref * (pot_term*f1 + (qxx_j*cx2 + qyy_j*cy2 + qzz_j*cz2)*f2)
786 >          vpair = vpair + vterm
787 >          epot = epot + sw*vterm
788            
789 <          endif
789 >          dudx = dudx - sw*pref*pot_term*riji*xhat*(5.0d0*f1 + f3) + &
790 >               sw*pref*ri4 * ( &
791 >               qxx_j*(2.0d0*cx_j*ux_j(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) + &
792 >               qyy_j*(2.0d0*cy_j*uy_j(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) + &
793 >               qzz_j*(2.0d0*cz_j*uz_j(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) ) &
794 >               + (qxx_j*cx2 + qyy_j*cy2 + qzz_j*cz2)*f4
795 >          dudy = dudy - sw*pref*pot_term*riji*yhat*(5.0d0*f1 + f3) + &
796 >               sw*pref*ri4 * ( &
797 >               qxx_j*(2.0d0*cx_j*ux_j(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) + &
798 >               qyy_j*(2.0d0*cy_j*uy_j(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) + &
799 >               qzz_j*(2.0d0*cz_j*uz_j(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) ) &
800 >               + (qxx_j*cx2 + qyy_j*cy2 + qzz_j*cz2)*f4
801 >          dudz = dudz - sw*pref*pot_term*riji*zhat*(5.0d0*f1 + f3) + &
802 >               sw*pref*ri4 * ( &
803 >               qxx_j*(2.0d0*cx_j*ux_j(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) + &
804 >               qyy_j*(2.0d0*cy_j*uy_j(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) + &
805 >               qzz_j*(2.0d0*cz_j*uz_j(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) ) &
806 >               + (qxx_j*cx2 + qyy_j*cy2 + qzz_j*cz2)*f4
807 >          
808 >          dudux_j(1) = dudux_j(1) + sw*pref*ri3*( (qxx_j*2.0d0*cx_j*xhat) &
809 >               * (3.0d0*f1 + f3) )
810 >          dudux_j(2) = dudux_j(2) + sw*pref*ri3*( (qxx_j*2.0d0*cx_j*yhat) &
811 >               * (3.0d0*f1 + f3) )
812 >          dudux_j(3) = dudux_j(3) + sw*pref*ri3*( (qxx_j*2.0d0*cx_j*zhat) &
813 >               * (3.0d0*f1 + f3) )
814 >          
815 >          duduy_j(1) = duduy_j(1) + sw*pref*ri3*( (qyy_j*2.0d0*cy_j*xhat) &
816 >               * (3.0d0*f1 + f3) )
817 >          duduy_j(2) = duduy_j(2) + sw*pref*ri3*( (qyy_j*2.0d0*cy_j*yhat) &
818 >               * (3.0d0*f1 + f3) )
819 >          duduy_j(3) = duduy_j(3) + sw*pref*ri3*( (qyy_j*2.0d0*cy_j*zhat) &
820 >               * (3.0d0*f1 + f3) )
821 >          
822 >          duduz_j(1) = duduz_j(1) + sw*pref*ri3*( (qzz_j*2.0d0*cz_j*xhat) &
823 >               * (3.0d0*f1 + f3) )
824 >          duduz_j(2) = duduz_j(2) + sw*pref*ri3*( (qzz_j*2.0d0*cz_j*yhat) &
825 >               * (3.0d0*f1 + f3) )
826 >          duduz_j(3) = duduz_j(3) + sw*pref*ri3*( (qzz_j*2.0d0*cz_j*zhat) &
827 >               * (3.0d0*f1 + f3) )
828 >          
829         endif
830      endif
831 <
831 >    
832      if (i_is_Dipole) then
833  
834         if (j_is_Charge) then
835 +          if (screeningMethod .eq. DAMPED) then
836 +             f0 = derfc(dampingAlpha*rij)
837 +             varEXP = exp(-alpha2*rij*rij)
838 +             f1 = alphaPi*rij*varEXP + f0
839 +             f3 = alphaPi*2.0d0*alpha2*varEXP*rij*rij*rij
840 +          endif
841            
842            pref = pre12 * q_j * mu_i
843            
844 <          if (summationMethod .eq. UNDAMPED_WOLF) then
844 >          if (summationMethod .eq. SHIFTED_POTENTIAL) then
845               ri2 = riji * riji
846               ri3 = ri2 * riji
847 +            
848 +             pot_term = ri2*f1 - rcuti2*f1c
849 +             vterm = pref * ct_i * pot_term
850 +             vpair = vpair + vterm
851 +             epot = epot + sw*vterm
852 +            
853 +             dudx = dudx + sw*pref*( ri3*(uz_i(1)*f1-ct_i*xhat*(3.0d0*f1+f3)) )
854 +             dudy = dudy + sw*pref*( ri3*(uz_i(2)*f1-ct_i*yhat*(3.0d0*f1+f3)) )
855 +             dudz = dudz + sw*pref*( ri3*(uz_i(3)*f1-ct_i*zhat*(3.0d0*f1+f3)) )
856 +            
857 +             duduz_i(1) = duduz_i(1) + sw*pref * xhat * pot_term
858 +             duduz_i(2) = duduz_i(2) + sw*pref * yhat * pot_term
859 +             duduz_i(3) = duduz_i(3) + sw*pref * zhat * pot_term
860  
861 <             pref = pre12 * q_j * mu_i
862 <             vterm = pref * ct_i * (ri2 - rcuti2)
861 >          elseif (summationMethod .eq. SHIFTED_FORCE) then
862 >             ri2 = riji * riji
863 >             ri3 = ri2 * riji
864 >
865 >             !! might need a -(f1c-f0c) or dct_i/dr in the derivative term...
866 >             pot_term = ri2*f1 - rcuti2*f1c + &
867 >                  (2.0d0*rcuti3*f1c + f2c)*( rij - defaultCutoff )
868 >             vterm = pref * ct_i * pot_term
869               vpair = vpair + vterm
870               epot = epot + sw*vterm
871              
872 <             !! this has a + sign in the () because the rij vector is
873 <             !! r_j - r_i and the charge-dipole potential takes the origin
874 <             !! as the point dipole, which is atom j in this case.
872 >             dudx = dudx + sw*pref*( ri3*(uz_i(1)*f1-ct_i*xhat*(3.0d0*f1+f3)) &
873 >                  - rcuti3*(uz_i(1)*f1c-ct_i*xhat*(3.0d0*f1c+f3c)) )
874 >             dudy = dudy + sw*pref*( ri3*(uz_i(2)*f1-ct_i*yhat*(3.0d0*f1+f3)) &
875 >                  - rcuti3*(uz_i(1)*f1c-ct_i*xhat*(3.0d0*f1c+f3c)) )
876 >             dudz = dudz + sw*pref*( ri3*(uz_i(3)*f1-ct_i*zhat*(3.0d0*f1+f3)) &
877 >                  - rcuti3*(uz_i(1)*f1c-ct_i*xhat*(3.0d0*f1c+f3c)) )
878              
879 <             dudx = dudx + sw*pref * ( ri3*( uz_i(1) - 3.0d0*ct_i*xhat) &
880 <                  - rcuti3*( uz_i(1) - 3.0d0*ct_i*d(1)*rcuti ) )
881 <             dudy = dudy + sw*pref * ( ri3*( uz_i(2) - 3.0d0*ct_i*yhat) &
882 <                  - rcuti3*( uz_i(2) - 3.0d0*ct_i*d(2)*rcuti ) )
883 <             dudz = dudz + sw*pref * ( ri3*( uz_i(3) - 3.0d0*ct_i*zhat) &
884 <                  - rcuti3*( uz_i(3) - 3.0d0*ct_i*d(3)*rcuti ) )
879 >             duduz_i(1) = duduz_i(1) + sw*pref * xhat * pot_term
880 >             duduz_i(2) = duduz_i(2) + sw*pref * yhat * pot_term
881 >             duduz_i(3) = duduz_i(3) + sw*pref * zhat * pot_term
882 >
883 >          elseif (summationMethod .eq. REACTION_FIELD) then
884 >             ri2 = riji * riji
885 >             ri3 = ri2 * riji
886 >
887 >             vterm = pref * ct_i * ( ri2 - preRF2*rij )
888 >             vpair = vpair + vterm
889 >             epot = epot + sw*vterm
890              
891 <             duduz_i(1) = duduz_i(1) - sw*pref*( ri2*xhat - d(1)*rcuti3 )
892 <             duduz_i(2) = duduz_i(2) - sw*pref*( ri2*yhat - d(2)*rcuti3 )
893 <             duduz_i(3) = duduz_i(3) - sw*pref*( ri2*zhat - d(3)*rcuti3 )
891 >             dudx = dudx + sw*pref * ( ri3*(uz_i(1) - 3.0d0*ct_i*xhat) - &
892 >                  preRF2*uz_i(1) )
893 >             dudy = dudy + sw*pref * ( ri3*(uz_i(2) - 3.0d0*ct_i*yhat) - &
894 >                  preRF2*uz_i(2) )
895 >             dudz = dudz + sw*pref * ( ri3*(uz_i(3) - 3.0d0*ct_i*zhat) - &
896 >                  preRF2*uz_i(3) )
897 >            
898 >             duduz_i(1) = duduz_i(1) + sw*pref * xhat * ( ri2 - preRF2*rij )
899 >             duduz_i(2) = duduz_i(2) + sw*pref * yhat * ( ri2 - preRF2*rij )
900 >             duduz_i(3) = duduz_i(3) + sw*pref * zhat * ( ri2 - preRF2*rij )
901  
902            else
903               if (i_is_SplitDipole) then
904 <                BigR = sqrt(r2 + 0.25_dp * d_i * d_i)
905 <                ri = 1.0_dp / BigR
904 >                BigR = sqrt(r2 + 0.25d0 * d_i * d_i)
905 >                ri = 1.0d0 / BigR
906                  scale = rij * ri
907               else
908                  ri = riji
909 <                scale = 1.0_dp
909 >                scale = 1.0d0
910               endif
911              
912               ri2 = ri * ri
913               ri3 = ri2 * ri
914               sc2 = scale * scale
915  
916 <             pref = pre12 * q_j * mu_i
917 <             vterm = pref * ct_i * ri2 * scale
916 >             pot_term = ri2 * f1 * scale
917 >             vterm = pref * ct_i * pot_term
918               vpair = vpair + vterm
919               epot = epot + sw*vterm
920              
921 <             dudx = dudx + sw*pref * ri3 * ( uz_i(1) - 3.0d0 * ct_i * xhat*sc2)
922 <             dudy = dudy + sw*pref * ri3 * ( uz_i(2) - 3.0d0 * ct_i * yhat*sc2)
923 <             dudz = dudz + sw*pref * ri3 * ( uz_i(3) - 3.0d0 * ct_i * zhat*sc2)
921 >             dudx = dudx + sw*pref * ri3 * ( uz_i(1)*f1 - &
922 >                  ct_i*xhat*sc2*( 3.0d0*f1 + f3 ) )
923 >             dudy = dudy + sw*pref * ri3 * ( uz_i(2)*f1 - &
924 >                  ct_i*yhat*sc2*( 3.0d0*f1 + f3 ) )
925 >             dudz = dudz + sw*pref * ri3 * ( uz_i(3)*f1 - &
926 >                  ct_i*zhat*sc2*( 3.0d0*f1 + f3 ) )
927              
928 <             duduz_i(1) = duduz_i(1) + sw*pref * ri2 * xhat * scale
929 <             duduz_i(2) = duduz_i(2) + sw*pref * ri2 * yhat * scale
930 <             duduz_i(3) = duduz_i(3) + sw*pref * ri2 * zhat * scale
928 >             duduz_i(1) = duduz_i(1) + sw*pref * pot_term * xhat
929 >             duduz_i(2) = duduz_i(2) + sw*pref * pot_term * yhat
930 >             duduz_i(3) = duduz_i(3) + sw*pref * pot_term * zhat
931            endif
932         endif
933        
934         if (j_is_Dipole) then
935 +          if (screeningMethod .eq. DAMPED) then
936 +             f0 = derfc(dampingAlpha*rij)
937 +             varEXP = exp(-alpha2*rij*rij)
938 +             f1 = alphaPi*rij*varEXP + f0
939 +             f2 = alphaPi*2.0d0*alpha2*varEXP
940 +             f3 = f2*rij*rij*rij
941 +             f4 = 2.0d0*alpha2*f3*rij*rij
942 +          endif
943  
944 <          if (summationMethod .eq. UNDAMPED_WOLF) then
945 <             ri2 = riji * riji
946 <             ri3 = ri2 * riji
947 <             ri4 = ri2 * ri2
944 >          ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
945 >          
946 >          ri2 = riji * riji
947 >          ri3 = ri2 * riji
948 >          ri4 = ri2 * ri2
949 >          
950 >          pref = pre22 * mu_i * mu_j
951  
952 <             pref = pre22 * mu_i * mu_j
953 <             vterm = pref * (ri3 - rcuti3) * (ct_ij - 3.0d0 * ct_i * ct_j)
952 >          if (summationMethod .eq. REACTION_FIELD) then
953 >             vterm = pref*( ri3*(ct_ij - 3.0d0 * ct_i * ct_j) - &
954 >                  preRF2*ct_ij )
955               vpair = vpair + vterm
956               epot = epot + sw*vterm
957              
958               a1 = 5.0d0 * ct_i * ct_j - ct_ij
959              
960               dudx = dudx + sw*pref*3.0d0*ri4 &
961 <                             * (a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1)) &
929 <                         - sw*pref*3.0d0*rcuti4 &
930 <                             * (a1*rcuti*d(1)-ct_i*uz_j(1)-ct_j*uz_i(1))
961 >                             * (a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
962               dudy = dudy + sw*pref*3.0d0*ri4 &
963 <                             * (a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2)) &
933 <                         - sw*pref*3.0d0*rcuti4 &
934 <                             * (a1*rcuti*d(2)-ct_i*uz_j(2)-ct_j*uz_i(2))
963 >                             * (a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
964               dudz = dudz + sw*pref*3.0d0*ri4 &
965 <                             * (a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3)) &
937 <                         - sw*pref*3.0d0*rcuti4 &
938 <                             * (a1*rcuti*d(3)-ct_i*uz_j(3)-ct_j*uz_i(3))
965 >                             * (a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
966              
967               duduz_i(1) = duduz_i(1) + sw*pref*(ri3*(uz_j(1)-3.0d0*ct_j*xhat) &
968 <                  - rcuti3*(uz_j(1) - 3.0d0*ct_j*d(1)*rcuti))
968 >                  - preRF2*uz_j(1))
969               duduz_i(2) = duduz_i(2) + sw*pref*(ri3*(uz_j(2)-3.0d0*ct_j*yhat) &
970 <                  - rcuti3*(uz_j(2) - 3.0d0*ct_j*d(2)*rcuti))
970 >                  - preRF2*uz_j(2))
971               duduz_i(3) = duduz_i(3) + sw*pref*(ri3*(uz_j(3)-3.0d0*ct_j*zhat) &
972 <                  - rcuti3*(uz_j(3) - 3.0d0*ct_j*d(3)*rcuti))
972 >                  - preRF2*uz_j(3))
973               duduz_j(1) = duduz_j(1) + sw*pref*(ri3*(uz_i(1)-3.0d0*ct_i*xhat) &
974 <                  - rcuti3*(uz_i(1) - 3.0d0*ct_i*d(1)*rcuti))
974 >                  - preRF2*uz_i(1))
975               duduz_j(2) = duduz_j(2) + sw*pref*(ri3*(uz_i(2)-3.0d0*ct_i*yhat) &
976 <                  - rcuti3*(uz_i(2) - 3.0d0*ct_i*d(2)*rcuti))
976 >                  - preRF2*uz_i(2))
977               duduz_j(3) = duduz_j(3) + sw*pref*(ri3*(uz_i(3)-3.0d0*ct_i*zhat) &
978 <                  - rcuti3*(uz_i(3) - 3.0d0*ct_i*d(3)*rcuti))
978 >                  - preRF2*uz_i(3))
979  
980            else
981               if (i_is_SplitDipole) then
982                  if (j_is_SplitDipole) then
983 <                   BigR = sqrt(r2 + 0.25_dp * d_i * d_i + 0.25_dp * d_j * d_j)
983 >                   BigR = sqrt(r2 + 0.25d0 * d_i * d_i + 0.25d0 * d_j * d_j)
984                  else
985 <                   BigR = sqrt(r2 + 0.25_dp * d_i * d_i)
985 >                   BigR = sqrt(r2 + 0.25d0 * d_i * d_i)
986                  endif
987 <                ri = 1.0_dp / BigR
987 >                ri = 1.0d0 / BigR
988                  scale = rij * ri                
989               else
990                  if (j_is_SplitDipole) then
991 <                   BigR = sqrt(r2 + 0.25_dp * d_j * d_j)
992 <                   ri = 1.0_dp / BigR
991 >                   BigR = sqrt(r2 + 0.25d0 * d_j * d_j)
992 >                   ri = 1.0d0 / BigR
993                     scale = rij * ri                            
994                  else                
995                     ri = riji
996 <                   scale = 1.0_dp
996 >                   scale = 1.0d0
997                  endif
998               endif
999              
973             ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
974            
975             ri2 = ri * ri
976             ri3 = ri2 * ri
977             ri4 = ri2 * ri2
1000               sc2 = scale * scale
1001 <            
1002 <             pref = pre22 * mu_i * mu_j
1003 <             vterm = pref * ri3 * (ct_ij - 3.0d0 * ct_i * ct_j * sc2)
1001 >
1002 >             pot_term = (ct_ij - 3.0d0 * ct_i * ct_j * sc2)
1003 >             vterm = pref * ( ri3*pot_term*f1 + (ct_i * ct_j)*f2 )
1004               vpair = vpair + vterm
1005               epot = epot + sw*vterm
1006              
1007 <             a1 = 5.0d0 * ct_i * ct_j * sc2 - ct_ij
1008 <            
987 <             dudx = dudx + sw*pref*3.0d0*ri4*scale &
988 <                             *(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
989 <             dudy = dudy + sw*pref*3.0d0*ri4*scale &
990 <                             *(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
991 <             dudz = dudz + sw*pref*3.0d0*ri4*scale &
992 <                             *(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
1007 >             f13 = f1+f3
1008 >             f134 = f13 + f4
1009              
1010 <             duduz_i(1) = duduz_i(1) + sw*pref*ri3 &
1011 <                                         *(uz_j(1) - 3.0d0*ct_j*xhat*sc2)
1012 <             duduz_i(2) = duduz_i(2) + sw*pref*ri3 &
1013 <                                         *(uz_j(2) - 3.0d0*ct_j*yhat*sc2)
1014 <             duduz_i(3) = duduz_i(3) + sw*pref*ri3 &
1015 <                                         *(uz_j(3) - 3.0d0*ct_j*zhat*sc2)
1010 > !!$             dudx = dudx + sw*pref * ( ri4*scale*( &
1011 > !!$                  3.0d0*(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))*f1 &
1012 > !!$                  - pot_term*f3) &
1013 > !!$                  + 2.0d0*ct_i*ct_j*xhat*(ct_i*uz_j(1)+ct_j*uz_i(1))*f3 &
1014 > !!$                  + (ct_i * ct_j)*f4 )
1015 > !!$             dudy = dudy + sw*pref * ( ri4*scale*( &
1016 > !!$                  3.0d0*(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))*f1 &
1017 > !!$                  - pot_term*f3) &
1018 > !!$                  + 2.0d0*ct_i*ct_j*yhat*(ct_i*uz_j(2)+ct_j*uz_i(2))*f3 &
1019 > !!$                  + (ct_i * ct_j)*f4 )
1020 > !!$             dudz = dudz + sw*pref * ( ri4*scale*( &
1021 > !!$                  3.0d0*(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))*f1 &
1022 > !!$                  - pot_term*f3) &
1023 > !!$                  + 2.0d0*ct_i*ct_j*zhat*(ct_i*uz_j(3)+ct_j*uz_i(3))*f3 &
1024 > !!$                  + (ct_i * ct_j)*f4 )
1025 >
1026 >             dudx = dudx + sw*pref * ( ri4*scale*( &
1027 >                  15.0d0*(ct_i * ct_j * sc2)*xhat*f134 - &
1028 >                  3.0d0*(ct_i*uz_j(1) + ct_j*uz_i(1) + ct_ij*xhat)*f134) )
1029 >             dudy = dudy + sw*pref * ( ri4*scale*( &
1030 >                  15.0d0*(ct_i * ct_j * sc2)*yhat*f134 - &
1031 >                  3.0d0*(ct_i*uz_j(2) + ct_j*uz_i(2) + ct_ij*yhat)*f134) )
1032 >             dudz = dudz + sw*pref * ( ri4*scale*( &
1033 >                  15.0d0*(ct_i * ct_j * sc2)*zhat*f134 - &
1034 >                  3.0d0*(ct_i*uz_j(3) + ct_j*uz_i(3) + ct_ij*zhat)*f134) )
1035              
1036 <             duduz_j(1) = duduz_j(1) + sw*pref*ri3 &
1037 <                                         *(uz_i(1) - 3.0d0*ct_i*xhat*sc2)
1038 <             duduz_j(2) = duduz_j(2) + sw*pref*ri3 &
1039 <                                         *(uz_i(2) - 3.0d0*ct_i*yhat*sc2)
1040 <             duduz_j(3) = duduz_j(3) + sw*pref*ri3 &
1041 <                                         *(uz_i(3) - 3.0d0*ct_i*zhat*sc2)
1036 >             duduz_i(1) = duduz_i(1) + sw*pref * &
1037 >                  ( ri3*(uz_j(1) - 3.0d0*ct_j*xhat*sc2)*f1 + (ct_j*xhat)*f2 )
1038 >             duduz_i(2) = duduz_i(2) + sw*pref * &
1039 >                  ( ri3*(uz_j(2) - 3.0d0*ct_j*yhat*sc2)*f1 + (ct_j*yhat)*f2 )
1040 >             duduz_i(3) = duduz_i(3) + sw*pref * &
1041 >                  ( ri3*(uz_j(3) - 3.0d0*ct_j*zhat*sc2)*f1 + (ct_j*zhat)*f2 )
1042 >            
1043 >             duduz_j(1) = duduz_j(1) + sw*pref * &
1044 >                  ( ri3*(uz_i(1) - 3.0d0*ct_i*xhat*sc2)*f1 + (ct_i*xhat)*f2 )
1045 >             duduz_j(2) = duduz_j(2) + sw*pref * &
1046 >                  ( ri3*(uz_i(2) - 3.0d0*ct_i*yhat*sc2)*f1 + (ct_i*yhat)*f2 )
1047 >             duduz_j(3) = duduz_j(3) + sw*pref * &
1048 >                  ( ri3*(uz_i(3) - 3.0d0*ct_i*zhat*sc2)*f1 + (ct_i*zhat)*f2 )
1049            endif
1050         endif
1051      endif
1052  
1053      if (i_is_Quadrupole) then
1054         if (j_is_Charge) then
1055 +          if (screeningMethod .eq. DAMPED) then
1056 +             f0 = derfc(dampingAlpha*rij)
1057 +             varEXP = exp(-alpha2*rij*rij)
1058 +             f1 = alphaPi*rij*varEXP + f0
1059 +             f2 = alphaPi*2.0d0*alpha2*varEXP
1060 +             f3 = f2*rij*rij*rij
1061 +             f4 = 2.0d0*alpha2*f2*rij
1062 +          endif
1063  
1064            ri2 = riji * riji
1065            ri3 = ri2 * riji
# Line 1018 | Line 1068 | contains
1068            cy2 = cy_i * cy_i
1069            cz2 = cz_i * cz_i
1070  
1071 <          if (summationMethod .eq. UNDAMPED_WOLF) then
1072 <             pref = pre14 * q_j / 3.0_dp
1073 <             vterm1 = pref * ri3*( qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1074 <                  qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1075 <                  qzz_i * (3.0_dp*cz2 - 1.0_dp) )
1076 <             vterm2 = pref * rcuti3*( qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1077 <                  qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1078 <                  qzz_i * (3.0_dp*cz2 - 1.0_dp) )
1079 <             vpair = vpair + ( vterm1 - vterm2 )
1080 <             epot = epot + sw*( vterm1 - vterm2 )
1081 <            
1082 <             dudx = dudx - sw*(5.0_dp*(vterm1*riji*xhat-vterm2*rcuti2*d(1))) +&
1083 <                  sw*pref * ( (ri4 - rcuti4)*(qxx_i*(6.0_dp*cx_i*ux_i(1)) - &
1084 <                  qxx_i*2.0_dp*(xhat - rcuti*d(1))) + &
1085 <                  (ri4 - rcuti4)*(qyy_i*(6.0_dp*cy_i*uy_i(1)) - &
1086 <                  qyy_i*2.0_dp*(xhat - rcuti*d(1))) + &
1087 <                  (ri4 - rcuti4)*(qzz_i*(6.0_dp*cz_i*uz_i(1)) - &
1088 <                  qzz_i*2.0_dp*(xhat - rcuti*d(1))) )
1089 <             dudy = dudy - sw*(5.0_dp*(vterm1*riji*yhat-vterm2*rcuti2*d(2))) +&
1090 <                  sw*pref * ( (ri4 - rcuti4)*(qxx_i*(6.0_dp*cx_i*ux_i(2)) - &
1091 <                  qxx_i*2.0_dp*(yhat - rcuti*d(2))) + &
1092 <                  (ri4 - rcuti4)*(qyy_i*(6.0_dp*cy_i*uy_i(2)) - &
1093 <                  qyy_i*2.0_dp*(yhat - rcuti*d(2))) + &
1094 <                  (ri4 - rcuti4)*(qzz_i*(6.0_dp*cz_i*uz_i(2)) - &
1095 <                  qzz_i*2.0_dp*(yhat - rcuti*d(2))) )
1096 <             dudz = dudz - sw*(5.0_dp*(vterm1*riji*zhat-vterm2*rcuti2*d(3))) +&
1097 <                  sw*pref * ( (ri4 - rcuti4)*(qxx_i*(6.0_dp*cx_i*ux_i(3)) - &
1098 <                  qxx_i*2.0_dp*(zhat - rcuti*d(3))) + &
1099 <                  (ri4 - rcuti4)*(qyy_i*(6.0_dp*cy_i*uy_i(3)) - &
1100 <                  qyy_i*2.0_dp*(zhat - rcuti*d(3))) + &
1101 <                  (ri4 - rcuti4)*(qzz_i*(6.0_dp*cz_i*uz_i(3)) - &
1102 <                  qzz_i*2.0_dp*(zhat - rcuti*d(3))) )
1103 <            
1104 <             dudux_i(1) = dudux_i(1) + sw*pref*(ri3*(qxx_i*6.0_dp*cx_i*xhat) -&
1105 <                  rcuti4*(qxx_i*6.0_dp*cx_i*d(1)))
1106 <             dudux_i(2) = dudux_i(2) + sw*pref*(ri3*(qxx_i*6.0_dp*cx_i*yhat) -&
1107 <                  rcuti4*(qxx_i*6.0_dp*cx_i*d(2)))
1108 <             dudux_i(3) = dudux_i(3) + sw*pref*(ri3*(qxx_i*6.0_dp*cx_i*zhat) -&
1109 <                  rcuti4*(qxx_i*6.0_dp*cx_i*d(3)))
1110 <            
1111 <             duduy_i(1) = duduy_i(1) + sw*pref*(ri3*(qyy_i*6.0_dp*cy_i*xhat) -&
1112 <                  rcuti4*(qyy_i*6.0_dp*cx_i*d(1)))
1113 <             duduy_i(2) = duduy_i(2) + sw*pref*(ri3*(qyy_i*6.0_dp*cy_i*yhat) -&
1114 <                  rcuti4*(qyy_i*6.0_dp*cx_i*d(2)))
1115 <             duduy_i(3) = duduy_i(3) + sw*pref*(ri3*(qyy_i*6.0_dp*cy_i*zhat) -&
1116 <                  rcuti4*(qyy_i*6.0_dp*cx_i*d(3)))
1117 <            
1068 <             duduz_i(1) = duduz_i(1) + sw*pref*(ri3*(qzz_i*6.0_dp*cz_i*xhat) -&
1069 <                  rcuti4*(qzz_i*6.0_dp*cx_i*d(1)))
1070 <             duduz_i(2) = duduz_i(2) + sw*pref*(ri3*(qzz_i*6.0_dp*cz_i*yhat) -&
1071 <                  rcuti4*(qzz_i*6.0_dp*cx_i*d(2)))
1072 <             duduz_i(3) = duduz_i(3) + sw*pref*(ri3*(qzz_i*6.0_dp*cz_i*zhat) -&
1073 <                  rcuti4*(qzz_i*6.0_dp*cx_i*d(3)))
1071 >          pref = pre14 * q_j / 3.0d0
1072 >          pot_term = ri3 * (qxx_i * (3.0d0*cx2 - 1.0d0) + &
1073 >                            qyy_i * (3.0d0*cy2 - 1.0d0) + &
1074 >                            qzz_i * (3.0d0*cz2 - 1.0d0))
1075 >          vterm = pref * (pot_term*f1 + (qxx_i*cx2 + qyy_i*cy2 + qzz_i*cz2)*f2)
1076 >          vpair = vpair + vterm
1077 >          epot = epot + sw*vterm
1078 >          
1079 >          dudx = dudx - sw*pref*pot_term*riji*xhat*(5.0d0*f1 + f3) + &
1080 >               sw*pref*ri4 * ( &
1081 >               qxx_i*(2.0d0*cx_i*ux_i(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) + &
1082 >               qyy_i*(2.0d0*cy_i*uy_i(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) + &
1083 >               qzz_i*(2.0d0*cz_i*uz_i(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) ) &
1084 >               + (qxx_i*cx2 + qyy_i*cy2 + qzz_i*cz2)*f4
1085 >          dudy = dudy - sw*pref*pot_term*riji*yhat*(5.0d0*f1 + f3) + &
1086 >               sw*pref*ri4 * ( &
1087 >               qxx_i*(2.0d0*cx_i*ux_i(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) + &
1088 >               qyy_i*(2.0d0*cy_i*uy_i(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) + &
1089 >               qzz_i*(2.0d0*cz_i*uz_i(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) ) &
1090 >               + (qxx_i*cx2 + qyy_i*cy2 + qzz_i*cz2)*f4
1091 >          dudz = dudz - sw*pref*pot_term*riji*zhat*(5.0d0*f1 + f3) + &
1092 >               sw*pref*ri4 * ( &
1093 >               qxx_i*(2.0d0*cx_i*ux_i(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) + &
1094 >               qyy_i*(2.0d0*cy_i*uy_i(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) + &
1095 >               qzz_i*(2.0d0*cz_i*uz_i(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) ) &
1096 >               + (qxx_i*cx2 + qyy_i*cy2 + qzz_i*cz2)*f4
1097 >          
1098 >          dudux_i(1) = dudux_i(1) + sw*pref*( ri3*(qxx_i*2.0d0*cx_i*xhat) &
1099 >               * (3.0d0*f1 + f3) )
1100 >          dudux_i(2) = dudux_i(2) + sw*pref*( ri3*(qxx_i*2.0d0*cx_i*yhat) &
1101 >               * (3.0d0*f1 + f3) )
1102 >          dudux_i(3) = dudux_i(3) + sw*pref*( ri3*(qxx_i*2.0d0*cx_i*zhat) &
1103 >               * (3.0d0*f1 + f3) )
1104 >          
1105 >          duduy_i(1) = duduy_i(1) + sw*pref*( ri3*(qyy_i*2.0d0*cy_i*xhat) &
1106 >               * (3.0d0*f1 + f3) )
1107 >          duduy_i(2) = duduy_i(2) + sw*pref*( ri3*(qyy_i*2.0d0*cy_i*yhat) &
1108 >               * (3.0d0*f1 + f3) )
1109 >          duduy_i(3) = duduy_i(3) + sw*pref*( ri3*(qyy_i*2.0d0*cy_i*zhat) &
1110 >               * (3.0d0*f1 + f3) )
1111 >          
1112 >          duduz_i(1) = duduz_i(1) + sw*pref*( ri3*(qzz_i*2.0d0*cz_i*xhat) &
1113 >               * (3.0d0*f1 + f3) )
1114 >          duduz_i(2) = duduz_i(2) + sw*pref*( ri3*(qzz_i*2.0d0*cz_i*yhat) &
1115 >               * (3.0d0*f1 + f3) )
1116 >          duduz_i(3) = duduz_i(3) + sw*pref*( ri3*(qzz_i*2.0d0*cz_i*zhat) &
1117 >               * (3.0d0*f1 + f3) )
1118  
1075          else
1076             pref = pre14 * q_j / 3.0_dp
1077             vterm = pref * ri3 * (qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1078                  qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1079                  qzz_i * (3.0_dp*cz2 - 1.0_dp))
1080             vpair = vpair + vterm
1081             epot = epot + sw*vterm
1082            
1083             dudx = dudx - 5.0_dp*sw*vterm*riji*xhat + sw*pref*ri4 * ( &
1084                  qxx_i*(6.0_dp*cx_i*ux_i(1) - 2.0_dp*xhat) + &
1085                  qyy_i*(6.0_dp*cy_i*uy_i(1) - 2.0_dp*xhat) + &
1086                  qzz_i*(6.0_dp*cz_i*uz_i(1) - 2.0_dp*xhat) )
1087             dudy = dudy - 5.0_dp*sw*vterm*riji*yhat + sw*pref*ri4 * ( &
1088                  qxx_i*(6.0_dp*cx_i*ux_i(2) - 2.0_dp*yhat) + &
1089                  qyy_i*(6.0_dp*cy_i*uy_i(2) - 2.0_dp*yhat) + &
1090                  qzz_i*(6.0_dp*cz_i*uz_i(2) - 2.0_dp*yhat) )
1091             dudz = dudz - 5.0_dp*sw*vterm*riji*zhat + sw*pref*ri4 * ( &
1092                  qxx_i*(6.0_dp*cx_i*ux_i(3) - 2.0_dp*zhat) + &
1093                  qyy_i*(6.0_dp*cy_i*uy_i(3) - 2.0_dp*zhat) + &
1094                  qzz_i*(6.0_dp*cz_i*uz_i(3) - 2.0_dp*zhat) )
1095            
1096             dudux_i(1) = dudux_i(1) + sw*pref*ri3*(qxx_i*6.0_dp*cx_i*xhat)
1097             dudux_i(2) = dudux_i(2) + sw*pref*ri3*(qxx_i*6.0_dp*cx_i*yhat)
1098             dudux_i(3) = dudux_i(3) + sw*pref*ri3*(qxx_i*6.0_dp*cx_i*zhat)
1099            
1100             duduy_i(1) = duduy_i(1) + sw*pref*ri3*(qyy_i*6.0_dp*cy_i*xhat)
1101             duduy_i(2) = duduy_i(2) + sw*pref*ri3*(qyy_i*6.0_dp*cy_i*yhat)
1102             duduy_i(3) = duduy_i(3) + sw*pref*ri3*(qyy_i*6.0_dp*cy_i*zhat)
1103            
1104             duduz_i(1) = duduz_i(1) + sw*pref*ri3*(qzz_i*6.0_dp*cz_i*xhat)
1105             duduz_i(2) = duduz_i(2) + sw*pref*ri3*(qzz_i*6.0_dp*cz_i*yhat)
1106             duduz_i(3) = duduz_i(3) + sw*pref*ri3*(qzz_i*6.0_dp*cz_i*zhat)
1107          endif
1119         endif
1120      endif
1121  
# Line 1217 | Line 1228 | contains
1228      return
1229    end subroutine doElectrostaticPair
1230  
1220  !! calculates the switching functions and their derivatives for a given
1221  subroutine calc_switch(r, mu, scale, dscale)
1222
1223    real (kind=dp), intent(in) :: r, mu
1224    real (kind=dp), intent(inout) :: scale, dscale
1225    real (kind=dp) :: rl, ru, mulow, minRatio, temp, scaleVal
1226
1227    ! distances must be in angstroms
1228    rl = 2.75d0
1229    ru = 3.75d0
1230    mulow = 0.0d0 !3.3856d0 ! 1.84 * 1.84
1231    minRatio = mulow / (mu*mu)
1232    scaleVal = 1.0d0 - minRatio
1233    
1234    if (r.lt.rl) then
1235       scale = minRatio
1236       dscale = 0.0d0
1237    elseif (r.gt.ru) then
1238       scale = 1.0d0
1239       dscale = 0.0d0
1240    else
1241       scale = 1.0d0 - scaleVal*((ru + 2.0d0*r - 3.0d0*rl) * (ru-r)**2) &
1242                        / ((ru - rl)**3)
1243       dscale = -scaleVal * 6.0d0 * (r-ru)*(r-rl)/((ru - rl)**3)    
1244    endif
1245        
1246    return
1247  end subroutine calc_switch
1248
1231    subroutine destroyElectrostaticTypes()
1232  
1233      if(allocated(ElectrostaticMap)) deallocate(ElectrostaticMap)
1234  
1235    end subroutine destroyElectrostaticTypes
1236  
1237 <  subroutine accumulate_rf(atom1, atom2, rij, eFrame, taper)
1237 >  subroutine self_self(atom1, eFrame, mypot, t, do_pot)
1238 >    logical, intent(in) :: do_pot
1239 >    integer, intent(in) :: atom1
1240 >    integer :: atid1
1241 >    real(kind=dp), dimension(9,nLocal) :: eFrame
1242 >    real(kind=dp), dimension(3,nLocal) :: t
1243 >    real(kind=dp) :: mu1, c1
1244 >    real(kind=dp) :: preVal, epot, mypot
1245 >    real(kind=dp) :: eix, eiy, eiz
1246  
1247 <    integer, intent(in) :: atom1, atom2
1248 <    real (kind = dp), intent(in) :: rij
1259 <    real (kind = dp), dimension(9,nLocal) :: eFrame
1247 >    ! this is a local only array, so we use the local atom type id's:
1248 >    atid1 = atid(atom1)
1249  
1250 <    integer :: me1, me2
1251 <    real (kind = dp), intent(in) :: taper
1252 <    real (kind = dp):: mu1, mu2
1253 <    real (kind = dp), dimension(3) :: ul1
1254 <    real (kind = dp), dimension(3) :: ul2  
1255 <
1256 <    integer :: localError
1257 <
1258 < #ifdef IS_MPI
1259 <    me1 = atid_Row(atom1)
1260 <    ul1(1) = eFrame_Row(3,atom1)
1261 <    ul1(2) = eFrame_Row(6,atom1)
1262 <    ul1(3) = eFrame_Row(9,atom1)
1263 <
1264 <    me2 = atid_Col(atom2)
1265 <    ul2(1) = eFrame_Col(3,atom2)
1266 <    ul2(2) = eFrame_Col(6,atom2)
1267 <    ul2(3) = eFrame_Col(9,atom2)
1268 < #else
1269 <    me1 = atid(atom1)
1270 <    ul1(1) = eFrame(3,atom1)
1271 <    ul1(2) = eFrame(6,atom1)
1272 <    ul1(3) = eFrame(9,atom1)
1273 <
1274 <    me2 = atid(atom2)
1275 <    ul2(1) = eFrame(3,atom2)
1276 <    ul2(2) = eFrame(6,atom2)
1277 <    ul2(3) = eFrame(9,atom2)
1289 < #endif
1290 <
1291 <    mu1 = getDipoleMoment(me1)
1292 <    mu2 = getDipoleMoment(me2)
1293 <
1294 < #ifdef IS_MPI
1295 <    rf_Row(1,atom1) = rf_Row(1,atom1) + ul2(1)*mu2*taper
1296 <    rf_Row(2,atom1) = rf_Row(2,atom1) + ul2(2)*mu2*taper
1297 <    rf_Row(3,atom1) = rf_Row(3,atom1) + ul2(3)*mu2*taper
1298 <
1299 <    rf_Col(1,atom2) = rf_Col(1,atom2) + ul1(1)*mu1*taper
1300 <    rf_Col(2,atom2) = rf_Col(2,atom2) + ul1(2)*mu1*taper
1301 <    rf_Col(3,atom2) = rf_Col(3,atom2) + ul1(3)*mu1*taper
1302 < #else
1303 <    rf(1,atom1) = rf(1,atom1) + ul2(1)*mu2*taper
1304 <    rf(2,atom1) = rf(2,atom1) + ul2(2)*mu2*taper
1305 <    rf(3,atom1) = rf(3,atom1) + ul2(3)*mu2*taper
1306 <
1307 <    rf(1,atom2) = rf(1,atom2) + ul1(1)*mu1*taper
1308 <    rf(2,atom2) = rf(2,atom2) + ul1(2)*mu1*taper
1309 <    rf(3,atom2) = rf(3,atom2) + ul1(3)*mu1*taper    
1310 < #endif
1311 <    return  
1312 <  end subroutine accumulate_rf
1250 >    if (.not.summationMethodChecked) then
1251 >       call checkSummationMethod()
1252 >    endif
1253 >    
1254 >    if (summationMethod .eq. REACTION_FIELD) then
1255 >       if (ElectrostaticMap(atid1)%is_Dipole) then
1256 >          mu1 = getDipoleMoment(atid1)
1257 >          
1258 >          preVal = pre22 * preRF2 * mu1*mu1
1259 >          mypot = mypot - 0.5d0*preVal
1260 >          
1261 >          ! The self-correction term adds into the reaction field vector
1262 >          
1263 >          eix = preVal * eFrame(3,atom1)
1264 >          eiy = preVal * eFrame(6,atom1)
1265 >          eiz = preVal * eFrame(9,atom1)
1266 >          
1267 >          ! once again, this is self-self, so only the local arrays are needed
1268 >          ! even for MPI jobs:
1269 >          
1270 >          t(1,atom1)=t(1,atom1) - eFrame(6,atom1)*eiz + &
1271 >               eFrame(9,atom1)*eiy
1272 >          t(2,atom1)=t(2,atom1) - eFrame(9,atom1)*eix + &
1273 >               eFrame(3,atom1)*eiz
1274 >          t(3,atom1)=t(3,atom1) - eFrame(3,atom1)*eiy + &
1275 >               eFrame(6,atom1)*eix
1276 >          
1277 >       endif
1278  
1279 <  subroutine accumulate_self_rf(atom1, mu1, eFrame)
1279 >    elseif ( (summationMethod .eq. SHIFTED_FORCE) .or. &
1280 >         (summationMethod .eq. SHIFTED_POTENTIAL) ) then
1281 >       if (ElectrostaticMap(atid1)%is_Charge) then
1282 >          c1 = getCharge(atid1)
1283 >          
1284 >          if (screeningMethod .eq. DAMPED) then
1285 >             mypot = mypot - (f0c * rcuti * 0.5d0 + &
1286 >                  dampingAlpha*invRootPi) * c1 * c1    
1287 >            
1288 >          else            
1289 >             mypot = mypot - (rcuti * 0.5d0 * c1 * c1)
1290 >            
1291 >          endif
1292 >       endif
1293 >    endif
1294 >    
1295 >    return
1296 >  end subroutine self_self
1297  
1298 +  subroutine rf_self_excludes(atom1, atom2, sw, eFrame, d, rij, vpair, myPot, &
1299 +       f, t, do_pot)
1300 +    logical, intent(in) :: do_pot
1301      integer, intent(in) :: atom1
1302 <    real(kind=dp), intent(in) :: mu1
1302 >    integer, intent(in) :: atom2
1303 >    logical :: i_is_Charge, j_is_Charge
1304 >    logical :: i_is_Dipole, j_is_Dipole
1305 >    integer :: atid1
1306 >    integer :: atid2
1307 >    real(kind=dp), intent(in) :: rij
1308 >    real(kind=dp), intent(in) :: sw
1309 >    real(kind=dp), intent(in), dimension(3) :: d
1310 >    real(kind=dp), intent(inout) :: vpair
1311      real(kind=dp), dimension(9,nLocal) :: eFrame
1312 +    real(kind=dp), dimension(3,nLocal) :: f
1313 +    real(kind=dp), dimension(3,nLocal) :: t
1314 +    real (kind = dp), dimension(3) :: duduz_i
1315 +    real (kind = dp), dimension(3) :: duduz_j
1316 +    real (kind = dp), dimension(3) :: uz_i
1317 +    real (kind = dp), dimension(3) :: uz_j
1318 +    real(kind=dp) :: q_i, q_j, mu_i, mu_j
1319 +    real(kind=dp) :: xhat, yhat, zhat
1320 +    real(kind=dp) :: ct_i, ct_j
1321 +    real(kind=dp) :: ri2, ri3, riji, vterm
1322 +    real(kind=dp) :: pref, preVal, rfVal, myPot
1323 +    real(kind=dp) :: dudx, dudy, dudz, dudr
1324  
1325 <    !! should work for both MPI and non-MPI version since this is not pairwise.
1326 <    rf(1,atom1) = rf(1,atom1) + eFrame(3,atom1)*mu1
1322 <    rf(2,atom1) = rf(2,atom1) + eFrame(6,atom1)*mu1
1323 <    rf(3,atom1) = rf(3,atom1) + eFrame(9,atom1)*mu1
1324 <
1325 <    return
1326 <  end subroutine accumulate_self_rf
1327 <
1328 <  subroutine reaction_field_final(a1, mu1, eFrame, rfpot, t, do_pot)
1329 <
1330 <    integer, intent(in) :: a1
1331 <    real (kind=dp), intent(in) :: mu1
1332 <    real (kind=dp), intent(inout) :: rfpot
1333 <    logical, intent(in) :: do_pot
1334 <    real (kind = dp), dimension(9,nLocal) :: eFrame
1335 <    real (kind = dp), dimension(3,nLocal) :: t
1336 <
1337 <    integer :: localError
1338 <
1339 <    if (.not.preRFCalculated) then
1340 <       call setReactionFieldPrefactor()
1325 >    if (.not.summationMethodChecked) then
1326 >       call checkSummationMethod()
1327      endif
1328  
1329 <    ! compute torques on dipoles:
1330 <    ! pre converts from mu in units of debye to kcal/mol
1329 >    dudx = 0.0d0
1330 >    dudy = 0.0d0
1331 >    dudz = 0.0d0
1332  
1333 <    ! The torque contribution is dipole cross reaction_field  
1333 >    riji = 1.0d0/rij
1334  
1335 <    t(1,a1) = t(1,a1) + preRF*mu1*(eFrame(6,a1)*rf(3,a1) - &
1336 <                                   eFrame(9,a1)*rf(2,a1))
1337 <    t(2,a1) = t(2,a1) + preRF*mu1*(eFrame(9,a1)*rf(1,a1) - &
1351 <                                   eFrame(3,a1)*rf(3,a1))
1352 <    t(3,a1) = t(3,a1) + preRF*mu1*(eFrame(3,a1)*rf(2,a1) - &
1353 <                                   eFrame(6,a1)*rf(1,a1))
1335 >    xhat = d(1) * riji
1336 >    yhat = d(2) * riji
1337 >    zhat = d(3) * riji
1338  
1339 <    ! the potential contribution is -1/2 dipole dot reaction_field
1339 >    ! this is a local only array, so we use the local atom type id's:
1340 >    atid1 = atid(atom1)
1341 >    atid2 = atid(atom2)
1342 >    i_is_Charge = ElectrostaticMap(atid1)%is_Charge
1343 >    j_is_Charge = ElectrostaticMap(atid2)%is_Charge
1344 >    i_is_Dipole = ElectrostaticMap(atid1)%is_Dipole
1345 >    j_is_Dipole = ElectrostaticMap(atid2)%is_Dipole
1346  
1347 <    if (do_pot) then
1348 <       rfpot = rfpot - 0.5d0 * preRF * mu1 * &
1349 <            (rf(1,a1)*eFrame(3,a1) + rf(2,a1)*eFrame(6,a1) + &
1350 <             rf(3,a1)*eFrame(9,a1))
1347 >    if (i_is_Charge.and.j_is_Charge) then
1348 >       q_i = ElectrostaticMap(atid1)%charge
1349 >       q_j = ElectrostaticMap(atid2)%charge
1350 >      
1351 >       preVal = pre11 * q_i * q_j
1352 >       rfVal = preRF*rij*rij
1353 >       vterm = preVal * rfVal
1354 >      
1355 >       myPot = myPot + sw*vterm
1356 >      
1357 >       dudr  = sw*preVal * 2.0d0*rfVal*riji
1358 >      
1359 >       dudx = dudx + dudr * xhat
1360 >       dudy = dudy + dudr * yhat
1361 >       dudz = dudz + dudr * zhat
1362 >      
1363 >    elseif (i_is_Charge.and.j_is_Dipole) then
1364 >       q_i = ElectrostaticMap(atid1)%charge
1365 >       mu_j = ElectrostaticMap(atid2)%dipole_moment
1366 >       uz_j(1) = eFrame(3,atom2)
1367 >       uz_j(2) = eFrame(6,atom2)
1368 >       uz_j(3) = eFrame(9,atom2)
1369 >       ct_j = uz_j(1)*xhat + uz_j(2)*yhat + uz_j(3)*zhat
1370 >      
1371 >       ri2 = riji * riji
1372 >       ri3 = ri2 * riji
1373 >      
1374 >       pref = pre12 * q_i * mu_j
1375 >       vterm = - pref * ct_j * ( ri2 - preRF2*rij )
1376 >       myPot = myPot + sw*vterm
1377 >      
1378 >       dudx = dudx - sw*pref*( ri3*(uz_j(1)-3.0d0*ct_j*xhat) &
1379 >            - preRF2*uz_j(1) )
1380 >       dudy = dudy - sw*pref*( ri3*(uz_j(2)-3.0d0*ct_j*yhat) &
1381 >            - preRF2*uz_j(2) )
1382 >       dudz = dudz - sw*pref*( ri3*(uz_j(3)-3.0d0*ct_j*zhat) &
1383 >            - preRF2*uz_j(3) )
1384 >      
1385 >       duduz_j(1) = duduz_j(1) - sw * pref * xhat * ( ri2 - preRF2*rij )
1386 >       duduz_j(2) = duduz_j(2) - sw * pref * yhat * ( ri2 - preRF2*rij )
1387 >       duduz_j(3) = duduz_j(3) - sw * pref * zhat * ( ri2 - preRF2*rij )
1388 >      
1389 >    elseif (i_is_Dipole.and.j_is_Charge) then
1390 >       mu_i = ElectrostaticMap(atid1)%dipole_moment
1391 >       q_j = ElectrostaticMap(atid2)%charge
1392 >       uz_i(1) = eFrame(3,atom1)
1393 >       uz_i(2) = eFrame(6,atom1)
1394 >       uz_i(3) = eFrame(9,atom1)
1395 >       ct_i = uz_i(1)*xhat + uz_i(2)*yhat + uz_i(3)*zhat
1396 >      
1397 >       ri2 = riji * riji
1398 >       ri3 = ri2 * riji
1399 >      
1400 >       pref = pre12 * q_j * mu_i
1401 >       vterm = pref * ct_i * ( ri2 - preRF2*rij )
1402 >       myPot = myPot + sw*vterm
1403 >      
1404 >       dudx = dudx + sw*pref*( ri3*(uz_i(1)-3.0d0*ct_i*xhat) &
1405 >            - preRF2*uz_i(1) )
1406 >       dudy = dudy + sw*pref*( ri3*(uz_i(2)-3.0d0*ct_i*yhat) &
1407 >            - preRF2*uz_i(2) )
1408 >       dudz = dudz + sw*pref*( ri3*(uz_i(3)-3.0d0*ct_i*zhat) &
1409 >            - preRF2*uz_i(3) )
1410 >      
1411 >       duduz_i(1) = duduz_i(1) + sw * pref * xhat * ( ri2 - preRF2*rij )
1412 >       duduz_i(2) = duduz_i(2) + sw * pref * yhat * ( ri2 - preRF2*rij )
1413 >       duduz_i(3) = duduz_i(3) + sw * pref * zhat * ( ri2 - preRF2*rij )
1414 >      
1415      endif
1416 +      
1417  
1418 <    return
1419 <  end subroutine reaction_field_final
1420 <
1421 <  subroutine rf_correct_forces(atom1, atom2, d, rij, eFrame, taper, f, fpair)
1422 <
1423 <    integer, intent(in) :: atom1, atom2
1424 <    real(kind=dp), dimension(3), intent(in) :: d
1425 <    real(kind=dp), intent(in) :: rij, taper
1426 <    real( kind = dp ), dimension(9,nLocal) :: eFrame
1427 <    real( kind = dp ), dimension(3,nLocal) :: f
1428 <    real( kind = dp ), dimension(3), intent(inout) :: fpair
1429 <
1430 <    real (kind = dp), dimension(3) :: ul1
1431 <    real (kind = dp), dimension(3) :: ul2
1432 <    real (kind = dp) :: dtdr
1433 <    real (kind = dp) :: dudx, dudy, dudz, u1dotu2
1434 <    integer :: me1, me2, id1, id2
1380 <    real (kind = dp) :: mu1, mu2
1381 <
1382 <    integer :: localError
1383 <
1384 <    if (.not.preRFCalculated) then
1385 <       call setReactionFieldPrefactor()
1418 >    ! accumulate the forces and torques resulting from the self term
1419 >    f(1,atom1) = f(1,atom1) + dudx
1420 >    f(2,atom1) = f(2,atom1) + dudy
1421 >    f(3,atom1) = f(3,atom1) + dudz
1422 >    
1423 >    f(1,atom2) = f(1,atom2) - dudx
1424 >    f(2,atom2) = f(2,atom2) - dudy
1425 >    f(3,atom2) = f(3,atom2) - dudz
1426 >    
1427 >    if (i_is_Dipole) then
1428 >       t(1,atom1)=t(1,atom1) - uz_i(2)*duduz_i(3) + uz_i(3)*duduz_i(2)
1429 >       t(2,atom1)=t(2,atom1) - uz_i(3)*duduz_i(1) + uz_i(1)*duduz_i(3)
1430 >       t(3,atom1)=t(3,atom1) - uz_i(1)*duduz_i(2) + uz_i(2)*duduz_i(1)
1431 >    elseif (j_is_Dipole) then
1432 >       t(1,atom2)=t(1,atom2) - uz_j(2)*duduz_j(3) + uz_j(3)*duduz_j(2)
1433 >       t(2,atom2)=t(2,atom2) - uz_j(3)*duduz_j(1) + uz_j(1)*duduz_j(3)
1434 >       t(3,atom2)=t(3,atom2) - uz_j(1)*duduz_j(2) + uz_j(2)*duduz_j(1)
1435      endif
1436  
1388    if (rij.le.rrf) then
1389
1390       if (rij.lt.rt) then
1391          dtdr = 0.0d0
1392       else
1393          !         write(*,*) 'rf correct in taper region'
1394          dtdr = 6.0d0*(rij*rij - rij*rt - rij*rrf +rrf*rt)/((rrf-rt)**3)
1395       endif
1396
1397 #ifdef IS_MPI
1398       me1 = atid_Row(atom1)
1399       ul1(1) = eFrame_Row(3,atom1)
1400       ul1(2) = eFrame_Row(6,atom1)
1401       ul1(3) = eFrame_Row(9,atom1)
1402
1403       me2 = atid_Col(atom2)
1404       ul2(1) = eFrame_Col(3,atom2)
1405       ul2(2) = eFrame_Col(6,atom2)
1406       ul2(3) = eFrame_Col(9,atom2)
1407 #else
1408       me1 = atid(atom1)
1409       ul1(1) = eFrame(3,atom1)
1410       ul1(2) = eFrame(6,atom1)
1411       ul1(3) = eFrame(9,atom1)
1412
1413       me2 = atid(atom2)
1414       ul2(1) = eFrame(3,atom2)
1415       ul2(2) = eFrame(6,atom2)
1416       ul2(3) = eFrame(9,atom2)
1417 #endif
1418
1419       mu1 = getDipoleMoment(me1)
1420       mu2 = getDipoleMoment(me2)
1421
1422       u1dotu2 = ul1(1)*ul2(1) + ul1(2)*ul2(2) + ul1(3)*ul2(3)
1423
1424       dudx = - preRF*mu1*mu2*u1dotu2*dtdr*d(1)/rij
1425       dudy = - preRF*mu1*mu2*u1dotu2*dtdr*d(2)/rij
1426       dudz = - preRF*mu1*mu2*u1dotu2*dtdr*d(3)/rij
1427
1428 #ifdef IS_MPI
1429       f_Row(1,atom1) = f_Row(1,atom1) + dudx
1430       f_Row(2,atom1) = f_Row(2,atom1) + dudy
1431       f_Row(3,atom1) = f_Row(3,atom1) + dudz
1432
1433       f_Col(1,atom2) = f_Col(1,atom2) - dudx
1434       f_Col(2,atom2) = f_Col(2,atom2) - dudy
1435       f_Col(3,atom2) = f_Col(3,atom2) - dudz
1436 #else
1437       f(1,atom1) = f(1,atom1) + dudx
1438       f(2,atom1) = f(2,atom1) + dudy
1439       f(3,atom1) = f(3,atom1) + dudz
1440
1441       f(1,atom2) = f(1,atom2) - dudx
1442       f(2,atom2) = f(2,atom2) - dudy
1443       f(3,atom2) = f(3,atom2) - dudz
1444 #endif
1445
1446 #ifdef IS_MPI
1447       id1 = AtomRowToGlobal(atom1)
1448       id2 = AtomColToGlobal(atom2)
1449 #else
1450       id1 = atom1
1451       id2 = atom2
1452 #endif
1453
1454       if (molMembershipList(id1) .ne. molMembershipList(id2)) then
1455
1456          fpair(1) = fpair(1) + dudx
1457          fpair(2) = fpair(2) + dudy
1458          fpair(3) = fpair(3) + dudz
1459
1460       endif
1461
1462    end if
1437      return
1438 <  end subroutine rf_correct_forces
1438 >  end subroutine rf_self_excludes
1439  
1440   end module electrostatic_module

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines