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 2310 by chrisfen, Mon Sep 19 23:21:46 2005 UTC vs.
Revision 2715 by chrisfen, Sun Apr 16 02:51:16 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines