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 2390 by chrisfen, Wed Oct 19 19:24:40 2005 UTC vs.
Revision 2418 by chrisfen, Tue Nov 8 13:31:36 2005 UTC

# Line 58 | Line 58 | module electrostatic_module
58   #define __FORTRAN90
59   #include "UseTheForce/DarkSide/fInteractionMap.h"
60   #include "UseTheForce/DarkSide/fElectrostaticSummationMethod.h"
61 + #include "UseTheForce/DarkSide/fElectrostaticScreeningMethod.h"
62  
63  
64    !! these prefactors convert the multipole interactions into kcal / mol
# Line 74 | Line 75 | module electrostatic_module
75    !! This unit is also known affectionately as an esu centi-barn.
76    real(kind=dp), parameter :: pre14 = 69.13373_dp
77  
78 <  !! variables to handle different summation methods for long-range electrostatics:
78 >  !! variables to handle different summation methods for long-range
79 >  !! electrostatics:
80    integer, save :: summationMethod = NONE
81 +  integer, save :: screeningMethod = UNDAMPED
82    logical, save :: summationMethodChecked = .false.
83    real(kind=DP), save :: defaultCutoff = 0.0_DP
84    real(kind=DP), save :: defaultCutoff2 = 0.0_DP
85    logical, save :: haveDefaultCutoff = .false.
86    real(kind=DP), save :: dampingAlpha = 0.0_DP
87 +  real(kind=DP), save :: alpha2 = 0.0_DP
88    logical, save :: haveDampingAlpha = .false.
89    real(kind=DP), save :: dielectric = 1.0_DP
90    logical, save :: haveDielectric = .false.
87  real(kind=DP), save :: constERFC = 0.0_DP
91    real(kind=DP), save :: constEXP = 0.0_DP
89  logical, save :: haveDWAconstants = .false.
92    real(kind=dp), save :: rcuti = 0.0_DP
93    real(kind=dp), save :: rcuti2 = 0.0_DP
94    real(kind=dp), save :: rcuti3 = 0.0_DP
# Line 97 | Line 99 | module electrostatic_module
99    real(kind=dp), save :: rt = 1.0_DP
100    real(kind=dp), save :: rrfsq = 1.0_DP
101    real(kind=dp), save :: preRF = 0.0_DP
102 <  logical, save :: preRFCalculated = .false.
103 <
102 >  real(kind=dp), save :: preRF2 = 0.0_DP
103 >  real(kind=dp), save :: f0 = 1.0_DP
104 >  real(kind=dp), save :: f1 = 1.0_DP
105 >  real(kind=dp), save :: f2 = 0.0_DP
106 >  real(kind=dp), save :: f0c = 1.0_DP
107 >  real(kind=dp), save :: f1c = 1.0_DP
108 >  real(kind=dp), save :: f2c = 0.0_DP
109 >
110   #ifdef __IFC
111   ! error function for ifc version > 7.
112    double precision, external :: derfc
113   #endif
114    
115    public :: setElectrostaticSummationMethod
116 +  public :: setScreeningMethod
117    public :: setElectrostaticCutoffRadius
118 <  public :: setDampedWolfAlpha
118 >  public :: setDampingAlpha
119    public :: setReactionFieldDielectric
111  public :: setReactionFieldPrefactor
120    public :: newElectrostaticType
121    public :: setCharge
122    public :: setDipoleMoment
# Line 117 | Line 125 | module electrostatic_module
125    public :: doElectrostaticPair
126    public :: getCharge
127    public :: getDipoleMoment
120  public :: pre22
128    public :: destroyElectrostaticTypes
129 <  public :: accumulate_rf
130 <  public :: accumulate_self_rf
124 <  public :: reaction_field_final
125 <  public :: rf_correct_forces
129 >  public :: self_self
130 >  public :: rf_self_excludes
131  
132    type :: Electrostatic
133       integer :: c_ident
# Line 152 | Line 157 | contains
157  
158    end subroutine setElectrostaticSummationMethod
159  
160 +  subroutine setScreeningMethod(the_SM)
161 +    integer, intent(in) :: the_SM    
162 +    screeningMethod = the_SM
163 +  end subroutine setScreeningMethod
164 +
165    subroutine setElectrostaticCutoffRadius(thisRcut, thisRsw)
166      real(kind=dp), intent(in) :: thisRcut
167      real(kind=dp), intent(in) :: thisRsw
# Line 161 | Line 171 | contains
171      haveDefaultCutoff = .true.
172    end subroutine setElectrostaticCutoffRadius
173  
174 <  subroutine setDampedWolfAlpha(thisAlpha)
174 >  subroutine setDampingAlpha(thisAlpha)
175      real(kind=dp), intent(in) :: thisAlpha
176      dampingAlpha = thisAlpha
177 +    alpha2 = dampingAlpha*dampingAlpha
178      haveDampingAlpha = .true.
179 <  end subroutine setDampedWolfAlpha
179 >  end subroutine setDampingAlpha
180    
181    subroutine setReactionFieldDielectric(thisDielectric)
182      real(kind=dp), intent(in) :: thisDielectric
# Line 173 | Line 184 | contains
184      haveDielectric = .true.
185    end subroutine setReactionFieldDielectric
186  
176  subroutine setReactionFieldPrefactor
177    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
188
187    subroutine newElectrostaticType(c_ident, is_Charge, is_Dipole, &
188         is_SplitDipole, is_Quadrupole, is_Tap, status)
189  
# Line 407 | Line 405 | contains
405      rcuti3 = rcuti2*rcuti
406      rcuti4 = rcuti2*rcuti2
407  
408 <    if (summationMethod .eq. DAMPED_WOLF) then
409 <       if (.not.haveDWAconstants) then
410 <          
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.
408 >    if (screeningMethod .eq. DAMPED) then
409 >       if (.not.haveDampingAlpha) then
410 >          call handleError("checkSummationMethod", "no Damping Alpha set!")
411         endif
412 +      
413 +       if (.not.haveDefaultCutoff) then
414 +          call handleError("checkSummationMethod", "no Default Cutoff set!")
415 +       endif
416 +
417 +       constEXP = exp(-alpha2*defaultCutoff*defaultCutoff)
418 +       invRootPi = 0.56418958354775628695d0
419 +       alphaPi = 2.0d0*dampingAlpha*invRootPi
420 +       f0c = derfc(dampingAlpha*defaultCutoff)
421 +       f1c = alphaPi*defaultCutoff*constEXP + f0c
422 +       f2c = alphaPi*2.0d0*alpha2*constEXP*rcuti2
423 +
424      endif
425  
426      if (summationMethod .eq. REACTION_FIELD) then
427 <       if (.not.haveDielectric) then
428 <          call handleError("checkSummationMethod", "no reaction field Dielectric set!")
427 >       if (haveDielectric) then
428 >          defaultCutoff2 = defaultCutoff*defaultCutoff
429 >          preRF = (dielectric-1.0d0) / &
430 >               ((2.0d0*dielectric+1.0d0)*defaultCutoff2*defaultCutoff)
431 >          preRF2 = 2.0d0*preRF
432 >       else
433 >          call handleError("checkSummationMethod", "Dielectric not set")
434         endif
435 +      
436      endif
437  
438      summationMethodChecked = .true.
439    end subroutine checkSummationMethod
440  
441  
440
442    subroutine doElectrostaticPair(atom1, atom2, d, rij, r2, sw, &
443         vpair, fpair, pot, eFrame, f, t, do_pot)
444  
# Line 449 | Line 450 | contains
450      real(kind=dp), intent(in) :: rij, r2, sw
451      real(kind=dp), intent(in), dimension(3) :: d
452      real(kind=dp), intent(inout) :: vpair
453 <    real(kind=dp), intent(inout), dimension(3) :: fpair
453 >    real(kind=dp), intent(inout), dimension(3) :: fpair    
454  
455      real( kind = dp ) :: pot
456      real( kind = dp ), dimension(9,nLocal) :: eFrame
457      real( kind = dp ), dimension(3,nLocal) :: f
458 +    real( kind = dp ), dimension(3,nLocal) :: felec
459      real( kind = dp ), dimension(3,nLocal) :: t
460  
461      real (kind = dp), dimension(3) :: ux_i, uy_i, uz_i
# Line 471 | Line 473 | contains
473      real (kind=dp) :: cx_i, cy_i, cz_i
474      real (kind=dp) :: cx_j, cy_j, cz_j
475      real (kind=dp) :: cx2, cy2, cz2
476 <    real (kind=dp) :: ct_i, ct_j, ct_ij, a1
476 >    real (kind=dp) :: ct_i, ct_j, ct_ij, a0, a1
477      real (kind=dp) :: riji, ri, ri2, ri3, ri4
478      real (kind=dp) :: pref, vterm, epot, dudr, vterm1, vterm2
479      real (kind=dp) :: xhat, yhat, zhat
480      real (kind=dp) :: dudx, dudy, dudz
481      real (kind=dp) :: scale, sc2, bigR
482 <    real (kind=dp) :: varERFC, varEXP
483 <    real (kind=dp) :: limScale
482 >    real (kind=dp) :: varEXP
483 >    real (kind=dp) :: pot_term
484 >    real (kind=dp) :: preVal, rfVal
485  
486      if (.not.allocated(ElectrostaticMap)) then
487         call handleError("electrostatic", "no ElectrostaticMap was present before first call of do_electrostatic_pair!")
# Line 487 | Line 490 | contains
490  
491      if (.not.summationMethodChecked) then
492         call checkSummationMethod()
490      
493      endif
494  
493
495   #ifdef IS_MPI
496      me1 = atid_Row(atom1)
497      me2 = atid_Col(atom2)
# Line 499 | Line 500 | contains
500      me2 = atid(atom2)
501   #endif
502  
503 + !!$    if (rij .ge. defaultCutoff) then
504 + !!$       write(*,*) 'warning: rij = ', rij, ' rcut = ', defaultCutoff, ' sw = ', sw
505 + !!$    endif
506 +
507      !! some variables we'll need independent of electrostatic type:
508  
509      riji = 1.0d0 / rij
# Line 642 | Line 647 | contains
647  
648         if (j_is_Charge) then
649  
650 <          if (summationMethod .eq. UNDAMPED_WOLF) then
650 >          if (summationMethod .eq. SHIFTED_POTENTIAL) then
651 >             if (screeningMethod .eq. DAMPED) then
652 >                f0 = derfc(dampingAlpha*rij)
653 >                varEXP = exp(-alpha2*rij*rij)
654 >                f1 = alphaPi*rij*varEXP + f0c
655 >             endif
656  
657 <             vterm = pre11 * q_i * q_j * (riji - rcuti)
657 >             vterm = pre11 * q_i * q_j * (riji*f0 - rcuti*f0c)
658               vpair = vpair + vterm
659               epot = epot + sw*vterm
660              
661 <             dudr  = -sw*pre11*q_i*q_j * (riji*riji-rcuti2)*riji
661 >             dudr  = -sw*pre11*q_i*q_j * riji * riji * f1
662              
663 <             dudx = dudx + dudr * d(1)
664 <             dudy = dudy + dudr * d(2)
665 <             dudz = dudz + dudr * d(3)
663 >             dudx = dudx + dudr * xhat
664 >             dudy = dudy + dudr * yhat
665 >             dudz = dudz + dudr * zhat
666  
667 <          elseif (summationMethod .eq. DAMPED_WOLF) then
667 >          elseif (summationMethod .eq. SHIFTED_FORCE) then
668 >             if (screeningMethod .eq. DAMPED) then
669 >                f0 = derfc(dampingAlpha*rij)
670 >                varEXP = exp(-alpha2*rij*rij)
671 >                f1 = alphaPi*rij*varEXP + f0
672 >             endif
673  
674 <             varERFC = derfc(dampingAlpha*rij)
675 <             varEXP = exp(-dampingAlpha*dampingAlpha*rij*rij)
676 <             vterm = pre11 * q_i * q_j * (varERFC*riji - constERFC*rcuti)
674 >             vterm = pre11 * q_i * q_j * ( riji*f0 - rcuti*f0c + &
675 >                  f1c*rcuti2*(rij-defaultCutoff) )
676 >            
677               vpair = vpair + vterm
678               epot = epot + sw*vterm
679              
680 <             dudr  = -sw*pre11*q_i*q_j * ( riji*((varERFC*riji*riji &
681 <                                                  + alphaPi*varEXP) &
682 <                                                 - (constERFC*rcuti2 &
683 <                                                    + alphaPi*constEXP)) )
680 >             dudr  = -sw*pre11*q_i*q_j * (riji*riji*f1 - rcuti2*f1c)
681 >                          
682 >             dudx = dudx + dudr * xhat
683 >             dudy = dudy + dudr * yhat
684 >             dudz = dudz + dudr * zhat
685 >
686 >          elseif (summationMethod .eq. REACTION_FIELD) then
687 >             preVal = pre11 * q_i * q_j
688 >             rfVal = preRF*rij*rij
689 >             vterm = preVal * ( riji + rfVal )
690              
691 <             dudx = dudx + dudr * d(1)
692 <             dudy = dudy + dudr * d(2)
693 <             dudz = dudz + dudr * d(3)
691 >             vpair = vpair + vterm
692 >             epot = epot + sw*vterm
693 >            
694 >             dudr  = sw * preVal * ( 2.0d0*rfVal - riji )*riji
695 >            
696 >             dudx = dudx + dudr * xhat
697 >             dudy = dudy + dudr * yhat
698 >             dudz = dudz + dudr * zhat
699  
700            else
675
701               vterm = pre11 * q_i * q_j * riji
702               vpair = vpair + vterm
703               epot = epot + sw*vterm
# Line 691 | Line 716 | contains
716  
717            pref = pre12 * q_i * mu_j
718  
719 <          if (summationMethod .eq. UNDAMPED_WOLF) then
719 > !!$          if (summationMethod .eq. UNDAMPED_WOLF) then
720 > !!$             ri2 = riji * riji
721 > !!$             ri3 = ri2 * riji
722 > !!$
723 > !!$             pref = pre12 * q_i * mu_j
724 > !!$             vterm = - pref * ct_j * (ri2 - rcuti2)
725 > !!$             vpair = vpair + vterm
726 > !!$             epot = epot + sw*vterm
727 > !!$            
728 > !!$             !! this has a + sign in the () because the rij vector is
729 > !!$             !! r_j - r_i and the charge-dipole potential takes the origin
730 > !!$             !! as the point dipole, which is atom j in this case.
731 > !!$            
732 > !!$             dudx = dudx - sw*pref * ( ri3*( uz_j(1) - 3.0d0*ct_j*xhat) &
733 > !!$                  - rcuti3*( uz_j(1) - 3.0d0*ct_j*d(1)*rcuti ) )
734 > !!$             dudy = dudy - sw*pref * ( ri3*( uz_j(2) - 3.0d0*ct_j*yhat) &
735 > !!$                  - rcuti3*( uz_j(2) - 3.0d0*ct_j*d(2)*rcuti ) )
736 > !!$             dudz = dudz - sw*pref * ( ri3*( uz_j(3) - 3.0d0*ct_j*zhat) &
737 > !!$                  - rcuti3*( uz_j(3) - 3.0d0*ct_j*d(3)*rcuti ) )
738 > !!$            
739 > !!$             duduz_j(1) = duduz_j(1) - sw*pref*( ri2*xhat - d(1)*rcuti3 )
740 > !!$             duduz_j(2) = duduz_j(2) - sw*pref*( ri2*yhat - d(2)*rcuti3 )
741 > !!$             duduz_j(3) = duduz_j(3) - sw*pref*( ri2*zhat - d(3)*rcuti3 )
742 > !!$
743 > !!$          elseif (summationMethod .eq. REACTION_FIELD) then
744 >
745 >          if (summationMethod .eq. REACTION_FIELD) then
746               ri2 = riji * riji
747               ri3 = ri2 * riji
748 <
748 >    
749               pref = pre12 * q_i * mu_j
750 <             vterm = - pref * ct_j * (ri2 - rcuti2)
750 >             vterm = - pref * ct_j * ( ri2 - preRF2*rij )
751               vpair = vpair + vterm
752               epot = epot + sw*vterm
753              
# Line 704 | Line 755 | contains
755               !! r_j - r_i and the charge-dipole potential takes the origin
756               !! as the point dipole, which is atom j in this case.
757              
758 <             dudx = dudx - sw*pref * ( ri3*( uz_j(1) - 3.0d0*ct_j*xhat) &
759 <                  - rcuti3*( uz_j(1) - 3.0d0*ct_j*d(1)*rcuti ) )
760 <             dudy = dudy - sw*pref * ( ri3*( uz_j(2) - 3.0d0*ct_j*yhat) &
761 <                  - rcuti3*( uz_j(2) - 3.0d0*ct_j*d(2)*rcuti ) )
762 <             dudz = dudz - sw*pref * ( ri3*( uz_j(3) - 3.0d0*ct_j*zhat) &
763 <                  - rcuti3*( uz_j(3) - 3.0d0*ct_j*d(3)*rcuti ) )
764 <            
765 <             duduz_j(1) = duduz_j(1) - sw*pref*( ri2*xhat - d(1)*rcuti3 )
766 <             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 )
758 >             dudx = dudx - sw*pref*( ri3*(uz_j(1) - 3.0d0*ct_j*xhat) - &
759 >                                     preRF2*uz_j(1) )
760 >             dudy = dudy - sw*pref*( ri3*(uz_j(2) - 3.0d0*ct_j*yhat) - &
761 >                                     preRF2*uz_j(2) )
762 >             dudz = dudz - sw*pref*( ri3*(uz_j(3) - 3.0d0*ct_j*zhat) - &
763 >                                     preRF2*uz_j(3) )        
764 >             duduz_j(1) = duduz_j(1) - sw*pref * xhat * ( ri2 - preRF2*rij )
765 >             duduz_j(2) = duduz_j(2) - sw*pref * yhat * ( ri2 - preRF2*rij )
766 >             duduz_j(3) = duduz_j(3) - sw*pref * zhat * ( ri2 - preRF2*rij )
767  
768            else
769               if (j_is_SplitDipole) then
# Line 757 | Line 807 | contains
807            cy2 = cy_j * cy_j
808            cz2 = cz_j * cz_j
809  
810 <          if (summationMethod .eq. UNDAMPED_WOLF) then
811 <             pref =  pre14 * q_i / 3.0_dp
812 <             vterm1 = pref * ri3*( qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
813 <                  qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
814 <                  qzz_j * (3.0_dp*cz2 - 1.0_dp) )
815 <             vterm2 = pref * rcuti3*( qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
816 <                  qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
817 <                  qzz_j * (3.0_dp*cz2 - 1.0_dp) )
818 <             vpair = vpair + ( vterm1 - vterm2 )
819 <             epot = epot + sw*( vterm1 - vterm2 )
820 <            
821 <             dudx = dudx - (5.0_dp * &
822 <                  (vterm1*riji*xhat - vterm2*rcuti2*d(1))) + sw*pref * ( &
823 <                  (ri4 - rcuti4)*(qxx_j*(6.0_dp*cx_j*ux_j(1)) - &
824 <                  qxx_j*2.0_dp*(xhat - rcuti*d(1))) + &
825 <                  (ri4 - rcuti4)*(qyy_j*(6.0_dp*cy_j*uy_j(1)) - &
826 <                  qyy_j*2.0_dp*(xhat - rcuti*d(1))) + &
827 <                  (ri4 - rcuti4)*(qzz_j*(6.0_dp*cz_j*uz_j(1)) - &
828 <                  qzz_j*2.0_dp*(xhat - rcuti*d(1))) )
829 <             dudy = dudy - (5.0_dp * &
830 <                  (vterm1*riji*yhat - vterm2*rcuti2*d(2))) + sw*pref * ( &
831 <                  (ri4 - rcuti4)*(qxx_j*(6.0_dp*cx_j*ux_j(2)) - &
832 <                  qxx_j*2.0_dp*(yhat - rcuti*d(2))) + &
833 <                  (ri4 - rcuti4)*(qyy_j*(6.0_dp*cy_j*uy_j(2)) - &
834 <                  qyy_j*2.0_dp*(yhat - rcuti*d(2))) + &
835 <                  (ri4 - rcuti4)*(qzz_j*(6.0_dp*cz_j*uz_j(2)) - &
836 <                  qzz_j*2.0_dp*(yhat - rcuti*d(2))) )
837 <             dudz = dudz - (5.0_dp * &
838 <                  (vterm1*riji*zhat - vterm2*rcuti2*d(3))) + sw*pref * ( &
839 <                  (ri4 - rcuti4)*(qxx_j*(6.0_dp*cx_j*ux_j(3)) - &
840 <                  qxx_j*2.0_dp*(zhat - rcuti*d(3))) + &
841 <                  (ri4 - rcuti4)*(qyy_j*(6.0_dp*cy_j*uy_j(3)) - &
842 <                  qyy_j*2.0_dp*(zhat - rcuti*d(3))) + &
843 <                  (ri4 - rcuti4)*(qzz_j*(6.0_dp*cz_j*uz_j(3)) - &
844 <                  qzz_j*2.0_dp*(zhat - rcuti*d(3))) )
845 <            
846 <             dudux_j(1) = dudux_j(1) + sw*pref*(ri3*(qxx_j*6.0_dp*cx_j*xhat) -&
847 <                  rcuti4*(qxx_j*6.0_dp*cx_j*d(1)))
848 <             dudux_j(2) = dudux_j(2) + sw*pref*(ri3*(qxx_j*6.0_dp*cx_j*yhat) -&
849 <                  rcuti4*(qxx_j*6.0_dp*cx_j*d(2)))
850 <             dudux_j(3) = dudux_j(3) + sw*pref*(ri3*(qxx_j*6.0_dp*cx_j*zhat) -&
851 <                  rcuti4*(qxx_j*6.0_dp*cx_j*d(3)))
852 <            
853 <             duduy_j(1) = duduy_j(1) + sw*pref*(ri3*(qyy_j*6.0_dp*cy_j*xhat) -&
854 <                  rcuti4*(qyy_j*6.0_dp*cx_j*d(1)))
855 <             duduy_j(2) = duduy_j(2) + sw*pref*(ri3*(qyy_j*6.0_dp*cy_j*yhat) -&
856 <                  rcuti4*(qyy_j*6.0_dp*cx_j*d(2)))
857 <             duduy_j(3) = duduy_j(3) + sw*pref*(ri3*(qyy_j*6.0_dp*cy_j*zhat) -&
858 <                  rcuti4*(qyy_j*6.0_dp*cx_j*d(3)))
859 <            
860 <             duduz_j(1) = duduz_j(1) + sw*pref*(ri3*(qzz_j*6.0_dp*cz_j*xhat) -&
861 <                  rcuti4*(qzz_j*6.0_dp*cx_j*d(1)))
862 <             duduz_j(2) = duduz_j(2) + sw*pref*(ri3*(qzz_j*6.0_dp*cz_j*yhat) -&
863 <                  rcuti4*(qzz_j*6.0_dp*cx_j*d(2)))
864 <             duduz_j(3) = duduz_j(3) + sw*pref*(ri3*(qzz_j*6.0_dp*cz_j*zhat) -&
865 <                  rcuti4*(qzz_j*6.0_dp*cx_j*d(3)))
866 <        
867 <          else
810 > !!$          if (summationMethod .eq. UNDAMPED_WOLF) then
811 > !!$             pref =  pre14 * q_i / 3.0_dp
812 > !!$             vterm1 = pref * ri3*( qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
813 > !!$                  qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
814 > !!$                  qzz_j * (3.0_dp*cz2 - 1.0_dp) )
815 > !!$             vterm2 = pref * rcuti3*( qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
816 > !!$                  qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
817 > !!$                  qzz_j * (3.0_dp*cz2 - 1.0_dp) )
818 > !!$             vpair = vpair + ( vterm1 - vterm2 )
819 > !!$             epot = epot + sw*( vterm1 - vterm2 )
820 > !!$            
821 > !!$             dudx = dudx - (5.0_dp * &
822 > !!$                  (vterm1*riji*xhat - vterm2*rcuti2*d(1))) + sw*pref * ( &
823 > !!$                  (ri4 - rcuti4)*(qxx_j*(6.0_dp*cx_j*ux_j(1)) - &
824 > !!$                  qxx_j*2.0_dp*(xhat - rcuti*d(1))) + &
825 > !!$                  (ri4 - rcuti4)*(qyy_j*(6.0_dp*cy_j*uy_j(1)) - &
826 > !!$                  qyy_j*2.0_dp*(xhat - rcuti*d(1))) + &
827 > !!$                  (ri4 - rcuti4)*(qzz_j*(6.0_dp*cz_j*uz_j(1)) - &
828 > !!$                  qzz_j*2.0_dp*(xhat - rcuti*d(1))) )
829 > !!$             dudy = dudy - (5.0_dp * &
830 > !!$                  (vterm1*riji*yhat - vterm2*rcuti2*d(2))) + sw*pref * ( &
831 > !!$                  (ri4 - rcuti4)*(qxx_j*(6.0_dp*cx_j*ux_j(2)) - &
832 > !!$                  qxx_j*2.0_dp*(yhat - rcuti*d(2))) + &
833 > !!$                  (ri4 - rcuti4)*(qyy_j*(6.0_dp*cy_j*uy_j(2)) - &
834 > !!$                  qyy_j*2.0_dp*(yhat - rcuti*d(2))) + &
835 > !!$                  (ri4 - rcuti4)*(qzz_j*(6.0_dp*cz_j*uz_j(2)) - &
836 > !!$                  qzz_j*2.0_dp*(yhat - rcuti*d(2))) )
837 > !!$             dudz = dudz - (5.0_dp * &
838 > !!$                  (vterm1*riji*zhat - vterm2*rcuti2*d(3))) + sw*pref * ( &
839 > !!$                  (ri4 - rcuti4)*(qxx_j*(6.0_dp*cx_j*ux_j(3)) - &
840 > !!$                  qxx_j*2.0_dp*(zhat - rcuti*d(3))) + &
841 > !!$                  (ri4 - rcuti4)*(qyy_j*(6.0_dp*cy_j*uy_j(3)) - &
842 > !!$                  qyy_j*2.0_dp*(zhat - rcuti*d(3))) + &
843 > !!$                  (ri4 - rcuti4)*(qzz_j*(6.0_dp*cz_j*uz_j(3)) - &
844 > !!$                  qzz_j*2.0_dp*(zhat - rcuti*d(3))) )
845 > !!$            
846 > !!$             dudux_j(1) = dudux_j(1) + sw*pref*(ri3*(qxx_j*6.0_dp*cx_j*xhat) -&
847 > !!$                  rcuti4*(qxx_j*6.0_dp*cx_j*d(1)))
848 > !!$             dudux_j(2) = dudux_j(2) + sw*pref*(ri3*(qxx_j*6.0_dp*cx_j*yhat) -&
849 > !!$                  rcuti4*(qxx_j*6.0_dp*cx_j*d(2)))
850 > !!$             dudux_j(3) = dudux_j(3) + sw*pref*(ri3*(qxx_j*6.0_dp*cx_j*zhat) -&
851 > !!$                  rcuti4*(qxx_j*6.0_dp*cx_j*d(3)))
852 > !!$            
853 > !!$             duduy_j(1) = duduy_j(1) + sw*pref*(ri3*(qyy_j*6.0_dp*cy_j*xhat) -&
854 > !!$                  rcuti4*(qyy_j*6.0_dp*cx_j*d(1)))
855 > !!$             duduy_j(2) = duduy_j(2) + sw*pref*(ri3*(qyy_j*6.0_dp*cy_j*yhat) -&
856 > !!$                  rcuti4*(qyy_j*6.0_dp*cx_j*d(2)))
857 > !!$             duduy_j(3) = duduy_j(3) + sw*pref*(ri3*(qyy_j*6.0_dp*cy_j*zhat) -&
858 > !!$                  rcuti4*(qyy_j*6.0_dp*cx_j*d(3)))
859 > !!$            
860 > !!$             duduz_j(1) = duduz_j(1) + sw*pref*(ri3*(qzz_j*6.0_dp*cz_j*xhat) -&
861 > !!$                  rcuti4*(qzz_j*6.0_dp*cx_j*d(1)))
862 > !!$             duduz_j(2) = duduz_j(2) + sw*pref*(ri3*(qzz_j*6.0_dp*cz_j*yhat) -&
863 > !!$                  rcuti4*(qzz_j*6.0_dp*cx_j*d(2)))
864 > !!$             duduz_j(3) = duduz_j(3) + sw*pref*(ri3*(qzz_j*6.0_dp*cz_j*zhat) -&
865 > !!$                  rcuti4*(qzz_j*6.0_dp*cx_j*d(3)))
866 > !!$        
867 > !!$          else
868               pref =  pre14 * q_i / 3.0_dp
869               vterm = pref * ri3 * (qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
870                    qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
# Line 847 | Line 897 | contains
897               duduz_j(2) = duduz_j(2) + sw*pref * ri3*(qzz_j*6.0_dp*cz_j*yhat)
898               duduz_j(3) = duduz_j(3) + sw*pref * ri3*(qzz_j*6.0_dp*cz_j*zhat)
899            
900 <          endif
900 > !!$          endif
901         endif
902      endif
903  
# Line 855 | Line 905 | contains
905  
906         if (j_is_Charge) then
907            
908 <          pref = pre12 * q_j * mu_i
859 <          
860 <          if (summationMethod .eq. UNDAMPED_WOLF) then
908 >          if (summationMethod .eq. SHIFTED_POTENTIAL) then
909               ri2 = riji * riji
910               ri3 = ri2 * riji
911 +            
912 +             pref = pre12 * q_j * mu_i
913 +             pot_term = ri2 - rcuti2
914 +             vterm = pref * ct_i * pot_term
915 +             vpair = vpair + vterm
916 +             epot = epot + sw*vterm
917 +            
918 +             dudx = dudx + sw*pref * ( ri3*(uz_i(1)-3.0d0*ct_i*xhat) )
919 +             dudy = dudy + sw*pref * ( ri3*(uz_i(2)-3.0d0*ct_i*yhat) )
920 +             dudz = dudz + sw*pref * ( ri3*(uz_i(3)-3.0d0*ct_i*zhat) )
921 +            
922 +             duduz_i(1) = duduz_i(1) + sw*pref * xhat * pot_term
923 +             duduz_i(2) = duduz_i(2) + sw*pref * yhat * pot_term
924 +             duduz_i(3) = duduz_i(3) + sw*pref * zhat * pot_term
925  
926 +          elseif (summationMethod .eq. SHIFTED_FORCE) then
927 +             ri2 = riji * riji
928 +             ri3 = ri2 * riji
929 +
930               pref = pre12 * q_j * mu_i
931 <             vterm = pref * ct_i * (ri2 - rcuti2)
931 >             pot_term = ri2 - rcuti2 + 2.0d0*rcuti3*( rij - defaultCutoff )
932 >             vterm = pref * ct_i * pot_term
933               vpair = vpair + vterm
934               epot = epot + sw*vterm
935              
936 <             !! this has a + sign in the () because the rij vector is
937 <             !! r_j - r_i and the charge-dipole potential takes the origin
938 <             !! as the point dipole, which is atom j in this case.
936 >             dudx = dudx + sw*pref * ( (ri3-rcuti3)*(uz_i(1)-3.0d0*ct_i*xhat) )
937 >             dudy = dudy + sw*pref * ( (ri3-rcuti3)*(uz_i(2)-3.0d0*ct_i*yhat) )
938 >             dudz = dudz + sw*pref * ( (ri3-rcuti3)*(uz_i(3)-3.0d0*ct_i*zhat) )
939              
940 <             dudx = dudx + sw*pref * ( ri3*( uz_i(1) - 3.0d0*ct_i*xhat) &
941 <                  - rcuti3*( uz_i(1) - 3.0d0*ct_i*d(1)*rcuti ) )
942 <             dudy = dudy + sw*pref * ( ri3*( uz_i(2) - 3.0d0*ct_i*yhat) &
943 <                  - rcuti3*( uz_i(2) - 3.0d0*ct_i*d(2)*rcuti ) )
944 <             dudz = dudz + sw*pref * ( ri3*( uz_i(3) - 3.0d0*ct_i*zhat) &
945 <                  - rcuti3*( uz_i(3) - 3.0d0*ct_i*d(3)*rcuti ) )
940 >             duduz_i(1) = duduz_i(1) + sw*pref * xhat * pot_term
941 >             duduz_i(2) = duduz_i(2) + sw*pref * yhat * pot_term
942 >             duduz_i(3) = duduz_i(3) + sw*pref * zhat * pot_term
943 >
944 >          elseif (summationMethod .eq. REACTION_FIELD) then
945 >             ri2 = riji * riji
946 >             ri3 = ri2 * riji
947 >
948 >             pref = pre12 * q_j * mu_i
949 >             vterm = pref * ct_i * ( ri2 - preRF2*rij )
950 >             vpair = vpair + vterm
951 >             epot = epot + sw*vterm
952              
953 <             duduz_i(1) = duduz_i(1) - sw*pref*( ri2*xhat - d(1)*rcuti3 )
954 <             duduz_i(2) = duduz_i(2) - sw*pref*( ri2*yhat - d(2)*rcuti3 )
955 <             duduz_i(3) = duduz_i(3) - sw*pref*( ri2*zhat - d(3)*rcuti3 )
953 >             dudx = dudx + sw*pref * ( ri3*(uz_i(1) - 3.0d0*ct_i*xhat) - &
954 >                  preRF2*uz_i(1) )
955 >             dudy = dudy + sw*pref * ( ri3*(uz_i(2) - 3.0d0*ct_i*yhat) - &
956 >                  preRF2*uz_i(2) )
957 >             dudz = dudz + sw*pref * ( ri3*(uz_i(3) - 3.0d0*ct_i*zhat) - &
958 >                  preRF2*uz_i(3) )
959 >            
960 >             duduz_i(1) = duduz_i(1) + sw*pref * xhat * ( ri2 - preRF2*rij )
961 >             duduz_i(2) = duduz_i(2) + sw*pref * yhat * ( ri2 - preRF2*rij )
962 >             duduz_i(3) = duduz_i(3) + sw*pref * zhat * ( ri2 - preRF2*rij )
963  
964            else
965               if (i_is_SplitDipole) then
# Line 911 | Line 991 | contains
991         endif
992        
993         if (j_is_Dipole) then
994 +          ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
995 +          
996 +          ri2 = riji * riji
997 +          ri3 = ri2 * riji
998 +          ri4 = ri2 * ri2
999 +          
1000 +          pref = pre22 * mu_i * mu_j
1001  
1002 <          if (summationMethod .eq. UNDAMPED_WOLF) then
1003 <             ri2 = riji * riji
1004 <             ri3 = ri2 * riji
1005 <             ri4 = ri2 * ri2
1006 <
1007 <             pref = pre22 * mu_i * mu_j
1008 <             vterm = pref * (ri3 - rcuti3) * (ct_ij - 3.0d0 * ct_i * ct_j)
1002 > !!$          if (summationMethod .eq. SHIFTED_POTENTIAL) then
1003 > !!$             a0 = ct_ij - 3.0d0 * ct_i * ct_j
1004 > !!$             pot_term = ri3 - rcuti3
1005 > !!$            
1006 > !!$             vterm = pref*pot_term*a0
1007 > !!$             vpair = vpair + vterm
1008 > !!$             epot = epot + sw*vterm
1009 > !!$            
1010 > !!$             a1 = 5.0d0 * ct_i * ct_j - ct_ij
1011 > !!$            
1012 > !!$             dudx = dudx + sw*pref*3.0d0*ri4 &
1013 > !!$                  * (a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
1014 > !!$             dudy = dudy + sw*pref*3.0d0*ri4 &
1015 > !!$                  * (a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
1016 > !!$             dudz = dudz + sw*pref*3.0d0*ri4 &
1017 > !!$                  * (a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
1018 > !!$            
1019 > !!$             duduz_i(1) = duduz_i(1) + sw*pref*( pot_term &
1020 > !!$                  * (uz_j(1) - 3.0d0*ct_j*xhat) )
1021 > !!$             duduz_i(2) = duduz_i(2) + sw*pref*( pot_term &
1022 > !!$                  * (uz_j(2) - 3.0d0*ct_j*yhat) )
1023 > !!$             duduz_i(3) = duduz_i(3) + sw*pref*( pot_term &
1024 > !!$                  * (uz_j(3) - 3.0d0*ct_j*zhat) )
1025 > !!$             duduz_j(1) = duduz_j(1) + sw*pref*( pot_term &
1026 > !!$                  * (uz_i(1) - 3.0d0*ct_i*xhat) )
1027 > !!$             duduz_j(2) = duduz_j(2) + sw*pref*( pot_term &
1028 > !!$                  * (uz_i(2) - 3.0d0*ct_i*yhat) )
1029 > !!$             duduz_j(3) = duduz_j(3) + sw*pref*( pot_term &
1030 > !!$                  * (uz_i(3) - 3.0d0*ct_i*zhat) )
1031 > !!$
1032 > !!$          elseif (summationMethod .eq. SHIFTED_FORCE) then
1033 > !!$             a0 = ct_ij - 3.0d0 * ct_i * ct_j
1034 > !!$             pot_term = ri3 - rcuti3 + 3.0d0*rcuti4*( rij - defaultCutoff )
1035 > !!$            
1036 > !!$             vterm = pref*pot_term*a0
1037 > !!$             vpair = vpair + vterm
1038 > !!$             epot = epot + sw*vterm
1039 > !!$            
1040 > !!$             a1 = 5.0d0 * ct_i * ct_j - ct_ij
1041 > !!$            
1042 > !!$             dudx = dudx + sw*pref*3.0d0*( ri4 - rcuti4 ) &
1043 > !!$                             * (a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
1044 > !!$             dudy = dudy + sw*pref*3.0d0*( ri4 - rcuti4 ) &
1045 > !!$                             * (a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
1046 > !!$             dudz = dudz + sw*pref*3.0d0*( ri4 - rcuti4 ) &
1047 > !!$                             * (a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
1048 > !!$            
1049 > !!$             duduz_i(1) = duduz_i(1) + sw*pref*( pot_term &
1050 > !!$                  * (uz_j(1) - 3.0d0*ct_j*xhat) )
1051 > !!$             duduz_i(2) = duduz_i(2) + sw*pref*( pot_term &
1052 > !!$                  * (uz_j(2) - 3.0d0*ct_j*yhat) )
1053 > !!$             duduz_i(3) = duduz_i(3) + sw*pref*( pot_term &
1054 > !!$                  * (uz_j(3) - 3.0d0*ct_j*zhat) )
1055 > !!$             duduz_j(1) = duduz_j(1) + sw*pref*( pot_term &
1056 > !!$                  * (uz_i(1) - 3.0d0*ct_i*xhat) )
1057 > !!$             duduz_j(2) = duduz_j(2) + sw*pref*( pot_term &
1058 > !!$                  * (uz_i(2) - 3.0d0*ct_i*yhat) )
1059 > !!$             duduz_j(3) = duduz_j(3) + sw*pref*( pot_term &
1060 > !!$                  * (uz_i(3) - 3.0d0*ct_i*zhat) )
1061 > !!$            
1062 > !!$          elseif (summationMethod .eq. REACTION_FIELD) then
1063 >          if (summationMethod .eq. REACTION_FIELD) then
1064 >             vterm = pref*( ri3*(ct_ij - 3.0d0 * ct_i * ct_j) - &
1065 >                  preRF2*ct_ij )
1066               vpair = vpair + vterm
1067               epot = epot + sw*vterm
1068              
1069               a1 = 5.0d0 * ct_i * ct_j - ct_ij
1070              
1071               dudx = dudx + sw*pref*3.0d0*ri4 &
1072 <                             * (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))
1072 >                             * (a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
1073               dudy = dudy + sw*pref*3.0d0*ri4 &
1074 <                             * (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))
1074 >                             * (a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
1075               dudz = dudz + sw*pref*3.0d0*ri4 &
1076 <                             * (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))
1076 >                             * (a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
1077              
1078               duduz_i(1) = duduz_i(1) + sw*pref*(ri3*(uz_j(1)-3.0d0*ct_j*xhat) &
1079 <                  - rcuti3*(uz_j(1) - 3.0d0*ct_j*d(1)*rcuti))
1079 >                  - preRF2*uz_j(1))
1080               duduz_i(2) = duduz_i(2) + sw*pref*(ri3*(uz_j(2)-3.0d0*ct_j*yhat) &
1081 <                  - rcuti3*(uz_j(2) - 3.0d0*ct_j*d(2)*rcuti))
1081 >                  - preRF2*uz_j(2))
1082               duduz_i(3) = duduz_i(3) + sw*pref*(ri3*(uz_j(3)-3.0d0*ct_j*zhat) &
1083 <                  - rcuti3*(uz_j(3) - 3.0d0*ct_j*d(3)*rcuti))
1083 >                  - preRF2*uz_j(3))
1084               duduz_j(1) = duduz_j(1) + sw*pref*(ri3*(uz_i(1)-3.0d0*ct_i*xhat) &
1085 <                  - rcuti3*(uz_i(1) - 3.0d0*ct_i*d(1)*rcuti))
1085 >                  - preRF2*uz_i(1))
1086               duduz_j(2) = duduz_j(2) + sw*pref*(ri3*(uz_i(2)-3.0d0*ct_i*yhat) &
1087 <                  - rcuti3*(uz_i(2) - 3.0d0*ct_i*d(2)*rcuti))
1087 >                  - preRF2*uz_i(2))
1088               duduz_j(3) = duduz_j(3) + sw*pref*(ri3*(uz_i(3)-3.0d0*ct_i*zhat) &
1089 <                  - rcuti3*(uz_i(3) - 3.0d0*ct_i*d(3)*rcuti))
1089 >                  - preRF2*uz_i(3))
1090  
1091            else
1092               if (i_is_SplitDipole) then
# Line 970 | Line 1108 | contains
1108                  endif
1109               endif
1110              
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
1111               sc2 = scale * scale
1112 <            
980 <             pref = pre22 * mu_i * mu_j
1112 >
1113               vterm = pref * ri3 * (ct_ij - 3.0d0 * ct_i * ct_j * sc2)
1114               vpair = vpair + vterm
1115               epot = epot + sw*vterm
# Line 1018 | Line 1150 | contains
1150            cy2 = cy_i * cy_i
1151            cz2 = cz_i * cz_i
1152  
1153 <          if (summationMethod .eq. UNDAMPED_WOLF) then
1153 > !!$          if (summationMethod .eq. UNDAMPED_WOLF) then
1154 > !!$             pref = pre14 * q_j / 3.0_dp
1155 > !!$             vterm1 = pref * ri3*( qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1156 > !!$                  qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1157 > !!$                  qzz_i * (3.0_dp*cz2 - 1.0_dp) )
1158 > !!$             vterm2 = pref * rcuti3*( qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1159 > !!$                  qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1160 > !!$                  qzz_i * (3.0_dp*cz2 - 1.0_dp) )
1161 > !!$             vpair = vpair + ( vterm1 - vterm2 )
1162 > !!$             epot = epot + sw*( vterm1 - vterm2 )
1163 > !!$            
1164 > !!$             dudx = dudx - sw*(5.0_dp*(vterm1*riji*xhat-vterm2*rcuti2*d(1))) +&
1165 > !!$                  sw*pref * ( (ri4 - rcuti4)*(qxx_i*(6.0_dp*cx_i*ux_i(1)) - &
1166 > !!$                  qxx_i*2.0_dp*(xhat - rcuti*d(1))) + &
1167 > !!$                  (ri4 - rcuti4)*(qyy_i*(6.0_dp*cy_i*uy_i(1)) - &
1168 > !!$                  qyy_i*2.0_dp*(xhat - rcuti*d(1))) + &
1169 > !!$                  (ri4 - rcuti4)*(qzz_i*(6.0_dp*cz_i*uz_i(1)) - &
1170 > !!$                  qzz_i*2.0_dp*(xhat - rcuti*d(1))) )
1171 > !!$             dudy = dudy - sw*(5.0_dp*(vterm1*riji*yhat-vterm2*rcuti2*d(2))) +&
1172 > !!$                  sw*pref * ( (ri4 - rcuti4)*(qxx_i*(6.0_dp*cx_i*ux_i(2)) - &
1173 > !!$                  qxx_i*2.0_dp*(yhat - rcuti*d(2))) + &
1174 > !!$                  (ri4 - rcuti4)*(qyy_i*(6.0_dp*cy_i*uy_i(2)) - &
1175 > !!$                  qyy_i*2.0_dp*(yhat - rcuti*d(2))) + &
1176 > !!$                  (ri4 - rcuti4)*(qzz_i*(6.0_dp*cz_i*uz_i(2)) - &
1177 > !!$                  qzz_i*2.0_dp*(yhat - rcuti*d(2))) )
1178 > !!$             dudz = dudz - sw*(5.0_dp*(vterm1*riji*zhat-vterm2*rcuti2*d(3))) +&
1179 > !!$                  sw*pref * ( (ri4 - rcuti4)*(qxx_i*(6.0_dp*cx_i*ux_i(3)) - &
1180 > !!$                  qxx_i*2.0_dp*(zhat - rcuti*d(3))) + &
1181 > !!$                  (ri4 - rcuti4)*(qyy_i*(6.0_dp*cy_i*uy_i(3)) - &
1182 > !!$                  qyy_i*2.0_dp*(zhat - rcuti*d(3))) + &
1183 > !!$                  (ri4 - rcuti4)*(qzz_i*(6.0_dp*cz_i*uz_i(3)) - &
1184 > !!$                  qzz_i*2.0_dp*(zhat - rcuti*d(3))) )
1185 > !!$            
1186 > !!$             dudux_i(1) = dudux_i(1) + sw*pref*(ri3*(qxx_i*6.0_dp*cx_i*xhat) -&
1187 > !!$                  rcuti4*(qxx_i*6.0_dp*cx_i*d(1)))
1188 > !!$             dudux_i(2) = dudux_i(2) + sw*pref*(ri3*(qxx_i*6.0_dp*cx_i*yhat) -&
1189 > !!$                  rcuti4*(qxx_i*6.0_dp*cx_i*d(2)))
1190 > !!$             dudux_i(3) = dudux_i(3) + sw*pref*(ri3*(qxx_i*6.0_dp*cx_i*zhat) -&
1191 > !!$                  rcuti4*(qxx_i*6.0_dp*cx_i*d(3)))
1192 > !!$            
1193 > !!$             duduy_i(1) = duduy_i(1) + sw*pref*(ri3*(qyy_i*6.0_dp*cy_i*xhat) -&
1194 > !!$                  rcuti4*(qyy_i*6.0_dp*cx_i*d(1)))
1195 > !!$             duduy_i(2) = duduy_i(2) + sw*pref*(ri3*(qyy_i*6.0_dp*cy_i*yhat) -&
1196 > !!$                  rcuti4*(qyy_i*6.0_dp*cx_i*d(2)))
1197 > !!$             duduy_i(3) = duduy_i(3) + sw*pref*(ri3*(qyy_i*6.0_dp*cy_i*zhat) -&
1198 > !!$                  rcuti4*(qyy_i*6.0_dp*cx_i*d(3)))
1199 > !!$            
1200 > !!$             duduz_i(1) = duduz_i(1) + sw*pref*(ri3*(qzz_i*6.0_dp*cz_i*xhat) -&
1201 > !!$                  rcuti4*(qzz_i*6.0_dp*cx_i*d(1)))
1202 > !!$             duduz_i(2) = duduz_i(2) + sw*pref*(ri3*(qzz_i*6.0_dp*cz_i*yhat) -&
1203 > !!$                  rcuti4*(qzz_i*6.0_dp*cx_i*d(2)))
1204 > !!$             duduz_i(3) = duduz_i(3) + sw*pref*(ri3*(qzz_i*6.0_dp*cz_i*zhat) -&
1205 > !!$                  rcuti4*(qzz_i*6.0_dp*cx_i*d(3)))
1206 > !!$
1207 > !!$          else
1208               pref = pre14 * q_j / 3.0_dp
1023             vterm1 = pref * ri3*( qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1024                  qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1025                  qzz_i * (3.0_dp*cz2 - 1.0_dp) )
1026             vterm2 = pref * rcuti3*( qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1027                  qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1028                  qzz_i * (3.0_dp*cz2 - 1.0_dp) )
1029             vpair = vpair + ( vterm1 - vterm2 )
1030             epot = epot + sw*( vterm1 - vterm2 )
1031            
1032             dudx = dudx - sw*(5.0_dp*(vterm1*riji*xhat-vterm2*rcuti2*d(1))) +&
1033                  sw*pref * ( (ri4 - rcuti4)*(qxx_i*(6.0_dp*cx_i*ux_i(1)) - &
1034                  qxx_i*2.0_dp*(xhat - rcuti*d(1))) + &
1035                  (ri4 - rcuti4)*(qyy_i*(6.0_dp*cy_i*uy_i(1)) - &
1036                  qyy_i*2.0_dp*(xhat - rcuti*d(1))) + &
1037                  (ri4 - rcuti4)*(qzz_i*(6.0_dp*cz_i*uz_i(1)) - &
1038                  qzz_i*2.0_dp*(xhat - rcuti*d(1))) )
1039             dudy = dudy - sw*(5.0_dp*(vterm1*riji*yhat-vterm2*rcuti2*d(2))) +&
1040                  sw*pref * ( (ri4 - rcuti4)*(qxx_i*(6.0_dp*cx_i*ux_i(2)) - &
1041                  qxx_i*2.0_dp*(yhat - rcuti*d(2))) + &
1042                  (ri4 - rcuti4)*(qyy_i*(6.0_dp*cy_i*uy_i(2)) - &
1043                  qyy_i*2.0_dp*(yhat - rcuti*d(2))) + &
1044                  (ri4 - rcuti4)*(qzz_i*(6.0_dp*cz_i*uz_i(2)) - &
1045                  qzz_i*2.0_dp*(yhat - rcuti*d(2))) )
1046             dudz = dudz - sw*(5.0_dp*(vterm1*riji*zhat-vterm2*rcuti2*d(3))) +&
1047                  sw*pref * ( (ri4 - rcuti4)*(qxx_i*(6.0_dp*cx_i*ux_i(3)) - &
1048                  qxx_i*2.0_dp*(zhat - rcuti*d(3))) + &
1049                  (ri4 - rcuti4)*(qyy_i*(6.0_dp*cy_i*uy_i(3)) - &
1050                  qyy_i*2.0_dp*(zhat - rcuti*d(3))) + &
1051                  (ri4 - rcuti4)*(qzz_i*(6.0_dp*cz_i*uz_i(3)) - &
1052                  qzz_i*2.0_dp*(zhat - rcuti*d(3))) )
1053            
1054             dudux_i(1) = dudux_i(1) + sw*pref*(ri3*(qxx_i*6.0_dp*cx_i*xhat) -&
1055                  rcuti4*(qxx_i*6.0_dp*cx_i*d(1)))
1056             dudux_i(2) = dudux_i(2) + sw*pref*(ri3*(qxx_i*6.0_dp*cx_i*yhat) -&
1057                  rcuti4*(qxx_i*6.0_dp*cx_i*d(2)))
1058             dudux_i(3) = dudux_i(3) + sw*pref*(ri3*(qxx_i*6.0_dp*cx_i*zhat) -&
1059                  rcuti4*(qxx_i*6.0_dp*cx_i*d(3)))
1060            
1061             duduy_i(1) = duduy_i(1) + sw*pref*(ri3*(qyy_i*6.0_dp*cy_i*xhat) -&
1062                  rcuti4*(qyy_i*6.0_dp*cx_i*d(1)))
1063             duduy_i(2) = duduy_i(2) + sw*pref*(ri3*(qyy_i*6.0_dp*cy_i*yhat) -&
1064                  rcuti4*(qyy_i*6.0_dp*cx_i*d(2)))
1065             duduy_i(3) = duduy_i(3) + sw*pref*(ri3*(qyy_i*6.0_dp*cy_i*zhat) -&
1066                  rcuti4*(qyy_i*6.0_dp*cx_i*d(3)))
1067            
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)))
1074
1075          else
1076             pref = pre14 * q_j / 3.0_dp
1209               vterm = pref * ri3 * (qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1210                    qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1211                    qzz_i * (3.0_dp*cz2 - 1.0_dp))
# Line 1104 | Line 1236 | contains
1236               duduz_i(1) = duduz_i(1) + sw*pref*ri3*(qzz_i*6.0_dp*cz_i*xhat)
1237               duduz_i(2) = duduz_i(2) + sw*pref*ri3*(qzz_i*6.0_dp*cz_i*yhat)
1238               duduz_i(3) = duduz_i(3) + sw*pref*ri3*(qzz_i*6.0_dp*cz_i*zhat)
1239 <          endif
1239 > !!$          endif
1240         endif
1241      endif
1242  
# Line 1223 | Line 1355 | contains
1355  
1356    end subroutine destroyElectrostaticTypes
1357  
1358 <  subroutine accumulate_rf(atom1, atom2, rij, eFrame, taper)
1358 >  subroutine self_self(atom1, eFrame, mypot, t, do_pot)
1359 >    logical, intent(in) :: do_pot
1360 >    integer, intent(in) :: atom1
1361 >    integer :: atid1
1362 >    real(kind=dp), dimension(9,nLocal) :: eFrame
1363 >    real(kind=dp), dimension(3,nLocal) :: t
1364 >    real(kind=dp) :: mu1, c1
1365 >    real(kind=dp) :: preVal, epot, mypot
1366 >    real(kind=dp) :: eix, eiy, eiz
1367  
1368 <    integer, intent(in) :: atom1, atom2
1369 <    real (kind = dp), intent(in) :: rij
1230 <    real (kind = dp), dimension(9,nLocal) :: eFrame
1368 >    ! this is a local only array, so we use the local atom type id's:
1369 >    atid1 = atid(atom1)
1370  
1371 <    integer :: me1, me2
1372 <    real (kind = dp), intent(in) :: taper
1373 <    real (kind = dp):: mu1, mu2
1374 <    real (kind = dp), dimension(3) :: ul1
1375 <    real (kind = dp), dimension(3) :: ul2  
1371 >    if (.not.summationMethodChecked) then
1372 >       call checkSummationMethod()
1373 >    endif
1374 >    
1375 >    if (summationMethod .eq. REACTION_FIELD) then
1376 >       if (ElectrostaticMap(atid1)%is_Dipole) then
1377 >          mu1 = getDipoleMoment(atid1)
1378 >          
1379 >          preVal = pre22 * preRF2 * mu1*mu1
1380 >          mypot = mypot - 0.5d0*preVal
1381 >          
1382 >          ! The self-correction term adds into the reaction field vector
1383 >          
1384 >          eix = preVal * eFrame(3,atom1)
1385 >          eiy = preVal * eFrame(6,atom1)
1386 >          eiz = preVal * eFrame(9,atom1)
1387 >          
1388 >          ! once again, this is self-self, so only the local arrays are needed
1389 >          ! even for MPI jobs:
1390 >          
1391 >          t(1,atom1)=t(1,atom1) - eFrame(6,atom1)*eiz + &
1392 >               eFrame(9,atom1)*eiy
1393 >          t(2,atom1)=t(2,atom1) - eFrame(9,atom1)*eix + &
1394 >               eFrame(3,atom1)*eiz
1395 >          t(3,atom1)=t(3,atom1) - eFrame(3,atom1)*eiy + &
1396 >               eFrame(6,atom1)*eix
1397 >          
1398 >       endif
1399  
1400 <    integer :: localError
1401 <
1402 < #ifdef IS_MPI
1403 <    me1 = atid_Row(atom1)
1404 <    ul1(1) = eFrame_Row(3,atom1)
1405 <    ul1(2) = eFrame_Row(6,atom1)
1406 <    ul1(3) = eFrame_Row(9,atom1)
1407 <
1408 <    me2 = atid_Col(atom2)
1409 <    ul2(1) = eFrame_Col(3,atom2)
1410 <    ul2(2) = eFrame_Col(6,atom2)
1411 <    ul2(3) = eFrame_Col(9,atom2)
1412 < #else
1413 <    me1 = atid(atom1)
1414 <    ul1(1) = eFrame(3,atom1)
1253 <    ul1(2) = eFrame(6,atom1)
1254 <    ul1(3) = eFrame(9,atom1)
1255 <
1256 <    me2 = atid(atom2)
1257 <    ul2(1) = eFrame(3,atom2)
1258 <    ul2(2) = eFrame(6,atom2)
1259 <    ul2(3) = eFrame(9,atom2)
1260 < #endif
1261 <
1262 <    mu1 = getDipoleMoment(me1)
1263 <    mu2 = getDipoleMoment(me2)
1264 <
1265 < #ifdef IS_MPI
1266 <    rf_Row(1,atom1) = rf_Row(1,atom1) + ul2(1)*mu2*taper
1267 <    rf_Row(2,atom1) = rf_Row(2,atom1) + ul2(2)*mu2*taper
1268 <    rf_Row(3,atom1) = rf_Row(3,atom1) + ul2(3)*mu2*taper
1269 <
1270 <    rf_Col(1,atom2) = rf_Col(1,atom2) + ul1(1)*mu1*taper
1271 <    rf_Col(2,atom2) = rf_Col(2,atom2) + ul1(2)*mu1*taper
1272 <    rf_Col(3,atom2) = rf_Col(3,atom2) + ul1(3)*mu1*taper
1273 < #else
1274 <    rf(1,atom1) = rf(1,atom1) + ul2(1)*mu2*taper
1275 <    rf(2,atom1) = rf(2,atom1) + ul2(2)*mu2*taper
1276 <    rf(3,atom1) = rf(3,atom1) + ul2(3)*mu2*taper
1277 <
1278 <    rf(1,atom2) = rf(1,atom2) + ul1(1)*mu1*taper
1279 <    rf(2,atom2) = rf(2,atom2) + ul1(2)*mu1*taper
1280 <    rf(3,atom2) = rf(3,atom2) + ul1(3)*mu1*taper    
1281 < #endif
1282 <    return  
1283 <  end subroutine accumulate_rf
1284 <
1285 <  subroutine accumulate_self_rf(atom1, mu1, eFrame)
1286 <
1287 <    integer, intent(in) :: atom1
1288 <    real(kind=dp), intent(in) :: mu1
1289 <    real(kind=dp), dimension(9,nLocal) :: eFrame
1290 <
1291 <    !! should work for both MPI and non-MPI version since this is not pairwise.
1292 <    rf(1,atom1) = rf(1,atom1) + eFrame(3,atom1)*mu1
1293 <    rf(2,atom1) = rf(2,atom1) + eFrame(6,atom1)*mu1
1294 <    rf(3,atom1) = rf(3,atom1) + eFrame(9,atom1)*mu1
1295 <
1400 >    elseif (summationMethod .eq. SHIFTED_FORCE) then
1401 >       if (ElectrostaticMap(atid1)%is_Charge) then
1402 >          c1 = getCharge(atid1)
1403 >          
1404 >          if (screeningMethod .eq. DAMPED) then
1405 >             mypot = mypot - (f0c * rcuti * 0.5_dp + &
1406 >                  dampingAlpha*invRootPi) * c1 * c1    
1407 >            
1408 >          else            
1409 >             mypot = mypot - (rcuti * 0.5_dp * c1 * c1)
1410 >            
1411 >          endif
1412 >       endif
1413 >    endif
1414 >    
1415      return
1416 <  end subroutine accumulate_self_rf
1416 >  end subroutine self_self
1417  
1418 <  subroutine reaction_field_final(a1, mu1, eFrame, rfpot, t, do_pot)
1419 <
1301 <    integer, intent(in) :: a1
1302 <    real (kind=dp), intent(in) :: mu1
1303 <    real (kind=dp), intent(inout) :: rfpot
1418 >  subroutine rf_self_excludes(atom1, atom2, sw, eFrame, d, rij, vpair, myPot, &
1419 >       f, t, do_pot)
1420      logical, intent(in) :: do_pot
1421 <    real (kind = dp), dimension(9,nLocal) :: eFrame
1422 <    real (kind = dp), dimension(3,nLocal) :: t
1423 <
1424 <    integer :: localError
1421 >    integer, intent(in) :: atom1
1422 >    integer, intent(in) :: atom2
1423 >    logical :: i_is_Charge, j_is_Charge
1424 >    logical :: i_is_Dipole, j_is_Dipole
1425 >    integer :: atid1
1426 >    integer :: atid2
1427 >    real(kind=dp), intent(in) :: rij
1428 >    real(kind=dp), intent(in) :: sw
1429 >    real(kind=dp), intent(in), dimension(3) :: d
1430 >    real(kind=dp), intent(inout) :: vpair
1431 >    real(kind=dp), dimension(9,nLocal) :: eFrame
1432 >    real(kind=dp), dimension(3,nLocal) :: f
1433 >    real(kind=dp), dimension(3,nLocal) :: t
1434 >    real (kind = dp), dimension(3) :: duduz_i
1435 >    real (kind = dp), dimension(3) :: duduz_j
1436 >    real (kind = dp), dimension(3) :: uz_i
1437 >    real (kind = dp), dimension(3) :: uz_j
1438 >    real(kind=dp) :: q_i, q_j, mu_i, mu_j
1439 >    real(kind=dp) :: xhat, yhat, zhat
1440 >    real(kind=dp) :: ct_i, ct_j
1441 >    real(kind=dp) :: ri2, ri3, riji, vterm
1442 >    real(kind=dp) :: pref, preVal, rfVal, myPot
1443 >    real(kind=dp) :: dudx, dudy, dudz, dudr
1444  
1445 <    if (.not.preRFCalculated) then
1446 <       call setReactionFieldPrefactor()
1445 >    if (.not.summationMethodChecked) then
1446 >       call checkSummationMethod()
1447      endif
1448  
1449 <    ! compute torques on dipoles:
1450 <    ! pre converts from mu in units of debye to kcal/mol
1449 >    dudx = 0.0d0
1450 >    dudy = 0.0d0
1451 >    dudz = 0.0d0
1452  
1453 <    ! The torque contribution is dipole cross reaction_field  
1453 >    riji = 1.0d0/rij
1454  
1455 <    t(1,a1) = t(1,a1) + preRF*mu1*(eFrame(6,a1)*rf(3,a1) - &
1456 <                                   eFrame(9,a1)*rf(2,a1))
1457 <    t(2,a1) = t(2,a1) + preRF*mu1*(eFrame(9,a1)*rf(1,a1) - &
1322 <                                   eFrame(3,a1)*rf(3,a1))
1323 <    t(3,a1) = t(3,a1) + preRF*mu1*(eFrame(3,a1)*rf(2,a1) - &
1324 <                                   eFrame(6,a1)*rf(1,a1))
1455 >    xhat = d(1) * riji
1456 >    yhat = d(2) * riji
1457 >    zhat = d(3) * riji
1458  
1459 <    ! the potential contribution is -1/2 dipole dot reaction_field
1459 >    ! this is a local only array, so we use the local atom type id's:
1460 >    atid1 = atid(atom1)
1461 >    atid2 = atid(atom2)
1462 >    i_is_Charge = ElectrostaticMap(atid1)%is_Charge
1463 >    j_is_Charge = ElectrostaticMap(atid2)%is_Charge
1464 >    i_is_Dipole = ElectrostaticMap(atid1)%is_Dipole
1465 >    j_is_Dipole = ElectrostaticMap(atid2)%is_Dipole
1466  
1467 <    if (do_pot) then
1468 <       rfpot = rfpot - 0.5d0 * preRF * mu1 * &
1469 <            (rf(1,a1)*eFrame(3,a1) + rf(2,a1)*eFrame(6,a1) + &
1470 <             rf(3,a1)*eFrame(9,a1))
1467 >    if (i_is_Charge.and.j_is_Charge) then
1468 >       q_i = ElectrostaticMap(atid1)%charge
1469 >       q_j = ElectrostaticMap(atid2)%charge
1470 >      
1471 >       preVal = pre11 * q_i * q_j
1472 >       rfVal = preRF*rij*rij
1473 >       vterm = preVal * rfVal
1474 >      
1475 >       myPot = myPot + sw*vterm
1476 >      
1477 >       dudr  = sw*preVal * 2.0d0*rfVal*riji
1478 >      
1479 >       dudx = dudx + dudr * xhat
1480 >       dudy = dudy + dudr * yhat
1481 >       dudz = dudz + dudr * zhat
1482 >      
1483 >    elseif (i_is_Charge.and.j_is_Dipole) then
1484 >       q_i = ElectrostaticMap(atid1)%charge
1485 >       mu_j = ElectrostaticMap(atid2)%dipole_moment
1486 >       uz_j(1) = eFrame(3,atom2)
1487 >       uz_j(2) = eFrame(6,atom2)
1488 >       uz_j(3) = eFrame(9,atom2)
1489 >       ct_j = uz_j(1)*xhat + uz_j(2)*yhat + uz_j(3)*zhat
1490 >      
1491 >       ri2 = riji * riji
1492 >       ri3 = ri2 * riji
1493 >      
1494 >       pref = pre12 * q_i * mu_j
1495 >       vterm = - pref * ct_j * ( ri2 - preRF2*rij )
1496 >       myPot = myPot + sw*vterm
1497 >      
1498 >       dudx = dudx - sw*pref*( ri3*(uz_j(1)-3.0d0*ct_j*xhat) &
1499 >            - preRF2*uz_j(1) )
1500 >       dudy = dudy - sw*pref*( ri3*(uz_j(2)-3.0d0*ct_j*yhat) &
1501 >            - preRF2*uz_j(2) )
1502 >       dudz = dudz - sw*pref*( ri3*(uz_j(3)-3.0d0*ct_j*zhat) &
1503 >            - preRF2*uz_j(3) )
1504 >      
1505 >       duduz_j(1) = duduz_j(1) - sw * pref * xhat * ( ri2 - preRF2*rij )
1506 >       duduz_j(2) = duduz_j(2) - sw * pref * yhat * ( ri2 - preRF2*rij )
1507 >       duduz_j(3) = duduz_j(3) - sw * pref * zhat * ( ri2 - preRF2*rij )
1508 >      
1509 >    elseif (i_is_Dipole.and.j_is_Charge) then
1510 >       mu_i = ElectrostaticMap(atid1)%dipole_moment
1511 >       q_j = ElectrostaticMap(atid2)%charge
1512 >       uz_i(1) = eFrame(3,atom1)
1513 >       uz_i(2) = eFrame(6,atom1)
1514 >       uz_i(3) = eFrame(9,atom1)
1515 >       ct_i = uz_i(1)*xhat + uz_i(2)*yhat + uz_i(3)*zhat
1516 >      
1517 >       ri2 = riji * riji
1518 >       ri3 = ri2 * riji
1519 >      
1520 >       pref = pre12 * q_j * mu_i
1521 >       vterm = pref * ct_i * ( ri2 - preRF2*rij )
1522 >       myPot = myPot + sw*vterm
1523 >      
1524 >       dudx = dudx + sw*pref*( ri3*(uz_i(1)-3.0d0*ct_i*xhat) &
1525 >            - preRF2*uz_i(1) )
1526 >       dudy = dudy + sw*pref*( ri3*(uz_i(2)-3.0d0*ct_i*yhat) &
1527 >            - preRF2*uz_i(2) )
1528 >       dudz = dudz + sw*pref*( ri3*(uz_i(3)-3.0d0*ct_i*zhat) &
1529 >            - preRF2*uz_i(3) )
1530 >      
1531 >       duduz_i(1) = duduz_i(1) + sw * pref * xhat * ( ri2 - preRF2*rij )
1532 >       duduz_i(2) = duduz_i(2) + sw * pref * yhat * ( ri2 - preRF2*rij )
1533 >       duduz_i(3) = duduz_i(3) + sw * pref * zhat * ( ri2 - preRF2*rij )
1534 >      
1535      endif
1536 +      
1537  
1538 <    return
1539 <  end subroutine reaction_field_final
1540 <
1541 <  subroutine rf_correct_forces(atom1, atom2, d, rij, eFrame, taper, f, fpair)
1542 <
1543 <    integer, intent(in) :: atom1, atom2
1544 <    real(kind=dp), dimension(3), intent(in) :: d
1545 <    real(kind=dp), intent(in) :: rij, taper
1546 <    real( kind = dp ), dimension(9,nLocal) :: eFrame
1547 <    real( kind = dp ), dimension(3,nLocal) :: f
1548 <    real( kind = dp ), dimension(3), intent(inout) :: fpair
1549 <
1550 <    real (kind = dp), dimension(3) :: ul1
1551 <    real (kind = dp), dimension(3) :: ul2
1552 <    real (kind = dp) :: dtdr
1553 <    real (kind = dp) :: dudx, dudy, dudz, u1dotu2
1554 <    integer :: me1, me2, id1, id2
1351 <    real (kind = dp) :: mu1, mu2
1352 <
1353 <    integer :: localError
1354 <
1355 <    if (.not.preRFCalculated) then
1356 <       call setReactionFieldPrefactor()
1538 >    ! accumulate the forces and torques resulting from the self term
1539 >    f(1,atom1) = f(1,atom1) + dudx
1540 >    f(2,atom1) = f(2,atom1) + dudy
1541 >    f(3,atom1) = f(3,atom1) + dudz
1542 >    
1543 >    f(1,atom2) = f(1,atom2) - dudx
1544 >    f(2,atom2) = f(2,atom2) - dudy
1545 >    f(3,atom2) = f(3,atom2) - dudz
1546 >    
1547 >    if (i_is_Dipole) then
1548 >       t(1,atom1)=t(1,atom1) - uz_i(2)*duduz_i(3) + uz_i(3)*duduz_i(2)
1549 >       t(2,atom1)=t(2,atom1) - uz_i(3)*duduz_i(1) + uz_i(1)*duduz_i(3)
1550 >       t(3,atom1)=t(3,atom1) - uz_i(1)*duduz_i(2) + uz_i(2)*duduz_i(1)
1551 >    elseif (j_is_Dipole) then
1552 >       t(1,atom2)=t(1,atom2) - uz_j(2)*duduz_j(3) + uz_j(3)*duduz_j(2)
1553 >       t(2,atom2)=t(2,atom2) - uz_j(3)*duduz_j(1) + uz_j(1)*duduz_j(3)
1554 >       t(3,atom2)=t(3,atom2) - uz_j(1)*duduz_j(2) + uz_j(2)*duduz_j(1)
1555      endif
1556  
1359    if (rij.le.rrf) then
1360
1361       if (rij.lt.rt) then
1362          dtdr = 0.0d0
1363       else
1364          !         write(*,*) 'rf correct in taper region'
1365          dtdr = 6.0d0*(rij*rij - rij*rt - rij*rrf +rrf*rt)/((rrf-rt)**3)
1366       endif
1367
1368 #ifdef IS_MPI
1369       me1 = atid_Row(atom1)
1370       ul1(1) = eFrame_Row(3,atom1)
1371       ul1(2) = eFrame_Row(6,atom1)
1372       ul1(3) = eFrame_Row(9,atom1)
1373
1374       me2 = atid_Col(atom2)
1375       ul2(1) = eFrame_Col(3,atom2)
1376       ul2(2) = eFrame_Col(6,atom2)
1377       ul2(3) = eFrame_Col(9,atom2)
1378 #else
1379       me1 = atid(atom1)
1380       ul1(1) = eFrame(3,atom1)
1381       ul1(2) = eFrame(6,atom1)
1382       ul1(3) = eFrame(9,atom1)
1383
1384       me2 = atid(atom2)
1385       ul2(1) = eFrame(3,atom2)
1386       ul2(2) = eFrame(6,atom2)
1387       ul2(3) = eFrame(9,atom2)
1388 #endif
1389
1390       mu1 = getDipoleMoment(me1)
1391       mu2 = getDipoleMoment(me2)
1392
1393       u1dotu2 = ul1(1)*ul2(1) + ul1(2)*ul2(2) + ul1(3)*ul2(3)
1394
1395       dudx = - preRF*mu1*mu2*u1dotu2*dtdr*d(1)/rij
1396       dudy = - preRF*mu1*mu2*u1dotu2*dtdr*d(2)/rij
1397       dudz = - preRF*mu1*mu2*u1dotu2*dtdr*d(3)/rij
1398
1399 #ifdef IS_MPI
1400       f_Row(1,atom1) = f_Row(1,atom1) + dudx
1401       f_Row(2,atom1) = f_Row(2,atom1) + dudy
1402       f_Row(3,atom1) = f_Row(3,atom1) + dudz
1403
1404       f_Col(1,atom2) = f_Col(1,atom2) - dudx
1405       f_Col(2,atom2) = f_Col(2,atom2) - dudy
1406       f_Col(3,atom2) = f_Col(3,atom2) - dudz
1407 #else
1408       f(1,atom1) = f(1,atom1) + dudx
1409       f(2,atom1) = f(2,atom1) + dudy
1410       f(3,atom1) = f(3,atom1) + dudz
1411
1412       f(1,atom2) = f(1,atom2) - dudx
1413       f(2,atom2) = f(2,atom2) - dudy
1414       f(3,atom2) = f(3,atom2) - dudz
1415 #endif
1416
1417 #ifdef IS_MPI
1418       id1 = AtomRowToGlobal(atom1)
1419       id2 = AtomColToGlobal(atom2)
1420 #else
1421       id1 = atom1
1422       id2 = atom2
1423 #endif
1424
1425       if (molMembershipList(id1) .ne. molMembershipList(id2)) then
1426
1427          fpair(1) = fpair(1) + dudx
1428          fpair(2) = fpair(2) + dudy
1429          fpair(3) = fpair(3) + dudz
1430
1431       endif
1432
1433    end if
1557      return
1558 <  end subroutine rf_correct_forces
1558 >  end subroutine rf_self_excludes
1559  
1560   end module electrostatic_module

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines