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 2162 by chrisfen, Mon Apr 11 20:19:22 2005 UTC vs.
Revision 2411 by chrisfen, Wed Nov 2 21:01:21 2005 UTC

# Line 40 | Line 40 | module electrostatic_module
40   !!
41  
42   module electrostatic_module
43 <  
43 >
44    use force_globals
45    use definitions
46    use atype_module
# 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/fScreeningMethod.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 68 | 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
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 +  logical, save :: haveDampingAlpha = .false.
88 +  real(kind=DP), save :: dielectric = 1.0_DP
89 +  logical, save :: haveDielectric = .false.
90 +  real(kind=DP), save :: constERFC = 0.0_DP
91 +  real(kind=DP), save :: constEXP = 0.0_DP
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 +
104 + #ifdef __IFC
105 + ! error function for ifc version > 7.
106 +  double precision, external :: derfc
107 + #endif
108 +  
109 +  public :: setElectrostaticSummationMethod
110 +  public :: setScreeningMethod
111 +  public :: setElectrostaticCutoffRadius
112 +  public :: setDampingAlpha
113 +  public :: setReactionFieldDielectric
114    public :: newElectrostaticType
115    public :: setCharge
116    public :: setDipoleMoment
# Line 76 | Line 119 | module electrostatic_module
119    public :: doElectrostaticPair
120    public :: getCharge
121    public :: getDipoleMoment
122 <  public :: pre22
122 >  public :: destroyElectrostaticTypes
123 >  public :: self_self
124 >  public :: rf_self_excludes
125  
126    type :: Electrostatic
127       integer :: c_ident
# Line 84 | Line 129 | module electrostatic_module
129       logical :: is_Dipole = .false.
130       logical :: is_SplitDipole = .false.
131       logical :: is_Quadrupole = .false.
132 +     logical :: is_Tap = .false.
133       real(kind=DP) :: charge = 0.0_DP
134       real(kind=DP) :: dipole_moment = 0.0_DP
135       real(kind=DP) :: split_dipole_distance = 0.0_DP
# Line 94 | Line 140 | contains
140  
141   contains
142  
143 +  subroutine setElectrostaticSummationMethod(the_ESM)
144 +    integer, intent(in) :: the_ESM    
145 +
146 +    if ((the_ESM .le. 0) .or. (the_ESM .gt. REACTION_FIELD)) then
147 +       call handleError("setElectrostaticSummationMethod", "Unsupported Summation Method")
148 +    endif
149 +
150 +    summationMethod = the_ESM
151 +
152 +  end subroutine setElectrostaticSummationMethod
153 +
154 +  subroutine setScreeningMethod(the_SM)
155 +    integer, intent(in) :: the_SM    
156 +    screeningMethod = the_SM
157 +  end subroutine setScreeningMethod
158 +
159 +  subroutine setElectrostaticCutoffRadius(thisRcut, thisRsw)
160 +    real(kind=dp), intent(in) :: thisRcut
161 +    real(kind=dp), intent(in) :: thisRsw
162 +    defaultCutoff = thisRcut
163 +    rrf = defaultCutoff
164 +    rt = thisRsw
165 +    haveDefaultCutoff = .true.
166 +  end subroutine setElectrostaticCutoffRadius
167 +
168 +  subroutine setDampingAlpha(thisAlpha)
169 +    real(kind=dp), intent(in) :: thisAlpha
170 +    dampingAlpha = thisAlpha
171 +    haveDampingAlpha = .true.
172 +  end subroutine setDampingAlpha
173 +  
174 +  subroutine setReactionFieldDielectric(thisDielectric)
175 +    real(kind=dp), intent(in) :: thisDielectric
176 +    dielectric = thisDielectric
177 +    haveDielectric = .true.
178 +  end subroutine setReactionFieldDielectric
179 +
180    subroutine newElectrostaticType(c_ident, is_Charge, is_Dipole, &
181 <       is_SplitDipole, is_Quadrupole, status)
182 <    
181 >       is_SplitDipole, is_Quadrupole, is_Tap, status)
182 >
183      integer, intent(in) :: c_ident
184      logical, intent(in) :: is_Charge
185      logical, intent(in) :: is_Dipole
186      logical, intent(in) :: is_SplitDipole
187      logical, intent(in) :: is_Quadrupole
188 +    logical, intent(in) :: is_Tap
189      integer, intent(out) :: status
190      integer :: nAtypes, myATID, i, j
191  
192      status = 0
193      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
194 <    
194 >
195      !! Be simple-minded and assume that we need an ElectrostaticMap that
196      !! is the same size as the total number of atom types
197  
198      if (.not.allocated(ElectrostaticMap)) then
199 <      
199 >
200         nAtypes = getSize(atypes)
201 <    
201 >
202         if (nAtypes == 0) then
203            status = -1
204            return
205         end if
206 <      
206 >
207         if (.not. allocated(ElectrostaticMap)) then
208            allocate(ElectrostaticMap(nAtypes))
209         endif
210 <      
210 >
211      end if
212  
213      if (myATID .gt. size(ElectrostaticMap)) then
214         status = -1
215         return
216      endif
217 <    
217 >
218      ! set the values for ElectrostaticMap for this atom type:
219  
220      ElectrostaticMap(myATID)%c_ident = c_ident
# Line 138 | Line 222 | contains
222      ElectrostaticMap(myATID)%is_Dipole = is_Dipole
223      ElectrostaticMap(myATID)%is_SplitDipole = is_SplitDipole
224      ElectrostaticMap(myATID)%is_Quadrupole = is_Quadrupole
225 <    
225 >    ElectrostaticMap(myATID)%is_Tap = is_Tap
226 >
227    end subroutine newElectrostaticType
228  
229    subroutine setCharge(c_ident, charge, status)
# Line 166 | Line 251 | contains
251         call handleError("electrostatic", "Attempt to setCharge of an atom type that is not a charge!")
252         status = -1
253         return
254 <    endif      
254 >    endif
255  
256      ElectrostaticMap(myATID)%charge = charge
257    end subroutine setCharge
# Line 257 | Line 342 | contains
342         status = -1
343         return
344      endif
345 <    
345 >
346      do i = 1, 3
347 <          ElectrostaticMap(myATID)%quadrupole_moments(i) = &
348 <               quadrupole_moments(i)
349 <       enddo
347 >       ElectrostaticMap(myATID)%quadrupole_moments(i) = &
348 >            quadrupole_moments(i)
349 >    enddo
350  
351    end subroutine setQuadrupoleMoments
352  
353 <  
353 >
354    function getCharge(atid) result (c)
355      integer, intent(in) :: atid
356      integer :: localError
357      real(kind=dp) :: c
358 <    
358 >
359      if (.not.allocated(ElectrostaticMap)) then
360         call handleError("electrostatic", "no ElectrostaticMap was present before first call of getCharge!")
361         return
362      end if
363 <    
363 >
364      if (.not.ElectrostaticMap(atid)%is_Charge) then
365         call handleError("electrostatic", "getCharge was called for an atom type that isn't a charge!")
366         return
367      endif
368 <    
368 >
369      c = ElectrostaticMap(atid)%charge
370    end function getCharge
371  
# Line 288 | Line 373 | contains
373      integer, intent(in) :: atid
374      integer :: localError
375      real(kind=dp) :: dm
376 <    
376 >
377      if (.not.allocated(ElectrostaticMap)) then
378         call handleError("electrostatic", "no ElectrostaticMap was present before first call of getDipoleMoment!")
379         return
380      end if
381 <    
381 >
382      if (.not.ElectrostaticMap(atid)%is_Dipole) then
383         call handleError("electrostatic", "getDipoleMoment was called for an atom type that isn't a dipole!")
384         return
385      endif
386 <    
386 >
387      dm = ElectrostaticMap(atid)%dipole_moment
388    end function getDipoleMoment
389  
390 +  subroutine checkSummationMethod()
391 +
392 +    if (.not.haveDefaultCutoff) then
393 +       call handleError("checkSummationMethod", "no Default Cutoff set!")
394 +    endif
395 +
396 +    rcuti = 1.0d0 / defaultCutoff
397 +    rcuti2 = rcuti*rcuti
398 +    rcuti3 = rcuti2*rcuti
399 +    rcuti4 = rcuti2*rcuti2
400 +
401 +    if (screeningMethod .eq. DAMPED) then
402 +       if (.not.haveDampingAlpha) then
403 +          call handleError("checkSummationMethod", "no Damping Alpha set!")
404 +       endif
405 +      
406 +       if (.not.haveDefaultCutoff) then
407 +          call handleError("checkSummationMethod", "no Default Cutoff set!")
408 +       endif
409 +
410 +       constEXP = exp(-dampingAlpha*dampingAlpha*defaultCutoff*defaultCutoff)
411 +       constERFC = derfc(dampingAlpha*defaultCutoff)
412 +       invRootPi = 0.56418958354775628695d0
413 +       alphaPi = 2*dampingAlpha*invRootPi
414 +      
415 +    endif
416 +
417 +    if (summationMethod .eq. REACTION_FIELD) then
418 +       if (haveDielectric) then
419 +          defaultCutoff2 = defaultCutoff*defaultCutoff
420 +          preRF = (dielectric-1.0d0) / &
421 +               ((2.0d0*dielectric+1.0d0)*defaultCutoff2*defaultCutoff)
422 +          preRF2 = 2.0d0*preRF
423 +       else
424 +          call handleError("checkSummationMethod", "Dielectric not set")
425 +       endif
426 +      
427 +    endif
428 +
429 +    summationMethodChecked = .true.
430 +  end subroutine checkSummationMethod
431 +
432 +
433    subroutine doElectrostaticPair(atom1, atom2, d, rij, r2, sw, &
434         vpair, fpair, pot, eFrame, f, t, do_pot)
435 <    
435 >
436      logical, intent(in) :: do_pot
437 <    
437 >
438      integer, intent(in) :: atom1, atom2
439      integer :: localError
440  
441      real(kind=dp), intent(in) :: rij, r2, sw
442      real(kind=dp), intent(in), dimension(3) :: d
443      real(kind=dp), intent(inout) :: vpair
444 <    real(kind=dp), intent(inout), dimension(3) :: fpair
444 >    real(kind=dp), intent(inout), dimension(3) :: fpair    
445  
446      real( kind = dp ) :: pot
447      real( kind = dp ), dimension(9,nLocal) :: eFrame
448      real( kind = dp ), dimension(3,nLocal) :: f
449 +    real( kind = dp ), dimension(3,nLocal) :: felec
450      real( kind = dp ), dimension(3,nLocal) :: t
451 <    
451 >
452      real (kind = dp), dimension(3) :: ux_i, uy_i, uz_i
453      real (kind = dp), dimension(3) :: ux_j, uy_j, uz_j
454      real (kind = dp), dimension(3) :: dudux_i, duduy_i, duduz_i
# Line 327 | Line 456 | contains
456  
457      logical :: i_is_Charge, i_is_Dipole, i_is_SplitDipole, i_is_Quadrupole
458      logical :: j_is_Charge, j_is_Dipole, j_is_SplitDipole, j_is_Quadrupole
459 +    logical :: i_is_Tap, j_is_Tap
460      integer :: me1, me2, id1, id2
461      real (kind=dp) :: q_i, q_j, mu_i, mu_j, d_i, d_j
462      real (kind=dp) :: qxx_i, qyy_i, qzz_i
# Line 336 | Line 466 | contains
466      real (kind=dp) :: cx2, cy2, cz2
467      real (kind=dp) :: ct_i, ct_j, ct_ij, a1
468      real (kind=dp) :: riji, ri, ri2, ri3, ri4
469 <    real (kind=dp) :: pref, vterm, epot, dudr    
469 >    real (kind=dp) :: pref, vterm, epot, dudr, vterm1, vterm2
470      real (kind=dp) :: xhat, yhat, zhat
471      real (kind=dp) :: dudx, dudy, dudz
472      real (kind=dp) :: scale, sc2, bigR
473 +    real (kind=dp) :: varERFC, varEXP
474 +    real (kind=dp) :: limScale
475 +    real (kind=dp) :: preVal, rfVal
476  
477      if (.not.allocated(ElectrostaticMap)) then
478         call handleError("electrostatic", "no ElectrostaticMap was present before first call of do_electrostatic_pair!")
479         return
480      end if
481  
482 +    if (.not.summationMethodChecked) then
483 +       call checkSummationMethod()
484 +    endif
485 +
486   #ifdef IS_MPI
487      me1 = atid_Row(atom1)
488      me2 = atid_Col(atom2)
# Line 354 | Line 491 | contains
491      me2 = atid(atom2)
492   #endif
493  
494 + !!$    if (rij .ge. defaultCutoff) then
495 + !!$       write(*,*) 'warning: rij = ', rij, ' rcut = ', defaultCutoff, ' sw = ', sw
496 + !!$    endif
497 +
498      !! some variables we'll need independent of electrostatic type:
499  
500      riji = 1.0d0 / rij
501 <
501 >  
502      xhat = d(1) * riji
503      yhat = d(2) * riji
504      zhat = d(3) * riji
505  
506      !! logicals
366
507      i_is_Charge = ElectrostaticMap(me1)%is_Charge
508      i_is_Dipole = ElectrostaticMap(me1)%is_Dipole
509      i_is_SplitDipole = ElectrostaticMap(me1)%is_SplitDipole
510      i_is_Quadrupole = ElectrostaticMap(me1)%is_Quadrupole
511 +    i_is_Tap = ElectrostaticMap(me1)%is_Tap
512  
513      j_is_Charge = ElectrostaticMap(me2)%is_Charge
514      j_is_Dipole = ElectrostaticMap(me2)%is_Dipole
515      j_is_SplitDipole = ElectrostaticMap(me2)%is_SplitDipole
516      j_is_Quadrupole = ElectrostaticMap(me2)%is_Quadrupole
517 +    j_is_Tap = ElectrostaticMap(me2)%is_Tap
518  
519      if (i_is_Charge) then
520         q_i = ElectrostaticMap(me1)%charge      
521      endif
522 <    
522 >
523      if (i_is_Dipole) then
524         mu_i = ElectrostaticMap(me1)%dipole_moment
525   #ifdef IS_MPI
# Line 394 | Line 536 | contains
536         if (i_is_SplitDipole) then
537            d_i = ElectrostaticMap(me1)%split_dipole_distance
538         endif
539 <      
539 >
540      endif
541  
542      if (i_is_Quadrupole) then
# Line 427 | Line 569 | contains
569         cz_i = uz_i(1)*xhat + uz_i(2)*yhat + uz_i(3)*zhat
570      endif
571  
430
572      if (j_is_Charge) then
573         q_j = ElectrostaticMap(me2)%charge      
574      endif
575 <    
575 >
576      if (j_is_Dipole) then
577         mu_j = ElectrostaticMap(me2)%dipole_moment
578   #ifdef IS_MPI
# Line 479 | Line 620 | contains
620         cy_j = uy_j(1)*xhat + uy_j(2)*yhat + uy_j(3)*zhat
621         cz_j = uz_j(1)*xhat + uz_j(2)*yhat + uz_j(3)*zhat
622      endif
623 <
623 >  
624      epot = 0.0_dp
625      dudx = 0.0_dp
626      dudy = 0.0_dp
# Line 496 | Line 637 | contains
637      if (i_is_Charge) then
638  
639         if (j_is_Charge) then
499          
500          vterm = pre11 * q_i * q_j * riji
501          vpair = vpair + vterm
502          epot = epot + sw*vterm
640  
641 <          dudr  = - sw * vterm * riji
641 >          if (summationMethod .eq. SHIFTED_POTENTIAL) then
642  
643 <          dudx = dudx + dudr * xhat
644 <          dudy = dudy + dudr * yhat
645 <          dudz = dudz + dudr * zhat
646 <      
647 <       endif
643 >             vterm = pre11 * q_i * q_j * (riji - rcuti)
644 >             vpair = vpair + vterm
645 >             epot = epot + sw*vterm
646 >            
647 >             dudr  = -sw*pre11*q_i*q_j * (riji*riji)
648 >            
649 >             dudx = dudx + dudr * xhat
650 >             dudy = dudy + dudr * yhat
651 >             dudz = dudz + dudr * zhat
652  
653 <       if (j_is_Dipole) then
653 > !!$          elseif (summationMethod .eq. DAMPED_WOLF) then
654 > !!$             varERFC = derfc(dampingAlpha*rij)
655 > !!$             varEXP = exp(-dampingAlpha*dampingAlpha*rij*rij)
656 > !!$             vterm = pre11 * q_i * q_j * (varERFC*riji - constERFC*rcuti)
657 > !!$             vpair = vpair + vterm
658 > !!$             epot = epot + sw*vterm
659 > !!$            
660 > !!$!             dudr  = -sw*pre11*q_i*q_j * (((varERFC*riji*riji &
661 > !!$!                  + alphaPi*varEXP*riji) - (constERFC*rcuti2 &
662 > !!$!                  + alphaPi*constEXP*rcuti)) )
663 > !!$             dudr  = -sw*pre11*q_i*q_j * (varERFC*riji*riji &
664 > !!$                  + alphaPi*varEXP*riji)
665 > !!$            
666 > !!$             dudx = dudx + dudr * xhat
667 > !!$             dudy = dudy + dudr * yhat
668 > !!$             dudz = dudz + dudr * zhat
669  
670 <          if (j_is_SplitDipole) then
671 <             BigR = sqrt(r2 + 0.25_dp * d_j * d_j)
672 <             ri = 1.0_dp / BigR
673 <             scale = rij * ri
518 <          else
519 <             ri = riji
520 <             scale = 1.0_dp
521 <          endif
522 <
523 <          ri2 = ri * ri
524 <          ri3 = ri2 * ri
525 <          sc2 = scale * scale
670 >          elseif (summationMethod .eq. SHIFTED_FORCE) then
671 >             vterm = pre11 * q_i * q_j * (riji + rij*rcuti2 - 2.0d0*rcuti)
672 >             vpair = vpair + vterm
673 >             epot = epot + sw*vterm
674              
675 <          pref = pre12 * q_i * mu_j
676 <          vterm = - pref * ct_j * ri2 * scale
677 <          vpair = vpair + vterm
678 <          epot = epot + sw * vterm
675 >             dudr  = -sw*pre11*q_i*q_j * (riji*riji-rcuti2)
676 >                          
677 >             dudx = dudx + dudr * xhat
678 >             dudy = dudy + dudr * yhat
679 >             dudz = dudz + dudr * zhat
680  
681 <          !! this has a + sign in the () because the rij vector is
682 <          !! r_j - r_i and the charge-dipole potential takes the origin
683 <          !! as the point dipole, which is atom j in this case.
681 > !!$          elseif (summationMethod .eq. DAMPED_SHIFTED_FORCE) then
682 > !!$             varERFC = derfc(dampingAlpha*rij)
683 > !!$             varEXP = exp(-dampingAlpha*dampingAlpha*rij*rij)
684 > !!$             vterm = pre11 * q_i * q_j * (varERFC*riji - constERFC*rcuti)
685 > !!$             vpair = vpair + vterm
686 > !!$             epot = epot + sw*vterm
687 > !!$            
688 > !!$!             dudr  = -sw*pre11*q_i*q_j * (((varERFC*riji*riji &
689 > !!$!                  + alphaPi*varEXP*riji) - (constERFC*rcuti2 &
690 > !!$!                  + alphaPi*constEXP*rcuti)) )
691 > !!$             dudr  = -sw*pre11*q_i*q_j * (varERFC*riji*riji &
692 > !!$                  + alphaPi*varEXP*riji)
693 > !!$            
694 > !!$             dudx = dudx + dudr * xhat
695 > !!$             dudy = dudy + dudr * yhat
696 > !!$             dudz = dudz + dudr * zhat
697  
698 <          dudx = dudx - pref * sw * ri3 * ( uz_j(1) - 3.0d0*ct_j*xhat*sc2)
699 <          dudy = dudy - pref * sw * ri3 * ( uz_j(2) - 3.0d0*ct_j*yhat*sc2)
700 <          dudz = dudz - pref * sw * ri3 * ( uz_j(3) - 3.0d0*ct_j*zhat*sc2)
698 >          elseif (summationMethod .eq. REACTION_FIELD) then
699 >             preVal = pre11 * q_i * q_j
700 >             rfVal = preRF*rij*rij
701 >             vterm = preVal * ( riji + rfVal )
702 >            
703 >             vpair = vpair + vterm
704 >             epot = epot + sw*vterm
705 >            
706 >             dudr  = sw * preVal * ( 2.0d0*rfVal - riji )*riji
707 >            
708 >             dudx = dudx + dudr * xhat
709 >             dudy = dudy + dudr * yhat
710 >             dudz = dudz + dudr * zhat
711  
712 <          duduz_j(1) = duduz_j(1) - pref * sw * ri2 * xhat * scale
713 <          duduz_j(2) = duduz_j(2) - pref * sw * ri2 * yhat * scale
714 <          duduz_j(3) = duduz_j(3) - pref * sw * ri2 * zhat * scale
715 <          
712 >          else
713 >             vterm = pre11 * q_i * q_j * riji
714 >             vpair = vpair + vterm
715 >             epot = epot + sw*vterm
716 >            
717 >             dudr  = - sw * vterm * riji
718 >            
719 >             dudx = dudx + dudr * xhat
720 >             dudy = dudy + dudr * yhat
721 >             dudz = dudz + dudr * zhat
722 >
723 >          endif
724 >
725         endif
726  
727 +       if (j_is_Dipole) then
728 +
729 +          pref = pre12 * q_i * mu_j
730 +
731 + !!$          if (summationMethod .eq. UNDAMPED_WOLF) then
732 + !!$             ri2 = riji * riji
733 + !!$             ri3 = ri2 * riji
734 + !!$
735 + !!$             pref = pre12 * q_i * mu_j
736 + !!$             vterm = - pref * ct_j * (ri2 - rcuti2)
737 + !!$             vpair = vpair + vterm
738 + !!$             epot = epot + sw*vterm
739 + !!$            
740 + !!$             !! this has a + sign in the () because the rij vector is
741 + !!$             !! r_j - r_i and the charge-dipole potential takes the origin
742 + !!$             !! as the point dipole, which is atom j in this case.
743 + !!$            
744 + !!$             dudx = dudx - sw*pref * ( ri3*( uz_j(1) - 3.0d0*ct_j*xhat) &
745 + !!$                  - rcuti3*( uz_j(1) - 3.0d0*ct_j*d(1)*rcuti ) )
746 + !!$             dudy = dudy - sw*pref * ( ri3*( uz_j(2) - 3.0d0*ct_j*yhat) &
747 + !!$                  - rcuti3*( uz_j(2) - 3.0d0*ct_j*d(2)*rcuti ) )
748 + !!$             dudz = dudz - sw*pref * ( ri3*( uz_j(3) - 3.0d0*ct_j*zhat) &
749 + !!$                  - rcuti3*( uz_j(3) - 3.0d0*ct_j*d(3)*rcuti ) )
750 + !!$            
751 + !!$             duduz_j(1) = duduz_j(1) - sw*pref*( ri2*xhat - d(1)*rcuti3 )
752 + !!$             duduz_j(2) = duduz_j(2) - sw*pref*( ri2*yhat - d(2)*rcuti3 )
753 + !!$             duduz_j(3) = duduz_j(3) - sw*pref*( ri2*zhat - d(3)*rcuti3 )
754 + !!$
755 + !!$          elseif (summationMethod .eq. REACTION_FIELD) then
756 +
757 +          if (summationMethod .eq. REACTION_FIELD) then
758 +             ri2 = riji * riji
759 +             ri3 = ri2 * riji
760 +    
761 +             pref = pre12 * q_i * mu_j
762 +             vterm = - pref * ct_j * ( ri2 - preRF2*rij )
763 +             vpair = vpair + vterm
764 +             epot = epot + sw*vterm
765 +            
766 +             !! this has a + sign in the () because the rij vector is
767 +             !! r_j - r_i and the charge-dipole potential takes the origin
768 +             !! as the point dipole, which is atom j in this case.
769 +            
770 +             dudx = dudx - sw*pref*( ri3*(uz_j(1) - 3.0d0*ct_j*xhat) - &
771 +                                     preRF2*uz_j(1) )
772 +             dudy = dudy - sw*pref*( ri3*(uz_j(2) - 3.0d0*ct_j*yhat) - &
773 +                                     preRF2*uz_j(2) )
774 +             dudz = dudz - sw*pref*( ri3*(uz_j(3) - 3.0d0*ct_j*zhat) - &
775 +                                     preRF2*uz_j(3) )        
776 +             duduz_j(1) = duduz_j(1) - sw*pref * xhat * ( ri2 - preRF2*rij )
777 +             duduz_j(2) = duduz_j(2) - sw*pref * yhat * ( ri2 - preRF2*rij )
778 +             duduz_j(3) = duduz_j(3) - sw*pref * zhat * ( ri2 - preRF2*rij )
779 +
780 +          else
781 +             if (j_is_SplitDipole) then
782 +                BigR = sqrt(r2 + 0.25_dp * d_j * d_j)
783 +                ri = 1.0_dp / BigR
784 +                scale = rij * ri
785 +             else
786 +                ri = riji
787 +                scale = 1.0_dp
788 +             endif
789 +            
790 +             ri2 = ri * ri
791 +             ri3 = ri2 * ri
792 +             sc2 = scale * scale
793 +
794 +             pref = pre12 * q_i * mu_j
795 +             vterm = - pref * ct_j * ri2 * scale
796 +             vpair = vpair + vterm
797 +             epot = epot + sw*vterm
798 +            
799 +             !! this has a + sign in the () because the rij vector is
800 +             !! r_j - r_i and the charge-dipole potential takes the origin
801 +             !! as the point dipole, which is atom j in this case.
802 +            
803 +             dudx = dudx - sw*pref * ri3 * ( uz_j(1) - 3.0d0*ct_j*xhat*sc2)
804 +             dudy = dudy - sw*pref * ri3 * ( uz_j(2) - 3.0d0*ct_j*yhat*sc2)
805 +             dudz = dudz - sw*pref * ri3 * ( uz_j(3) - 3.0d0*ct_j*zhat*sc2)
806 +            
807 +             duduz_j(1) = duduz_j(1) - sw*pref * ri2 * xhat * scale
808 +             duduz_j(2) = duduz_j(2) - sw*pref * ri2 * yhat * scale
809 +             duduz_j(3) = duduz_j(3) - sw*pref * ri2 * zhat * scale
810 +
811 +          endif
812 +       endif
813 +
814         if (j_is_Quadrupole) then
815            ri2 = riji * riji
816            ri3 = ri2 * riji
# Line 551 | Line 819 | contains
819            cy2 = cy_j * cy_j
820            cz2 = cz_j * cz_j
821  
822 <
823 <          pref =  pre14 * q_i / 3.0_dp
824 <          vterm = pref * ri3 * (qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
825 <               qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
826 <               qzz_j * (3.0_dp*cz2 - 1.0_dp))
827 <          vpair = vpair + vterm
828 <          epot = epot + sw * vterm
829 <
830 <          dudx = dudx - 5.0_dp*sw*vterm*riji*xhat + pref * sw * ri4 * ( &
831 <               qxx_j*(6.0_dp*cx_j*ux_j(1) - 2.0_dp*xhat) + &
832 <               qyy_j*(6.0_dp*cy_j*uy_j(1) - 2.0_dp*xhat) + &
833 <               qzz_j*(6.0_dp*cz_j*uz_j(1) - 2.0_dp*xhat) )
834 <          dudy = dudy - 5.0_dp*sw*vterm*riji*yhat + pref * sw * ri4 * ( &
835 <               qxx_j*(6.0_dp*cx_j*ux_j(2) - 2.0_dp*yhat) + &
836 <               qyy_j*(6.0_dp*cy_j*uy_j(2) - 2.0_dp*yhat) + &
837 <               qzz_j*(6.0_dp*cz_j*uz_j(2) - 2.0_dp*yhat) )
838 <          dudz = dudz - 5.0_dp*sw*vterm*riji*zhat + pref * sw * ri4 * ( &
839 <               qxx_j*(6.0_dp*cx_j*ux_j(3) - 2.0_dp*zhat) + &
840 <               qyy_j*(6.0_dp*cy_j*uy_j(3) - 2.0_dp*zhat) + &
841 <               qzz_j*(6.0_dp*cz_j*uz_j(3) - 2.0_dp*zhat) )
822 > !!$          if (summationMethod .eq. UNDAMPED_WOLF) then
823 > !!$             pref =  pre14 * q_i / 3.0_dp
824 > !!$             vterm1 = pref * ri3*( qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
825 > !!$                  qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
826 > !!$                  qzz_j * (3.0_dp*cz2 - 1.0_dp) )
827 > !!$             vterm2 = pref * rcuti3*( qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
828 > !!$                  qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
829 > !!$                  qzz_j * (3.0_dp*cz2 - 1.0_dp) )
830 > !!$             vpair = vpair + ( vterm1 - vterm2 )
831 > !!$             epot = epot + sw*( vterm1 - vterm2 )
832 > !!$            
833 > !!$             dudx = dudx - (5.0_dp * &
834 > !!$                  (vterm1*riji*xhat - vterm2*rcuti2*d(1))) + sw*pref * ( &
835 > !!$                  (ri4 - rcuti4)*(qxx_j*(6.0_dp*cx_j*ux_j(1)) - &
836 > !!$                  qxx_j*2.0_dp*(xhat - rcuti*d(1))) + &
837 > !!$                  (ri4 - rcuti4)*(qyy_j*(6.0_dp*cy_j*uy_j(1)) - &
838 > !!$                  qyy_j*2.0_dp*(xhat - rcuti*d(1))) + &
839 > !!$                  (ri4 - rcuti4)*(qzz_j*(6.0_dp*cz_j*uz_j(1)) - &
840 > !!$                  qzz_j*2.0_dp*(xhat - rcuti*d(1))) )
841 > !!$             dudy = dudy - (5.0_dp * &
842 > !!$                  (vterm1*riji*yhat - vterm2*rcuti2*d(2))) + sw*pref * ( &
843 > !!$                  (ri4 - rcuti4)*(qxx_j*(6.0_dp*cx_j*ux_j(2)) - &
844 > !!$                  qxx_j*2.0_dp*(yhat - rcuti*d(2))) + &
845 > !!$                  (ri4 - rcuti4)*(qyy_j*(6.0_dp*cy_j*uy_j(2)) - &
846 > !!$                  qyy_j*2.0_dp*(yhat - rcuti*d(2))) + &
847 > !!$                  (ri4 - rcuti4)*(qzz_j*(6.0_dp*cz_j*uz_j(2)) - &
848 > !!$                  qzz_j*2.0_dp*(yhat - rcuti*d(2))) )
849 > !!$             dudz = dudz - (5.0_dp * &
850 > !!$                  (vterm1*riji*zhat - vterm2*rcuti2*d(3))) + sw*pref * ( &
851 > !!$                  (ri4 - rcuti4)*(qxx_j*(6.0_dp*cx_j*ux_j(3)) - &
852 > !!$                  qxx_j*2.0_dp*(zhat - rcuti*d(3))) + &
853 > !!$                  (ri4 - rcuti4)*(qyy_j*(6.0_dp*cy_j*uy_j(3)) - &
854 > !!$                  qyy_j*2.0_dp*(zhat - rcuti*d(3))) + &
855 > !!$                  (ri4 - rcuti4)*(qzz_j*(6.0_dp*cz_j*uz_j(3)) - &
856 > !!$                  qzz_j*2.0_dp*(zhat - rcuti*d(3))) )
857 > !!$            
858 > !!$             dudux_j(1) = dudux_j(1) + sw*pref*(ri3*(qxx_j*6.0_dp*cx_j*xhat) -&
859 > !!$                  rcuti4*(qxx_j*6.0_dp*cx_j*d(1)))
860 > !!$             dudux_j(2) = dudux_j(2) + sw*pref*(ri3*(qxx_j*6.0_dp*cx_j*yhat) -&
861 > !!$                  rcuti4*(qxx_j*6.0_dp*cx_j*d(2)))
862 > !!$             dudux_j(3) = dudux_j(3) + sw*pref*(ri3*(qxx_j*6.0_dp*cx_j*zhat) -&
863 > !!$                  rcuti4*(qxx_j*6.0_dp*cx_j*d(3)))
864 > !!$            
865 > !!$             duduy_j(1) = duduy_j(1) + sw*pref*(ri3*(qyy_j*6.0_dp*cy_j*xhat) -&
866 > !!$                  rcuti4*(qyy_j*6.0_dp*cx_j*d(1)))
867 > !!$             duduy_j(2) = duduy_j(2) + sw*pref*(ri3*(qyy_j*6.0_dp*cy_j*yhat) -&
868 > !!$                  rcuti4*(qyy_j*6.0_dp*cx_j*d(2)))
869 > !!$             duduy_j(3) = duduy_j(3) + sw*pref*(ri3*(qyy_j*6.0_dp*cy_j*zhat) -&
870 > !!$                  rcuti4*(qyy_j*6.0_dp*cx_j*d(3)))
871 > !!$            
872 > !!$             duduz_j(1) = duduz_j(1) + sw*pref*(ri3*(qzz_j*6.0_dp*cz_j*xhat) -&
873 > !!$                  rcuti4*(qzz_j*6.0_dp*cx_j*d(1)))
874 > !!$             duduz_j(2) = duduz_j(2) + sw*pref*(ri3*(qzz_j*6.0_dp*cz_j*yhat) -&
875 > !!$                  rcuti4*(qzz_j*6.0_dp*cx_j*d(2)))
876 > !!$             duduz_j(3) = duduz_j(3) + sw*pref*(ri3*(qzz_j*6.0_dp*cz_j*zhat) -&
877 > !!$                  rcuti4*(qzz_j*6.0_dp*cx_j*d(3)))
878 > !!$        
879 > !!$          else
880 >             pref =  pre14 * q_i / 3.0_dp
881 >             vterm = pref * ri3 * (qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
882 >                  qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
883 >                  qzz_j * (3.0_dp*cz2 - 1.0_dp))
884 >             vpair = vpair + vterm
885 >             epot = epot + sw*vterm
886 >            
887 >             dudx = dudx - 5.0_dp*sw*vterm*riji*xhat + sw*pref * ri4 * ( &
888 >                  qxx_j*(6.0_dp*cx_j*ux_j(1) - 2.0_dp*xhat) + &
889 >                  qyy_j*(6.0_dp*cy_j*uy_j(1) - 2.0_dp*xhat) + &
890 >                  qzz_j*(6.0_dp*cz_j*uz_j(1) - 2.0_dp*xhat) )
891 >             dudy = dudy - 5.0_dp*sw*vterm*riji*yhat + sw*pref * ri4 * ( &
892 >                  qxx_j*(6.0_dp*cx_j*ux_j(2) - 2.0_dp*yhat) + &
893 >                  qyy_j*(6.0_dp*cy_j*uy_j(2) - 2.0_dp*yhat) + &
894 >                  qzz_j*(6.0_dp*cz_j*uz_j(2) - 2.0_dp*yhat) )
895 >             dudz = dudz - 5.0_dp*sw*vterm*riji*zhat + sw*pref * ri4 * ( &
896 >                  qxx_j*(6.0_dp*cx_j*ux_j(3) - 2.0_dp*zhat) + &
897 >                  qyy_j*(6.0_dp*cy_j*uy_j(3) - 2.0_dp*zhat) + &
898 >                  qzz_j*(6.0_dp*cz_j*uz_j(3) - 2.0_dp*zhat) )
899 >            
900 >             dudux_j(1) = dudux_j(1) + sw*pref * ri3*(qxx_j*6.0_dp*cx_j*xhat)
901 >             dudux_j(2) = dudux_j(2) + sw*pref * ri3*(qxx_j*6.0_dp*cx_j*yhat)
902 >             dudux_j(3) = dudux_j(3) + sw*pref * ri3*(qxx_j*6.0_dp*cx_j*zhat)
903 >            
904 >             duduy_j(1) = duduy_j(1) + sw*pref * ri3*(qyy_j*6.0_dp*cy_j*xhat)
905 >             duduy_j(2) = duduy_j(2) + sw*pref * ri3*(qyy_j*6.0_dp*cy_j*yhat)
906 >             duduy_j(3) = duduy_j(3) + sw*pref * ri3*(qyy_j*6.0_dp*cy_j*zhat)
907 >            
908 >             duduz_j(1) = duduz_j(1) + sw*pref * ri3*(qzz_j*6.0_dp*cz_j*xhat)
909 >             duduz_j(2) = duduz_j(2) + sw*pref * ri3*(qzz_j*6.0_dp*cz_j*yhat)
910 >             duduz_j(3) = duduz_j(3) + sw*pref * ri3*(qzz_j*6.0_dp*cz_j*zhat)
911            
912 <          dudux_j(1) = dudux_j(1) + pref * sw * ri3 * (qxx_j*6.0_dp*cx_j*xhat)
576 <          dudux_j(2) = dudux_j(2) + pref * sw * ri3 * (qxx_j*6.0_dp*cx_j*yhat)
577 <          dudux_j(3) = dudux_j(3) + pref * sw * ri3 * (qxx_j*6.0_dp*cx_j*zhat)
578 <
579 <          duduy_j(1) = duduy_j(1) + pref * sw * ri3 * (qyy_j*6.0_dp*cy_j*xhat)
580 <          duduy_j(2) = duduy_j(2) + pref * sw * ri3 * (qyy_j*6.0_dp*cy_j*yhat)
581 <          duduy_j(3) = duduy_j(3) + pref * sw * ri3 * (qyy_j*6.0_dp*cy_j*zhat)
582 <
583 <          duduz_j(1) = duduz_j(1) + pref * sw * ri3 * (qzz_j*6.0_dp*cz_j*xhat)
584 <          duduz_j(2) = duduz_j(2) + pref * sw * ri3 * (qzz_j*6.0_dp*cz_j*yhat)
585 <          duduz_j(3) = duduz_j(3) + pref * sw * ri3 * (qzz_j*6.0_dp*cz_j*zhat)
912 > !!$          endif
913         endif
587
914      endif
915 <  
915 >
916      if (i_is_Dipole) then
591      
592       if (j_is_Charge) then
917  
918 <          if (i_is_SplitDipole) then
919 <             BigR = sqrt(r2 + 0.25_dp * d_i * d_i)
596 <             ri = 1.0_dp / BigR
597 <             scale = rij * ri
598 <          else
599 <             ri = riji
600 <             scale = 1.0_dp
601 <          endif
602 <
603 <          ri2 = ri * ri
604 <          ri3 = ri2 * ri
605 <          sc2 = scale * scale
606 <            
918 >       if (j_is_Charge) then
919 >          
920            pref = pre12 * q_j * mu_i
921 <          vterm = pref * ct_i * ri2 * scale
922 <          vpair = vpair + vterm
923 <          epot = epot + sw * vterm
921 >          
922 > !!$          if (summationMethod .eq. UNDAMPED_WOLF) then
923 > !!$             ri2 = riji * riji
924 > !!$             ri3 = ri2 * riji
925 > !!$
926 > !!$             pref = pre12 * q_j * mu_i
927 > !!$             vterm = pref * ct_i * (ri2 - rcuti2)
928 > !!$             vpair = vpair + vterm
929 > !!$             epot = epot + sw*vterm
930 > !!$            
931 > !!$             dudx = dudx + sw*pref * ( ri3*( uz_i(1) - 3.0d0*ct_i*xhat) &
932 > !!$                  - rcuti3*( uz_i(1) - 3.0d0*ct_i*d(1)*rcuti ) )
933 > !!$             dudy = dudy + sw*pref * ( ri3*( uz_i(2) - 3.0d0*ct_i*yhat) &
934 > !!$                  - rcuti3*( uz_i(2) - 3.0d0*ct_i*d(2)*rcuti ) )
935 > !!$             dudz = dudz + sw*pref * ( ri3*( uz_i(3) - 3.0d0*ct_i*zhat) &
936 > !!$                  - rcuti3*( uz_i(3) - 3.0d0*ct_i*d(3)*rcuti ) )
937 > !!$            
938 > !!$             duduz_i(1) = duduz_i(1) + sw*pref*( ri2*xhat - d(1)*rcuti3 )
939 > !!$             duduz_i(2) = duduz_i(2) + sw*pref*( ri2*yhat - d(2)*rcuti3 )
940 > !!$             duduz_i(3) = duduz_i(3) + sw*pref*( ri2*zhat - d(3)*rcuti3 )
941 > !!$
942 > !!$          elseif (summationMethod .eq. REACTION_FIELD) then
943 >          if (summationMethod .eq. REACTION_FIELD) then
944 >             ri2 = riji * riji
945 >             ri3 = ri2 * riji
946  
947 <          dudx = dudx + pref * sw * ri3 * ( uz_i(1) - 3.0d0 * ct_i * xhat*sc2)
948 <          dudy = dudy + pref * sw * ri3 * ( uz_i(2) - 3.0d0 * ct_i * yhat*sc2)
949 <          dudz = dudz + pref * sw * ri3 * ( uz_i(3) - 3.0d0 * ct_i * zhat*sc2)
950 <
951 <          duduz_i(1) = duduz_i(1) + pref * sw * ri2 * xhat * scale
952 <          duduz_i(2) = duduz_i(2) + pref * sw * ri2 * yhat * scale
953 <          duduz_i(3) = duduz_i(3) + pref * sw * ri2 * zhat * scale
954 <       endif
955 <
956 <       if (j_is_Dipole) then
947 >             pref = pre12 * q_j * mu_i
948 >             vterm = pref * ct_i * ( ri2 - preRF2*rij )
949 >             vpair = vpair + vterm
950 >             epot = epot + sw*vterm
951 >            
952 >             dudx = dudx + sw*pref * ( ri3*(uz_i(1) - 3.0d0*ct_i*xhat) - &
953 >                  preRF2*uz_i(1) )
954 >             dudy = dudy + sw*pref * ( ri3*(uz_i(2) - 3.0d0*ct_i*yhat) - &
955 >                  preRF2*uz_i(2) )
956 >             dudz = dudz + sw*pref * ( ri3*(uz_i(3) - 3.0d0*ct_i*zhat) - &
957 >                  preRF2*uz_i(3) )
958 >            
959 >             duduz_i(1) = duduz_i(1) + sw*pref * xhat * ( ri2 - preRF2*rij )
960 >             duduz_i(2) = duduz_i(2) + sw*pref * yhat * ( ri2 - preRF2*rij )
961 >             duduz_i(3) = duduz_i(3) + sw*pref * zhat * ( ri2 - preRF2*rij )
962  
623          if (i_is_SplitDipole) then
624             if (j_is_SplitDipole) then
625                BigR = sqrt(r2 + 0.25_dp * d_i * d_i + 0.25_dp * d_j * d_j)
626             else
627                BigR = sqrt(r2 + 0.25_dp * d_i * d_i)
628             endif
629             ri = 1.0_dp / BigR
630             scale = rij * ri                
963            else
964 <             if (j_is_SplitDipole) then
965 <                BigR = sqrt(r2 + 0.25_dp * d_j * d_j)
964 >             if (i_is_SplitDipole) then
965 >                BigR = sqrt(r2 + 0.25_dp * d_i * d_i)
966                  ri = 1.0_dp / BigR
967 <                scale = rij * ri                            
968 <             else                
967 >                scale = rij * ri
968 >             else
969                  ri = riji
970                  scale = 1.0_dp
971               endif
972 +            
973 +             ri2 = ri * ri
974 +             ri3 = ri2 * ri
975 +             sc2 = scale * scale
976 +
977 +             pref = pre12 * q_j * mu_i
978 +             vterm = pref * ct_i * ri2 * scale
979 +             vpair = vpair + vterm
980 +             epot = epot + sw*vterm
981 +            
982 +             dudx = dudx + sw*pref * ri3 * ( uz_i(1) - 3.0d0 * ct_i * xhat*sc2)
983 +             dudy = dudy + sw*pref * ri3 * ( uz_i(2) - 3.0d0 * ct_i * yhat*sc2)
984 +             dudz = dudz + sw*pref * ri3 * ( uz_i(3) - 3.0d0 * ct_i * zhat*sc2)
985 +            
986 +             duduz_i(1) = duduz_i(1) + sw*pref * ri2 * xhat * scale
987 +             duduz_i(2) = duduz_i(2) + sw*pref * ri2 * yhat * scale
988 +             duduz_i(3) = duduz_i(3) + sw*pref * ri2 * zhat * scale
989            endif
990 +       endif
991 +      
992 +       if (j_is_Dipole) then
993  
994 <          ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
994 > !!$          if (summationMethod .eq. UNDAMPED_WOLF) then
995 > !!$             ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
996 > !!$
997 > !!$             ri2 = riji * riji
998 > !!$             ri3 = ri2 * riji
999 > !!$             ri4 = ri2 * ri2
1000 > !!$
1001 > !!$             pref = pre22 * mu_i * mu_j
1002 > !!$             vterm = pref * (ri3 - rcuti3) * (ct_ij - 3.0d0 * ct_i * ct_j)
1003 > !!$             vpair = vpair + vterm
1004 > !!$             epot = epot + sw*vterm
1005 > !!$            
1006 > !!$             a1 = 5.0d0 * ct_i * ct_j - ct_ij
1007 > !!$            
1008 > !!$             dudx = dudx + sw*pref*3.0d0*( &
1009 > !!$                  ri4*(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1)) &
1010 > !!$                  - rcuti4*(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1)) )
1011 > !!$             dudy = dudy + sw*pref*3.0d0*( &
1012 > !!$                  ri4*(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2)) &
1013 > !!$                  - rcuti4*(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2)) )
1014 > !!$             dudz = dudz + sw*pref*3.0d0*( &
1015 > !!$                  ri4*(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3)) &
1016 > !!$                  - rcuti4*(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3)) )
1017 > !!$            
1018 > !!$             duduz_i(1) = duduz_i(1) + sw*pref*(ri3*(uz_j(1)-3.0d0*ct_j*xhat) &
1019 > !!$                  - rcuti3*(uz_j(1) - 3.0d0*ct_j*xhat))
1020 > !!$             duduz_i(2) = duduz_i(2) + sw*pref*(ri3*(uz_j(2)-3.0d0*ct_j*yhat) &
1021 > !!$                  - rcuti3*(uz_j(2) - 3.0d0*ct_j*yhat))
1022 > !!$             duduz_i(3) = duduz_i(3) + sw*pref*(ri3*(uz_j(3)-3.0d0*ct_j*zhat) &
1023 > !!$                  - rcuti3*(uz_j(3) - 3.0d0*ct_j*zhat))
1024 > !!$             duduz_j(1) = duduz_j(1) + sw*pref*(ri3*(uz_i(1)-3.0d0*ct_i*xhat) &
1025 > !!$                  - rcuti3*(uz_i(1) - 3.0d0*ct_i*xhat))
1026 > !!$             duduz_j(2) = duduz_j(2) + sw*pref*(ri3*(uz_i(2)-3.0d0*ct_i*yhat) &
1027 > !!$                  - rcuti3*(uz_i(2) - 3.0d0*ct_i*yhat))
1028 > !!$             duduz_j(3) = duduz_j(3) + sw*pref*(ri3*(uz_i(3)-3.0d0*ct_i*zhat) &
1029 > !!$                  - rcuti3*(uz_i(3) - 3.0d0*ct_i*zhat))
1030 > !!$          
1031 > !!$          elseif (summationMethod .eq. DAMPED_WOLF) then
1032 > !!$             ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
1033 > !!$            
1034 > !!$             ri2 = riji * riji
1035 > !!$             ri3 = ri2 * riji
1036 > !!$             ri4 = ri2 * ri2
1037 > !!$             sc2 = scale * scale
1038 > !!$            
1039 > !!$             pref = pre22 * mu_i * mu_j
1040 > !!$             vterm = pref * ri3 * (ct_ij - 3.0d0 * ct_i * ct_j)
1041 > !!$             vpair = vpair + vterm
1042 > !!$             epot = epot + sw*vterm
1043 > !!$            
1044 > !!$             a1 = 5.0d0 * ct_i * ct_j * sc2 - ct_ij
1045 > !!$            
1046 > !!$             dudx = dudx + sw*pref*3.0d0*ri4*(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
1047 > !!$             dudy = dudy + sw*pref*3.0d0*ri4*(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
1048 > !!$             dudz = dudz + sw*pref*3.0d0*ri4*(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
1049 > !!$            
1050 > !!$             duduz_i(1) = duduz_i(1) + sw*pref*ri3 *(uz_j(1) - 3.0d0*ct_j*xhat)
1051 > !!$             duduz_i(2) = duduz_i(2) + sw*pref*ri3 *(uz_j(2) - 3.0d0*ct_j*yhat)
1052 > !!$             duduz_i(3) = duduz_i(3) + sw*pref*ri3 *(uz_j(3) - 3.0d0*ct_j*zhat)
1053 > !!$            
1054 > !!$             duduz_j(1) = duduz_j(1) + sw*pref*ri3 *(uz_i(1) - 3.0d0*ct_i*xhat)
1055 > !!$             duduz_j(2) = duduz_j(2) + sw*pref*ri3 *(uz_i(2) - 3.0d0*ct_i*yhat)
1056 > !!$             duduz_j(3) = duduz_j(3) + sw*pref*ri3 *(uz_i(3) - 3.0d0*ct_i*zhat)
1057 > !!$            
1058 > !!$          elseif (summationMethod .eq. REACTION_FIELD) then
1059 >          if (summationMethod .eq. REACTION_FIELD) then
1060 >             ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
1061  
1062 <          ri2 = ri * ri
1063 <          ri3 = ri2 * ri
1064 <          ri4 = ri2 * ri2
647 <          sc2 = scale * scale
1062 >             ri2 = riji * riji
1063 >             ri3 = ri2 * riji
1064 >             ri4 = ri2 * ri2
1065  
1066 <          pref = pre22 * mu_i * mu_j
1067 <          vterm = pref * ri3 * (ct_ij - 3.0d0 * ct_i * ct_j * sc2)
1068 <          vpair = vpair + vterm
1069 <          epot = epot + sw * vterm
1070 <          
1071 <          a1 = 5.0d0 * ct_i * ct_j * sc2 - ct_ij
1066 >             pref = pre22 * mu_i * mu_j
1067 >              
1068 >             vterm = pref*( ri3*(ct_ij - 3.0d0 * ct_i * ct_j) - &
1069 >                  preRF2*ct_ij )
1070 >             vpair = vpair + vterm
1071 >             epot = epot + sw*vterm
1072 >            
1073 >             a1 = 5.0d0 * ct_i * ct_j - ct_ij
1074 >            
1075 >             dudx = dudx + sw*pref*3.0d0*ri4 &
1076 >                             * (a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
1077 >             dudy = dudy + sw*pref*3.0d0*ri4 &
1078 >                             * (a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
1079 >             dudz = dudz + sw*pref*3.0d0*ri4 &
1080 >                             * (a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
1081 >            
1082 >             duduz_i(1) = duduz_i(1) + sw*pref*(ri3*(uz_j(1)-3.0d0*ct_j*xhat) &
1083 >                  - preRF2*uz_j(1))
1084 >             duduz_i(2) = duduz_i(2) + sw*pref*(ri3*(uz_j(2)-3.0d0*ct_j*yhat) &
1085 >                  - preRF2*uz_j(2))
1086 >             duduz_i(3) = duduz_i(3) + sw*pref*(ri3*(uz_j(3)-3.0d0*ct_j*zhat) &
1087 >                  - preRF2*uz_j(3))
1088 >             duduz_j(1) = duduz_j(1) + sw*pref*(ri3*(uz_i(1)-3.0d0*ct_i*xhat) &
1089 >                  - preRF2*uz_i(1))
1090 >             duduz_j(2) = duduz_j(2) + sw*pref*(ri3*(uz_i(2)-3.0d0*ct_i*yhat) &
1091 >                  - preRF2*uz_i(2))
1092 >             duduz_j(3) = duduz_j(3) + sw*pref*(ri3*(uz_i(3)-3.0d0*ct_i*zhat) &
1093 >                  - preRF2*uz_i(3))
1094  
1095 <          dudx=dudx+pref*sw*3.0d0*ri4*scale*(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
1096 <          dudy=dudy+pref*sw*3.0d0*ri4*scale*(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
1097 <          dudz=dudz+pref*sw*3.0d0*ri4*scale*(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
1098 <
1099 <          duduz_i(1) = duduz_i(1) + pref*sw*ri3*(uz_j(1) - 3.0d0*ct_j*xhat*sc2)
1100 <          duduz_i(2) = duduz_i(2) + pref*sw*ri3*(uz_j(2) - 3.0d0*ct_j*yhat*sc2)
1101 <          duduz_i(3) = duduz_i(3) + pref*sw*ri3*(uz_j(3) - 3.0d0*ct_j*zhat*sc2)
1102 <
1103 <          duduz_j(1) = duduz_j(1) + pref*sw*ri3*(uz_i(1) - 3.0d0*ct_i*xhat*sc2)
1104 <          duduz_j(2) = duduz_j(2) + pref*sw*ri3*(uz_i(2) - 3.0d0*ct_i*yhat*sc2)
1105 <          duduz_j(3) = duduz_j(3) + pref*sw*ri3*(uz_i(3) - 3.0d0*ct_i*zhat*sc2)
1095 >          else
1096 >             if (i_is_SplitDipole) then
1097 >                if (j_is_SplitDipole) then
1098 >                   BigR = sqrt(r2 + 0.25_dp * d_i * d_i + 0.25_dp * d_j * d_j)
1099 >                else
1100 >                   BigR = sqrt(r2 + 0.25_dp * d_i * d_i)
1101 >                endif
1102 >                ri = 1.0_dp / BigR
1103 >                scale = rij * ri                
1104 >             else
1105 >                if (j_is_SplitDipole) then
1106 >                   BigR = sqrt(r2 + 0.25_dp * d_j * d_j)
1107 >                   ri = 1.0_dp / BigR
1108 >                   scale = rij * ri                            
1109 >                else                
1110 >                   ri = riji
1111 >                   scale = 1.0_dp
1112 >                endif
1113 >             endif
1114 >            
1115 >             ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
1116 >            
1117 >             ri2 = ri * ri
1118 >             ri3 = ri2 * ri
1119 >             ri4 = ri2 * ri2
1120 >             sc2 = scale * scale
1121 >            
1122 >             pref = pre22 * mu_i * mu_j
1123 >             vterm = pref * ri3 * (ct_ij - 3.0d0 * ct_i * ct_j * sc2)
1124 >             vpair = vpair + vterm
1125 >             epot = epot + sw*vterm
1126 >            
1127 >             a1 = 5.0d0 * ct_i * ct_j * sc2 - ct_ij
1128 >            
1129 >             dudx = dudx + sw*pref*3.0d0*ri4*scale &
1130 >                             *(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
1131 >             dudy = dudy + sw*pref*3.0d0*ri4*scale &
1132 >                             *(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
1133 >             dudz = dudz + sw*pref*3.0d0*ri4*scale &
1134 >                             *(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
1135 >            
1136 >             duduz_i(1) = duduz_i(1) + sw*pref*ri3 &
1137 >                                         *(uz_j(1) - 3.0d0*ct_j*xhat*sc2)
1138 >             duduz_i(2) = duduz_i(2) + sw*pref*ri3 &
1139 >                                         *(uz_j(2) - 3.0d0*ct_j*yhat*sc2)
1140 >             duduz_i(3) = duduz_i(3) + sw*pref*ri3 &
1141 >                                         *(uz_j(3) - 3.0d0*ct_j*zhat*sc2)
1142 >            
1143 >             duduz_j(1) = duduz_j(1) + sw*pref*ri3 &
1144 >                                         *(uz_i(1) - 3.0d0*ct_i*xhat*sc2)
1145 >             duduz_j(2) = duduz_j(2) + sw*pref*ri3 &
1146 >                                         *(uz_i(2) - 3.0d0*ct_i*yhat*sc2)
1147 >             duduz_j(3) = duduz_j(3) + sw*pref*ri3 &
1148 >                                         *(uz_i(3) - 3.0d0*ct_i*zhat*sc2)
1149 >          endif
1150         endif
668
1151      endif
1152  
1153      if (i_is_Quadrupole) then
1154         if (j_is_Charge) then
1155 <          
1155 >
1156            ri2 = riji * riji
1157            ri3 = ri2 * riji
1158            ri4 = ri2 * ri2
1159            cx2 = cx_i * cx_i
1160            cy2 = cy_i * cy_i
1161            cz2 = cz_i * cz_i
1162 <          
1163 <          pref = pre14 * q_j / 3.0_dp
1164 <          vterm = pref * ri3 * (qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1165 <               qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1166 <               qzz_i * (3.0_dp*cz2 - 1.0_dp))
1167 <          vpair = vpair + vterm
1168 <          epot = epot + sw * vterm
1169 <          
1170 <          dudx = dudx - 5.0_dp*sw*vterm*riji*xhat + pref * sw * ri4 * ( &
1171 <               qxx_i*(6.0_dp*cx_i*ux_i(1) - 2.0_dp*xhat) + &
1172 <               qyy_i*(6.0_dp*cy_i*uy_i(1) - 2.0_dp*xhat) + &
1173 <               qzz_i*(6.0_dp*cz_i*uz_i(1) - 2.0_dp*xhat) )
1174 <          dudy = dudy - 5.0_dp*sw*vterm*riji*yhat + pref * sw * ri4 * ( &
1175 <               qxx_i*(6.0_dp*cx_i*ux_i(2) - 2.0_dp*yhat) + &
1176 <               qyy_i*(6.0_dp*cy_i*uy_i(2) - 2.0_dp*yhat) + &
1177 <               qzz_i*(6.0_dp*cz_i*uz_i(2) - 2.0_dp*yhat) )
1178 <          dudz = dudz - 5.0_dp*sw*vterm*riji*zhat + pref * sw * ri4 * ( &
1179 <               qxx_i*(6.0_dp*cx_i*ux_i(3) - 2.0_dp*zhat) + &
1180 <               qyy_i*(6.0_dp*cy_i*uy_i(3) - 2.0_dp*zhat) + &
1181 <               qzz_i*(6.0_dp*cz_i*uz_i(3) - 2.0_dp*zhat) )
1182 <          
1183 <          dudux_i(1) = dudux_i(1) + pref * sw * ri3 * (qxx_i*6.0_dp*cx_i*xhat)
1184 <          dudux_i(2) = dudux_i(2) + pref * sw * ri3 * (qxx_i*6.0_dp*cx_i*yhat)
1185 <          dudux_i(3) = dudux_i(3) + pref * sw * ri3 * (qxx_i*6.0_dp*cx_i*zhat)
1186 <          
1187 <          duduy_i(1) = duduy_i(1) + pref * sw * ri3 * (qyy_i*6.0_dp*cy_i*xhat)
1188 <          duduy_i(2) = duduy_i(2) + pref * sw * ri3 * (qyy_i*6.0_dp*cy_i*yhat)
1189 <          duduy_i(3) = duduy_i(3) + pref * sw * ri3 * (qyy_i*6.0_dp*cy_i*zhat)
1190 <          
1191 <          duduz_i(1) = duduz_i(1) + pref * sw * ri3 * (qzz_i*6.0_dp*cz_i*xhat)
1192 <          duduz_i(2) = duduz_i(2) + pref * sw * ri3 * (qzz_i*6.0_dp*cz_i*yhat)
1193 <          duduz_i(3) = duduz_i(3) + pref * sw * ri3 * (qzz_i*6.0_dp*cz_i*zhat)
1162 >
1163 > !!$          if (summationMethod .eq. UNDAMPED_WOLF) then
1164 > !!$             pref = pre14 * q_j / 3.0_dp
1165 > !!$             vterm1 = pref * ri3*( qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1166 > !!$                  qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1167 > !!$                  qzz_i * (3.0_dp*cz2 - 1.0_dp) )
1168 > !!$             vterm2 = pref * rcuti3*( qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1169 > !!$                  qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1170 > !!$                  qzz_i * (3.0_dp*cz2 - 1.0_dp) )
1171 > !!$             vpair = vpair + ( vterm1 - vterm2 )
1172 > !!$             epot = epot + sw*( vterm1 - vterm2 )
1173 > !!$            
1174 > !!$             dudx = dudx - sw*(5.0_dp*(vterm1*riji*xhat-vterm2*rcuti2*d(1))) +&
1175 > !!$                  sw*pref * ( (ri4 - rcuti4)*(qxx_i*(6.0_dp*cx_i*ux_i(1)) - &
1176 > !!$                  qxx_i*2.0_dp*(xhat - rcuti*d(1))) + &
1177 > !!$                  (ri4 - rcuti4)*(qyy_i*(6.0_dp*cy_i*uy_i(1)) - &
1178 > !!$                  qyy_i*2.0_dp*(xhat - rcuti*d(1))) + &
1179 > !!$                  (ri4 - rcuti4)*(qzz_i*(6.0_dp*cz_i*uz_i(1)) - &
1180 > !!$                  qzz_i*2.0_dp*(xhat - rcuti*d(1))) )
1181 > !!$             dudy = dudy - sw*(5.0_dp*(vterm1*riji*yhat-vterm2*rcuti2*d(2))) +&
1182 > !!$                  sw*pref * ( (ri4 - rcuti4)*(qxx_i*(6.0_dp*cx_i*ux_i(2)) - &
1183 > !!$                  qxx_i*2.0_dp*(yhat - rcuti*d(2))) + &
1184 > !!$                  (ri4 - rcuti4)*(qyy_i*(6.0_dp*cy_i*uy_i(2)) - &
1185 > !!$                  qyy_i*2.0_dp*(yhat - rcuti*d(2))) + &
1186 > !!$                  (ri4 - rcuti4)*(qzz_i*(6.0_dp*cz_i*uz_i(2)) - &
1187 > !!$                  qzz_i*2.0_dp*(yhat - rcuti*d(2))) )
1188 > !!$             dudz = dudz - sw*(5.0_dp*(vterm1*riji*zhat-vterm2*rcuti2*d(3))) +&
1189 > !!$                  sw*pref * ( (ri4 - rcuti4)*(qxx_i*(6.0_dp*cx_i*ux_i(3)) - &
1190 > !!$                  qxx_i*2.0_dp*(zhat - rcuti*d(3))) + &
1191 > !!$                  (ri4 - rcuti4)*(qyy_i*(6.0_dp*cy_i*uy_i(3)) - &
1192 > !!$                  qyy_i*2.0_dp*(zhat - rcuti*d(3))) + &
1193 > !!$                  (ri4 - rcuti4)*(qzz_i*(6.0_dp*cz_i*uz_i(3)) - &
1194 > !!$                  qzz_i*2.0_dp*(zhat - rcuti*d(3))) )
1195 > !!$            
1196 > !!$             dudux_i(1) = dudux_i(1) + sw*pref*(ri3*(qxx_i*6.0_dp*cx_i*xhat) -&
1197 > !!$                  rcuti4*(qxx_i*6.0_dp*cx_i*d(1)))
1198 > !!$             dudux_i(2) = dudux_i(2) + sw*pref*(ri3*(qxx_i*6.0_dp*cx_i*yhat) -&
1199 > !!$                  rcuti4*(qxx_i*6.0_dp*cx_i*d(2)))
1200 > !!$             dudux_i(3) = dudux_i(3) + sw*pref*(ri3*(qxx_i*6.0_dp*cx_i*zhat) -&
1201 > !!$                  rcuti4*(qxx_i*6.0_dp*cx_i*d(3)))
1202 > !!$            
1203 > !!$             duduy_i(1) = duduy_i(1) + sw*pref*(ri3*(qyy_i*6.0_dp*cy_i*xhat) -&
1204 > !!$                  rcuti4*(qyy_i*6.0_dp*cx_i*d(1)))
1205 > !!$             duduy_i(2) = duduy_i(2) + sw*pref*(ri3*(qyy_i*6.0_dp*cy_i*yhat) -&
1206 > !!$                  rcuti4*(qyy_i*6.0_dp*cx_i*d(2)))
1207 > !!$             duduy_i(3) = duduy_i(3) + sw*pref*(ri3*(qyy_i*6.0_dp*cy_i*zhat) -&
1208 > !!$                  rcuti4*(qyy_i*6.0_dp*cx_i*d(3)))
1209 > !!$            
1210 > !!$             duduz_i(1) = duduz_i(1) + sw*pref*(ri3*(qzz_i*6.0_dp*cz_i*xhat) -&
1211 > !!$                  rcuti4*(qzz_i*6.0_dp*cx_i*d(1)))
1212 > !!$             duduz_i(2) = duduz_i(2) + sw*pref*(ri3*(qzz_i*6.0_dp*cz_i*yhat) -&
1213 > !!$                  rcuti4*(qzz_i*6.0_dp*cx_i*d(2)))
1214 > !!$             duduz_i(3) = duduz_i(3) + sw*pref*(ri3*(qzz_i*6.0_dp*cz_i*zhat) -&
1215 > !!$                  rcuti4*(qzz_i*6.0_dp*cx_i*d(3)))
1216 > !!$
1217 > !!$          else
1218 >             pref = pre14 * q_j / 3.0_dp
1219 >             vterm = pref * ri3 * (qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1220 >                  qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1221 >                  qzz_i * (3.0_dp*cz2 - 1.0_dp))
1222 >             vpair = vpair + vterm
1223 >             epot = epot + sw*vterm
1224 >            
1225 >             dudx = dudx - 5.0_dp*sw*vterm*riji*xhat + sw*pref*ri4 * ( &
1226 >                  qxx_i*(6.0_dp*cx_i*ux_i(1) - 2.0_dp*xhat) + &
1227 >                  qyy_i*(6.0_dp*cy_i*uy_i(1) - 2.0_dp*xhat) + &
1228 >                  qzz_i*(6.0_dp*cz_i*uz_i(1) - 2.0_dp*xhat) )
1229 >             dudy = dudy - 5.0_dp*sw*vterm*riji*yhat + sw*pref*ri4 * ( &
1230 >                  qxx_i*(6.0_dp*cx_i*ux_i(2) - 2.0_dp*yhat) + &
1231 >                  qyy_i*(6.0_dp*cy_i*uy_i(2) - 2.0_dp*yhat) + &
1232 >                  qzz_i*(6.0_dp*cz_i*uz_i(2) - 2.0_dp*yhat) )
1233 >             dudz = dudz - 5.0_dp*sw*vterm*riji*zhat + sw*pref*ri4 * ( &
1234 >                  qxx_i*(6.0_dp*cx_i*ux_i(3) - 2.0_dp*zhat) + &
1235 >                  qyy_i*(6.0_dp*cy_i*uy_i(3) - 2.0_dp*zhat) + &
1236 >                  qzz_i*(6.0_dp*cz_i*uz_i(3) - 2.0_dp*zhat) )
1237 >            
1238 >             dudux_i(1) = dudux_i(1) + sw*pref*ri3*(qxx_i*6.0_dp*cx_i*xhat)
1239 >             dudux_i(2) = dudux_i(2) + sw*pref*ri3*(qxx_i*6.0_dp*cx_i*yhat)
1240 >             dudux_i(3) = dudux_i(3) + sw*pref*ri3*(qxx_i*6.0_dp*cx_i*zhat)
1241 >            
1242 >             duduy_i(1) = duduy_i(1) + sw*pref*ri3*(qyy_i*6.0_dp*cy_i*xhat)
1243 >             duduy_i(2) = duduy_i(2) + sw*pref*ri3*(qyy_i*6.0_dp*cy_i*yhat)
1244 >             duduy_i(3) = duduy_i(3) + sw*pref*ri3*(qyy_i*6.0_dp*cy_i*zhat)
1245 >            
1246 >             duduz_i(1) = duduz_i(1) + sw*pref*ri3*(qzz_i*6.0_dp*cz_i*xhat)
1247 >             duduz_i(2) = duduz_i(2) + sw*pref*ri3*(qzz_i*6.0_dp*cz_i*yhat)
1248 >             duduz_i(3) = duduz_i(3) + sw*pref*ri3*(qzz_i*6.0_dp*cz_i*zhat)
1249 > !!$          endif
1250         endif
1251      endif
1252 <      
1253 <    
1252 >
1253 >
1254      if (do_pot) then
1255   #ifdef IS_MPI
1256 <       pot_row(atom1) = pot_row(atom1) + 0.5d0*epot
1257 <       pot_col(atom2) = pot_col(atom2) + 0.5d0*epot
1256 >       pot_row(ELECTROSTATIC_POT,atom1) = pot_row(ELECTROSTATIC_POT,atom1) + 0.5d0*epot
1257 >       pot_col(ELECTROSTATIC_POT,atom2) = pot_col(ELECTROSTATIC_POT,atom2) + 0.5d0*epot
1258   #else
1259         pot = pot + epot
1260   #endif
1261      endif
1262 <        
1262 >
1263   #ifdef IS_MPI
1264      f_Row(1,atom1) = f_Row(1,atom1) + dudx
1265      f_Row(2,atom1) = f_Row(2,atom1) + dudy
1266      f_Row(3,atom1) = f_Row(3,atom1) + dudz
1267 <    
1267 >
1268      f_Col(1,atom2) = f_Col(1,atom2) - dudx
1269      f_Col(2,atom2) = f_Col(2,atom2) - dudy
1270      f_Col(3,atom2) = f_Col(3,atom2) - dudz
1271 <    
1271 >
1272      if (i_is_Dipole .or. i_is_Quadrupole) then
1273         t_Row(1,atom1)=t_Row(1,atom1) - uz_i(2)*duduz_i(3) + uz_i(3)*duduz_i(2)
1274         t_Row(2,atom1)=t_Row(2,atom1) - uz_i(3)*duduz_i(1) + uz_i(1)*duduz_i(3)
# Line 765 | Line 1303 | contains
1303      f(1,atom1) = f(1,atom1) + dudx
1304      f(2,atom1) = f(2,atom1) + dudy
1305      f(3,atom1) = f(3,atom1) + dudz
1306 <    
1306 >
1307      f(1,atom2) = f(1,atom2) - dudx
1308      f(2,atom2) = f(2,atom2) - dudy
1309      f(3,atom2) = f(3,atom2) - dudz
1310 <    
1310 >
1311      if (i_is_Dipole .or. i_is_Quadrupole) then
1312         t(1,atom1)=t(1,atom1) - uz_i(2)*duduz_i(3) + uz_i(3)*duduz_i(2)
1313         t(2,atom1)=t(2,atom1) - uz_i(3)*duduz_i(1) + uz_i(1)*duduz_i(3)
# Line 801 | Line 1339 | contains
1339      endif
1340  
1341   #endif
1342 <    
1342 >
1343   #ifdef IS_MPI
1344      id1 = AtomRowToGlobal(atom1)
1345      id2 = AtomColToGlobal(atom2)
# Line 811 | Line 1349 | contains
1349   #endif
1350  
1351      if (molMembershipList(id1) .ne. molMembershipList(id2)) then
1352 <      
1352 >
1353         fpair(1) = fpair(1) + dudx
1354         fpair(2) = fpair(2) + dudy
1355         fpair(3) = fpair(3) + dudz
# Line 820 | Line 1358 | contains
1358  
1359      return
1360    end subroutine doElectrostaticPair
1361 <  
1361 >
1362 >  subroutine destroyElectrostaticTypes()
1363 >
1364 >    if(allocated(ElectrostaticMap)) deallocate(ElectrostaticMap)
1365 >
1366 >  end subroutine destroyElectrostaticTypes
1367 >
1368 >  subroutine self_self(atom1, eFrame, mypot, t, do_pot)
1369 >    logical, intent(in) :: do_pot
1370 >    integer, intent(in) :: atom1
1371 >    integer :: atid1
1372 >    real(kind=dp), dimension(9,nLocal) :: eFrame
1373 >    real(kind=dp), dimension(3,nLocal) :: t
1374 >    real(kind=dp) :: mu1, c1
1375 >    real(kind=dp) :: preVal, epot, mypot
1376 >    real(kind=dp) :: eix, eiy, eiz
1377 >
1378 >    ! this is a local only array, so we use the local atom type id's:
1379 >    atid1 = atid(atom1)
1380 >
1381 >    if (.not.summationMethodChecked) then
1382 >       call checkSummationMethod()
1383 >    endif
1384 >    
1385 >    if (summationMethod .eq. REACTION_FIELD) then
1386 >       if (ElectrostaticMap(atid1)%is_Dipole) then
1387 >          mu1 = getDipoleMoment(atid1)
1388 >          
1389 >          preVal = pre22 * preRF2 * mu1*mu1
1390 >          mypot = mypot - 0.5d0*preVal
1391 >          
1392 >          ! The self-correction term adds into the reaction field vector
1393 >          
1394 >          eix = preVal * eFrame(3,atom1)
1395 >          eiy = preVal * eFrame(6,atom1)
1396 >          eiz = preVal * eFrame(9,atom1)
1397 >          
1398 >          ! once again, this is self-self, so only the local arrays are needed
1399 >          ! even for MPI jobs:
1400 >          
1401 >          t(1,atom1)=t(1,atom1) - eFrame(6,atom1)*eiz + &
1402 >               eFrame(9,atom1)*eiy
1403 >          t(2,atom1)=t(2,atom1) - eFrame(9,atom1)*eix + &
1404 >               eFrame(3,atom1)*eiz
1405 >          t(3,atom1)=t(3,atom1) - eFrame(3,atom1)*eiy + &
1406 >               eFrame(6,atom1)*eix
1407 >          
1408 >       endif
1409 >
1410 > !!$    elseif (summationMethod .eq. UNDAMPED_WOLF) then
1411 > !!$       if (ElectrostaticMap(atid1)%is_Charge) then
1412 > !!$          c1 = getCharge(atid1)
1413 > !!$          
1414 > !!$          mypot = mypot - (rcuti * 0.5_dp * c1 * c1)
1415 > !!$       endif
1416 > !!$      
1417 > !!$    elseif (summationMethod .eq. DAMPED_WOLF) then
1418 > !!$       if (ElectrostaticMap(atid1)%is_Charge) then
1419 > !!$          c1 = getCharge(atid1)
1420 > !!$          
1421 > !!$          mypot = mypot - (constERFC * rcuti * 0.5_dp + &
1422 > !!$               dampingAlpha*invRootPi) * c1 * c1      
1423 > !!$       endif
1424 >    endif
1425 >    
1426 >    return
1427 >  end subroutine self_self
1428 >
1429 >  subroutine rf_self_excludes(atom1, atom2, sw, eFrame, d, rij, vpair, myPot, &
1430 >       f, t, do_pot)
1431 >    logical, intent(in) :: do_pot
1432 >    integer, intent(in) :: atom1
1433 >    integer, intent(in) :: atom2
1434 >    logical :: i_is_Charge, j_is_Charge
1435 >    logical :: i_is_Dipole, j_is_Dipole
1436 >    integer :: atid1
1437 >    integer :: atid2
1438 >    real(kind=dp), intent(in) :: rij
1439 >    real(kind=dp), intent(in) :: sw
1440 >    real(kind=dp), intent(in), dimension(3) :: d
1441 >    real(kind=dp), intent(inout) :: vpair
1442 >    real(kind=dp), dimension(9,nLocal) :: eFrame
1443 >    real(kind=dp), dimension(3,nLocal) :: f
1444 >    real(kind=dp), dimension(3,nLocal) :: t
1445 >    real (kind = dp), dimension(3) :: duduz_i
1446 >    real (kind = dp), dimension(3) :: duduz_j
1447 >    real (kind = dp), dimension(3) :: uz_i
1448 >    real (kind = dp), dimension(3) :: uz_j
1449 >    real(kind=dp) :: q_i, q_j, mu_i, mu_j
1450 >    real(kind=dp) :: xhat, yhat, zhat
1451 >    real(kind=dp) :: ct_i, ct_j
1452 >    real(kind=dp) :: ri2, ri3, riji, vterm
1453 >    real(kind=dp) :: pref, preVal, rfVal, myPot
1454 >    real(kind=dp) :: dudx, dudy, dudz, dudr
1455 >
1456 >    if (.not.summationMethodChecked) then
1457 >       call checkSummationMethod()
1458 >    endif
1459 >
1460 >    dudx = 0.0d0
1461 >    dudy = 0.0d0
1462 >    dudz = 0.0d0
1463 >
1464 >    riji = 1.0d0/rij
1465 >
1466 >    xhat = d(1) * riji
1467 >    yhat = d(2) * riji
1468 >    zhat = d(3) * riji
1469 >
1470 >    ! this is a local only array, so we use the local atom type id's:
1471 >    atid1 = atid(atom1)
1472 >    atid2 = atid(atom2)
1473 >    i_is_Charge = ElectrostaticMap(atid1)%is_Charge
1474 >    j_is_Charge = ElectrostaticMap(atid2)%is_Charge
1475 >    i_is_Dipole = ElectrostaticMap(atid1)%is_Dipole
1476 >    j_is_Dipole = ElectrostaticMap(atid2)%is_Dipole
1477 >
1478 >    if (i_is_Charge.and.j_is_Charge) then
1479 >       q_i = ElectrostaticMap(atid1)%charge
1480 >       q_j = ElectrostaticMap(atid2)%charge
1481 >      
1482 >       preVal = pre11 * q_i * q_j
1483 >       rfVal = preRF*rij*rij
1484 >       vterm = preVal * rfVal
1485 >      
1486 >       myPot = myPot + sw*vterm
1487 >      
1488 >       dudr  = sw*preVal * 2.0d0*rfVal*riji
1489 >      
1490 >       dudx = dudx + dudr * xhat
1491 >       dudy = dudy + dudr * yhat
1492 >       dudz = dudz + dudr * zhat
1493 >      
1494 >    elseif (i_is_Charge.and.j_is_Dipole) then
1495 >       q_i = ElectrostaticMap(atid1)%charge
1496 >       mu_j = ElectrostaticMap(atid2)%dipole_moment
1497 >       uz_j(1) = eFrame(3,atom2)
1498 >       uz_j(2) = eFrame(6,atom2)
1499 >       uz_j(3) = eFrame(9,atom2)
1500 >       ct_j = uz_j(1)*xhat + uz_j(2)*yhat + uz_j(3)*zhat
1501 >      
1502 >       ri2 = riji * riji
1503 >       ri3 = ri2 * riji
1504 >      
1505 >       pref = pre12 * q_i * mu_j
1506 >       vterm = - pref * ct_j * ( ri2 - preRF2*rij )
1507 >       myPot = myPot + sw*vterm
1508 >      
1509 >       dudx = dudx - sw*pref*( ri3*(uz_j(1)-3.0d0*ct_j*xhat) &
1510 >            - preRF2*uz_j(1) )
1511 >       dudy = dudy - sw*pref*( ri3*(uz_j(2)-3.0d0*ct_j*yhat) &
1512 >            - preRF2*uz_j(2) )
1513 >       dudz = dudz - sw*pref*( ri3*(uz_j(3)-3.0d0*ct_j*zhat) &
1514 >            - preRF2*uz_j(3) )
1515 >      
1516 >       duduz_j(1) = duduz_j(1) - sw * pref * xhat * ( ri2 - preRF2*rij )
1517 >       duduz_j(2) = duduz_j(2) - sw * pref * yhat * ( ri2 - preRF2*rij )
1518 >       duduz_j(3) = duduz_j(3) - sw * pref * zhat * ( ri2 - preRF2*rij )
1519 >      
1520 >    elseif (i_is_Dipole.and.j_is_Charge) then
1521 >       mu_i = ElectrostaticMap(atid1)%dipole_moment
1522 >       q_j = ElectrostaticMap(atid2)%charge
1523 >       uz_i(1) = eFrame(3,atom1)
1524 >       uz_i(2) = eFrame(6,atom1)
1525 >       uz_i(3) = eFrame(9,atom1)
1526 >       ct_i = uz_i(1)*xhat + uz_i(2)*yhat + uz_i(3)*zhat
1527 >      
1528 >       ri2 = riji * riji
1529 >       ri3 = ri2 * riji
1530 >      
1531 >       pref = pre12 * q_j * mu_i
1532 >       vterm = pref * ct_i * ( ri2 - preRF2*rij )
1533 >       myPot = myPot + sw*vterm
1534 >      
1535 >       dudx = dudx + sw*pref*( ri3*(uz_i(1)-3.0d0*ct_i*xhat) &
1536 >            - preRF2*uz_i(1) )
1537 >       dudy = dudy + sw*pref*( ri3*(uz_i(2)-3.0d0*ct_i*yhat) &
1538 >            - preRF2*uz_i(2) )
1539 >       dudz = dudz + sw*pref*( ri3*(uz_i(3)-3.0d0*ct_i*zhat) &
1540 >            - preRF2*uz_i(3) )
1541 >      
1542 >       duduz_i(1) = duduz_i(1) + sw * pref * xhat * ( ri2 - preRF2*rij )
1543 >       duduz_i(2) = duduz_i(2) + sw * pref * yhat * ( ri2 - preRF2*rij )
1544 >       duduz_i(3) = duduz_i(3) + sw * pref * zhat * ( ri2 - preRF2*rij )
1545 >      
1546 >    endif
1547 >      
1548 >
1549 >    ! accumulate the forces and torques resulting from the self term
1550 >    f(1,atom1) = f(1,atom1) + dudx
1551 >    f(2,atom1) = f(2,atom1) + dudy
1552 >    f(3,atom1) = f(3,atom1) + dudz
1553 >    
1554 >    f(1,atom2) = f(1,atom2) - dudx
1555 >    f(2,atom2) = f(2,atom2) - dudy
1556 >    f(3,atom2) = f(3,atom2) - dudz
1557 >    
1558 >    if (i_is_Dipole) then
1559 >       t(1,atom1)=t(1,atom1) - uz_i(2)*duduz_i(3) + uz_i(3)*duduz_i(2)
1560 >       t(2,atom1)=t(2,atom1) - uz_i(3)*duduz_i(1) + uz_i(1)*duduz_i(3)
1561 >       t(3,atom1)=t(3,atom1) - uz_i(1)*duduz_i(2) + uz_i(2)*duduz_i(1)
1562 >    elseif (j_is_Dipole) then
1563 >       t(1,atom2)=t(1,atom2) - uz_j(2)*duduz_j(3) + uz_j(3)*duduz_j(2)
1564 >       t(2,atom2)=t(2,atom2) - uz_j(3)*duduz_j(1) + uz_j(1)*duduz_j(3)
1565 >       t(3,atom2)=t(3,atom2) - uz_j(1)*duduz_j(2) + uz_j(2)*duduz_j(1)
1566 >    endif
1567 >
1568 >    return
1569 >  end subroutine rf_self_excludes
1570 >
1571   end module electrostatic_module

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines