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 2409 by chrisfen, Wed Nov 2 20:36:25 2005 UTC vs.
Revision 2724 by chrisfen, Fri Apr 21 03:19:52 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/fScreeningMethod.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 >  !! number of points for electrostatic splines
82 >  integer, parameter :: np = 100
83 >
84 >  !! variables to handle different summation methods for long-range
85 >  !! electrostatics:
86    integer, save :: summationMethod = NONE
87    integer, save :: screeningMethod = UNDAMPED
88    logical, save :: summationMethodChecked = .false.
# Line 83 | Line 90 | module electrostatic_module
90    real(kind=DP), save :: defaultCutoff2 = 0.0_DP
91    logical, save :: haveDefaultCutoff = .false.
92    real(kind=DP), save :: dampingAlpha = 0.0_DP
93 +  real(kind=DP), save :: alpha2 = 0.0_DP
94    logical, save :: haveDampingAlpha = .false.
95    real(kind=DP), save :: dielectric = 1.0_DP
96    logical, save :: haveDielectric = .false.
89  real(kind=DP), save :: constERFC = 0.0_DP
97    real(kind=DP), save :: constEXP = 0.0_DP
98    real(kind=dp), save :: rcuti = 0.0_DP
99    real(kind=dp), save :: rcuti2 = 0.0_DP
# Line 99 | Line 106 | module electrostatic_module
106    real(kind=dp), save :: rrfsq = 1.0_DP
107    real(kind=dp), save :: preRF = 0.0_DP
108    real(kind=dp), save :: preRF2 = 0.0_DP
109 <
110 < #ifdef __IFC
109 >  real(kind=dp), save :: f0 = 1.0_DP
110 >  real(kind=dp), save :: f1 = 1.0_DP
111 >  real(kind=dp), save :: f2 = 0.0_DP
112 >  real(kind=dp), save :: f3 = 0.0_DP
113 >  real(kind=dp), save :: f4 = 0.0_DP
114 >  real(kind=dp), save :: f0c = 1.0_DP
115 >  real(kind=dp), save :: f1c = 1.0_DP
116 >  real(kind=dp), save :: f2c = 0.0_DP
117 >  real(kind=dp), save :: f3c = 0.0_DP
118 >  real(kind=dp), save :: f4c = 0.0_DP
119 >  real(kind=dp), save :: df0 = 0.0_DP
120 >  type(cubicSpline), save :: f0spline
121 >  logical, save :: haveElectroSpline = .false.
122 >
123 >
124 > #if defined(__IFC) || defined(__PGI)
125   ! error function for ifc version > 7.
126    double precision, external :: derfc
127   #endif
# Line 110 | Line 131 | module electrostatic_module
131    public :: setElectrostaticCutoffRadius
132    public :: setDampingAlpha
133    public :: setReactionFieldDielectric
134 +  public :: buildElectroSpline
135    public :: newElectrostaticType
136    public :: setCharge
137    public :: setDipoleMoment
# Line 122 | Line 144 | module electrostatic_module
144    public :: self_self
145    public :: rf_self_excludes
146  
147 +
148    type :: Electrostatic
149       integer :: c_ident
150       logical :: is_Charge = .false.
# Line 137 | Line 160 | contains
160  
161    type(Electrostatic), dimension(:), allocatable :: ElectrostaticMap
162  
163 +  logical, save :: hasElectrostaticMap
164 +
165   contains
166  
167    subroutine setElectrostaticSummationMethod(the_ESM)
# Line 159 | Line 184 | contains
184      real(kind=dp), intent(in) :: thisRcut
185      real(kind=dp), intent(in) :: thisRsw
186      defaultCutoff = thisRcut
187 +    defaultCutoff2 = defaultCutoff*defaultCutoff
188      rrf = defaultCutoff
189      rt = thisRsw
190      haveDefaultCutoff = .true.
# Line 167 | Line 193 | contains
193    subroutine setDampingAlpha(thisAlpha)
194      real(kind=dp), intent(in) :: thisAlpha
195      dampingAlpha = thisAlpha
196 +    alpha2 = dampingAlpha*dampingAlpha
197      haveDampingAlpha = .true.
198    end subroutine setDampingAlpha
199    
# Line 175 | Line 202 | contains
202      dielectric = thisDielectric
203      haveDielectric = .true.
204    end subroutine setReactionFieldDielectric
205 +
206 +  subroutine buildElectroSpline()
207 +    real( kind = dp ), dimension(np) :: xvals, yvals
208 +    real( kind = dp ) :: dx, rmin, rval
209 +    integer :: i
210 +
211 +    rmin = 0.0d0
212 +
213 +    dx = (defaultCutoff-rmin) / dble(np-1)
214 +    
215 +    do i = 1, np
216 +       rval = rmin + dble(i-1)*dx
217 +       xvals(i) = rval
218 +       yvals(i) = derfc(dampingAlpha*rval)
219 +    enddo
220 +
221 +    call newSpline(f0spline, xvals, yvals, .true.)
222 +
223 +    haveElectroSpline = .true.
224 +  end subroutine buildElectroSpline
225  
226    subroutine newElectrostaticType(c_ident, is_Charge, is_Dipole, &
227         is_SplitDipole, is_Quadrupole, is_Tap, status)
# Line 203 | Line 250 | contains
250            return
251         end if
252  
253 <       if (.not. allocated(ElectrostaticMap)) then
207 <          allocate(ElectrostaticMap(nAtypes))
208 <       endif
253 >       allocate(ElectrostaticMap(nAtypes))
254  
255      end if
256  
# Line 223 | Line 268 | contains
268      ElectrostaticMap(myATID)%is_Quadrupole = is_Quadrupole
269      ElectrostaticMap(myATID)%is_Tap = is_Tap
270  
271 +    hasElectrostaticMap = .true.
272 +
273    end subroutine newElectrostaticType
274  
275    subroutine setCharge(c_ident, charge, status)
# Line 234 | Line 281 | contains
281      status = 0
282      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
283  
284 <    if (.not.allocated(ElectrostaticMap)) then
284 >    if (.not.hasElectrostaticMap) then
285         call handleError("electrostatic", "no ElectrostaticMap was present before first call of setCharge!")
286         status = -1
287         return
# Line 264 | Line 311 | contains
311      status = 0
312      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
313  
314 <    if (.not.allocated(ElectrostaticMap)) then
314 >    if (.not.hasElectrostaticMap) then
315         call handleError("electrostatic", "no ElectrostaticMap was present before first call of setDipoleMoment!")
316         status = -1
317         return
# Line 294 | Line 341 | contains
341      status = 0
342      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
343  
344 <    if (.not.allocated(ElectrostaticMap)) then
344 >    if (.not.hasElectrostaticMap) then
345         call handleError("electrostatic", "no ElectrostaticMap was present before first call of setSplitDipoleDistance!")
346         status = -1
347         return
# Line 324 | Line 371 | contains
371      status = 0
372      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
373  
374 <    if (.not.allocated(ElectrostaticMap)) then
374 >    if (.not.hasElectrostaticMap) then
375         call handleError("electrostatic", "no ElectrostaticMap was present before first call of setQuadrupoleMoments!")
376         status = -1
377         return
# Line 355 | Line 402 | contains
402      integer :: localError
403      real(kind=dp) :: c
404  
405 <    if (.not.allocated(ElectrostaticMap)) then
405 >    if (.not.hasElectrostaticMap) then
406         call handleError("electrostatic", "no ElectrostaticMap was present before first call of getCharge!")
407         return
408      end if
# Line 373 | Line 420 | contains
420      integer :: localError
421      real(kind=dp) :: dm
422  
423 <    if (.not.allocated(ElectrostaticMap)) then
423 >    if (.not.hasElectrostaticMap) then
424         call handleError("electrostatic", "no ElectrostaticMap was present before first call of getDipoleMoment!")
425         return
426      end if
# Line 406 | Line 453 | contains
453            call handleError("checkSummationMethod", "no Default Cutoff set!")
454         endif
455  
456 <       constEXP = exp(-dampingAlpha*dampingAlpha*defaultCutoff*defaultCutoff)
410 <       constERFC = derfc(dampingAlpha*defaultCutoff)
456 >       constEXP = exp(-alpha2*defaultCutoff2)
457         invRootPi = 0.56418958354775628695d0
458 <       alphaPi = 2*dampingAlpha*invRootPi
459 <      
458 >       alphaPi = 2.0d0*dampingAlpha*invRootPi
459 >       f0c = derfc(dampingAlpha*defaultCutoff)
460 >       f1c = alphaPi*defaultCutoff*constEXP + f0c
461 >       f2c = alphaPi*2.0d0*alpha2*constEXP
462 >       f3c = alphaPi*2.0d0*alpha2*constEXP*defaultCutoff2*defaultCutoff
463      endif
464  
465      if (summationMethod .eq. REACTION_FIELD) then
# Line 425 | Line 474 | contains
474        
475      endif
476  
477 +    if (.not.haveElectroSpline) then
478 +       call buildElectroSpline()
479 +    end if
480 +
481      summationMethodChecked = .true.
482    end subroutine checkSummationMethod
483  
431 !!$
432 !!$  subroutine doElectrostaticPair(atom1, atom2, d, rij, r2, sw, &
433 !!$       vpair, fpair, pot, eFrame, f, t, do_pot)
434  subroutine doElectrostaticPair(atom1, atom2, d, rij, r2, sw, &
435       vpair, fpair, pot, eFrame, f, t, do_pot, fstrs)
484  
485 +  subroutine doElectrostaticPair(atom1, atom2, d, rij, r2, rcut, sw, &
486 +       vpair, fpair, pot, eFrame, f, t, do_pot)
487 +
488      logical, intent(in) :: do_pot
489  
490      integer, intent(in) :: atom1, atom2
491      integer :: localError
492  
493 <    real(kind=dp), intent(in) :: rij, r2, sw
493 >    real(kind=dp), intent(in) :: rij, r2, sw, rcut
494      real(kind=dp), intent(in), dimension(3) :: d
495      real(kind=dp), intent(inout) :: vpair
496      real(kind=dp), intent(inout), dimension(3) :: fpair    
446    real(kind=dp), intent(inout), dimension(3) :: fstrs
497  
498      real( kind = dp ) :: pot
499      real( kind = dp ), dimension(9,nLocal) :: eFrame
# Line 466 | Line 516 | contains
516      real (kind=dp) :: cx_i, cy_i, cz_i
517      real (kind=dp) :: cx_j, cy_j, cz_j
518      real (kind=dp) :: cx2, cy2, cz2
519 <    real (kind=dp) :: ct_i, ct_j, ct_ij, a1
519 >    real (kind=dp) :: ct_i, ct_j, ct_ij, a0, a1
520      real (kind=dp) :: riji, ri, ri2, ri3, ri4
521      real (kind=dp) :: pref, vterm, epot, dudr, vterm1, vterm2
522      real (kind=dp) :: xhat, yhat, zhat
523      real (kind=dp) :: dudx, dudy, dudz
524      real (kind=dp) :: scale, sc2, bigR
525 <    real (kind=dp) :: varERFC, varEXP
526 <    real (kind=dp) :: limScale
525 >    real (kind=dp) :: varEXP
526 >    real (kind=dp) :: pot_term
527      real (kind=dp) :: preVal, rfVal
528 +    real (kind=dp) :: f13, f134
529  
479    if (.not.allocated(ElectrostaticMap)) then
480       call handleError("electrostatic", "no ElectrostaticMap was present before first call of do_electrostatic_pair!")
481       return
482    end if
483
530      if (.not.summationMethodChecked) then
531         call checkSummationMethod()
532      endif
# Line 493 | Line 539 | contains
539      me2 = atid(atom2)
540   #endif
541  
496 !!$    if (rij .ge. defaultCutoff) then
497 !!$       write(*,*) 'warning: rij = ', rij, ' rcut = ', defaultCutoff, ' sw = ', sw
498 !!$    endif
499
542      !! some variables we'll need independent of electrostatic type:
543  
544      riji = 1.0d0 / rij
# Line 538 | Line 580 | contains
580         if (i_is_SplitDipole) then
581            d_i = ElectrostaticMap(me1)%split_dipole_distance
582         endif
583 <
583 >       duduz_i = zero
584      endif
585  
586      if (i_is_Quadrupole) then
# Line 569 | Line 611 | contains
611         cx_i = ux_i(1)*xhat + ux_i(2)*yhat + ux_i(3)*zhat
612         cy_i = uy_i(1)*xhat + uy_i(2)*yhat + uy_i(3)*zhat
613         cz_i = uz_i(1)*xhat + uz_i(2)*yhat + uz_i(3)*zhat
614 +       dudux_i = zero
615 +       duduy_i = zero
616 +       duduz_i = zero
617      endif
618  
619      if (j_is_Charge) then
# Line 591 | Line 636 | contains
636         if (j_is_SplitDipole) then
637            d_j = ElectrostaticMap(me2)%split_dipole_distance
638         endif
639 +       duduz_j = zero
640      endif
641  
642      if (j_is_Quadrupole) then
# Line 621 | Line 667 | contains
667         cx_j = ux_j(1)*xhat + ux_j(2)*yhat + ux_j(3)*zhat
668         cy_j = uy_j(1)*xhat + uy_j(2)*yhat + uy_j(3)*zhat
669         cz_j = uz_j(1)*xhat + uz_j(2)*yhat + uz_j(3)*zhat
670 +       dudux_j = zero
671 +       duduy_j = zero
672 +       duduz_j = zero
673      endif
674    
675 <    epot = 0.0_dp
676 <    dudx = 0.0_dp
677 <    dudy = 0.0_dp
678 <    dudz = 0.0_dp
675 >    epot = zero
676 >    dudx = zero
677 >    dudy = zero
678 >    dudz = zero  
679  
631    dudux_i = 0.0_dp
632    duduy_i = 0.0_dp
633    duduz_i = 0.0_dp
634
635    dudux_j = 0.0_dp
636    duduy_j = 0.0_dp
637    duduz_j = 0.0_dp
638
680      if (i_is_Charge) then
681  
682         if (j_is_Charge) then
683 +          if (screeningMethod .eq. DAMPED) then
684 +             call lookupUniformSpline1d(f0spline, rij, f0, df0)
685 +             f1 = -rij * df0 + f0
686 + !!$             f0 = derfc(dampingAlpha*rij)
687 + !!$             varEXP = exp(-alpha2*rij*rij)
688 + !!$             f1 = alphaPi*rij*varEXP + f0
689 +          endif
690  
691 <          if (summationMethod .eq. SHIFTED_POTENTIAL) then
691 >          preVal = pre11 * q_i * q_j
692  
693 <             vterm = pre11 * q_i * q_j * (riji - rcuti)
694 <             vpair = vpair + vterm
647 <             epot = epot + sw*vterm
693 >          if (summationMethod .eq. SHIFTED_POTENTIAL) then
694 >             vterm = preVal * (riji*f0 - rcuti*f0c)
695              
696 <             dudr  = -sw*pre11*q_i*q_j * (riji*riji)
697 <            
651 <             dudx = dudx + dudr * xhat
652 <             dudy = dudy + dudr * yhat
653 <             dudz = dudz + dudr * zhat
654 <
655 < !!$          elseif (summationMethod .eq. DAMPED_WOLF) then
656 < !!$             varERFC = derfc(dampingAlpha*rij)
657 < !!$             varEXP = exp(-dampingAlpha*dampingAlpha*rij*rij)
658 < !!$             vterm = pre11 * q_i * q_j * (varERFC*riji - constERFC*rcuti)
659 < !!$             vpair = vpair + vterm
660 < !!$             epot = epot + sw*vterm
661 < !!$            
662 < !!$!             dudr  = -sw*pre11*q_i*q_j * (((varERFC*riji*riji &
663 < !!$!                  + alphaPi*varEXP*riji) - (constERFC*rcuti2 &
664 < !!$!                  + alphaPi*constEXP*rcuti)) )
665 < !!$             dudr  = -sw*pre11*q_i*q_j * (varERFC*riji*riji &
666 < !!$                  + alphaPi*varEXP*riji)
667 < !!$            
668 < !!$             dudx = dudx + dudr * xhat
669 < !!$             dudy = dudy + dudr * yhat
670 < !!$             dudz = dudz + dudr * zhat
671 <
696 >             dudr  = -sw * preVal * riji * riji * f1
697 >  
698            elseif (summationMethod .eq. SHIFTED_FORCE) then
699 <             vterm = pre11 * q_i * q_j * (riji + rij*rcuti2 - 2.0d0*rcuti)
700 <             vpair = vpair + vterm
675 <             epot = epot + sw*vterm
699 >             vterm = preVal * ( riji*f0 - rcuti*f0c + &
700 >                  f1c*rcuti2*(rij-defaultCutoff) )
701              
702 <             dudr  = -sw*pre11*q_i*q_j * (riji*riji-rcuti2)
703 <                          
679 <             dudx = dudx + dudr * xhat
680 <             dudy = dudy + dudr * yhat
681 <             dudz = dudz + dudr * zhat
682 <
683 < !!$          elseif (summationMethod .eq. DAMPED_SHIFTED_FORCE) then
684 < !!$             varERFC = derfc(dampingAlpha*rij)
685 < !!$             varEXP = exp(-dampingAlpha*dampingAlpha*rij*rij)
686 < !!$             vterm = pre11 * q_i * q_j * (varERFC*riji - constERFC*rcuti)
687 < !!$             vpair = vpair + vterm
688 < !!$             epot = epot + sw*vterm
689 < !!$            
690 < !!$!             dudr  = -sw*pre11*q_i*q_j * (((varERFC*riji*riji &
691 < !!$!                  + alphaPi*varEXP*riji) - (constERFC*rcuti2 &
692 < !!$!                  + alphaPi*constEXP*rcuti)) )
693 < !!$             dudr  = -sw*pre11*q_i*q_j * (varERFC*riji*riji &
694 < !!$                  + alphaPi*varEXP*riji)
695 < !!$            
696 < !!$             dudx = dudx + dudr * xhat
697 < !!$             dudy = dudy + dudr * yhat
698 < !!$             dudz = dudz + dudr * zhat
699 <
702 >             dudr  = -sw*preVal * (riji*riji*f1 - rcuti2*f1c)
703 >  
704            elseif (summationMethod .eq. REACTION_FIELD) then
701             preVal = pre11 * q_i * q_j
705               rfVal = preRF*rij*rij
706               vterm = preVal * ( riji + rfVal )
707              
705             vpair = vpair + vterm
706             epot = epot + sw*vterm
707            
708               dudr  = sw * preVal * ( 2.0d0*rfVal - riji )*riji
709 <            
710 <             dudx = dudx + dudr * xhat
711 <             dudy = dudy + dudr * yhat
712 <             dudz = dudz + dudr * zhat
713 <
709 >  
710            else
711 <             vterm = pre11 * q_i * q_j * riji
716 <             vpair = vpair + vterm
717 <             epot = epot + sw*vterm
718 <            
719 <             dudr  = - sw * vterm * riji
711 >             vterm = preVal * riji*f0
712              
713 <             dudx = dudx + dudr * xhat
714 <             dudy = dudy + dudr * yhat
723 <             dudz = dudz + dudr * zhat
724 <
713 >             dudr  = - sw * preVal * riji*riji*f1
714 >  
715            endif
716  
717 +          vpair = vpair + vterm
718 +          epot = epot + sw*vterm
719 +
720 +          dudx = dudx + dudr * xhat
721 +          dudy = dudy + dudr * yhat
722 +          dudz = dudz + dudr * zhat
723 +
724         endif
725  
726         if (j_is_Dipole) then
727 +          if (screeningMethod .eq. DAMPED) then
728 +             call lookupUniformSpline1d(f0spline, rij, f0, df0)
729 +             f1 = -rij * df0 + f0
730 +             f3 = -2.0d0*alpha2*df0*rij*rij*rij
731 + !!$             f0 = derfc(dampingAlpha*rij)
732 + !!$             varEXP = exp(-alpha2*rij*rij)
733 + !!$             f1 = alphaPi*rij*varEXP + f0
734 + !!$             f3 = alphaPi*2.0d0*alpha2*varEXP*rij*rij*rij
735 +          endif
736  
737            pref = pre12 * q_i * mu_j
738  
733 !!$          if (summationMethod .eq. UNDAMPED_WOLF) then
734 !!$             ri2 = riji * riji
735 !!$             ri3 = ri2 * riji
736 !!$
737 !!$             pref = pre12 * q_i * mu_j
738 !!$             vterm = - pref * ct_j * (ri2 - rcuti2)
739 !!$             vpair = vpair + vterm
740 !!$             epot = epot + sw*vterm
741 !!$            
742 !!$             !! this has a + sign in the () because the rij vector is
743 !!$             !! r_j - r_i and the charge-dipole potential takes the origin
744 !!$             !! as the point dipole, which is atom j in this case.
745 !!$            
746 !!$             dudx = dudx - sw*pref * ( ri3*( uz_j(1) - 3.0d0*ct_j*xhat) &
747 !!$                  - rcuti3*( uz_j(1) - 3.0d0*ct_j*d(1)*rcuti ) )
748 !!$             dudy = dudy - sw*pref * ( ri3*( uz_j(2) - 3.0d0*ct_j*yhat) &
749 !!$                  - rcuti3*( uz_j(2) - 3.0d0*ct_j*d(2)*rcuti ) )
750 !!$             dudz = dudz - sw*pref * ( ri3*( uz_j(3) - 3.0d0*ct_j*zhat) &
751 !!$                  - rcuti3*( uz_j(3) - 3.0d0*ct_j*d(3)*rcuti ) )
752 !!$            
753 !!$             duduz_j(1) = duduz_j(1) - sw*pref*( ri2*xhat - d(1)*rcuti3 )
754 !!$             duduz_j(2) = duduz_j(2) - sw*pref*( ri2*yhat - d(2)*rcuti3 )
755 !!$             duduz_j(3) = duduz_j(3) - sw*pref*( ri2*zhat - d(3)*rcuti3 )
756 !!$
757 !!$          elseif (summationMethod .eq. REACTION_FIELD) then
758
739            if (summationMethod .eq. REACTION_FIELD) then
740               ri2 = riji * riji
741               ri3 = ri2 * riji
742      
763             pref = pre12 * q_i * mu_j
743               vterm = - pref * ct_j * ( ri2 - preRF2*rij )
744               vpair = vpair + vterm
745               epot = epot + sw*vterm
# Line 781 | Line 760 | contains
760  
761            else
762               if (j_is_SplitDipole) then
763 <                BigR = sqrt(r2 + 0.25_dp * d_j * d_j)
764 <                ri = 1.0_dp / BigR
763 >                BigR = sqrt(r2 + 0.25d0 * d_j * d_j)
764 >                ri = 1.0d0 / BigR
765                  scale = rij * ri
766               else
767                  ri = riji
768 <                scale = 1.0_dp
768 >                scale = 1.0d0
769               endif
770              
771               ri2 = ri * ri
772               ri3 = ri2 * ri
773               sc2 = scale * scale
774  
775 <             pref = pre12 * q_i * mu_j
776 <             vterm = - pref * ct_j * ri2 * scale
775 >             pot_term =  ri2 * scale * f1
776 >             vterm = - pref * ct_j * pot_term
777               vpair = vpair + vterm
778               epot = epot + sw*vterm
779              
# Line 802 | Line 781 | contains
781               !! r_j - r_i and the charge-dipole potential takes the origin
782               !! as the point dipole, which is atom j in this case.
783              
784 <             dudx = dudx - sw*pref * ri3 * ( uz_j(1) - 3.0d0*ct_j*xhat*sc2)
785 <             dudy = dudy - sw*pref * ri3 * ( uz_j(2) - 3.0d0*ct_j*yhat*sc2)
786 <             dudz = dudz - sw*pref * ri3 * ( uz_j(3) - 3.0d0*ct_j*zhat*sc2)
787 <            
788 <             duduz_j(1) = duduz_j(1) - sw*pref * ri2 * xhat * scale
789 <             duduz_j(2) = duduz_j(2) - sw*pref * ri2 * yhat * scale
790 <             duduz_j(3) = duduz_j(3) - sw*pref * ri2 * zhat * scale
784 >             dudx = dudx - sw*pref * ri3 * ( uz_j(1)*f1 - &
785 >                  ct_j*xhat*sc2*( 3.0d0*f1 + f3 ) )
786 >             dudy = dudy - sw*pref * ri3 * ( uz_j(2)*f1 - &
787 >                  ct_j*yhat*sc2*( 3.0d0*f1 + f3 ) )
788 >             dudz = dudz - sw*pref * ri3 * ( uz_j(3)*f1 - &
789 >                  ct_j*zhat*sc2*( 3.0d0*f1 + f3 ) )
790 >                          
791 >             duduz_j(1) = duduz_j(1) - sw*pref * pot_term * xhat
792 >             duduz_j(2) = duduz_j(2) - sw*pref * pot_term * yhat
793 >             duduz_j(3) = duduz_j(3) - sw*pref * pot_term * zhat
794  
795            endif
796         endif
797  
798         if (j_is_Quadrupole) then
799 +          if (screeningMethod .eq. DAMPED) then
800 +             call lookupUniformSpline1d(f0spline, rij, f0, df0)
801 + !!$             f0 = derfc(dampingAlpha*rij)
802 + !!$             varEXP = exp(-alpha2*rij*rij)
803 + !!$             f1 = alphaPi*rij*varEXP + f0
804 + !!$             f2 = alphaPi*2.0d0*alpha2*varEXP
805 +             f1 = -rij * df0 + f0
806 +             f2 = -2.0d0*alpha2*df0
807 +             f3 = f2*rij*rij*rij
808 +             f4 = 2.0d0*alpha2*f2*rij
809 +          endif
810 +
811            ri2 = riji * riji
812            ri3 = ri2 * riji
813            ri4 = ri2 * ri2
# Line 821 | Line 815 | contains
815            cy2 = cy_j * cy_j
816            cz2 = cz_j * cz_j
817  
818 < !!$          if (summationMethod .eq. UNDAMPED_WOLF) then
819 < !!$             pref =  pre14 * q_i / 3.0_dp
820 < !!$             vterm1 = pref * ri3*( qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
821 < !!$                  qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
822 < !!$                  qzz_j * (3.0_dp*cz2 - 1.0_dp) )
823 < !!$             vterm2 = pref * rcuti3*( qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
824 < !!$                  qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
831 < !!$                  qzz_j * (3.0_dp*cz2 - 1.0_dp) )
832 < !!$             vpair = vpair + ( vterm1 - vterm2 )
833 < !!$             epot = epot + sw*( vterm1 - vterm2 )
834 < !!$            
835 < !!$             dudx = dudx - (5.0_dp * &
836 < !!$                  (vterm1*riji*xhat - vterm2*rcuti2*d(1))) + sw*pref * ( &
837 < !!$                  (ri4 - rcuti4)*(qxx_j*(6.0_dp*cx_j*ux_j(1)) - &
838 < !!$                  qxx_j*2.0_dp*(xhat - rcuti*d(1))) + &
839 < !!$                  (ri4 - rcuti4)*(qyy_j*(6.0_dp*cy_j*uy_j(1)) - &
840 < !!$                  qyy_j*2.0_dp*(xhat - rcuti*d(1))) + &
841 < !!$                  (ri4 - rcuti4)*(qzz_j*(6.0_dp*cz_j*uz_j(1)) - &
842 < !!$                  qzz_j*2.0_dp*(xhat - rcuti*d(1))) )
843 < !!$             dudy = dudy - (5.0_dp * &
844 < !!$                  (vterm1*riji*yhat - vterm2*rcuti2*d(2))) + sw*pref * ( &
845 < !!$                  (ri4 - rcuti4)*(qxx_j*(6.0_dp*cx_j*ux_j(2)) - &
846 < !!$                  qxx_j*2.0_dp*(yhat - rcuti*d(2))) + &
847 < !!$                  (ri4 - rcuti4)*(qyy_j*(6.0_dp*cy_j*uy_j(2)) - &
848 < !!$                  qyy_j*2.0_dp*(yhat - rcuti*d(2))) + &
849 < !!$                  (ri4 - rcuti4)*(qzz_j*(6.0_dp*cz_j*uz_j(2)) - &
850 < !!$                  qzz_j*2.0_dp*(yhat - rcuti*d(2))) )
851 < !!$             dudz = dudz - (5.0_dp * &
852 < !!$                  (vterm1*riji*zhat - vterm2*rcuti2*d(3))) + sw*pref * ( &
853 < !!$                  (ri4 - rcuti4)*(qxx_j*(6.0_dp*cx_j*ux_j(3)) - &
854 < !!$                  qxx_j*2.0_dp*(zhat - rcuti*d(3))) + &
855 < !!$                  (ri4 - rcuti4)*(qyy_j*(6.0_dp*cy_j*uy_j(3)) - &
856 < !!$                  qyy_j*2.0_dp*(zhat - rcuti*d(3))) + &
857 < !!$                  (ri4 - rcuti4)*(qzz_j*(6.0_dp*cz_j*uz_j(3)) - &
858 < !!$                  qzz_j*2.0_dp*(zhat - rcuti*d(3))) )
859 < !!$            
860 < !!$             dudux_j(1) = dudux_j(1) + sw*pref*(ri3*(qxx_j*6.0_dp*cx_j*xhat) -&
861 < !!$                  rcuti4*(qxx_j*6.0_dp*cx_j*d(1)))
862 < !!$             dudux_j(2) = dudux_j(2) + sw*pref*(ri3*(qxx_j*6.0_dp*cx_j*yhat) -&
863 < !!$                  rcuti4*(qxx_j*6.0_dp*cx_j*d(2)))
864 < !!$             dudux_j(3) = dudux_j(3) + sw*pref*(ri3*(qxx_j*6.0_dp*cx_j*zhat) -&
865 < !!$                  rcuti4*(qxx_j*6.0_dp*cx_j*d(3)))
866 < !!$            
867 < !!$             duduy_j(1) = duduy_j(1) + sw*pref*(ri3*(qyy_j*6.0_dp*cy_j*xhat) -&
868 < !!$                  rcuti4*(qyy_j*6.0_dp*cx_j*d(1)))
869 < !!$             duduy_j(2) = duduy_j(2) + sw*pref*(ri3*(qyy_j*6.0_dp*cy_j*yhat) -&
870 < !!$                  rcuti4*(qyy_j*6.0_dp*cx_j*d(2)))
871 < !!$             duduy_j(3) = duduy_j(3) + sw*pref*(ri3*(qyy_j*6.0_dp*cy_j*zhat) -&
872 < !!$                  rcuti4*(qyy_j*6.0_dp*cx_j*d(3)))
873 < !!$            
874 < !!$             duduz_j(1) = duduz_j(1) + sw*pref*(ri3*(qzz_j*6.0_dp*cz_j*xhat) -&
875 < !!$                  rcuti4*(qzz_j*6.0_dp*cx_j*d(1)))
876 < !!$             duduz_j(2) = duduz_j(2) + sw*pref*(ri3*(qzz_j*6.0_dp*cz_j*yhat) -&
877 < !!$                  rcuti4*(qzz_j*6.0_dp*cx_j*d(2)))
878 < !!$             duduz_j(3) = duduz_j(3) + sw*pref*(ri3*(qzz_j*6.0_dp*cz_j*zhat) -&
879 < !!$                  rcuti4*(qzz_j*6.0_dp*cx_j*d(3)))
880 < !!$        
881 < !!$          else
882 <             pref =  pre14 * q_i / 3.0_dp
883 <             vterm = pref * ri3 * (qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
884 <                  qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
885 <                  qzz_j * (3.0_dp*cz2 - 1.0_dp))
886 <             vpair = vpair + vterm
887 <             epot = epot + sw*vterm
888 <            
889 <             dudx = dudx - 5.0_dp*sw*vterm*riji*xhat + sw*pref * ri4 * ( &
890 <                  qxx_j*(6.0_dp*cx_j*ux_j(1) - 2.0_dp*xhat) + &
891 <                  qyy_j*(6.0_dp*cy_j*uy_j(1) - 2.0_dp*xhat) + &
892 <                  qzz_j*(6.0_dp*cz_j*uz_j(1) - 2.0_dp*xhat) )
893 <             dudy = dudy - 5.0_dp*sw*vterm*riji*yhat + sw*pref * ri4 * ( &
894 <                  qxx_j*(6.0_dp*cx_j*ux_j(2) - 2.0_dp*yhat) + &
895 <                  qyy_j*(6.0_dp*cy_j*uy_j(2) - 2.0_dp*yhat) + &
896 <                  qzz_j*(6.0_dp*cz_j*uz_j(2) - 2.0_dp*yhat) )
897 <             dudz = dudz - 5.0_dp*sw*vterm*riji*zhat + sw*pref * ri4 * ( &
898 <                  qxx_j*(6.0_dp*cx_j*ux_j(3) - 2.0_dp*zhat) + &
899 <                  qyy_j*(6.0_dp*cy_j*uy_j(3) - 2.0_dp*zhat) + &
900 <                  qzz_j*(6.0_dp*cz_j*uz_j(3) - 2.0_dp*zhat) )
901 <            
902 <             dudux_j(1) = dudux_j(1) + sw*pref * ri3*(qxx_j*6.0_dp*cx_j*xhat)
903 <             dudux_j(2) = dudux_j(2) + sw*pref * ri3*(qxx_j*6.0_dp*cx_j*yhat)
904 <             dudux_j(3) = dudux_j(3) + sw*pref * ri3*(qxx_j*6.0_dp*cx_j*zhat)
905 <            
906 <             duduy_j(1) = duduy_j(1) + sw*pref * ri3*(qyy_j*6.0_dp*cy_j*xhat)
907 <             duduy_j(2) = duduy_j(2) + sw*pref * ri3*(qyy_j*6.0_dp*cy_j*yhat)
908 <             duduy_j(3) = duduy_j(3) + sw*pref * ri3*(qyy_j*6.0_dp*cy_j*zhat)
909 <            
910 <             duduz_j(1) = duduz_j(1) + sw*pref * ri3*(qzz_j*6.0_dp*cz_j*xhat)
911 <             duduz_j(2) = duduz_j(2) + sw*pref * ri3*(qzz_j*6.0_dp*cz_j*yhat)
912 <             duduz_j(3) = duduz_j(3) + sw*pref * ri3*(qzz_j*6.0_dp*cz_j*zhat)
818 >          pref =  pre14 * q_i / 3.0d0
819 >          pot_term = ri3*(qxx_j * (3.0d0*cx2 - 1.0d0) + &
820 >               qyy_j * (3.0d0*cy2 - 1.0d0) + &
821 >               qzz_j * (3.0d0*cz2 - 1.0d0))
822 >          vterm = pref * (pot_term*f1 + (qxx_j*cx2 + qyy_j*cy2 + qzz_j*cz2)*f2)
823 >          vpair = vpair + vterm
824 >          epot = epot + sw*vterm
825            
826 < !!$          endif
826 >          dudx = dudx - sw*pref*pot_term*riji*xhat*(5.0d0*f1 + f3) + &
827 >               sw*pref*ri4 * ( &
828 >               qxx_j*(2.0d0*cx_j*ux_j(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) + &
829 >               qyy_j*(2.0d0*cy_j*uy_j(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) + &
830 >               qzz_j*(2.0d0*cz_j*uz_j(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) ) &
831 >               + (qxx_j*cx2 + qyy_j*cy2 + qzz_j*cz2)*f4
832 >          dudy = dudy - sw*pref*pot_term*riji*yhat*(5.0d0*f1 + f3) + &
833 >               sw*pref*ri4 * ( &
834 >               qxx_j*(2.0d0*cx_j*ux_j(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) + &
835 >               qyy_j*(2.0d0*cy_j*uy_j(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) + &
836 >               qzz_j*(2.0d0*cz_j*uz_j(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) ) &
837 >               + (qxx_j*cx2 + qyy_j*cy2 + qzz_j*cz2)*f4
838 >          dudz = dudz - sw*pref*pot_term*riji*zhat*(5.0d0*f1 + f3) + &
839 >               sw*pref*ri4 * ( &
840 >               qxx_j*(2.0d0*cx_j*ux_j(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) + &
841 >               qyy_j*(2.0d0*cy_j*uy_j(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) + &
842 >               qzz_j*(2.0d0*cz_j*uz_j(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) ) &
843 >               + (qxx_j*cx2 + qyy_j*cy2 + qzz_j*cz2)*f4
844 >          
845 >          dudux_j(1) = dudux_j(1) + sw*pref*ri3*( (qxx_j*2.0d0*cx_j*xhat) &
846 >               * (3.0d0*f1 + f3) )
847 >          dudux_j(2) = dudux_j(2) + sw*pref*ri3*( (qxx_j*2.0d0*cx_j*yhat) &
848 >               * (3.0d0*f1 + f3) )
849 >          dudux_j(3) = dudux_j(3) + sw*pref*ri3*( (qxx_j*2.0d0*cx_j*zhat) &
850 >               * (3.0d0*f1 + f3) )
851 >          
852 >          duduy_j(1) = duduy_j(1) + sw*pref*ri3*( (qyy_j*2.0d0*cy_j*xhat) &
853 >               * (3.0d0*f1 + f3) )
854 >          duduy_j(2) = duduy_j(2) + sw*pref*ri3*( (qyy_j*2.0d0*cy_j*yhat) &
855 >               * (3.0d0*f1 + f3) )
856 >          duduy_j(3) = duduy_j(3) + sw*pref*ri3*( (qyy_j*2.0d0*cy_j*zhat) &
857 >               * (3.0d0*f1 + f3) )
858 >          
859 >          duduz_j(1) = duduz_j(1) + sw*pref*ri3*( (qzz_j*2.0d0*cz_j*xhat) &
860 >               * (3.0d0*f1 + f3) )
861 >          duduz_j(2) = duduz_j(2) + sw*pref*ri3*( (qzz_j*2.0d0*cz_j*yhat) &
862 >               * (3.0d0*f1 + f3) )
863 >          duduz_j(3) = duduz_j(3) + sw*pref*ri3*( (qzz_j*2.0d0*cz_j*zhat) &
864 >               * (3.0d0*f1 + f3) )
865 >          
866         endif
867      endif
868 <
868 >    
869      if (i_is_Dipole) then
870  
871         if (j_is_Charge) then
872 +          if (screeningMethod .eq. DAMPED) then
873 +             call lookupUniformSpline1d(f0spline, rij, f0, df0)
874 +             f1 = -rij * df0 + f0
875 +             f3 = -2.0d0*alpha2*df0*rij*rij*rij
876 + !!$             f0 = derfc(dampingAlpha*rij)
877 + !!$             varEXP = exp(-alpha2*rij*rij)
878 + !!$             f1 = alphaPi*rij*varEXP + f0
879 + !!$             f3 = alphaPi*2.0d0*alpha2*varEXP*rij*rij*rij
880 +          endif
881            
882            pref = pre12 * q_j * mu_i
883            
884 < !!$          if (summationMethod .eq. UNDAMPED_WOLF) then
925 < !!$             ri2 = riji * riji
926 < !!$             ri3 = ri2 * riji
927 < !!$
928 < !!$             pref = pre12 * q_j * mu_i
929 < !!$             vterm = pref * ct_i * (ri2 - rcuti2)
930 < !!$             vpair = vpair + vterm
931 < !!$             epot = epot + sw*vterm
932 < !!$            
933 < !!$             dudx = dudx + sw*pref * ( ri3*( uz_i(1) - 3.0d0*ct_i*xhat) &
934 < !!$                  - rcuti3*( uz_i(1) - 3.0d0*ct_i*d(1)*rcuti ) )
935 < !!$             dudy = dudy + sw*pref * ( ri3*( uz_i(2) - 3.0d0*ct_i*yhat) &
936 < !!$                  - rcuti3*( uz_i(2) - 3.0d0*ct_i*d(2)*rcuti ) )
937 < !!$             dudz = dudz + sw*pref * ( ri3*( uz_i(3) - 3.0d0*ct_i*zhat) &
938 < !!$                  - rcuti3*( uz_i(3) - 3.0d0*ct_i*d(3)*rcuti ) )
939 < !!$            
940 < !!$             duduz_i(1) = duduz_i(1) + sw*pref*( ri2*xhat - d(1)*rcuti3 )
941 < !!$             duduz_i(2) = duduz_i(2) + sw*pref*( ri2*yhat - d(2)*rcuti3 )
942 < !!$             duduz_i(3) = duduz_i(3) + sw*pref*( ri2*zhat - d(3)*rcuti3 )
943 < !!$
944 < !!$          elseif (summationMethod .eq. REACTION_FIELD) then
945 <          if (summationMethod .eq. REACTION_FIELD) then
884 >          if (summationMethod .eq. SHIFTED_POTENTIAL) then
885               ri2 = riji * riji
886               ri3 = ri2 * riji
887 +            
888 +             pot_term = ri2*f1 - rcuti2*f1c
889 +             vterm = pref * ct_i * pot_term
890 +             vpair = vpair + vterm
891 +             epot = epot + sw*vterm
892 +            
893 +             dudx = dudx + sw*pref*( ri3*(uz_i(1)*f1-ct_i*xhat*(3.0d0*f1+f3)) )
894 +             dudy = dudy + sw*pref*( ri3*(uz_i(2)*f1-ct_i*yhat*(3.0d0*f1+f3)) )
895 +             dudz = dudz + sw*pref*( ri3*(uz_i(3)*f1-ct_i*zhat*(3.0d0*f1+f3)) )
896 +            
897 +             duduz_i(1) = duduz_i(1) + sw*pref * xhat * pot_term
898 +             duduz_i(2) = duduz_i(2) + sw*pref * yhat * pot_term
899 +             duduz_i(3) = duduz_i(3) + sw*pref * zhat * pot_term
900  
901 <             pref = pre12 * q_j * mu_i
901 >          elseif (summationMethod .eq. SHIFTED_FORCE) then
902 >             ri2 = riji * riji
903 >             ri3 = ri2 * riji
904 >
905 >             !! might need a -(f1c-f0c) or dct_i/dr in the derivative term...
906 >             pot_term = ri2*f1 - rcuti2*f1c + &
907 >                  (2.0d0*rcuti3*f1c + f2c)*( rij - defaultCutoff )
908 >             vterm = pref * ct_i * pot_term
909 >             vpair = vpair + vterm
910 >             epot = epot + sw*vterm
911 >            
912 >             dudx = dudx + sw*pref*( ri3*(uz_i(1)*f1-ct_i*xhat*(3.0d0*f1+f3)) &
913 >                  - rcuti3*(uz_i(1)*f1c-ct_i*xhat*(3.0d0*f1c+f3c)) )
914 >             dudy = dudy + sw*pref*( ri3*(uz_i(2)*f1-ct_i*yhat*(3.0d0*f1+f3)) &
915 >                  - rcuti3*(uz_i(1)*f1c-ct_i*xhat*(3.0d0*f1c+f3c)) )
916 >             dudz = dudz + sw*pref*( ri3*(uz_i(3)*f1-ct_i*zhat*(3.0d0*f1+f3)) &
917 >                  - rcuti3*(uz_i(1)*f1c-ct_i*xhat*(3.0d0*f1c+f3c)) )
918 >            
919 >             duduz_i(1) = duduz_i(1) + sw*pref * xhat * pot_term
920 >             duduz_i(2) = duduz_i(2) + sw*pref * yhat * pot_term
921 >             duduz_i(3) = duduz_i(3) + sw*pref * zhat * pot_term
922 >
923 >          elseif (summationMethod .eq. REACTION_FIELD) then
924 >             ri2 = riji * riji
925 >             ri3 = ri2 * riji
926 >
927               vterm = pref * ct_i * ( ri2 - preRF2*rij )
928               vpair = vpair + vterm
929               epot = epot + sw*vterm
# Line 964 | Line 941 | contains
941  
942            else
943               if (i_is_SplitDipole) then
944 <                BigR = sqrt(r2 + 0.25_dp * d_i * d_i)
945 <                ri = 1.0_dp / BigR
944 >                BigR = sqrt(r2 + 0.25d0 * d_i * d_i)
945 >                ri = 1.0d0 / BigR
946                  scale = rij * ri
947               else
948                  ri = riji
949 <                scale = 1.0_dp
949 >                scale = 1.0d0
950               endif
951              
952               ri2 = ri * ri
953               ri3 = ri2 * ri
954               sc2 = scale * scale
955  
956 <             pref = pre12 * q_j * mu_i
957 <             vterm = pref * ct_i * ri2 * scale
956 >             pot_term = ri2 * f1 * scale
957 >             vterm = pref * ct_i * pot_term
958               vpair = vpair + vterm
959               epot = epot + sw*vterm
960              
961 <             dudx = dudx + sw*pref * ri3 * ( uz_i(1) - 3.0d0 * ct_i * xhat*sc2)
962 <             dudy = dudy + sw*pref * ri3 * ( uz_i(2) - 3.0d0 * ct_i * yhat*sc2)
963 <             dudz = dudz + sw*pref * ri3 * ( uz_i(3) - 3.0d0 * ct_i * zhat*sc2)
961 >             dudx = dudx + sw*pref * ri3 * ( uz_i(1)*f1 - &
962 >                  ct_i*xhat*sc2*( 3.0d0*f1 + f3 ) )
963 >             dudy = dudy + sw*pref * ri3 * ( uz_i(2)*f1 - &
964 >                  ct_i*yhat*sc2*( 3.0d0*f1 + f3 ) )
965 >             dudz = dudz + sw*pref * ri3 * ( uz_i(3)*f1 - &
966 >                  ct_i*zhat*sc2*( 3.0d0*f1 + f3 ) )
967              
968 <             duduz_i(1) = duduz_i(1) + sw*pref * ri2 * xhat * scale
969 <             duduz_i(2) = duduz_i(2) + sw*pref * ri2 * yhat * scale
970 <             duduz_i(3) = duduz_i(3) + sw*pref * ri2 * zhat * scale
968 >             duduz_i(1) = duduz_i(1) + sw*pref * pot_term * xhat
969 >             duduz_i(2) = duduz_i(2) + sw*pref * pot_term * yhat
970 >             duduz_i(3) = duduz_i(3) + sw*pref * pot_term * zhat
971            endif
972         endif
973        
974         if (j_is_Dipole) then
975 +          if (screeningMethod .eq. DAMPED) then
976 +             call lookupUniformSpline1d(f0spline, rij, f0, df0)
977 + !!$             f0 = derfc(dampingAlpha*rij)
978 + !!$             varEXP = exp(-alpha2*rij*rij)
979 + !!$             f1 = alphaPi*rij*varEXP + f0
980 + !!$             f2 = alphaPi*2.0d0*alpha2*varEXP
981 +             f1 = -rij * df0 + f0
982 +             f2 = -2.0d0*alpha2*df0
983 +             f3 = f2*rij*rij*rij
984 +             f4 = 2.0d0*alpha2*f3*rij*rij
985 +          endif
986  
987 < !!$          if (summationMethod .eq. UNDAMPED_WOLF) then
988 < !!$             ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
989 < !!$
990 < !!$             ri2 = riji * riji
991 < !!$             ri3 = ri2 * riji
992 < !!$             ri4 = ri2 * ri2
993 < !!$
1003 < !!$             pref = pre22 * mu_i * mu_j
1004 < !!$             vterm = pref * (ri3 - rcuti3) * (ct_ij - 3.0d0 * ct_i * ct_j)
1005 < !!$             vpair = vpair + vterm
1006 < !!$             epot = epot + sw*vterm
1007 < !!$            
1008 < !!$             a1 = 5.0d0 * ct_i * ct_j - ct_ij
1009 < !!$            
1010 < !!$             dudx = dudx + sw*pref*3.0d0*( &
1011 < !!$                  ri4*(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1)) &
1012 < !!$                  - rcuti4*(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1)) )
1013 < !!$             dudy = dudy + sw*pref*3.0d0*( &
1014 < !!$                  ri4*(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2)) &
1015 < !!$                  - rcuti4*(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2)) )
1016 < !!$             dudz = dudz + sw*pref*3.0d0*( &
1017 < !!$                  ri4*(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3)) &
1018 < !!$                  - rcuti4*(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3)) )
1019 < !!$            
1020 < !!$             duduz_i(1) = duduz_i(1) + sw*pref*(ri3*(uz_j(1)-3.0d0*ct_j*xhat) &
1021 < !!$                  - rcuti3*(uz_j(1) - 3.0d0*ct_j*xhat))
1022 < !!$             duduz_i(2) = duduz_i(2) + sw*pref*(ri3*(uz_j(2)-3.0d0*ct_j*yhat) &
1023 < !!$                  - rcuti3*(uz_j(2) - 3.0d0*ct_j*yhat))
1024 < !!$             duduz_i(3) = duduz_i(3) + sw*pref*(ri3*(uz_j(3)-3.0d0*ct_j*zhat) &
1025 < !!$                  - rcuti3*(uz_j(3) - 3.0d0*ct_j*zhat))
1026 < !!$             duduz_j(1) = duduz_j(1) + sw*pref*(ri3*(uz_i(1)-3.0d0*ct_i*xhat) &
1027 < !!$                  - rcuti3*(uz_i(1) - 3.0d0*ct_i*xhat))
1028 < !!$             duduz_j(2) = duduz_j(2) + sw*pref*(ri3*(uz_i(2)-3.0d0*ct_i*yhat) &
1029 < !!$                  - rcuti3*(uz_i(2) - 3.0d0*ct_i*yhat))
1030 < !!$             duduz_j(3) = duduz_j(3) + sw*pref*(ri3*(uz_i(3)-3.0d0*ct_i*zhat) &
1031 < !!$                  - rcuti3*(uz_i(3) - 3.0d0*ct_i*zhat))
1032 < !!$          
1033 < !!$          elseif (summationMethod .eq. DAMPED_WOLF) then
1034 < !!$             ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
1035 < !!$            
1036 < !!$             ri2 = riji * riji
1037 < !!$             ri3 = ri2 * riji
1038 < !!$             ri4 = ri2 * ri2
1039 < !!$             sc2 = scale * scale
1040 < !!$            
1041 < !!$             pref = pre22 * mu_i * mu_j
1042 < !!$             vterm = pref * ri3 * (ct_ij - 3.0d0 * ct_i * ct_j)
1043 < !!$             vpair = vpair + vterm
1044 < !!$             epot = epot + sw*vterm
1045 < !!$            
1046 < !!$             a1 = 5.0d0 * ct_i * ct_j * sc2 - ct_ij
1047 < !!$            
1048 < !!$             dudx = dudx + sw*pref*3.0d0*ri4*(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
1049 < !!$             dudy = dudy + sw*pref*3.0d0*ri4*(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
1050 < !!$             dudz = dudz + sw*pref*3.0d0*ri4*(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
1051 < !!$            
1052 < !!$             duduz_i(1) = duduz_i(1) + sw*pref*ri3 *(uz_j(1) - 3.0d0*ct_j*xhat)
1053 < !!$             duduz_i(2) = duduz_i(2) + sw*pref*ri3 *(uz_j(2) - 3.0d0*ct_j*yhat)
1054 < !!$             duduz_i(3) = duduz_i(3) + sw*pref*ri3 *(uz_j(3) - 3.0d0*ct_j*zhat)
1055 < !!$            
1056 < !!$             duduz_j(1) = duduz_j(1) + sw*pref*ri3 *(uz_i(1) - 3.0d0*ct_i*xhat)
1057 < !!$             duduz_j(2) = duduz_j(2) + sw*pref*ri3 *(uz_i(2) - 3.0d0*ct_i*yhat)
1058 < !!$             duduz_j(3) = duduz_j(3) + sw*pref*ri3 *(uz_i(3) - 3.0d0*ct_i*zhat)
1059 < !!$            
1060 < !!$          elseif (summationMethod .eq. REACTION_FIELD) then
1061 <          if (summationMethod .eq. REACTION_FIELD) then
1062 <             ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
987 >          ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
988 >          
989 >          ri2 = riji * riji
990 >          ri3 = ri2 * riji
991 >          ri4 = ri2 * ri2
992 >          
993 >          pref = pre22 * mu_i * mu_j
994  
995 <             ri2 = riji * riji
1065 <             ri3 = ri2 * riji
1066 <             ri4 = ri2 * ri2
1067 <
1068 <             pref = pre22 * mu_i * mu_j
1069 <              
995 >          if (summationMethod .eq. REACTION_FIELD) then
996               vterm = pref*( ri3*(ct_ij - 3.0d0 * ct_i * ct_j) - &
997                    preRF2*ct_ij )
998               vpair = vpair + vterm
# Line 1097 | Line 1023 | contains
1023            else
1024               if (i_is_SplitDipole) then
1025                  if (j_is_SplitDipole) then
1026 <                   BigR = sqrt(r2 + 0.25_dp * d_i * d_i + 0.25_dp * d_j * d_j)
1026 >                   BigR = sqrt(r2 + 0.25d0 * d_i * d_i + 0.25d0 * d_j * d_j)
1027                  else
1028 <                   BigR = sqrt(r2 + 0.25_dp * d_i * d_i)
1028 >                   BigR = sqrt(r2 + 0.25d0 * d_i * d_i)
1029                  endif
1030 <                ri = 1.0_dp / BigR
1030 >                ri = 1.0d0 / BigR
1031                  scale = rij * ri                
1032               else
1033                  if (j_is_SplitDipole) then
1034 <                   BigR = sqrt(r2 + 0.25_dp * d_j * d_j)
1035 <                   ri = 1.0_dp / BigR
1034 >                   BigR = sqrt(r2 + 0.25d0 * d_j * d_j)
1035 >                   ri = 1.0d0 / BigR
1036                     scale = rij * ri                            
1037                  else                
1038                     ri = riji
1039 <                   scale = 1.0_dp
1039 >                   scale = 1.0d0
1040                  endif
1041               endif
1042              
1117             ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
1118            
1119             ri2 = ri * ri
1120             ri3 = ri2 * ri
1121             ri4 = ri2 * ri2
1043               sc2 = scale * scale
1044 <            
1045 <             pref = pre22 * mu_i * mu_j
1046 <             vterm = pref * ri3 * (ct_ij - 3.0d0 * ct_i * ct_j * sc2)
1044 >
1045 >             pot_term = (ct_ij - 3.0d0 * ct_i * ct_j * sc2)
1046 >             vterm = pref * ( ri3*pot_term*f1 + (ct_i * ct_j)*f2 )
1047               vpair = vpair + vterm
1048               epot = epot + sw*vterm
1049              
1050 <             a1 = 5.0d0 * ct_i * ct_j * sc2 - ct_ij
1050 >             f13 = f1+f3
1051 >             f134 = f13 + f4
1052              
1053 <             dudx = dudx + sw*pref*3.0d0*ri4*scale &
1054 <                             *(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
1055 <             dudy = dudy + sw*pref*3.0d0*ri4*scale &
1056 <                             *(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
1057 <             dudz = dudz + sw*pref*3.0d0*ri4*scale &
1058 <                             *(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
1053 > !!$             dudx = dudx + sw*pref * ( ri4*scale*( &
1054 > !!$                  3.0d0*(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))*f1 &
1055 > !!$                  - pot_term*f3) &
1056 > !!$                  + 2.0d0*ct_i*ct_j*xhat*(ct_i*uz_j(1)+ct_j*uz_i(1))*f3 &
1057 > !!$                  + (ct_i * ct_j)*f4 )
1058 > !!$             dudy = dudy + sw*pref * ( ri4*scale*( &
1059 > !!$                  3.0d0*(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))*f1 &
1060 > !!$                  - pot_term*f3) &
1061 > !!$                  + 2.0d0*ct_i*ct_j*yhat*(ct_i*uz_j(2)+ct_j*uz_i(2))*f3 &
1062 > !!$                  + (ct_i * ct_j)*f4 )
1063 > !!$             dudz = dudz + sw*pref * ( ri4*scale*( &
1064 > !!$                  3.0d0*(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))*f1 &
1065 > !!$                  - pot_term*f3) &
1066 > !!$                  + 2.0d0*ct_i*ct_j*zhat*(ct_i*uz_j(3)+ct_j*uz_i(3))*f3 &
1067 > !!$                  + (ct_i * ct_j)*f4 )
1068 >
1069 >             dudx = dudx + sw*pref * ( ri4*scale*( &
1070 >                  15.0d0*(ct_i * ct_j * sc2)*xhat*f134 - &
1071 >                  3.0d0*(ct_i*uz_j(1) + ct_j*uz_i(1) + ct_ij*xhat)*f134) )
1072 >             dudy = dudy + sw*pref * ( ri4*scale*( &
1073 >                  15.0d0*(ct_i * ct_j * sc2)*yhat*f134 - &
1074 >                  3.0d0*(ct_i*uz_j(2) + ct_j*uz_i(2) + ct_ij*yhat)*f134) )
1075 >             dudz = dudz + sw*pref * ( ri4*scale*( &
1076 >                  15.0d0*(ct_i * ct_j * sc2)*zhat*f134 - &
1077 >                  3.0d0*(ct_i*uz_j(3) + ct_j*uz_i(3) + ct_ij*zhat)*f134) )
1078              
1079 <             duduz_i(1) = duduz_i(1) + sw*pref*ri3 &
1080 <                                         *(uz_j(1) - 3.0d0*ct_j*xhat*sc2)
1081 <             duduz_i(2) = duduz_i(2) + sw*pref*ri3 &
1082 <                                         *(uz_j(2) - 3.0d0*ct_j*yhat*sc2)
1083 <             duduz_i(3) = duduz_i(3) + sw*pref*ri3 &
1084 <                                         *(uz_j(3) - 3.0d0*ct_j*zhat*sc2)
1079 >             duduz_i(1) = duduz_i(1) + sw*pref * &
1080 >                  ( ri3*(uz_j(1) - 3.0d0*ct_j*xhat*sc2)*f1 + (ct_j*xhat)*f2 )
1081 >             duduz_i(2) = duduz_i(2) + sw*pref * &
1082 >                  ( ri3*(uz_j(2) - 3.0d0*ct_j*yhat*sc2)*f1 + (ct_j*yhat)*f2 )
1083 >             duduz_i(3) = duduz_i(3) + sw*pref * &
1084 >                  ( ri3*(uz_j(3) - 3.0d0*ct_j*zhat*sc2)*f1 + (ct_j*zhat)*f2 )
1085              
1086 <             duduz_j(1) = duduz_j(1) + sw*pref*ri3 &
1087 <                                         *(uz_i(1) - 3.0d0*ct_i*xhat*sc2)
1088 <             duduz_j(2) = duduz_j(2) + sw*pref*ri3 &
1089 <                                         *(uz_i(2) - 3.0d0*ct_i*yhat*sc2)
1090 <             duduz_j(3) = duduz_j(3) + sw*pref*ri3 &
1091 <                                         *(uz_i(3) - 3.0d0*ct_i*zhat*sc2)
1086 >             duduz_j(1) = duduz_j(1) + sw*pref * &
1087 >                  ( ri3*(uz_i(1) - 3.0d0*ct_i*xhat*sc2)*f1 + (ct_i*xhat)*f2 )
1088 >             duduz_j(2) = duduz_j(2) + sw*pref * &
1089 >                  ( ri3*(uz_i(2) - 3.0d0*ct_i*yhat*sc2)*f1 + (ct_i*yhat)*f2 )
1090 >             duduz_j(3) = duduz_j(3) + sw*pref * &
1091 >                  ( ri3*(uz_i(3) - 3.0d0*ct_i*zhat*sc2)*f1 + (ct_i*zhat)*f2 )
1092            endif
1093         endif
1094      endif
1095  
1096      if (i_is_Quadrupole) then
1097         if (j_is_Charge) then
1098 +          if (screeningMethod .eq. DAMPED) then
1099 +             call lookupUniformSpline1d(f0spline, rij, f0, df0)
1100 + !!$             f0 = derfc(dampingAlpha*rij)
1101 + !!$             varEXP = exp(-alpha2*rij*rij)
1102 + !!$             f1 = alphaPi*rij*varEXP + f0
1103 + !!$             f2 = alphaPi*2.0d0*alpha2*varEXP
1104 +             f1 = -rij * df0 + f0
1105 +             f2 = -2.0d0*alpha2*df0
1106 +             f3 = f2*rij*rij*rij
1107 +             f4 = 2.0d0*alpha2*f2*rij
1108 +          endif
1109  
1110            ri2 = riji * riji
1111            ri3 = ri2 * riji
# Line 1162 | Line 1114 | contains
1114            cy2 = cy_i * cy_i
1115            cz2 = cz_i * cz_i
1116  
1117 < !!$          if (summationMethod .eq. UNDAMPED_WOLF) then
1118 < !!$             pref = pre14 * q_j / 3.0_dp
1119 < !!$             vterm1 = pref * ri3*( qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1120 < !!$                  qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1121 < !!$                  qzz_i * (3.0_dp*cz2 - 1.0_dp) )
1122 < !!$             vterm2 = pref * rcuti3*( qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1123 < !!$                  qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1124 < !!$                  qzz_i * (3.0_dp*cz2 - 1.0_dp) )
1125 < !!$             vpair = vpair + ( vterm1 - vterm2 )
1126 < !!$             epot = epot + sw*( vterm1 - vterm2 )
1127 < !!$            
1128 < !!$             dudx = dudx - sw*(5.0_dp*(vterm1*riji*xhat-vterm2*rcuti2*d(1))) +&
1129 < !!$                  sw*pref * ( (ri4 - rcuti4)*(qxx_i*(6.0_dp*cx_i*ux_i(1)) - &
1130 < !!$                  qxx_i*2.0_dp*(xhat - rcuti*d(1))) + &
1131 < !!$                  (ri4 - rcuti4)*(qyy_i*(6.0_dp*cy_i*uy_i(1)) - &
1132 < !!$                  qyy_i*2.0_dp*(xhat - rcuti*d(1))) + &
1133 < !!$                  (ri4 - rcuti4)*(qzz_i*(6.0_dp*cz_i*uz_i(1)) - &
1134 < !!$                  qzz_i*2.0_dp*(xhat - rcuti*d(1))) )
1135 < !!$             dudy = dudy - sw*(5.0_dp*(vterm1*riji*yhat-vterm2*rcuti2*d(2))) +&
1136 < !!$                  sw*pref * ( (ri4 - rcuti4)*(qxx_i*(6.0_dp*cx_i*ux_i(2)) - &
1137 < !!$                  qxx_i*2.0_dp*(yhat - rcuti*d(2))) + &
1138 < !!$                  (ri4 - rcuti4)*(qyy_i*(6.0_dp*cy_i*uy_i(2)) - &
1139 < !!$                  qyy_i*2.0_dp*(yhat - rcuti*d(2))) + &
1140 < !!$                  (ri4 - rcuti4)*(qzz_i*(6.0_dp*cz_i*uz_i(2)) - &
1141 < !!$                  qzz_i*2.0_dp*(yhat - rcuti*d(2))) )
1142 < !!$             dudz = dudz - sw*(5.0_dp*(vterm1*riji*zhat-vterm2*rcuti2*d(3))) +&
1143 < !!$                  sw*pref * ( (ri4 - rcuti4)*(qxx_i*(6.0_dp*cx_i*ux_i(3)) - &
1144 < !!$                  qxx_i*2.0_dp*(zhat - rcuti*d(3))) + &
1145 < !!$                  (ri4 - rcuti4)*(qyy_i*(6.0_dp*cy_i*uy_i(3)) - &
1146 < !!$                  qyy_i*2.0_dp*(zhat - rcuti*d(3))) + &
1147 < !!$                  (ri4 - rcuti4)*(qzz_i*(6.0_dp*cz_i*uz_i(3)) - &
1148 < !!$                  qzz_i*2.0_dp*(zhat - rcuti*d(3))) )
1149 < !!$            
1150 < !!$             dudux_i(1) = dudux_i(1) + sw*pref*(ri3*(qxx_i*6.0_dp*cx_i*xhat) -&
1151 < !!$                  rcuti4*(qxx_i*6.0_dp*cx_i*d(1)))
1152 < !!$             dudux_i(2) = dudux_i(2) + sw*pref*(ri3*(qxx_i*6.0_dp*cx_i*yhat) -&
1153 < !!$                  rcuti4*(qxx_i*6.0_dp*cx_i*d(2)))
1154 < !!$             dudux_i(3) = dudux_i(3) + sw*pref*(ri3*(qxx_i*6.0_dp*cx_i*zhat) -&
1155 < !!$                  rcuti4*(qxx_i*6.0_dp*cx_i*d(3)))
1156 < !!$            
1157 < !!$             duduy_i(1) = duduy_i(1) + sw*pref*(ri3*(qyy_i*6.0_dp*cy_i*xhat) -&
1158 < !!$                  rcuti4*(qyy_i*6.0_dp*cx_i*d(1)))
1159 < !!$             duduy_i(2) = duduy_i(2) + sw*pref*(ri3*(qyy_i*6.0_dp*cy_i*yhat) -&
1160 < !!$                  rcuti4*(qyy_i*6.0_dp*cx_i*d(2)))
1161 < !!$             duduy_i(3) = duduy_i(3) + sw*pref*(ri3*(qyy_i*6.0_dp*cy_i*zhat) -&
1162 < !!$                  rcuti4*(qyy_i*6.0_dp*cx_i*d(3)))
1163 < !!$            
1164 < !!$             duduz_i(1) = duduz_i(1) + sw*pref*(ri3*(qzz_i*6.0_dp*cz_i*xhat) -&
1213 < !!$                  rcuti4*(qzz_i*6.0_dp*cx_i*d(1)))
1214 < !!$             duduz_i(2) = duduz_i(2) + sw*pref*(ri3*(qzz_i*6.0_dp*cz_i*yhat) -&
1215 < !!$                  rcuti4*(qzz_i*6.0_dp*cx_i*d(2)))
1216 < !!$             duduz_i(3) = duduz_i(3) + sw*pref*(ri3*(qzz_i*6.0_dp*cz_i*zhat) -&
1217 < !!$                  rcuti4*(qzz_i*6.0_dp*cx_i*d(3)))
1218 < !!$
1219 < !!$          else
1220 <             pref = pre14 * q_j / 3.0_dp
1221 <             vterm = pref * ri3 * (qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1222 <                  qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1223 <                  qzz_i * (3.0_dp*cz2 - 1.0_dp))
1224 <             vpair = vpair + vterm
1225 <             epot = epot + sw*vterm
1226 <            
1227 <             dudx = dudx - 5.0_dp*sw*vterm*riji*xhat + sw*pref*ri4 * ( &
1228 <                  qxx_i*(6.0_dp*cx_i*ux_i(1) - 2.0_dp*xhat) + &
1229 <                  qyy_i*(6.0_dp*cy_i*uy_i(1) - 2.0_dp*xhat) + &
1230 <                  qzz_i*(6.0_dp*cz_i*uz_i(1) - 2.0_dp*xhat) )
1231 <             dudy = dudy - 5.0_dp*sw*vterm*riji*yhat + sw*pref*ri4 * ( &
1232 <                  qxx_i*(6.0_dp*cx_i*ux_i(2) - 2.0_dp*yhat) + &
1233 <                  qyy_i*(6.0_dp*cy_i*uy_i(2) - 2.0_dp*yhat) + &
1234 <                  qzz_i*(6.0_dp*cz_i*uz_i(2) - 2.0_dp*yhat) )
1235 <             dudz = dudz - 5.0_dp*sw*vterm*riji*zhat + sw*pref*ri4 * ( &
1236 <                  qxx_i*(6.0_dp*cx_i*ux_i(3) - 2.0_dp*zhat) + &
1237 <                  qyy_i*(6.0_dp*cy_i*uy_i(3) - 2.0_dp*zhat) + &
1238 <                  qzz_i*(6.0_dp*cz_i*uz_i(3) - 2.0_dp*zhat) )
1239 <            
1240 <             dudux_i(1) = dudux_i(1) + sw*pref*ri3*(qxx_i*6.0_dp*cx_i*xhat)
1241 <             dudux_i(2) = dudux_i(2) + sw*pref*ri3*(qxx_i*6.0_dp*cx_i*yhat)
1242 <             dudux_i(3) = dudux_i(3) + sw*pref*ri3*(qxx_i*6.0_dp*cx_i*zhat)
1243 <            
1244 <             duduy_i(1) = duduy_i(1) + sw*pref*ri3*(qyy_i*6.0_dp*cy_i*xhat)
1245 <             duduy_i(2) = duduy_i(2) + sw*pref*ri3*(qyy_i*6.0_dp*cy_i*yhat)
1246 <             duduy_i(3) = duduy_i(3) + sw*pref*ri3*(qyy_i*6.0_dp*cy_i*zhat)
1247 <            
1248 <             duduz_i(1) = duduz_i(1) + sw*pref*ri3*(qzz_i*6.0_dp*cz_i*xhat)
1249 <             duduz_i(2) = duduz_i(2) + sw*pref*ri3*(qzz_i*6.0_dp*cz_i*yhat)
1250 <             duduz_i(3) = duduz_i(3) + sw*pref*ri3*(qzz_i*6.0_dp*cz_i*zhat)
1251 < !!$          endif
1117 >          pref = pre14 * q_j / 3.0d0
1118 >          pot_term = ri3 * (qxx_i * (3.0d0*cx2 - 1.0d0) + &
1119 >                            qyy_i * (3.0d0*cy2 - 1.0d0) + &
1120 >                            qzz_i * (3.0d0*cz2 - 1.0d0))
1121 >          vterm = pref * (pot_term*f1 + (qxx_i*cx2 + qyy_i*cy2 + qzz_i*cz2)*f2)
1122 >          vpair = vpair + vterm
1123 >          epot = epot + sw*vterm
1124 >          
1125 >          dudx = dudx - sw*pref*pot_term*riji*xhat*(5.0d0*f1 + f3) + &
1126 >               sw*pref*ri4 * ( &
1127 >               qxx_i*(2.0d0*cx_i*ux_i(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) + &
1128 >               qyy_i*(2.0d0*cy_i*uy_i(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) + &
1129 >               qzz_i*(2.0d0*cz_i*uz_i(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) ) &
1130 >               + (qxx_i*cx2 + qyy_i*cy2 + qzz_i*cz2)*f4
1131 >          dudy = dudy - sw*pref*pot_term*riji*yhat*(5.0d0*f1 + f3) + &
1132 >               sw*pref*ri4 * ( &
1133 >               qxx_i*(2.0d0*cx_i*ux_i(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) + &
1134 >               qyy_i*(2.0d0*cy_i*uy_i(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) + &
1135 >               qzz_i*(2.0d0*cz_i*uz_i(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) ) &
1136 >               + (qxx_i*cx2 + qyy_i*cy2 + qzz_i*cz2)*f4
1137 >          dudz = dudz - sw*pref*pot_term*riji*zhat*(5.0d0*f1 + f3) + &
1138 >               sw*pref*ri4 * ( &
1139 >               qxx_i*(2.0d0*cx_i*ux_i(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) + &
1140 >               qyy_i*(2.0d0*cy_i*uy_i(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) + &
1141 >               qzz_i*(2.0d0*cz_i*uz_i(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) ) &
1142 >               + (qxx_i*cx2 + qyy_i*cy2 + qzz_i*cz2)*f4
1143 >          
1144 >          dudux_i(1) = dudux_i(1) + sw*pref*( ri3*(qxx_i*2.0d0*cx_i*xhat) &
1145 >               * (3.0d0*f1 + f3) )
1146 >          dudux_i(2) = dudux_i(2) + sw*pref*( ri3*(qxx_i*2.0d0*cx_i*yhat) &
1147 >               * (3.0d0*f1 + f3) )
1148 >          dudux_i(3) = dudux_i(3) + sw*pref*( ri3*(qxx_i*2.0d0*cx_i*zhat) &
1149 >               * (3.0d0*f1 + f3) )
1150 >          
1151 >          duduy_i(1) = duduy_i(1) + sw*pref*( ri3*(qyy_i*2.0d0*cy_i*xhat) &
1152 >               * (3.0d0*f1 + f3) )
1153 >          duduy_i(2) = duduy_i(2) + sw*pref*( ri3*(qyy_i*2.0d0*cy_i*yhat) &
1154 >               * (3.0d0*f1 + f3) )
1155 >          duduy_i(3) = duduy_i(3) + sw*pref*( ri3*(qyy_i*2.0d0*cy_i*zhat) &
1156 >               * (3.0d0*f1 + f3) )
1157 >          
1158 >          duduz_i(1) = duduz_i(1) + sw*pref*( ri3*(qzz_i*2.0d0*cz_i*xhat) &
1159 >               * (3.0d0*f1 + f3) )
1160 >          duduz_i(2) = duduz_i(2) + sw*pref*( ri3*(qzz_i*2.0d0*cz_i*yhat) &
1161 >               * (3.0d0*f1 + f3) )
1162 >          duduz_i(3) = duduz_i(3) + sw*pref*( ri3*(qzz_i*2.0d0*cz_i*zhat) &
1163 >               * (3.0d0*f1 + f3) )
1164 >
1165         endif
1166      endif
1167  
# Line 1409 | Line 1322 | contains
1322            
1323         endif
1324  
1325 < !!$    elseif (summationMethod .eq. UNDAMPED_WOLF) then
1326 < !!$       if (ElectrostaticMap(atid1)%is_Charge) then
1327 < !!$          c1 = getCharge(atid1)
1328 < !!$          
1329 < !!$          mypot = mypot - (rcuti * 0.5_dp * c1 * c1)
1330 < !!$       endif
1331 < !!$      
1332 < !!$    elseif (summationMethod .eq. DAMPED_WOLF) then
1333 < !!$       if (ElectrostaticMap(atid1)%is_Charge) then
1334 < !!$          c1 = getCharge(atid1)
1335 < !!$          
1336 < !!$          mypot = mypot - (constERFC * rcuti * 0.5_dp + &
1337 < !!$               dampingAlpha*invRootPi) * c1 * c1      
1338 < !!$       endif
1325 >    elseif ( (summationMethod .eq. SHIFTED_FORCE) .or. &
1326 >         (summationMethod .eq. SHIFTED_POTENTIAL) ) then
1327 >       if (ElectrostaticMap(atid1)%is_Charge) then
1328 >          c1 = getCharge(atid1)
1329 >          
1330 >          if (screeningMethod .eq. DAMPED) then
1331 >             mypot = mypot - (f0c * rcuti * 0.5d0 + &
1332 >                  dampingAlpha*invRootPi) * c1 * c1    
1333 >            
1334 >          else            
1335 >             mypot = mypot - (rcuti * 0.5d0 * c1 * c1)
1336 >            
1337 >          endif
1338 >       endif
1339      endif
1340      
1341      return
# Line 1459 | Line 1372 | contains
1372         call checkSummationMethod()
1373      endif
1374  
1375 <    dudx = 0.0d0
1376 <    dudy = 0.0d0
1377 <    dudz = 0.0d0
1375 >    dudx = zero
1376 >    dudy = zero
1377 >    dudz = zero
1378  
1379      riji = 1.0d0/rij
1380  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines