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 2153 by chrisfen, Fri Apr 8 14:43:06 2005 UTC vs.
Revision 2715 by chrisfen, Sun Apr 16 02:51:16 2006 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
47    use vector_class
48    use simulation
49    use status
50 +  use interpolation
51   #ifdef IS_MPI
52    use mpiSimulation
53   #endif
# Line 54 | Line 55 | module electrostatic_module
55  
56    PRIVATE
57  
58 +
59 + #define __FORTRAN90
60 + #include "UseTheForce/DarkSide/fInteractionMap.h"
61 + #include "UseTheForce/DarkSide/fElectrostaticSummationMethod.h"
62 + #include "UseTheForce/DarkSide/fElectrostaticScreeningMethod.h"
63 +
64 +
65    !! these prefactors convert the multipole interactions into kcal / mol
66    !! all were computed assuming distances are measured in angstroms
67    !! Charge-Charge, assuming charges are measured in electrons
# Line 68 | Line 76 | module electrostatic_module
76    !! This unit is also known affectionately as an esu centi-barn.
77    real(kind=dp), parameter :: pre14 = 69.13373_dp
78  
79 +  !! variables to handle different summation methods for long-range
80 +  !! electrostatics:
81 +  integer, save :: summationMethod = NONE
82 +  integer, save :: screeningMethod = UNDAMPED
83 +  logical, save :: summationMethodChecked = .false.
84 +  real(kind=DP), save :: defaultCutoff = 0.0_DP
85 +  real(kind=DP), save :: defaultCutoff2 = 0.0_DP
86 +  logical, save :: haveDefaultCutoff = .false.
87 +  real(kind=DP), save :: dampingAlpha = 0.0_DP
88 +  real(kind=DP), save :: alpha2 = 0.0_DP
89 +  logical, save :: haveDampingAlpha = .false.
90 +  real(kind=DP), save :: dielectric = 1.0_DP
91 +  logical, save :: haveDielectric = .false.
92 +  real(kind=DP), save :: constEXP = 0.0_DP
93 +  real(kind=dp), save :: rcuti = 0.0_DP
94 +  real(kind=dp), save :: rcuti2 = 0.0_DP
95 +  real(kind=dp), save :: rcuti3 = 0.0_DP
96 +  real(kind=dp), save :: rcuti4 = 0.0_DP
97 +  real(kind=dp), save :: alphaPi = 0.0_DP
98 +  real(kind=dp), save :: invRootPi = 0.0_DP
99 +  real(kind=dp), save :: rrf = 1.0_DP
100 +  real(kind=dp), save :: rt = 1.0_DP
101 +  real(kind=dp), save :: rrfsq = 1.0_DP
102 +  real(kind=dp), save :: preRF = 0.0_DP
103 +  real(kind=dp), save :: preRF2 = 0.0_DP
104 +  real(kind=dp), save :: f0 = 1.0_DP
105 +  real(kind=dp), save :: f1 = 1.0_DP
106 +  real(kind=dp), save :: f2 = 0.0_DP
107 +  real(kind=dp), save :: f3 = 0.0_DP
108 +  real(kind=dp), save :: f4 = 0.0_DP
109 +  real(kind=dp), save :: f0c = 1.0_DP
110 +  real(kind=dp), save :: f1c = 1.0_DP
111 +  real(kind=dp), save :: f2c = 0.0_DP
112 +  real(kind=dp), save :: f3c = 0.0_DP
113 +  real(kind=dp), save :: f4c = 0.0_DP
114 +
115 + #if defined(__IFC) || defined(__PGI)
116 + ! error function for ifc version > 7.
117 +  double precision, external :: derfc
118 + #endif
119 +  
120 +  public :: setElectrostaticSummationMethod
121 +  public :: setScreeningMethod
122 +  public :: setElectrostaticCutoffRadius
123 +  public :: setDampingAlpha
124 +  public :: setReactionFieldDielectric
125 +  public :: buildElectroSplines
126    public :: newElectrostaticType
127    public :: setCharge
128    public :: setDipoleMoment
# Line 76 | Line 131 | module electrostatic_module
131    public :: doElectrostaticPair
132    public :: getCharge
133    public :: getDipoleMoment
134 <  public :: pre22
134 >  public :: destroyElectrostaticTypes
135 >  public :: self_self
136 >  public :: rf_self_excludes
137  
138 +
139    type :: Electrostatic
140       integer :: c_ident
141       logical :: is_Charge = .false.
142       logical :: is_Dipole = .false.
143       logical :: is_SplitDipole = .false.
144       logical :: is_Quadrupole = .false.
145 +     logical :: is_Tap = .false.
146       real(kind=DP) :: charge = 0.0_DP
147       real(kind=DP) :: dipole_moment = 0.0_DP
148       real(kind=DP) :: split_dipole_distance = 0.0_DP
# Line 94 | Line 153 | contains
153  
154   contains
155  
156 +  subroutine setElectrostaticSummationMethod(the_ESM)
157 +    integer, intent(in) :: the_ESM    
158 +
159 +    if ((the_ESM .le. 0) .or. (the_ESM .gt. REACTION_FIELD)) then
160 +       call handleError("setElectrostaticSummationMethod", "Unsupported Summation Method")
161 +    endif
162 +
163 +    summationMethod = the_ESM
164 +
165 +  end subroutine setElectrostaticSummationMethod
166 +
167 +  subroutine setScreeningMethod(the_SM)
168 +    integer, intent(in) :: the_SM    
169 +    screeningMethod = the_SM
170 +  end subroutine setScreeningMethod
171 +
172 +  subroutine setElectrostaticCutoffRadius(thisRcut, thisRsw)
173 +    real(kind=dp), intent(in) :: thisRcut
174 +    real(kind=dp), intent(in) :: thisRsw
175 +    defaultCutoff = thisRcut
176 +    defaultCutoff2 = defaultCutoff*defaultCutoff
177 +    rrf = defaultCutoff
178 +    rt = thisRsw
179 +    haveDefaultCutoff = .true.
180 +  end subroutine setElectrostaticCutoffRadius
181 +
182 +  subroutine setDampingAlpha(thisAlpha)
183 +    real(kind=dp), intent(in) :: thisAlpha
184 +    dampingAlpha = thisAlpha
185 +    alpha2 = dampingAlpha*dampingAlpha
186 +    haveDampingAlpha = .true.
187 +  end subroutine setDampingAlpha
188 +  
189 +  subroutine setReactionFieldDielectric(thisDielectric)
190 +    real(kind=dp), intent(in) :: thisDielectric
191 +    dielectric = thisDielectric
192 +    haveDielectric = .true.
193 +  end subroutine setReactionFieldDielectric
194 +
195 +  subroutine buildElectroSplines()
196 +  end subroutine buildElectroSplines
197 +
198    subroutine newElectrostaticType(c_ident, is_Charge, is_Dipole, &
199 <       is_SplitDipole, is_Quadrupole, status)
200 <    
199 >       is_SplitDipole, is_Quadrupole, is_Tap, status)
200 >
201      integer, intent(in) :: c_ident
202      logical, intent(in) :: is_Charge
203      logical, intent(in) :: is_Dipole
204      logical, intent(in) :: is_SplitDipole
205      logical, intent(in) :: is_Quadrupole
206 +    logical, intent(in) :: is_Tap
207      integer, intent(out) :: status
208      integer :: nAtypes, myATID, i, j
209  
210      status = 0
211      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
212 <    
212 >
213      !! Be simple-minded and assume that we need an ElectrostaticMap that
214      !! is the same size as the total number of atom types
215  
216      if (.not.allocated(ElectrostaticMap)) then
217 <      
217 >
218         nAtypes = getSize(atypes)
219 <    
219 >
220         if (nAtypes == 0) then
221            status = -1
222            return
223         end if
224 <      
224 >
225         if (.not. allocated(ElectrostaticMap)) then
226            allocate(ElectrostaticMap(nAtypes))
227         endif
228 <      
228 >
229      end if
230  
231      if (myATID .gt. size(ElectrostaticMap)) then
232         status = -1
233         return
234      endif
235 <    
235 >
236      ! set the values for ElectrostaticMap for this atom type:
237  
238      ElectrostaticMap(myATID)%c_ident = c_ident
# Line 138 | Line 240 | contains
240      ElectrostaticMap(myATID)%is_Dipole = is_Dipole
241      ElectrostaticMap(myATID)%is_SplitDipole = is_SplitDipole
242      ElectrostaticMap(myATID)%is_Quadrupole = is_Quadrupole
243 <    
243 >    ElectrostaticMap(myATID)%is_Tap = is_Tap
244 >
245    end subroutine newElectrostaticType
246  
247    subroutine setCharge(c_ident, charge, status)
# Line 166 | Line 269 | contains
269         call handleError("electrostatic", "Attempt to setCharge of an atom type that is not a charge!")
270         status = -1
271         return
272 <    endif      
272 >    endif
273  
274      ElectrostaticMap(myATID)%charge = charge
275    end subroutine setCharge
# Line 257 | Line 360 | contains
360         status = -1
361         return
362      endif
363 <    
363 >
364      do i = 1, 3
365 <          ElectrostaticMap(myATID)%quadrupole_moments(i) = &
366 <               quadrupole_moments(i)
367 <       enddo
365 >       ElectrostaticMap(myATID)%quadrupole_moments(i) = &
366 >            quadrupole_moments(i)
367 >    enddo
368  
369    end subroutine setQuadrupoleMoments
370  
371 <  
371 >
372    function getCharge(atid) result (c)
373      integer, intent(in) :: atid
374      integer :: localError
375      real(kind=dp) :: c
376 <    
376 >
377      if (.not.allocated(ElectrostaticMap)) then
378         call handleError("electrostatic", "no ElectrostaticMap was present before first call of getCharge!")
379         return
380      end if
381 <    
381 >
382      if (.not.ElectrostaticMap(atid)%is_Charge) then
383         call handleError("electrostatic", "getCharge was called for an atom type that isn't a charge!")
384         return
385      endif
386 <    
386 >
387      c = ElectrostaticMap(atid)%charge
388    end function getCharge
389  
# Line 288 | Line 391 | contains
391      integer, intent(in) :: atid
392      integer :: localError
393      real(kind=dp) :: dm
394 <    
394 >
395      if (.not.allocated(ElectrostaticMap)) then
396         call handleError("electrostatic", "no ElectrostaticMap was present before first call of getDipoleMoment!")
397         return
398      end if
399 <    
399 >
400      if (.not.ElectrostaticMap(atid)%is_Dipole) then
401         call handleError("electrostatic", "getDipoleMoment was called for an atom type that isn't a dipole!")
402         return
403      endif
404 <    
404 >
405      dm = ElectrostaticMap(atid)%dipole_moment
406    end function getDipoleMoment
407  
408 <  subroutine doElectrostaticPair(atom1, atom2, d, rij, r2, sw, &
408 >  subroutine checkSummationMethod()
409 >
410 >    if (.not.haveDefaultCutoff) then
411 >       call handleError("checkSummationMethod", "no Default Cutoff set!")
412 >    endif
413 >
414 >    rcuti = 1.0d0 / defaultCutoff
415 >    rcuti2 = rcuti*rcuti
416 >    rcuti3 = rcuti2*rcuti
417 >    rcuti4 = rcuti2*rcuti2
418 >
419 >    if (screeningMethod .eq. DAMPED) then
420 >       if (.not.haveDampingAlpha) then
421 >          call handleError("checkSummationMethod", "no Damping Alpha set!")
422 >       endif
423 >      
424 >       if (.not.haveDefaultCutoff) then
425 >          call handleError("checkSummationMethod", "no Default Cutoff set!")
426 >       endif
427 >
428 >       constEXP = exp(-alpha2*defaultCutoff2)
429 >       invRootPi = 0.56418958354775628695d0
430 >       alphaPi = 2.0d0*dampingAlpha*invRootPi
431 >       f0c = derfc(dampingAlpha*defaultCutoff)
432 >       f1c = alphaPi*defaultCutoff*constEXP + f0c
433 >       f2c = alphaPi*2.0d0*alpha2*constEXP
434 >       f3c = alphaPi*2.0d0*alpha2*constEXP*defaultCutoff2*defaultCutoff
435 >    endif
436 >
437 >    if (summationMethod .eq. REACTION_FIELD) then
438 >       if (haveDielectric) then
439 >          defaultCutoff2 = defaultCutoff*defaultCutoff
440 >          preRF = (dielectric-1.0d0) / &
441 >               ((2.0d0*dielectric+1.0d0)*defaultCutoff2*defaultCutoff)
442 >          preRF2 = 2.0d0*preRF
443 >       else
444 >          call handleError("checkSummationMethod", "Dielectric not set")
445 >       endif
446 >      
447 >    endif
448 >
449 >    summationMethodChecked = .true.
450 >  end subroutine checkSummationMethod
451 >
452 >
453 >  subroutine doElectrostaticPair(atom1, atom2, d, rij, r2, rcut, sw, &
454         vpair, fpair, pot, eFrame, f, t, do_pot)
455 <    
455 >
456      logical, intent(in) :: do_pot
457 <    
457 >
458      integer, intent(in) :: atom1, atom2
459      integer :: localError
460  
461 <    real(kind=dp), intent(in) :: rij, r2, sw
461 >    real(kind=dp), intent(in) :: rij, r2, sw, rcut
462      real(kind=dp), intent(in), dimension(3) :: d
463      real(kind=dp), intent(inout) :: vpair
464 <    real(kind=dp), intent(inout), dimension(3) :: fpair
464 >    real(kind=dp), intent(inout), dimension(3) :: fpair    
465  
466      real( kind = dp ) :: pot
467      real( kind = dp ), dimension(9,nLocal) :: eFrame
468      real( kind = dp ), dimension(3,nLocal) :: f
469 +    real( kind = dp ), dimension(3,nLocal) :: felec
470      real( kind = dp ), dimension(3,nLocal) :: t
471 <    
471 >
472      real (kind = dp), dimension(3) :: ux_i, uy_i, uz_i
473      real (kind = dp), dimension(3) :: ux_j, uy_j, uz_j
474      real (kind = dp), dimension(3) :: dudux_i, duduy_i, duduz_i
# Line 327 | Line 476 | contains
476  
477      logical :: i_is_Charge, i_is_Dipole, i_is_SplitDipole, i_is_Quadrupole
478      logical :: j_is_Charge, j_is_Dipole, j_is_SplitDipole, j_is_Quadrupole
479 +    logical :: i_is_Tap, j_is_Tap
480      integer :: me1, me2, id1, id2
481      real (kind=dp) :: q_i, q_j, mu_i, mu_j, d_i, d_j
482      real (kind=dp) :: qxx_i, qyy_i, qzz_i
# Line 334 | Line 484 | contains
484      real (kind=dp) :: cx_i, cy_i, cz_i
485      real (kind=dp) :: cx_j, cy_j, cz_j
486      real (kind=dp) :: cx2, cy2, cz2
487 <    real (kind=dp) :: ct_i, ct_j, ct_ij, a1
487 >    real (kind=dp) :: ct_i, ct_j, ct_ij, a0, a1
488      real (kind=dp) :: riji, ri, ri2, ri3, ri4
489 <    real (kind=dp) :: pref, vterm, epot, dudr    
489 >    real (kind=dp) :: pref, vterm, epot, dudr, vterm1, vterm2
490      real (kind=dp) :: xhat, yhat, zhat
491      real (kind=dp) :: dudx, dudy, dudz
342    real (kind=dp) :: drdxj, drdyj, drdzj
492      real (kind=dp) :: scale, sc2, bigR
493 +    real (kind=dp) :: varEXP
494 +    real (kind=dp) :: pot_term
495 +    real (kind=dp) :: preVal, rfVal
496 +    real (kind=dp) :: f13, f134
497  
498      if (.not.allocated(ElectrostaticMap)) then
499         call handleError("electrostatic", "no ElectrostaticMap was present before first call of do_electrostatic_pair!")
500         return
501      end if
502  
503 +    if (.not.summationMethodChecked) then
504 +       call checkSummationMethod()
505 +    endif
506 +
507   #ifdef IS_MPI
508      me1 = atid_Row(atom1)
509      me2 = atid_Col(atom2)
# Line 358 | Line 515 | contains
515      !! some variables we'll need independent of electrostatic type:
516  
517      riji = 1.0d0 / rij
518 <
518 >  
519      xhat = d(1) * riji
520      yhat = d(2) * riji
521      zhat = d(3) * riji
522  
366    drdxj = xhat
367    drdyj = yhat
368    drdzj = zhat
369
523      !! logicals
371
524      i_is_Charge = ElectrostaticMap(me1)%is_Charge
525      i_is_Dipole = ElectrostaticMap(me1)%is_Dipole
526      i_is_SplitDipole = ElectrostaticMap(me1)%is_SplitDipole
527      i_is_Quadrupole = ElectrostaticMap(me1)%is_Quadrupole
528 +    i_is_Tap = ElectrostaticMap(me1)%is_Tap
529  
530      j_is_Charge = ElectrostaticMap(me2)%is_Charge
531      j_is_Dipole = ElectrostaticMap(me2)%is_Dipole
532      j_is_SplitDipole = ElectrostaticMap(me2)%is_SplitDipole
533      j_is_Quadrupole = ElectrostaticMap(me2)%is_Quadrupole
534 +    j_is_Tap = ElectrostaticMap(me2)%is_Tap
535  
536      if (i_is_Charge) then
537         q_i = ElectrostaticMap(me1)%charge      
538      endif
539 <    
539 >
540      if (i_is_Dipole) then
541         mu_i = ElectrostaticMap(me1)%dipole_moment
542   #ifdef IS_MPI
# Line 399 | Line 553 | contains
553         if (i_is_SplitDipole) then
554            d_i = ElectrostaticMap(me1)%split_dipole_distance
555         endif
556 <      
556 >
557      endif
558  
559      if (i_is_Quadrupole) then
# Line 432 | Line 586 | contains
586         cz_i = uz_i(1)*xhat + uz_i(2)*yhat + uz_i(3)*zhat
587      endif
588  
435
589      if (j_is_Charge) then
590         q_j = ElectrostaticMap(me2)%charge      
591      endif
592 <    
592 >
593      if (j_is_Dipole) then
594         mu_j = ElectrostaticMap(me2)%dipole_moment
595   #ifdef IS_MPI
# Line 448 | Line 601 | contains
601         uz_j(2) = eFrame(6,atom2)
602         uz_j(3) = eFrame(9,atom2)
603   #endif
604 <       ct_j = uz_j(1)*drdxj + uz_j(2)*drdyj + uz_j(3)*drdzj
604 >       ct_j = uz_j(1)*xhat + uz_j(2)*yhat + uz_j(3)*zhat
605  
606         if (j_is_SplitDipole) then
607            d_j = ElectrostaticMap(me2)%split_dipole_distance
# Line 484 | Line 637 | contains
637         cy_j = uy_j(1)*xhat + uy_j(2)*yhat + uy_j(3)*zhat
638         cz_j = uz_j(1)*xhat + uz_j(2)*yhat + uz_j(3)*zhat
639      endif
640 <
640 >  
641      epot = 0.0_dp
642      dudx = 0.0_dp
643      dudy = 0.0_dp
# Line 501 | Line 654 | contains
654      if (i_is_Charge) then
655  
656         if (j_is_Charge) then
657 <          
658 <          vterm = pre11 * q_i * q_j * riji
657 >          if (screeningMethod .eq. DAMPED) then
658 >             f0 = derfc(dampingAlpha*rij)
659 >             varEXP = exp(-alpha2*rij*rij)
660 >             f1 = alphaPi*rij*varEXP + f0
661 >          endif
662 >
663 >          preVal = pre11 * q_i * q_j
664 >
665 >          if (summationMethod .eq. SHIFTED_POTENTIAL) then
666 >             vterm = preVal * (riji*f0 - rcuti*f0c)
667 >            
668 >             dudr  = -sw * preVal * riji * riji * f1
669 >  
670 >          elseif (summationMethod .eq. SHIFTED_FORCE) then
671 >             vterm = preVal * ( riji*f0 - rcuti*f0c + &
672 >                  f1c*rcuti2*(rij-defaultCutoff) )
673 >            
674 >             dudr  = -sw*preVal * (riji*riji*f1 - rcuti2*f1c)
675 >  
676 >          elseif (summationMethod .eq. REACTION_FIELD) then
677 >             rfVal = preRF*rij*rij
678 >             vterm = preVal * ( riji + rfVal )
679 >            
680 >             dudr  = sw * preVal * ( 2.0d0*rfVal - riji )*riji
681 >  
682 >          else
683 >             vterm = preVal * riji*f0
684 >            
685 >             dudr  = - sw * preVal * riji*riji*f1
686 >  
687 >          endif
688 >
689            vpair = vpair + vterm
690            epot = epot + sw*vterm
691  
692 <          dudr  = - sw * vterm * riji
692 >          dudx = dudx + dudr * xhat
693 >          dudy = dudy + dudr * yhat
694 >          dudz = dudz + dudr * zhat
695  
511          dudx = dudx + dudr * drdxj
512          dudy = dudy + dudr * drdyj
513          dudz = dudz + dudr * drdzj
514      
696         endif
697  
698         if (j_is_Dipole) then
699 <
700 <          if (j_is_SplitDipole) then
701 <             BigR = sqrt(r2 + 0.25_dp * d_j * d_j)
702 <             ri = 1.0_dp / BigR
703 <             scale = rij * ri
523 <          else
524 <             ri = riji
525 <             scale = 1.0_dp
699 >          if (screeningMethod .eq. DAMPED) then
700 >             f0 = derfc(dampingAlpha*rij)
701 >             varEXP = exp(-alpha2*rij*rij)
702 >             f1 = alphaPi*rij*varEXP + f0
703 >             f3 = alphaPi*2.0d0*alpha2*varEXP*rij*rij*rij
704            endif
705  
528          ri2 = ri * ri
529          ri3 = ri2 * ri
530          sc2 = scale * scale
531            
706            pref = pre12 * q_i * mu_j
533          vterm = - pref * ct_j * ri2 * scale
534          vpair = vpair + vterm
535          epot = epot + sw * vterm
707  
708 <          !! this has a + sign in the () because the rij vector is
709 <          !! r_j - r_i and the charge-dipole potential takes the origin
710 <          !! as the point dipole, which is atom j in this case.
708 >          if (summationMethod .eq. REACTION_FIELD) then
709 >             ri2 = riji * riji
710 >             ri3 = ri2 * riji
711 >    
712 >             vterm = - pref * ct_j * ( ri2 - preRF2*rij )
713 >             vpair = vpair + vterm
714 >             epot = epot + sw*vterm
715 >            
716 >             !! this has a + sign in the () because the rij vector is
717 >             !! r_j - r_i and the charge-dipole potential takes the origin
718 >             !! as the point dipole, which is atom j in this case.
719 >            
720 >             dudx = dudx - sw*pref*( ri3*(uz_j(1) - 3.0d0*ct_j*xhat) - &
721 >                                     preRF2*uz_j(1) )
722 >             dudy = dudy - sw*pref*( ri3*(uz_j(2) - 3.0d0*ct_j*yhat) - &
723 >                                     preRF2*uz_j(2) )
724 >             dudz = dudz - sw*pref*( ri3*(uz_j(3) - 3.0d0*ct_j*zhat) - &
725 >                                     preRF2*uz_j(3) )        
726 >             duduz_j(1) = duduz_j(1) - sw*pref * xhat * ( ri2 - preRF2*rij )
727 >             duduz_j(2) = duduz_j(2) - sw*pref * yhat * ( ri2 - preRF2*rij )
728 >             duduz_j(3) = duduz_j(3) - sw*pref * zhat * ( ri2 - preRF2*rij )
729  
730 <          dudx = dudx - pref * sw * ri3 * ( uz_j(1) - 3.0d0*ct_j*xhat*sc2)
731 <          dudy = dudy - pref * sw * ri3 * ( uz_j(2) - 3.0d0*ct_j*yhat*sc2)
732 <          dudz = dudz - pref * sw * ri3 * ( uz_j(3) - 3.0d0*ct_j*zhat*sc2)
730 >          else
731 >             if (j_is_SplitDipole) then
732 >                BigR = sqrt(r2 + 0.25_dp * d_j * d_j)
733 >                ri = 1.0_dp / BigR
734 >                scale = rij * ri
735 >             else
736 >                ri = riji
737 >                scale = 1.0_dp
738 >             endif
739 >            
740 >             ri2 = ri * ri
741 >             ri3 = ri2 * ri
742 >             sc2 = scale * scale
743  
744 <          duduz_j(1) = duduz_j(1) - pref * sw * ri2 * xhat * scale
745 <          duduz_j(2) = duduz_j(2) - pref * sw * ri2 * yhat * scale
746 <          duduz_j(3) = duduz_j(3) - pref * sw * ri2 * zhat * scale
747 <          
744 >             pot_term =  ri2 * scale * f1
745 >             vterm = - pref * ct_j * pot_term
746 >             vpair = vpair + vterm
747 >             epot = epot + sw*vterm
748 >            
749 >             !! this has a + sign in the () because the rij vector is
750 >             !! r_j - r_i and the charge-dipole potential takes the origin
751 >             !! as the point dipole, which is atom j in this case.
752 >            
753 >             dudx = dudx - sw*pref * ri3 * ( uz_j(1)*f1 - &
754 >                  ct_j*xhat*sc2*( 3.0d0*f1 + f3 ) )
755 >             dudy = dudy - sw*pref * ri3 * ( uz_j(2)*f1 - &
756 >                  ct_j*yhat*sc2*( 3.0d0*f1 + f3 ) )
757 >             dudz = dudz - sw*pref * ri3 * ( uz_j(3)*f1 - &
758 >                  ct_j*zhat*sc2*( 3.0d0*f1 + f3 ) )
759 >                          
760 >             duduz_j(1) = duduz_j(1) - sw*pref * pot_term * xhat
761 >             duduz_j(2) = duduz_j(2) - sw*pref * pot_term * yhat
762 >             duduz_j(3) = duduz_j(3) - sw*pref * pot_term * zhat
763 >
764 >          endif
765         endif
766  
767         if (j_is_Quadrupole) then
768 +          if (screeningMethod .eq. DAMPED) then
769 +             f0 = derfc(dampingAlpha*rij)
770 +             varEXP = exp(-alpha2*rij*rij)
771 +             f1 = alphaPi*rij*varEXP + f0
772 +             f2 = alphaPi*2.0d0*alpha2*varEXP
773 +             f3 = f2*rij*rij*rij
774 +             f4 = 2.0d0*alpha2*f2*rij
775 +          endif
776 +
777            ri2 = riji * riji
778            ri3 = ri2 * riji
779            ri4 = ri2 * ri2
# Line 556 | Line 781 | contains
781            cy2 = cy_j * cy_j
782            cz2 = cz_j * cz_j
783  
784 <
785 <          pref =  pre14 * q_i / 1.0_dp
561 <          vterm = pref * ri3 * (qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
784 >          pref =  pre14 * q_i / 3.0_dp
785 >          pot_term = ri3*(qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
786                 qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
787                 qzz_j * (3.0_dp*cz2 - 1.0_dp))
788 +          vterm = pref * (pot_term*f1 + (qxx_j*cx2 + qyy_j*cy2 + qzz_j*cz2)*f2)
789            vpair = vpair + vterm
790 <          epot = epot + sw * vterm
566 <
567 <          dudx = dudx - 5.0_dp*sw*vterm*riji*xhat - pref * sw * ri4 * ( &
568 <               qxx_j*(6.0_dp*cx_j*ux_j(1) - 2.0_dp*xhat) + &
569 <               qyy_j*(6.0_dp*cy_j*uy_j(1) - 2.0_dp*xhat) + &
570 <               qzz_j*(6.0_dp*cz_j*uz_j(1) - 2.0_dp*xhat) )
571 <          dudy = dudy - 5.0_dp*sw*vterm*riji*yhat - pref * sw * ri4 * ( &
572 <               qxx_j*(6.0_dp*cx_j*ux_j(2) - 2.0_dp*yhat) + &
573 <               qyy_j*(6.0_dp*cy_j*uy_j(2) - 2.0_dp*yhat) + &
574 <               qzz_j*(6.0_dp*cz_j*uz_j(2) - 2.0_dp*yhat) )
575 <          dudz = dudz - 5.0_dp*sw*vterm*riji*zhat - pref * sw * ri4 * ( &
576 <               qxx_j*(6.0_dp*cx_j*ux_j(3) - 2.0_dp*zhat) + &
577 <               qyy_j*(6.0_dp*cy_j*uy_j(3) - 2.0_dp*zhat) + &
578 <               qzz_j*(6.0_dp*cz_j*uz_j(3) - 2.0_dp*zhat) )
790 >          epot = epot + sw*vterm
791            
792 <          dudux_j(1) = dudux_j(1) + pref * sw * ri3 * (qxx_j*6.0_dp*cx_j*xhat)
793 <          dudux_j(2) = dudux_j(2) + pref * sw * ri3 * (qxx_j*6.0_dp*cx_j*yhat)
794 <          dudux_j(3) = dudux_j(3) + pref * sw * ri3 * (qxx_j*6.0_dp*cx_j*zhat)
795 <
796 <          duduy_j(1) = duduy_j(1) + pref * sw * ri3 * (qyy_j*6.0_dp*cy_j*xhat)
797 <          duduy_j(2) = duduy_j(2) + pref * sw * ri3 * (qyy_j*6.0_dp*cy_j*yhat)
798 <          duduy_j(3) = duduy_j(3) + pref * sw * ri3 * (qyy_j*6.0_dp*cy_j*zhat)
799 <
800 <          duduz_j(1) = duduz_j(1) + pref * sw * ri3 * (qzz_j*6.0_dp*cz_j*xhat)
801 <          duduz_j(2) = duduz_j(2) + pref * sw * ri3 * (qzz_j*6.0_dp*cz_j*yhat)
802 <          duduz_j(3) = duduz_j(3) + pref * sw * ri3 * (qzz_j*6.0_dp*cz_j*zhat)
792 >          dudx = dudx - sw*pref*pot_term*riji*xhat*(5.0d0*f1 + f3) + &
793 >               sw*pref*ri4 * ( &
794 >               qxx_j*(2.0_dp*cx_j*ux_j(1)*(3.0d0*f1 + f3) - 2.0_dp*xhat*f1) + &
795 >               qyy_j*(2.0_dp*cy_j*uy_j(1)*(3.0d0*f1 + f3) - 2.0_dp*xhat*f1) + &
796 >               qzz_j*(2.0_dp*cz_j*uz_j(1)*(3.0d0*f1 + f3) - 2.0_dp*xhat*f1) ) &
797 >               + (qxx_j*cx2 + qyy_j*cy2 + qzz_j*cz2)*f4
798 >          dudy = dudy - sw*pref*pot_term*riji*yhat*(5.0d0*f1 + f3) + &
799 >               sw*pref*ri4 * ( &
800 >               qxx_j*(2.0_dp*cx_j*ux_j(2)*(3.0d0*f1 + f3) - 2.0_dp*yhat*f1) + &
801 >               qyy_j*(2.0_dp*cy_j*uy_j(2)*(3.0d0*f1 + f3) - 2.0_dp*yhat*f1) + &
802 >               qzz_j*(2.0_dp*cz_j*uz_j(2)*(3.0d0*f1 + f3) - 2.0_dp*yhat*f1) ) &
803 >               + (qxx_j*cx2 + qyy_j*cy2 + qzz_j*cz2)*f4
804 >          dudz = dudz - sw*pref*pot_term*riji*zhat*(5.0d0*f1 + f3) + &
805 >               sw*pref*ri4 * ( &
806 >               qxx_j*(2.0_dp*cx_j*ux_j(3)*(3.0d0*f1 + f3) - 2.0_dp*zhat*f1) + &
807 >               qyy_j*(2.0_dp*cy_j*uy_j(3)*(3.0d0*f1 + f3) - 2.0_dp*zhat*f1) + &
808 >               qzz_j*(2.0_dp*cz_j*uz_j(3)*(3.0d0*f1 + f3) - 2.0_dp*zhat*f1) ) &
809 >               + (qxx_j*cx2 + qyy_j*cy2 + qzz_j*cz2)*f4
810 >          
811 >          dudux_j(1) = dudux_j(1) + sw*pref*ri3*( (qxx_j*2.0_dp*cx_j*xhat) &
812 >               * (3.0d0*f1 + f3) )
813 >          dudux_j(2) = dudux_j(2) + sw*pref*ri3*( (qxx_j*2.0_dp*cx_j*yhat) &
814 >               * (3.0d0*f1 + f3) )
815 >          dudux_j(3) = dudux_j(3) + sw*pref*ri3*( (qxx_j*2.0_dp*cx_j*zhat) &
816 >               * (3.0d0*f1 + f3) )
817 >          
818 >          duduy_j(1) = duduy_j(1) + sw*pref*ri3*( (qyy_j*2.0_dp*cy_j*xhat) &
819 >               * (3.0d0*f1 + f3) )
820 >          duduy_j(2) = duduy_j(2) + sw*pref*ri3*( (qyy_j*2.0_dp*cy_j*yhat) &
821 >               * (3.0d0*f1 + f3) )
822 >          duduy_j(3) = duduy_j(3) + sw*pref*ri3*( (qyy_j*2.0_dp*cy_j*zhat) &
823 >               * (3.0d0*f1 + f3) )
824 >          
825 >          duduz_j(1) = duduz_j(1) + sw*pref*ri3*( (qzz_j*2.0_dp*cz_j*xhat) &
826 >               * (3.0d0*f1 + f3) )
827 >          duduz_j(2) = duduz_j(2) + sw*pref*ri3*( (qzz_j*2.0_dp*cz_j*yhat) &
828 >               * (3.0d0*f1 + f3) )
829 >          duduz_j(3) = duduz_j(3) + sw*pref*ri3*( (qzz_j*2.0_dp*cz_j*zhat) &
830 >               * (3.0d0*f1 + f3) )
831 >          
832         endif
592
833      endif
834 <  
834 >    
835      if (i_is_Dipole) then
596      
597       if (j_is_Charge) then
836  
837 <          if (i_is_SplitDipole) then
838 <             BigR = sqrt(r2 + 0.25_dp * d_i * d_i)
839 <             ri = 1.0_dp / BigR
840 <             scale = rij * ri
841 <          else
842 <             ri = riji
605 <             scale = 1.0_dp
837 >       if (j_is_Charge) then
838 >          if (screeningMethod .eq. DAMPED) then
839 >             f0 = derfc(dampingAlpha*rij)
840 >             varEXP = exp(-alpha2*rij*rij)
841 >             f1 = alphaPi*rij*varEXP + f0
842 >             f3 = alphaPi*2.0d0*alpha2*varEXP*rij*rij*rij
843            endif
844 <
608 <          ri2 = ri * ri
609 <          ri3 = ri2 * ri
610 <          sc2 = scale * scale
611 <            
844 >          
845            pref = pre12 * q_j * mu_i
846 <          vterm = pref * ct_i * ri2 * scale
847 <          vpair = vpair + vterm
848 <          epot = epot + sw * vterm
846 >          
847 >          if (summationMethod .eq. SHIFTED_POTENTIAL) then
848 >             ri2 = riji * riji
849 >             ri3 = ri2 * riji
850 >            
851 >             pot_term = ri2*f1 - rcuti2*f1c
852 >             vterm = pref * ct_i * pot_term
853 >             vpair = vpair + vterm
854 >             epot = epot + sw*vterm
855 >            
856 >             dudx = dudx + sw*pref*( ri3*(uz_i(1)*f1-ct_i*xhat*(3.0d0*f1+f3)) )
857 >             dudy = dudy + sw*pref*( ri3*(uz_i(2)*f1-ct_i*yhat*(3.0d0*f1+f3)) )
858 >             dudz = dudz + sw*pref*( ri3*(uz_i(3)*f1-ct_i*zhat*(3.0d0*f1+f3)) )
859 >            
860 >             duduz_i(1) = duduz_i(1) + sw*pref * xhat * pot_term
861 >             duduz_i(2) = duduz_i(2) + sw*pref * yhat * pot_term
862 >             duduz_i(3) = duduz_i(3) + sw*pref * zhat * pot_term
863  
864 <          dudx = dudx + pref * sw * ri3 * ( uz_i(1) - 3.0d0 * ct_i * xhat*sc2)
865 <          dudy = dudy + pref * sw * ri3 * ( uz_i(2) - 3.0d0 * ct_i * yhat*sc2)
866 <          dudz = dudz + pref * sw * ri3 * ( uz_i(3) - 3.0d0 * ct_i * zhat*sc2)
864 >          elseif (summationMethod .eq. SHIFTED_FORCE) then
865 >             ri2 = riji * riji
866 >             ri3 = ri2 * riji
867  
868 <          duduz_i(1) = duduz_i(1) + pref * sw * ri2 * xhat * scale
869 <          duduz_i(2) = duduz_i(2) + pref * sw * ri2 * yhat * scale
870 <          duduz_i(3) = duduz_i(3) + pref * sw * ri2 * zhat * scale
871 <       endif
872 <
873 <       if (j_is_Dipole) then
868 >             !! might need a -(f1c-f0c) or dct_i/dr in the derivative term...
869 >             pot_term = ri2*f1 - rcuti2*f1c + &
870 >                  (2.0d0*rcuti3*f1c + f2c)*( rij - defaultCutoff )
871 >             vterm = pref * ct_i * pot_term
872 >             vpair = vpair + vterm
873 >             epot = epot + sw*vterm
874 >            
875 >             dudx = dudx + sw*pref*( ri3*(uz_i(1)*f1-ct_i*xhat*(3.0d0*f1+f3)) &
876 >                  - rcuti3*(uz_i(1)*f1c-ct_i*xhat*(3.0d0*f1c+f3c)) )
877 >             dudy = dudy + sw*pref*( ri3*(uz_i(2)*f1-ct_i*yhat*(3.0d0*f1+f3)) &
878 >                  - rcuti3*(uz_i(1)*f1c-ct_i*xhat*(3.0d0*f1c+f3c)) )
879 >             dudz = dudz + sw*pref*( ri3*(uz_i(3)*f1-ct_i*zhat*(3.0d0*f1+f3)) &
880 >                  - rcuti3*(uz_i(1)*f1c-ct_i*xhat*(3.0d0*f1c+f3c)) )
881 >            
882 >             duduz_i(1) = duduz_i(1) + sw*pref * xhat * pot_term
883 >             duduz_i(2) = duduz_i(2) + sw*pref * yhat * pot_term
884 >             duduz_i(3) = duduz_i(3) + sw*pref * zhat * pot_term
885 >
886 >          elseif (summationMethod .eq. REACTION_FIELD) then
887 >             ri2 = riji * riji
888 >             ri3 = ri2 * riji
889  
890 <          if (i_is_SplitDipole) then
891 <             if (j_is_SplitDipole) then
892 <                BigR = sqrt(r2 + 0.25_dp * d_i * d_i + 0.25_dp * d_j * d_j)
893 <             else
894 <                BigR = sqrt(r2 + 0.25_dp * d_i * d_i)
895 <             endif
896 <             ri = 1.0_dp / BigR
897 <             scale = rij * ri                
890 >             vterm = pref * ct_i * ( ri2 - preRF2*rij )
891 >             vpair = vpair + vterm
892 >             epot = epot + sw*vterm
893 >            
894 >             dudx = dudx + sw*pref * ( ri3*(uz_i(1) - 3.0d0*ct_i*xhat) - &
895 >                  preRF2*uz_i(1) )
896 >             dudy = dudy + sw*pref * ( ri3*(uz_i(2) - 3.0d0*ct_i*yhat) - &
897 >                  preRF2*uz_i(2) )
898 >             dudz = dudz + sw*pref * ( ri3*(uz_i(3) - 3.0d0*ct_i*zhat) - &
899 >                  preRF2*uz_i(3) )
900 >            
901 >             duduz_i(1) = duduz_i(1) + sw*pref * xhat * ( ri2 - preRF2*rij )
902 >             duduz_i(2) = duduz_i(2) + sw*pref * yhat * ( ri2 - preRF2*rij )
903 >             duduz_i(3) = duduz_i(3) + sw*pref * zhat * ( ri2 - preRF2*rij )
904 >
905            else
906 <             if (j_is_SplitDipole) then
907 <                BigR = sqrt(r2 + 0.25_dp * d_j * d_j)
906 >             if (i_is_SplitDipole) then
907 >                BigR = sqrt(r2 + 0.25_dp * d_i * d_i)
908                  ri = 1.0_dp / BigR
909 <                scale = rij * ri                            
910 <             else                
909 >                scale = rij * ri
910 >             else
911                  ri = riji
912                  scale = 1.0_dp
913               endif
914 +            
915 +             ri2 = ri * ri
916 +             ri3 = ri2 * ri
917 +             sc2 = scale * scale
918 +
919 +             pot_term = ri2 * f1 * scale
920 +             vterm = pref * ct_i * pot_term
921 +             vpair = vpair + vterm
922 +             epot = epot + sw*vterm
923 +            
924 +             dudx = dudx + sw*pref * ri3 * ( uz_i(1)*f1 - &
925 +                  ct_i*xhat*sc2*( 3.0d0*f1 + f3 ) )
926 +             dudy = dudy + sw*pref * ri3 * ( uz_i(2)*f1 - &
927 +                  ct_i*yhat*sc2*( 3.0d0*f1 + f3 ) )
928 +             dudz = dudz + sw*pref * ri3 * ( uz_i(3)*f1 - &
929 +                  ct_i*zhat*sc2*( 3.0d0*f1 + f3 ) )
930 +            
931 +             duduz_i(1) = duduz_i(1) + sw*pref * pot_term * xhat
932 +             duduz_i(2) = duduz_i(2) + sw*pref * pot_term * yhat
933 +             duduz_i(3) = duduz_i(3) + sw*pref * pot_term * zhat
934            endif
935 +       endif
936 +      
937 +       if (j_is_Dipole) then
938 +          if (screeningMethod .eq. DAMPED) then
939 +             f0 = derfc(dampingAlpha*rij)
940 +             varEXP = exp(-alpha2*rij*rij)
941 +             f1 = alphaPi*rij*varEXP + f0
942 +             f2 = alphaPi*2.0d0*alpha2*varEXP
943 +             f3 = f2*rij*rij*rij
944 +             f4 = 2.0d0*alpha2*f3*rij*rij
945 +          endif
946  
947            ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
948 <
949 <          ri2 = ri * ri
950 <          ri3 = ri2 * ri
948 >          
949 >          ri2 = riji * riji
950 >          ri3 = ri2 * riji
951            ri4 = ri2 * ri2
652          sc2 = scale * scale
653
654          pref = pre22 * mu_i * mu_j
655          vterm = pref * ri3 * (ct_ij - 3.0d0 * ct_i * ct_j * sc2)
656          vpair = vpair + vterm
657          epot = epot + sw * vterm
952            
953 <          a1 = 5.0d0 * ct_i * ct_j * sc2 - ct_ij
953 >          pref = pre22 * mu_i * mu_j
954  
955 <          dudx=dudx+pref*sw*3.0d0*ri4*scale*(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
956 <          dudy=dudy+pref*sw*3.0d0*ri4*scale*(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
957 <          dudz=dudz+pref*sw*3.0d0*ri4*scale*(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
955 >          if (summationMethod .eq. REACTION_FIELD) then
956 >             vterm = pref*( ri3*(ct_ij - 3.0d0 * ct_i * ct_j) - &
957 >                  preRF2*ct_ij )
958 >             vpair = vpair + vterm
959 >             epot = epot + sw*vterm
960 >            
961 >             a1 = 5.0d0 * ct_i * ct_j - ct_ij
962 >            
963 >             dudx = dudx + sw*pref*3.0d0*ri4 &
964 >                             * (a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
965 >             dudy = dudy + sw*pref*3.0d0*ri4 &
966 >                             * (a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
967 >             dudz = dudz + sw*pref*3.0d0*ri4 &
968 >                             * (a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
969 >            
970 >             duduz_i(1) = duduz_i(1) + sw*pref*(ri3*(uz_j(1)-3.0d0*ct_j*xhat) &
971 >                  - preRF2*uz_j(1))
972 >             duduz_i(2) = duduz_i(2) + sw*pref*(ri3*(uz_j(2)-3.0d0*ct_j*yhat) &
973 >                  - preRF2*uz_j(2))
974 >             duduz_i(3) = duduz_i(3) + sw*pref*(ri3*(uz_j(3)-3.0d0*ct_j*zhat) &
975 >                  - preRF2*uz_j(3))
976 >             duduz_j(1) = duduz_j(1) + sw*pref*(ri3*(uz_i(1)-3.0d0*ct_i*xhat) &
977 >                  - preRF2*uz_i(1))
978 >             duduz_j(2) = duduz_j(2) + sw*pref*(ri3*(uz_i(2)-3.0d0*ct_i*yhat) &
979 >                  - preRF2*uz_i(2))
980 >             duduz_j(3) = duduz_j(3) + sw*pref*(ri3*(uz_i(3)-3.0d0*ct_i*zhat) &
981 >                  - preRF2*uz_i(3))
982  
983 <          duduz_i(1) = duduz_i(1) + pref*sw*ri3*(uz_j(1) - 3.0d0*ct_j*xhat*sc2)
984 <          duduz_i(2) = duduz_i(2) + pref*sw*ri3*(uz_j(2) - 3.0d0*ct_j*yhat*sc2)
985 <          duduz_i(3) = duduz_i(3) + pref*sw*ri3*(uz_j(3) - 3.0d0*ct_j*zhat*sc2)
983 >          else
984 >             if (i_is_SplitDipole) then
985 >                if (j_is_SplitDipole) then
986 >                   BigR = sqrt(r2 + 0.25_dp * d_i * d_i + 0.25_dp * d_j * d_j)
987 >                else
988 >                   BigR = sqrt(r2 + 0.25_dp * d_i * d_i)
989 >                endif
990 >                ri = 1.0_dp / BigR
991 >                scale = rij * ri                
992 >             else
993 >                if (j_is_SplitDipole) then
994 >                   BigR = sqrt(r2 + 0.25_dp * d_j * d_j)
995 >                   ri = 1.0_dp / BigR
996 >                   scale = rij * ri                            
997 >                else                
998 >                   ri = riji
999 >                   scale = 1.0_dp
1000 >                endif
1001 >             endif
1002 >            
1003 >             sc2 = scale * scale
1004  
1005 <          duduz_j(1) = duduz_j(1) + pref*sw*ri3*(uz_i(1) - 3.0d0*ct_i*xhat*sc2)
1006 <          duduz_j(2) = duduz_j(2) + pref*sw*ri3*(uz_i(2) - 3.0d0*ct_i*yhat*sc2)
1007 <          duduz_j(3) = duduz_j(3) + pref*sw*ri3*(uz_i(3) - 3.0d0*ct_i*zhat*sc2)
1008 <       endif
1005 >             pot_term = (ct_ij - 3.0d0 * ct_i * ct_j * sc2)
1006 >             vterm = pref * ( ri3*pot_term*f1 + (ct_i * ct_j)*f2 )
1007 >             vpair = vpair + vterm
1008 >             epot = epot + sw*vterm
1009 >            
1010 >             f13 = f1+f3
1011 >             f134 = f13 + f4
1012 >            
1013 > !!$             dudx = dudx + sw*pref * ( ri4*scale*( &
1014 > !!$                  3.0d0*(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))*f1 &
1015 > !!$                  - pot_term*f3) &
1016 > !!$                  + 2.0d0*ct_i*ct_j*xhat*(ct_i*uz_j(1)+ct_j*uz_i(1))*f3 &
1017 > !!$                  + (ct_i * ct_j)*f4 )
1018 > !!$             dudy = dudy + sw*pref * ( ri4*scale*( &
1019 > !!$                  3.0d0*(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))*f1 &
1020 > !!$                  - pot_term*f3) &
1021 > !!$                  + 2.0d0*ct_i*ct_j*yhat*(ct_i*uz_j(2)+ct_j*uz_i(2))*f3 &
1022 > !!$                  + (ct_i * ct_j)*f4 )
1023 > !!$             dudz = dudz + sw*pref * ( ri4*scale*( &
1024 > !!$                  3.0d0*(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))*f1 &
1025 > !!$                  - pot_term*f3) &
1026 > !!$                  + 2.0d0*ct_i*ct_j*zhat*(ct_i*uz_j(3)+ct_j*uz_i(3))*f3 &
1027 > !!$                  + (ct_i * ct_j)*f4 )
1028  
1029 +             dudx = dudx + sw*pref * ( ri4*scale*( &
1030 +                  15.0d0*(ct_i * ct_j * sc2)*xhat*f134 - &
1031 +                  3.0d0*(ct_i*uz_j(1) + ct_j*uz_i(1) + ct_ij*xhat)*f134) )
1032 +             dudy = dudy + sw*pref * ( ri4*scale*( &
1033 +                  15.0d0*(ct_i * ct_j * sc2)*yhat*f134 - &
1034 +                  3.0d0*(ct_i*uz_j(2) + ct_j*uz_i(2) + ct_ij*yhat)*f134) )
1035 +             dudz = dudz + sw*pref * ( ri4*scale*( &
1036 +                  15.0d0*(ct_i * ct_j * sc2)*zhat*f134 - &
1037 +                  3.0d0*(ct_i*uz_j(3) + ct_j*uz_i(3) + ct_ij*zhat)*f134) )
1038 +            
1039 +             duduz_i(1) = duduz_i(1) + sw*pref * &
1040 +                  ( ri3*(uz_j(1) - 3.0d0*ct_j*xhat*sc2)*f1 + (ct_j*xhat)*f2 )
1041 +             duduz_i(2) = duduz_i(2) + sw*pref * &
1042 +                  ( ri3*(uz_j(2) - 3.0d0*ct_j*yhat*sc2)*f1 + (ct_j*yhat)*f2 )
1043 +             duduz_i(3) = duduz_i(3) + sw*pref * &
1044 +                  ( ri3*(uz_j(3) - 3.0d0*ct_j*zhat*sc2)*f1 + (ct_j*zhat)*f2 )
1045 +            
1046 +             duduz_j(1) = duduz_j(1) + sw*pref * &
1047 +                  ( ri3*(uz_i(1) - 3.0d0*ct_i*xhat*sc2)*f1 + (ct_i*xhat)*f2 )
1048 +             duduz_j(2) = duduz_j(2) + sw*pref * &
1049 +                  ( ri3*(uz_i(2) - 3.0d0*ct_i*yhat*sc2)*f1 + (ct_i*yhat)*f2 )
1050 +             duduz_j(3) = duduz_j(3) + sw*pref * &
1051 +                  ( ri3*(uz_i(3) - 3.0d0*ct_i*zhat*sc2)*f1 + (ct_i*zhat)*f2 )
1052 +          endif
1053 +       endif
1054      endif
1055  
1056      if (i_is_Quadrupole) then
1057         if (j_is_Charge) then
1058 <          
1058 >          if (screeningMethod .eq. DAMPED) then
1059 >             f0 = derfc(dampingAlpha*rij)
1060 >             varEXP = exp(-alpha2*rij*rij)
1061 >             f1 = alphaPi*rij*varEXP + f0
1062 >             f2 = alphaPi*2.0d0*alpha2*varEXP
1063 >             f3 = f2*rij*rij*rij
1064 >             f4 = 2.0d0*alpha2*f2*rij
1065 >          endif
1066 >
1067            ri2 = riji * riji
1068            ri3 = ri2 * riji
1069            ri4 = ri2 * ri2
1070            cx2 = cx_i * cx_i
1071            cy2 = cy_i * cy_i
1072            cz2 = cz_i * cz_i
1073 <          
1074 <          pref = pre14 * q_j / 1.0_dp
1075 <          vterm = pref * ri3 * (qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1076 <               qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1077 <               qzz_i * (3.0_dp*cz2 - 1.0_dp))
1073 >
1074 >          pref = pre14 * q_j / 3.0_dp
1075 >          pot_term = ri3 * (qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1076 >                            qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1077 >                            qzz_i * (3.0_dp*cz2 - 1.0_dp))
1078 >          vterm = pref * (pot_term*f1 + (qxx_i*cx2 + qyy_i*cy2 + qzz_i*cz2)*f2)
1079            vpair = vpair + vterm
1080 <          epot = epot + sw * vterm
1080 >          epot = epot + sw*vterm
1081            
1082 <          dudx = dudx - 5.0_dp*sw*vterm*riji*xhat - pref * sw * ri4 * ( &
1083 <               qxx_i*(6.0_dp*cx_i*ux_i(1) - 2.0_dp*xhat) + &
1084 <               qyy_i*(6.0_dp*cy_i*uy_i(1) - 2.0_dp*xhat) + &
1085 <               qzz_i*(6.0_dp*cz_i*uz_i(1) - 2.0_dp*xhat) )
1086 <          dudy = dudy - 5.0_dp*sw*vterm*riji*yhat - pref * sw * ri4 * ( &
1087 <               qxx_i*(6.0_dp*cx_i*ux_i(2) - 2.0_dp*yhat) + &
1088 <               qyy_i*(6.0_dp*cy_i*uy_i(2) - 2.0_dp*yhat) + &
1089 <               qzz_i*(6.0_dp*cz_i*uz_i(2) - 2.0_dp*yhat) )
1090 <          dudz = dudz - 5.0_dp*sw*vterm*riji*zhat - pref * sw * ri4 * ( &
1091 <               qxx_i*(6.0_dp*cx_i*ux_i(3) - 2.0_dp*zhat) + &
1092 <               qyy_i*(6.0_dp*cy_i*uy_i(3) - 2.0_dp*zhat) + &
1093 <               qzz_i*(6.0_dp*cz_i*uz_i(3) - 2.0_dp*zhat) )
1082 >          dudx = dudx - sw*pref*pot_term*riji*xhat*(5.0d0*f1 + f3) + &
1083 >               sw*pref*ri4 * ( &
1084 >               qxx_i*(2.0_dp*cx_i*ux_i(1)*(3.0d0*f1 + f3) - 2.0_dp*xhat*f1) + &
1085 >               qyy_i*(2.0_dp*cy_i*uy_i(1)*(3.0d0*f1 + f3) - 2.0_dp*xhat*f1) + &
1086 >               qzz_i*(2.0_dp*cz_i*uz_i(1)*(3.0d0*f1 + f3) - 2.0_dp*xhat*f1) ) &
1087 >               + (qxx_i*cx2 + qyy_i*cy2 + qzz_i*cz2)*f4
1088 >          dudy = dudy - sw*pref*pot_term*riji*yhat*(5.0d0*f1 + f3) + &
1089 >               sw*pref*ri4 * ( &
1090 >               qxx_i*(2.0_dp*cx_i*ux_i(2)*(3.0d0*f1 + f3) - 2.0_dp*yhat*f1) + &
1091 >               qyy_i*(2.0_dp*cy_i*uy_i(2)*(3.0d0*f1 + f3) - 2.0_dp*yhat*f1) + &
1092 >               qzz_i*(2.0_dp*cz_i*uz_i(2)*(3.0d0*f1 + f3) - 2.0_dp*yhat*f1) ) &
1093 >               + (qxx_i*cx2 + qyy_i*cy2 + qzz_i*cz2)*f4
1094 >          dudz = dudz - sw*pref*pot_term*riji*zhat*(5.0d0*f1 + f3) + &
1095 >               sw*pref*ri4 * ( &
1096 >               qxx_i*(2.0_dp*cx_i*ux_i(3)*(3.0d0*f1 + f3) - 2.0_dp*zhat*f1) + &
1097 >               qyy_i*(2.0_dp*cy_i*uy_i(3)*(3.0d0*f1 + f3) - 2.0_dp*zhat*f1) + &
1098 >               qzz_i*(2.0_dp*cz_i*uz_i(3)*(3.0d0*f1 + f3) - 2.0_dp*zhat*f1) ) &
1099 >               + (qxx_i*cx2 + qyy_i*cy2 + qzz_i*cz2)*f4
1100            
1101 <          dudux_i(1) = dudux_i(1) + pref * sw * ri3 * (qxx_i*6.0_dp*cx_i*xhat)
1102 <          dudux_i(2) = dudux_i(2) + pref * sw * ri3 * (qxx_i*6.0_dp*cx_i*yhat)
1103 <          dudux_i(3) = dudux_i(3) + pref * sw * ri3 * (qxx_i*6.0_dp*cx_i*zhat)
1104 <          
1105 <          duduy_i(1) = duduy_i(1) + pref * sw * ri3 * (qyy_i*6.0_dp*cy_i*xhat)
1106 <          duduy_i(2) = duduy_i(2) + pref * sw * ri3 * (qyy_i*6.0_dp*cy_i*yhat)
712 <          duduy_i(3) = duduy_i(3) + pref * sw * ri3 * (qyy_i*6.0_dp*cy_i*zhat)
1101 >          dudux_i(1) = dudux_i(1) + sw*pref*( ri3*(qxx_i*2.0_dp*cx_i*xhat) &
1102 >               * (3.0d0*f1 + f3) )
1103 >          dudux_i(2) = dudux_i(2) + sw*pref*( ri3*(qxx_i*2.0_dp*cx_i*yhat) &
1104 >               * (3.0d0*f1 + f3) )
1105 >          dudux_i(3) = dudux_i(3) + sw*pref*( ri3*(qxx_i*2.0_dp*cx_i*zhat) &
1106 >               * (3.0d0*f1 + f3) )
1107            
1108 <          duduz_i(1) = duduz_i(1) + pref * sw * ri3 * (qzz_i*6.0_dp*cz_i*xhat)
1109 <          duduz_i(2) = duduz_i(2) + pref * sw * ri3 * (qzz_i*6.0_dp*cz_i*yhat)
1110 <          duduz_i(3) = duduz_i(3) + pref * sw * ri3 * (qzz_i*6.0_dp*cz_i*zhat)
1108 >          duduy_i(1) = duduy_i(1) + sw*pref*( ri3*(qyy_i*2.0_dp*cy_i*xhat) &
1109 >               * (3.0d0*f1 + f3) )
1110 >          duduy_i(2) = duduy_i(2) + sw*pref*( ri3*(qyy_i*2.0_dp*cy_i*yhat) &
1111 >               * (3.0d0*f1 + f3) )
1112 >          duduy_i(3) = duduy_i(3) + sw*pref*( ri3*(qyy_i*2.0_dp*cy_i*zhat) &
1113 >               * (3.0d0*f1 + f3) )
1114 >          
1115 >          duduz_i(1) = duduz_i(1) + sw*pref*( ri3*(qzz_i*2.0_dp*cz_i*xhat) &
1116 >               * (3.0d0*f1 + f3) )
1117 >          duduz_i(2) = duduz_i(2) + sw*pref*( ri3*(qzz_i*2.0_dp*cz_i*yhat) &
1118 >               * (3.0d0*f1 + f3) )
1119 >          duduz_i(3) = duduz_i(3) + sw*pref*( ri3*(qzz_i*2.0_dp*cz_i*zhat) &
1120 >               * (3.0d0*f1 + f3) )
1121 >
1122         endif
1123      endif
1124 <      
1125 <    
1124 >
1125 >
1126      if (do_pot) then
1127   #ifdef IS_MPI
1128 <       pot_row(atom1) = pot_row(atom1) + 0.5d0*epot
1129 <       pot_col(atom2) = pot_col(atom2) + 0.5d0*epot
1128 >       pot_row(ELECTROSTATIC_POT,atom1) = pot_row(ELECTROSTATIC_POT,atom1) + 0.5d0*epot
1129 >       pot_col(ELECTROSTATIC_POT,atom2) = pot_col(ELECTROSTATIC_POT,atom2) + 0.5d0*epot
1130   #else
1131         pot = pot + epot
1132   #endif
1133      endif
1134 <        
1134 >
1135   #ifdef IS_MPI
1136      f_Row(1,atom1) = f_Row(1,atom1) + dudx
1137      f_Row(2,atom1) = f_Row(2,atom1) + dudy
1138      f_Row(3,atom1) = f_Row(3,atom1) + dudz
1139 <    
1139 >
1140      f_Col(1,atom2) = f_Col(1,atom2) - dudx
1141      f_Col(2,atom2) = f_Col(2,atom2) - dudy
1142      f_Col(3,atom2) = f_Col(3,atom2) - dudz
1143 <    
1143 >
1144      if (i_is_Dipole .or. i_is_Quadrupole) then
1145         t_Row(1,atom1)=t_Row(1,atom1) - uz_i(2)*duduz_i(3) + uz_i(3)*duduz_i(2)
1146         t_Row(2,atom1)=t_Row(2,atom1) - uz_i(3)*duduz_i(1) + uz_i(1)*duduz_i(3)
# Line 770 | Line 1175 | contains
1175      f(1,atom1) = f(1,atom1) + dudx
1176      f(2,atom1) = f(2,atom1) + dudy
1177      f(3,atom1) = f(3,atom1) + dudz
1178 <    
1178 >
1179      f(1,atom2) = f(1,atom2) - dudx
1180      f(2,atom2) = f(2,atom2) - dudy
1181      f(3,atom2) = f(3,atom2) - dudz
1182 <    
1182 >
1183      if (i_is_Dipole .or. i_is_Quadrupole) then
1184         t(1,atom1)=t(1,atom1) - uz_i(2)*duduz_i(3) + uz_i(3)*duduz_i(2)
1185         t(2,atom1)=t(2,atom1) - uz_i(3)*duduz_i(1) + uz_i(1)*duduz_i(3)
# Line 806 | Line 1211 | contains
1211      endif
1212  
1213   #endif
1214 <    
1214 >
1215   #ifdef IS_MPI
1216      id1 = AtomRowToGlobal(atom1)
1217      id2 = AtomColToGlobal(atom2)
# Line 816 | Line 1221 | contains
1221   #endif
1222  
1223      if (molMembershipList(id1) .ne. molMembershipList(id2)) then
1224 <      
1224 >
1225         fpair(1) = fpair(1) + dudx
1226         fpair(2) = fpair(2) + dudy
1227         fpair(3) = fpair(3) + dudz
# Line 825 | Line 1230 | contains
1230  
1231      return
1232    end subroutine doElectrostaticPair
1233 <  
1233 >
1234 >  subroutine destroyElectrostaticTypes()
1235 >
1236 >    if(allocated(ElectrostaticMap)) deallocate(ElectrostaticMap)
1237 >
1238 >  end subroutine destroyElectrostaticTypes
1239 >
1240 >  subroutine self_self(atom1, eFrame, mypot, t, do_pot)
1241 >    logical, intent(in) :: do_pot
1242 >    integer, intent(in) :: atom1
1243 >    integer :: atid1
1244 >    real(kind=dp), dimension(9,nLocal) :: eFrame
1245 >    real(kind=dp), dimension(3,nLocal) :: t
1246 >    real(kind=dp) :: mu1, c1
1247 >    real(kind=dp) :: preVal, epot, mypot
1248 >    real(kind=dp) :: eix, eiy, eiz
1249 >
1250 >    ! this is a local only array, so we use the local atom type id's:
1251 >    atid1 = atid(atom1)
1252 >
1253 >    if (.not.summationMethodChecked) then
1254 >       call checkSummationMethod()
1255 >    endif
1256 >    
1257 >    if (summationMethod .eq. REACTION_FIELD) then
1258 >       if (ElectrostaticMap(atid1)%is_Dipole) then
1259 >          mu1 = getDipoleMoment(atid1)
1260 >          
1261 >          preVal = pre22 * preRF2 * mu1*mu1
1262 >          mypot = mypot - 0.5d0*preVal
1263 >          
1264 >          ! The self-correction term adds into the reaction field vector
1265 >          
1266 >          eix = preVal * eFrame(3,atom1)
1267 >          eiy = preVal * eFrame(6,atom1)
1268 >          eiz = preVal * eFrame(9,atom1)
1269 >          
1270 >          ! once again, this is self-self, so only the local arrays are needed
1271 >          ! even for MPI jobs:
1272 >          
1273 >          t(1,atom1)=t(1,atom1) - eFrame(6,atom1)*eiz + &
1274 >               eFrame(9,atom1)*eiy
1275 >          t(2,atom1)=t(2,atom1) - eFrame(9,atom1)*eix + &
1276 >               eFrame(3,atom1)*eiz
1277 >          t(3,atom1)=t(3,atom1) - eFrame(3,atom1)*eiy + &
1278 >               eFrame(6,atom1)*eix
1279 >          
1280 >       endif
1281 >
1282 >    elseif ( (summationMethod .eq. SHIFTED_FORCE) .or. &
1283 >         (summationMethod .eq. SHIFTED_POTENTIAL) ) then
1284 >       if (ElectrostaticMap(atid1)%is_Charge) then
1285 >          c1 = getCharge(atid1)
1286 >          
1287 >          if (screeningMethod .eq. DAMPED) then
1288 >             mypot = mypot - (f0c * rcuti * 0.5_dp + &
1289 >                  dampingAlpha*invRootPi) * c1 * c1    
1290 >            
1291 >          else            
1292 >             mypot = mypot - (rcuti * 0.5_dp * c1 * c1)
1293 >            
1294 >          endif
1295 >       endif
1296 >    endif
1297 >    
1298 >    return
1299 >  end subroutine self_self
1300 >
1301 >  subroutine rf_self_excludes(atom1, atom2, sw, eFrame, d, rij, vpair, myPot, &
1302 >       f, t, do_pot)
1303 >    logical, intent(in) :: do_pot
1304 >    integer, intent(in) :: atom1
1305 >    integer, intent(in) :: atom2
1306 >    logical :: i_is_Charge, j_is_Charge
1307 >    logical :: i_is_Dipole, j_is_Dipole
1308 >    integer :: atid1
1309 >    integer :: atid2
1310 >    real(kind=dp), intent(in) :: rij
1311 >    real(kind=dp), intent(in) :: sw
1312 >    real(kind=dp), intent(in), dimension(3) :: d
1313 >    real(kind=dp), intent(inout) :: vpair
1314 >    real(kind=dp), dimension(9,nLocal) :: eFrame
1315 >    real(kind=dp), dimension(3,nLocal) :: f
1316 >    real(kind=dp), dimension(3,nLocal) :: t
1317 >    real (kind = dp), dimension(3) :: duduz_i
1318 >    real (kind = dp), dimension(3) :: duduz_j
1319 >    real (kind = dp), dimension(3) :: uz_i
1320 >    real (kind = dp), dimension(3) :: uz_j
1321 >    real(kind=dp) :: q_i, q_j, mu_i, mu_j
1322 >    real(kind=dp) :: xhat, yhat, zhat
1323 >    real(kind=dp) :: ct_i, ct_j
1324 >    real(kind=dp) :: ri2, ri3, riji, vterm
1325 >    real(kind=dp) :: pref, preVal, rfVal, myPot
1326 >    real(kind=dp) :: dudx, dudy, dudz, dudr
1327 >
1328 >    if (.not.summationMethodChecked) then
1329 >       call checkSummationMethod()
1330 >    endif
1331 >
1332 >    dudx = 0.0d0
1333 >    dudy = 0.0d0
1334 >    dudz = 0.0d0
1335 >
1336 >    riji = 1.0d0/rij
1337 >
1338 >    xhat = d(1) * riji
1339 >    yhat = d(2) * riji
1340 >    zhat = d(3) * riji
1341 >
1342 >    ! this is a local only array, so we use the local atom type id's:
1343 >    atid1 = atid(atom1)
1344 >    atid2 = atid(atom2)
1345 >    i_is_Charge = ElectrostaticMap(atid1)%is_Charge
1346 >    j_is_Charge = ElectrostaticMap(atid2)%is_Charge
1347 >    i_is_Dipole = ElectrostaticMap(atid1)%is_Dipole
1348 >    j_is_Dipole = ElectrostaticMap(atid2)%is_Dipole
1349 >
1350 >    if (i_is_Charge.and.j_is_Charge) then
1351 >       q_i = ElectrostaticMap(atid1)%charge
1352 >       q_j = ElectrostaticMap(atid2)%charge
1353 >      
1354 >       preVal = pre11 * q_i * q_j
1355 >       rfVal = preRF*rij*rij
1356 >       vterm = preVal * rfVal
1357 >      
1358 >       myPot = myPot + sw*vterm
1359 >      
1360 >       dudr  = sw*preVal * 2.0d0*rfVal*riji
1361 >      
1362 >       dudx = dudx + dudr * xhat
1363 >       dudy = dudy + dudr * yhat
1364 >       dudz = dudz + dudr * zhat
1365 >      
1366 >    elseif (i_is_Charge.and.j_is_Dipole) then
1367 >       q_i = ElectrostaticMap(atid1)%charge
1368 >       mu_j = ElectrostaticMap(atid2)%dipole_moment
1369 >       uz_j(1) = eFrame(3,atom2)
1370 >       uz_j(2) = eFrame(6,atom2)
1371 >       uz_j(3) = eFrame(9,atom2)
1372 >       ct_j = uz_j(1)*xhat + uz_j(2)*yhat + uz_j(3)*zhat
1373 >      
1374 >       ri2 = riji * riji
1375 >       ri3 = ri2 * riji
1376 >      
1377 >       pref = pre12 * q_i * mu_j
1378 >       vterm = - pref * ct_j * ( ri2 - preRF2*rij )
1379 >       myPot = myPot + sw*vterm
1380 >      
1381 >       dudx = dudx - sw*pref*( ri3*(uz_j(1)-3.0d0*ct_j*xhat) &
1382 >            - preRF2*uz_j(1) )
1383 >       dudy = dudy - sw*pref*( ri3*(uz_j(2)-3.0d0*ct_j*yhat) &
1384 >            - preRF2*uz_j(2) )
1385 >       dudz = dudz - sw*pref*( ri3*(uz_j(3)-3.0d0*ct_j*zhat) &
1386 >            - preRF2*uz_j(3) )
1387 >      
1388 >       duduz_j(1) = duduz_j(1) - sw * pref * xhat * ( ri2 - preRF2*rij )
1389 >       duduz_j(2) = duduz_j(2) - sw * pref * yhat * ( ri2 - preRF2*rij )
1390 >       duduz_j(3) = duduz_j(3) - sw * pref * zhat * ( ri2 - preRF2*rij )
1391 >      
1392 >    elseif (i_is_Dipole.and.j_is_Charge) then
1393 >       mu_i = ElectrostaticMap(atid1)%dipole_moment
1394 >       q_j = ElectrostaticMap(atid2)%charge
1395 >       uz_i(1) = eFrame(3,atom1)
1396 >       uz_i(2) = eFrame(6,atom1)
1397 >       uz_i(3) = eFrame(9,atom1)
1398 >       ct_i = uz_i(1)*xhat + uz_i(2)*yhat + uz_i(3)*zhat
1399 >      
1400 >       ri2 = riji * riji
1401 >       ri3 = ri2 * riji
1402 >      
1403 >       pref = pre12 * q_j * mu_i
1404 >       vterm = pref * ct_i * ( ri2 - preRF2*rij )
1405 >       myPot = myPot + sw*vterm
1406 >      
1407 >       dudx = dudx + sw*pref*( ri3*(uz_i(1)-3.0d0*ct_i*xhat) &
1408 >            - preRF2*uz_i(1) )
1409 >       dudy = dudy + sw*pref*( ri3*(uz_i(2)-3.0d0*ct_i*yhat) &
1410 >            - preRF2*uz_i(2) )
1411 >       dudz = dudz + sw*pref*( ri3*(uz_i(3)-3.0d0*ct_i*zhat) &
1412 >            - preRF2*uz_i(3) )
1413 >      
1414 >       duduz_i(1) = duduz_i(1) + sw * pref * xhat * ( ri2 - preRF2*rij )
1415 >       duduz_i(2) = duduz_i(2) + sw * pref * yhat * ( ri2 - preRF2*rij )
1416 >       duduz_i(3) = duduz_i(3) + sw * pref * zhat * ( ri2 - preRF2*rij )
1417 >      
1418 >    endif
1419 >      
1420 >
1421 >    ! accumulate the forces and torques resulting from the self term
1422 >    f(1,atom1) = f(1,atom1) + dudx
1423 >    f(2,atom1) = f(2,atom1) + dudy
1424 >    f(3,atom1) = f(3,atom1) + dudz
1425 >    
1426 >    f(1,atom2) = f(1,atom2) - dudx
1427 >    f(2,atom2) = f(2,atom2) - dudy
1428 >    f(3,atom2) = f(3,atom2) - dudz
1429 >    
1430 >    if (i_is_Dipole) then
1431 >       t(1,atom1)=t(1,atom1) - uz_i(2)*duduz_i(3) + uz_i(3)*duduz_i(2)
1432 >       t(2,atom1)=t(2,atom1) - uz_i(3)*duduz_i(1) + uz_i(1)*duduz_i(3)
1433 >       t(3,atom1)=t(3,atom1) - uz_i(1)*duduz_i(2) + uz_i(2)*duduz_i(1)
1434 >    elseif (j_is_Dipole) then
1435 >       t(1,atom2)=t(1,atom2) - uz_j(2)*duduz_j(3) + uz_j(3)*duduz_j(2)
1436 >       t(2,atom2)=t(2,atom2) - uz_j(3)*duduz_j(1) + uz_j(1)*duduz_j(3)
1437 >       t(3,atom2)=t(3,atom2) - uz_j(1)*duduz_j(2) + uz_j(2)*duduz_j(1)
1438 >    endif
1439 >
1440 >    return
1441 >  end subroutine rf_self_excludes
1442 >
1443   end module electrostatic_module

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines