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

Comparing trunk/OOPSE-4/src/UseTheForce/DarkSide/electrostatic.F90 (file contents):
Revision 2302 by chrisfen, Fri Sep 16 16:07:39 2005 UTC vs.
Revision 2548 by chrisfen, Thu Jan 12 04:13:46 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines