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 2325 by chrisfen, Sat Sep 24 17:39:36 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 + #define __FORTRAN90
58 + #include "UseTheForce/DarkSide/fElectrostaticSummationMethod.h"
59 +
60    !! these prefactors convert the multipole interactions into kcal / mol
61    !! all were computed assuming distances are measured in angstroms
62    !! Charge-Charge, assuming charges are measured in electrons
# Line 68 | Line 71 | module electrostatic_module
71    !! This unit is also known affectionately as an esu centi-barn.
72    real(kind=dp), parameter :: pre14 = 69.13373_dp
73  
74 +  !! variables to handle different summation methods for long-range electrostatics:
75 +  integer, save :: summationMethod = NONE
76 +  logical, save :: summationMethodChecked = .false.
77 +  real(kind=DP), save :: defaultCutoff = 0.0_DP
78 +  logical, save :: haveDefaultCutoff = .false.
79 +  real(kind=DP), save :: dampingAlpha = 0.0_DP
80 +  logical, save :: haveDampingAlpha = .false.
81 +  real(kind=DP), save :: dielectric = 0.0_DP
82 +  logical, save :: haveDielectric = .false.
83 +  real(kind=DP), save :: constERFC = 0.0_DP
84 +  real(kind=DP), save :: constEXP = 0.0_DP
85 +  logical, save :: haveDWAconstants = .false.
86 +  real(kind=dp), save :: rcuti = 0.0_dp
87 +  real(kind=dp), save :: rcuti2 = 0.0_dp
88 +  real(kind=dp), save :: rcuti3 = 0.0_dp
89 +  real(kind=dp), save :: rcuti4 = 0.0_dp
90 +  logical, save :: is_Undamped_Wolf = .false.
91 +  logical, save :: is_Damped_Wolf = .false.
92 +
93 +
94 +  public :: setElectrostaticSummationMethod
95 +  public :: setElectrostaticCutoffRadius
96 +  public :: setDampedWolfAlpha
97 +  public :: setReactionFieldDielectric
98    public :: newElectrostaticType
99    public :: setCharge
100    public :: setDipoleMoment
# Line 77 | Line 104 | module electrostatic_module
104    public :: getCharge
105    public :: getDipoleMoment
106    public :: pre22
107 +  public :: destroyElectrostaticTypes
108  
109    type :: Electrostatic
110       integer :: c_ident
# Line 84 | Line 112 | module electrostatic_module
112       logical :: is_Dipole = .false.
113       logical :: is_SplitDipole = .false.
114       logical :: is_Quadrupole = .false.
115 +     logical :: is_Tap = .false.
116       real(kind=DP) :: charge = 0.0_DP
117       real(kind=DP) :: dipole_moment = 0.0_DP
118       real(kind=DP) :: split_dipole_distance = 0.0_DP
# Line 94 | Line 123 | contains
123  
124   contains
125  
126 +  subroutine setElectrostaticSummationMethod(the_ESM)
127 +    integer, intent(in) :: the_ESM    
128 +
129 +    if ((the_ESM .le. 0) .or. (the_ESM .gt. REACTION_FIELD)) then
130 +       call handleError("setElectrostaticSummationMethod", "Unsupported Summation Method")
131 +    endif
132 +
133 +    summationMethod = the_ESM
134 +
135 +    if (summationMethod .eq. UNDAMPED_WOLF) is_Undamped_Wolf = .true.
136 +    if (summationMethod .eq. DAMPED_WOLF) is_Damped_Wolf = .true.
137 +  end subroutine setElectrostaticSummationMethod
138 +
139 +  subroutine setElectrostaticCutoffRadius(thisRcut)
140 +    real(kind=dp), intent(in) :: thisRcut
141 +    defaultCutoff = thisRcut
142 +    haveDefaultCutoff = .true.
143 +  end subroutine setElectrostaticCutoffRadius
144 +
145 +  subroutine setDampedWolfAlpha(thisAlpha)
146 +    real(kind=dp), intent(in) :: thisAlpha
147 +    dampingAlpha = thisAlpha
148 +    haveDampingAlpha = .true.
149 +  end subroutine setDampedWolfAlpha
150 +  
151 +  subroutine setReactionFieldDielectric(thisDielectric)
152 +    real(kind=dp), intent(in) :: thisDielectric
153 +    dielectric = thisDielectric
154 +    haveDielectric = .true.
155 +  end subroutine setReactionFieldDielectric
156 +
157    subroutine newElectrostaticType(c_ident, is_Charge, is_Dipole, &
158 <       is_SplitDipole, is_Quadrupole, status)
159 <    
158 >       is_SplitDipole, is_Quadrupole, is_Tap, status)
159 >
160      integer, intent(in) :: c_ident
161      logical, intent(in) :: is_Charge
162      logical, intent(in) :: is_Dipole
163      logical, intent(in) :: is_SplitDipole
164      logical, intent(in) :: is_Quadrupole
165 +    logical, intent(in) :: is_Tap
166      integer, intent(out) :: status
167      integer :: nAtypes, myATID, i, j
168  
169      status = 0
170      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
171 <    
171 >
172      !! Be simple-minded and assume that we need an ElectrostaticMap that
173      !! is the same size as the total number of atom types
174  
175      if (.not.allocated(ElectrostaticMap)) then
176 <      
176 >
177         nAtypes = getSize(atypes)
178 <    
178 >
179         if (nAtypes == 0) then
180            status = -1
181            return
182         end if
183 <      
183 >
184         if (.not. allocated(ElectrostaticMap)) then
185            allocate(ElectrostaticMap(nAtypes))
186         endif
187 <      
187 >
188      end if
189  
190      if (myATID .gt. size(ElectrostaticMap)) then
191         status = -1
192         return
193      endif
194 <    
194 >
195      ! set the values for ElectrostaticMap for this atom type:
196  
197      ElectrostaticMap(myATID)%c_ident = c_ident
# Line 138 | Line 199 | contains
199      ElectrostaticMap(myATID)%is_Dipole = is_Dipole
200      ElectrostaticMap(myATID)%is_SplitDipole = is_SplitDipole
201      ElectrostaticMap(myATID)%is_Quadrupole = is_Quadrupole
202 <    
202 >    ElectrostaticMap(myATID)%is_Tap = is_Tap
203 >
204    end subroutine newElectrostaticType
205  
206    subroutine setCharge(c_ident, charge, status)
# Line 166 | Line 228 | contains
228         call handleError("electrostatic", "Attempt to setCharge of an atom type that is not a charge!")
229         status = -1
230         return
231 <    endif      
231 >    endif
232  
233      ElectrostaticMap(myATID)%charge = charge
234    end subroutine setCharge
# Line 257 | Line 319 | contains
319         status = -1
320         return
321      endif
322 <    
322 >
323      do i = 1, 3
324 <          ElectrostaticMap(myATID)%quadrupole_moments(i) = &
325 <               quadrupole_moments(i)
326 <       enddo
324 >       ElectrostaticMap(myATID)%quadrupole_moments(i) = &
325 >            quadrupole_moments(i)
326 >    enddo
327  
328    end subroutine setQuadrupoleMoments
329  
330 <  
330 >
331    function getCharge(atid) result (c)
332      integer, intent(in) :: atid
333      integer :: localError
334      real(kind=dp) :: c
335 <    
335 >
336      if (.not.allocated(ElectrostaticMap)) then
337         call handleError("electrostatic", "no ElectrostaticMap was present before first call of getCharge!")
338         return
339      end if
340 <    
340 >
341      if (.not.ElectrostaticMap(atid)%is_Charge) then
342         call handleError("electrostatic", "getCharge was called for an atom type that isn't a charge!")
343         return
344      endif
345 <    
345 >
346      c = ElectrostaticMap(atid)%charge
347    end function getCharge
348  
# Line 288 | Line 350 | contains
350      integer, intent(in) :: atid
351      integer :: localError
352      real(kind=dp) :: dm
353 <    
353 >
354      if (.not.allocated(ElectrostaticMap)) then
355         call handleError("electrostatic", "no ElectrostaticMap was present before first call of getDipoleMoment!")
356         return
357      end if
358 <    
358 >
359      if (.not.ElectrostaticMap(atid)%is_Dipole) then
360         call handleError("electrostatic", "getDipoleMoment was called for an atom type that isn't a dipole!")
361         return
362      endif
363 <    
363 >
364      dm = ElectrostaticMap(atid)%dipole_moment
365    end function getDipoleMoment
366 +
367 +  subroutine checkSummationMethod()
368 +
369 +    if (.not.haveDefaultCutoff) then
370 +       call handleError("checkSummationMethod", "no Default Cutoff set!")
371 +    endif
372  
373 +    rcuti = 1.0d0 / defaultCutoff
374 +    rcuti2 = rcuti*rcuti
375 +    rcuti3 = rcuti2*rcuti
376 +    rcuti4 = rcuti2*rcuti2
377 +
378 +    if (summationMethod .eq. DAMPED_WOLF) then
379 +       if (.not.haveDWAconstants) then
380 +          
381 +          if (.not.haveDampingAlpha) then
382 +             call handleError("checkSummationMethod", "no Damping Alpha set!")
383 +          endif
384 +          
385 +          if (.not.haveDefaultCutoff) then
386 +             call handleError("checkSummationMethod", "no Default Cutoff set!")
387 +          endif
388 +
389 +          constEXP = exp(-dampingAlpha*dampingAlpha*defaultCutoff*defaultCutoff)
390 +          constERFC = erfc(dampingAlpha*defaultCutoff)
391 +          
392 +          haveDWAconstants = .true.
393 +       endif
394 +    endif
395 +
396 +    if (summationMethod .eq. REACTION_FIELD) then
397 +       if (.not.haveDielectric) then
398 +          call handleError("checkSummationMethod", "no reaction field Dielectric set!")
399 +       endif
400 +    endif
401 +
402 +    summationMethodChecked = .true.
403 +  end subroutine checkSummationMethod
404 +
405 +
406 +
407    subroutine doElectrostaticPair(atom1, atom2, d, rij, r2, sw, &
408         vpair, fpair, pot, eFrame, f, t, do_pot)
409 <    
409 >
410      logical, intent(in) :: do_pot
411 <    
411 >
412      integer, intent(in) :: atom1, atom2
413      integer :: localError
414  
# Line 319 | Line 421 | contains
421      real( kind = dp ), dimension(9,nLocal) :: eFrame
422      real( kind = dp ), dimension(3,nLocal) :: f
423      real( kind = dp ), dimension(3,nLocal) :: t
424 <    
424 >
425      real (kind = dp), dimension(3) :: ux_i, uy_i, uz_i
426      real (kind = dp), dimension(3) :: ux_j, uy_j, uz_j
427      real (kind = dp), dimension(3) :: dudux_i, duduy_i, duduz_i
# Line 327 | Line 429 | contains
429  
430      logical :: i_is_Charge, i_is_Dipole, i_is_SplitDipole, i_is_Quadrupole
431      logical :: j_is_Charge, j_is_Dipole, j_is_SplitDipole, j_is_Quadrupole
432 +    logical :: i_is_Tap, j_is_Tap
433      integer :: me1, me2, id1, id2
434      real (kind=dp) :: q_i, q_j, mu_i, mu_j, d_i, d_j
435      real (kind=dp) :: qxx_i, qyy_i, qzz_i
# Line 336 | Line 439 | contains
439      real (kind=dp) :: cx2, cy2, cz2
440      real (kind=dp) :: ct_i, ct_j, ct_ij, a1
441      real (kind=dp) :: riji, ri, ri2, ri3, ri4
442 <    real (kind=dp) :: pref, vterm, epot, dudr    
442 >    real (kind=dp) :: pref, vterm, epot, dudr, vterm1, vterm2
443      real (kind=dp) :: xhat, yhat, zhat
444      real (kind=dp) :: dudx, dudy, dudz
445      real (kind=dp) :: scale, sc2, bigR
# Line 346 | Line 449 | contains
449         return
450      end if
451  
452 +    if (.not.summationMethodChecked) then
453 +       call checkSummationMethod()
454 +      
455 +    endif
456 +
457 +
458   #ifdef IS_MPI
459      me1 = atid_Row(atom1)
460      me2 = atid_Col(atom2)
# Line 363 | Line 472 | contains
472      zhat = d(3) * riji
473  
474      !! logicals
366
475      i_is_Charge = ElectrostaticMap(me1)%is_Charge
476      i_is_Dipole = ElectrostaticMap(me1)%is_Dipole
477      i_is_SplitDipole = ElectrostaticMap(me1)%is_SplitDipole
478      i_is_Quadrupole = ElectrostaticMap(me1)%is_Quadrupole
479 +    i_is_Tap = ElectrostaticMap(me1)%is_Tap
480  
481      j_is_Charge = ElectrostaticMap(me2)%is_Charge
482      j_is_Dipole = ElectrostaticMap(me2)%is_Dipole
483      j_is_SplitDipole = ElectrostaticMap(me2)%is_SplitDipole
484      j_is_Quadrupole = ElectrostaticMap(me2)%is_Quadrupole
485 +    j_is_Tap = ElectrostaticMap(me2)%is_Tap
486  
487      if (i_is_Charge) then
488         q_i = ElectrostaticMap(me1)%charge      
489      endif
490 <    
490 >
491      if (i_is_Dipole) then
492         mu_i = ElectrostaticMap(me1)%dipole_moment
493   #ifdef IS_MPI
# Line 394 | Line 504 | contains
504         if (i_is_SplitDipole) then
505            d_i = ElectrostaticMap(me1)%split_dipole_distance
506         endif
507 <      
507 >
508      endif
509  
510      if (i_is_Quadrupole) then
# Line 427 | Line 537 | contains
537         cz_i = uz_i(1)*xhat + uz_i(2)*yhat + uz_i(3)*zhat
538      endif
539  
430
540      if (j_is_Charge) then
541         q_j = ElectrostaticMap(me2)%charge      
542      endif
543 <    
543 >
544      if (j_is_Dipole) then
545         mu_j = ElectrostaticMap(me2)%dipole_moment
546   #ifdef IS_MPI
# Line 479 | Line 588 | contains
588         cy_j = uy_j(1)*xhat + uy_j(2)*yhat + uy_j(3)*zhat
589         cz_j = uz_j(1)*xhat + uz_j(2)*yhat + uz_j(3)*zhat
590      endif
591 <
591 >  
592      epot = 0.0_dp
593      dudx = 0.0_dp
594      dudy = 0.0_dp
# Line 496 | Line 605 | contains
605      if (i_is_Charge) then
606  
607         if (j_is_Charge) then
499          
500          vterm = pre11 * q_i * q_j * riji
501          vpair = vpair + vterm
502          epot = epot + sw*vterm
608  
609 <          dudr  = - sw * vterm * riji
609 >          if (summationMethod .eq. UNDAMPED_WOLF) then
610  
611 <          dudx = dudx + dudr * xhat
612 <          dudy = dudy + dudr * yhat
613 <          dudz = dudz + dudr * zhat
614 <      
615 <       endif
611 >             vterm = pre11 * q_i * q_j * (riji - rcuti)
612 >             vpair = vpair + vterm
613 >             epot = epot + sw*vterm
614 >            
615 >             dudr  = - sw * pre11 * q_i * q_j * (riji*riji*riji - rcuti2*rcuti)
616 >            
617 >             dudx = dudx + dudr * d(1)
618 >             dudy = dudy + dudr * d(2)
619 >             dudz = dudz + dudr * d(3)
620  
512       if (j_is_Dipole) then
513
514          if (j_is_SplitDipole) then
515             BigR = sqrt(r2 + 0.25_dp * d_j * d_j)
516             ri = 1.0_dp / BigR
517             scale = rij * ri
621            else
519             ri = riji
520             scale = 1.0_dp
521          endif
622  
623 <          ri2 = ri * ri
624 <          ri3 = ri2 * ri
625 <          sc2 = scale * scale
623 >             vterm = pre11 * q_i * q_j * riji
624 >             vpair = vpair + vterm
625 >             epot = epot + sw*vterm
626              
627 +             dudr  = - sw * vterm * riji
628 +            
629 +             dudx = dudx + dudr * xhat
630 +             dudy = dudy + dudr * yhat
631 +             dudz = dudz + dudr * zhat
632 +
633 +          endif
634 +
635 +       endif
636 +
637 +       if (j_is_Dipole) then
638 +
639            pref = pre12 * q_i * mu_j
528          vterm = - pref * ct_j * ri2 * scale
529          vpair = vpair + vterm
530          epot = epot + sw * vterm
640  
641 <          !! this has a + sign in the () because the rij vector is
642 <          !! r_j - r_i and the charge-dipole potential takes the origin
643 <          !! as the point dipole, which is atom j in this case.
641 >          if (summationMethod .eq. UNDAMPED_WOLF) then
642 >             ri2 = riji * riji
643 >             ri3 = ri2 * riji
644  
645 <          dudx = dudx - pref * sw * ri3 * ( uz_j(1) - 3.0d0*ct_j*xhat*sc2)
646 <          dudy = dudy - pref * sw * ri3 * ( uz_j(2) - 3.0d0*ct_j*yhat*sc2)
647 <          dudz = dudz - pref * sw * ri3 * ( uz_j(3) - 3.0d0*ct_j*zhat*sc2)
645 >             pref = pre12 * q_i * mu_j
646 >             vterm = - pref * ct_j * (ri2 - rcuti2)
647 >             vpair = vpair + vterm
648 >             epot = epot + sw*vterm
649 >            
650 >             !! this has a + sign in the () because the rij vector is
651 >             !! r_j - r_i and the charge-dipole potential takes the origin
652 >             !! as the point dipole, which is atom j in this case.
653 >            
654 >             dudx = dudx - sw*pref * ( ri3*( uz_j(1) - 3.0d0*ct_j*xhat) &
655 >                  - rcuti3*( uz_j(1) - 3.0d0*ct_j*d(1)*rcuti ) )
656 >             dudy = dudy - sw*pref * ( ri3*( uz_j(2) - 3.0d0*ct_j*yhat) &
657 >                  - rcuti3*( uz_j(2) - 3.0d0*ct_j*d(2)*rcuti ) )
658 >             dudz = dudz - sw*pref * ( ri3*( uz_j(3) - 3.0d0*ct_j*zhat) &
659 >                  - rcuti3*( uz_j(3) - 3.0d0*ct_j*d(3)*rcuti ) )
660 >            
661 >             duduz_j(1) = duduz_j(1) - sw*pref*( ri2*xhat - d(1)*rcuti3 )
662 >             duduz_j(2) = duduz_j(2) - sw*pref*( ri2*yhat - d(2)*rcuti3 )
663 >             duduz_j(3) = duduz_j(3) - sw*pref*( ri2*zhat - d(3)*rcuti3 )
664  
665 <          duduz_j(1) = duduz_j(1) - pref * sw * ri2 * xhat * scale
666 <          duduz_j(2) = duduz_j(2) - pref * sw * ri2 * yhat * scale
667 <          duduz_j(3) = duduz_j(3) - pref * sw * ri2 * zhat * scale
668 <          
665 >          else
666 >             if (j_is_SplitDipole) then
667 >                BigR = sqrt(r2 + 0.25_dp * d_j * d_j)
668 >                ri = 1.0_dp / BigR
669 >                scale = rij * ri
670 >             else
671 >                ri = riji
672 >                scale = 1.0_dp
673 >             endif
674 >            
675 >             ri2 = ri * ri
676 >             ri3 = ri2 * ri
677 >             sc2 = scale * scale
678 >
679 >             pref = pre12 * q_i * mu_j
680 >             vterm = - pref * ct_j * ri2 * scale
681 >             vpair = vpair + vterm
682 >             epot = epot + sw*vterm
683 >            
684 >             !! this has a + sign in the () because the rij vector is
685 >             !! r_j - r_i and the charge-dipole potential takes the origin
686 >             !! as the point dipole, which is atom j in this case.
687 >            
688 >             dudx = dudx - sw*pref * ri3 * ( uz_j(1) - 3.0d0*ct_j*xhat*sc2)
689 >             dudy = dudy - sw*pref * ri3 * ( uz_j(2) - 3.0d0*ct_j*yhat*sc2)
690 >             dudz = dudz - sw*pref * ri3 * ( uz_j(3) - 3.0d0*ct_j*zhat*sc2)
691 >            
692 >             duduz_j(1) = duduz_j(1) - sw*pref * ri2 * xhat * scale
693 >             duduz_j(2) = duduz_j(2) - sw*pref * ri2 * yhat * scale
694 >             duduz_j(3) = duduz_j(3) - sw*pref * ri2 * zhat * scale
695 >
696 >          endif
697         endif
698  
699         if (j_is_Quadrupole) then
# Line 551 | Line 704 | contains
704            cy2 = cy_j * cy_j
705            cz2 = cz_j * cz_j
706  
707 <
708 <          pref =  pre14 * q_i / 3.0_dp
709 <          vterm = pref * ri3 * (qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
710 <               qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
711 <               qzz_j * (3.0_dp*cz2 - 1.0_dp))
712 <          vpair = vpair + vterm
713 <          epot = epot + sw * vterm
714 <
715 <          dudx = dudx - 5.0_dp*sw*vterm*riji*xhat + pref * sw * ri4 * ( &
716 <               qxx_j*(6.0_dp*cx_j*ux_j(1) - 2.0_dp*xhat) + &
717 <               qyy_j*(6.0_dp*cy_j*uy_j(1) - 2.0_dp*xhat) + &
718 <               qzz_j*(6.0_dp*cz_j*uz_j(1) - 2.0_dp*xhat) )
719 <          dudy = dudy - 5.0_dp*sw*vterm*riji*yhat + pref * sw * ri4 * ( &
720 <               qxx_j*(6.0_dp*cx_j*ux_j(2) - 2.0_dp*yhat) + &
721 <               qyy_j*(6.0_dp*cy_j*uy_j(2) - 2.0_dp*yhat) + &
722 <               qzz_j*(6.0_dp*cz_j*uz_j(2) - 2.0_dp*yhat) )
723 <          dudz = dudz - 5.0_dp*sw*vterm*riji*zhat + pref * sw * ri4 * ( &
724 <               qxx_j*(6.0_dp*cx_j*ux_j(3) - 2.0_dp*zhat) + &
725 <               qyy_j*(6.0_dp*cy_j*uy_j(3) - 2.0_dp*zhat) + &
726 <               qzz_j*(6.0_dp*cz_j*uz_j(3) - 2.0_dp*zhat) )
707 >          if (summationMethod .eq. UNDAMPED_WOLF) then
708 >             pref =  pre14 * q_i / 3.0_dp
709 >             vterm1 = pref * ri3*( qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
710 >                  qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
711 >                  qzz_j * (3.0_dp*cz2 - 1.0_dp) )
712 >             vterm2 = pref * rcuti3*( qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
713 >                  qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
714 >                  qzz_j * (3.0_dp*cz2 - 1.0_dp) )
715 >             vpair = vpair + ( vterm1 - vterm2 )
716 >             epot = epot + sw*( vterm1 - vterm2 )
717 >            
718 >             dudx = dudx - (5.0_dp * &
719 >                  (vterm1*riji*xhat - vterm2*rcuti2*d(1))) + sw*pref * ( &
720 >                  (ri4 - rcuti4)*(qxx_j*(6.0_dp*cx_j*ux_j(1)) - &
721 >                  qxx_j*2.0_dp*(xhat - rcuti*d(1))) + &
722 >                  (ri4 - rcuti4)*(qyy_j*(6.0_dp*cy_j*uy_j(1)) - &
723 >                  qyy_j*2.0_dp*(xhat - rcuti*d(1))) + &
724 >                  (ri4 - rcuti4)*(qzz_j*(6.0_dp*cz_j*uz_j(1)) - &
725 >                  qzz_j*2.0_dp*(xhat - rcuti*d(1))) )
726 >             dudy = dudy - (5.0_dp * &
727 >                  (vterm1*riji*yhat - vterm2*rcuti2*d(2))) + sw*pref * ( &
728 >                  (ri4 - rcuti4)*(qxx_j*(6.0_dp*cx_j*ux_j(2)) - &
729 >                  qxx_j*2.0_dp*(yhat - rcuti*d(2))) + &
730 >                  (ri4 - rcuti4)*(qyy_j*(6.0_dp*cy_j*uy_j(2)) - &
731 >                  qyy_j*2.0_dp*(yhat - rcuti*d(2))) + &
732 >                  (ri4 - rcuti4)*(qzz_j*(6.0_dp*cz_j*uz_j(2)) - &
733 >                  qzz_j*2.0_dp*(yhat - rcuti*d(2))) )
734 >             dudz = dudz - (5.0_dp * &
735 >                  (vterm1*riji*zhat - vterm2*rcuti2*d(3))) + sw*pref * ( &
736 >                  (ri4 - rcuti4)*(qxx_j*(6.0_dp*cx_j*ux_j(3)) - &
737 >                  qxx_j*2.0_dp*(zhat - rcuti*d(3))) + &
738 >                  (ri4 - rcuti4)*(qyy_j*(6.0_dp*cy_j*uy_j(3)) - &
739 >                  qyy_j*2.0_dp*(zhat - rcuti*d(3))) + &
740 >                  (ri4 - rcuti4)*(qzz_j*(6.0_dp*cz_j*uz_j(3)) - &
741 >                  qzz_j*2.0_dp*(zhat - rcuti*d(3))) )
742 >            
743 >             dudux_j(1) = dudux_j(1) + sw*pref*(ri3*(qxx_j*6.0_dp*cx_j*xhat) -&
744 >                  rcuti4*(qxx_j*6.0_dp*cx_j*d(1)))
745 >             dudux_j(2) = dudux_j(2) + sw*pref*(ri3*(qxx_j*6.0_dp*cx_j*yhat) -&
746 >                  rcuti4*(qxx_j*6.0_dp*cx_j*d(2)))
747 >             dudux_j(3) = dudux_j(3) + sw*pref*(ri3*(qxx_j*6.0_dp*cx_j*zhat) -&
748 >                  rcuti4*(qxx_j*6.0_dp*cx_j*d(3)))
749 >            
750 >             duduy_j(1) = duduy_j(1) + sw*pref*(ri3*(qyy_j*6.0_dp*cy_j*xhat) -&
751 >                  rcuti4*(qyy_j*6.0_dp*cx_j*d(1)))
752 >             duduy_j(2) = duduy_j(2) + sw*pref*(ri3*(qyy_j*6.0_dp*cy_j*yhat) -&
753 >                  rcuti4*(qyy_j*6.0_dp*cx_j*d(2)))
754 >             duduy_j(3) = duduy_j(3) + sw*pref*(ri3*(qyy_j*6.0_dp*cy_j*zhat) -&
755 >                  rcuti4*(qyy_j*6.0_dp*cx_j*d(3)))
756 >            
757 >             duduz_j(1) = duduz_j(1) + sw*pref*(ri3*(qzz_j*6.0_dp*cz_j*xhat) -&
758 >                  rcuti4*(qzz_j*6.0_dp*cx_j*d(1)))
759 >             duduz_j(2) = duduz_j(2) + sw*pref*(ri3*(qzz_j*6.0_dp*cz_j*yhat) -&
760 >                  rcuti4*(qzz_j*6.0_dp*cx_j*d(2)))
761 >             duduz_j(3) = duduz_j(3) + sw*pref*(ri3*(qzz_j*6.0_dp*cz_j*zhat) -&
762 >                  rcuti4*(qzz_j*6.0_dp*cx_j*d(3)))
763 >        
764 >          else
765 >             pref =  pre14 * q_i / 3.0_dp
766 >             vterm = pref * ri3 * (qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
767 >                  qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
768 >                  qzz_j * (3.0_dp*cz2 - 1.0_dp))
769 >             vpair = vpair + vterm
770 >             epot = epot + sw*vterm
771 >            
772 >             dudx = dudx - 5.0_dp*sw*vterm*riji*xhat + sw*pref * ri4 * ( &
773 >                  qxx_j*(6.0_dp*cx_j*ux_j(1) - 2.0_dp*xhat) + &
774 >                  qyy_j*(6.0_dp*cy_j*uy_j(1) - 2.0_dp*xhat) + &
775 >                  qzz_j*(6.0_dp*cz_j*uz_j(1) - 2.0_dp*xhat) )
776 >             dudy = dudy - 5.0_dp*sw*vterm*riji*yhat + sw*pref * ri4 * ( &
777 >                  qxx_j*(6.0_dp*cx_j*ux_j(2) - 2.0_dp*yhat) + &
778 >                  qyy_j*(6.0_dp*cy_j*uy_j(2) - 2.0_dp*yhat) + &
779 >                  qzz_j*(6.0_dp*cz_j*uz_j(2) - 2.0_dp*yhat) )
780 >             dudz = dudz - 5.0_dp*sw*vterm*riji*zhat + sw*pref * ri4 * ( &
781 >                  qxx_j*(6.0_dp*cx_j*ux_j(3) - 2.0_dp*zhat) + &
782 >                  qyy_j*(6.0_dp*cy_j*uy_j(3) - 2.0_dp*zhat) + &
783 >                  qzz_j*(6.0_dp*cz_j*uz_j(3) - 2.0_dp*zhat) )
784 >            
785 >             dudux_j(1) = dudux_j(1) + sw*pref * ri3*(qxx_j*6.0_dp*cx_j*xhat)
786 >             dudux_j(2) = dudux_j(2) + sw*pref * ri3*(qxx_j*6.0_dp*cx_j*yhat)
787 >             dudux_j(3) = dudux_j(3) + sw*pref * ri3*(qxx_j*6.0_dp*cx_j*zhat)
788 >            
789 >             duduy_j(1) = duduy_j(1) + sw*pref * ri3*(qyy_j*6.0_dp*cy_j*xhat)
790 >             duduy_j(2) = duduy_j(2) + sw*pref * ri3*(qyy_j*6.0_dp*cy_j*yhat)
791 >             duduy_j(3) = duduy_j(3) + sw*pref * ri3*(qyy_j*6.0_dp*cy_j*zhat)
792 >            
793 >             duduz_j(1) = duduz_j(1) + sw*pref * ri3*(qzz_j*6.0_dp*cz_j*xhat)
794 >             duduz_j(2) = duduz_j(2) + sw*pref * ri3*(qzz_j*6.0_dp*cz_j*yhat)
795 >             duduz_j(3) = duduz_j(3) + sw*pref * ri3*(qzz_j*6.0_dp*cz_j*zhat)
796            
797 <          dudux_j(1) = dudux_j(1) + pref * sw * ri3 * (qxx_j*6.0_dp*cx_j*xhat)
798 <          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)
586 <       endif
587 <
797 >          endif
798 >       endif
799      endif
800 <  
800 >
801      if (i_is_Dipole) then
802 <      
802 >
803         if (j_is_Charge) then
804 +          
805 +          pref = pre12 * q_j * mu_i
806 +          
807 +          if (summationMethod .eq. UNDAMPED_WOLF) then
808 +             ri2 = riji * riji
809 +             ri3 = ri2 * riji
810  
811 <          if (i_is_SplitDipole) then
812 <             BigR = sqrt(r2 + 0.25_dp * d_i * d_i)
813 <             ri = 1.0_dp / BigR
814 <             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
811 >             pref = pre12 * q_j * mu_i
812 >             vterm = pref * ct_i * (ri2 - rcuti2)
813 >             vpair = vpair + vterm
814 >             epot = epot + sw*vterm
815              
816 <          pref = pre12 * q_j * mu_i
817 <          vterm = pref * ct_i * ri2 * scale
818 <          vpair = vpair + vterm
819 <          epot = epot + sw * vterm
816 >             !! this has a + sign in the () because the rij vector is
817 >             !! r_j - r_i and the charge-dipole potential takes the origin
818 >             !! as the point dipole, which is atom j in this case.
819 >            
820 >             dudx = dudx + sw*pref * ( ri3*( uz_i(1) - 3.0d0*ct_i*xhat) &
821 >                  - rcuti3*( uz_i(1) - 3.0d0*ct_i*d(1)*rcuti ) )
822 >             dudy = dudy + sw*pref * ( ri3*( uz_i(2) - 3.0d0*ct_i*yhat) &
823 >                  - rcuti3*( uz_i(2) - 3.0d0*ct_i*d(2)*rcuti ) )
824 >             dudz = dudz + sw*pref * ( ri3*( uz_i(3) - 3.0d0*ct_i*zhat) &
825 >                  - rcuti3*( uz_i(3) - 3.0d0*ct_i*d(3)*rcuti ) )
826 >            
827 >             duduz_i(1) = duduz_i(1) - sw*pref*( ri2*xhat - d(1)*rcuti3 )
828 >             duduz_i(2) = duduz_i(2) - sw*pref*( ri2*yhat - d(2)*rcuti3 )
829 >             duduz_i(3) = duduz_i(3) - sw*pref*( ri2*zhat - d(3)*rcuti3 )
830  
612          dudx = dudx + pref * sw * ri3 * ( uz_i(1) - 3.0d0 * ct_i * xhat*sc2)
613          dudy = dudy + pref * sw * ri3 * ( uz_i(2) - 3.0d0 * ct_i * yhat*sc2)
614          dudz = dudz + pref * sw * ri3 * ( uz_i(3) - 3.0d0 * ct_i * zhat*sc2)
615
616          duduz_i(1) = duduz_i(1) + pref * sw * ri2 * xhat * scale
617          duduz_i(2) = duduz_i(2) + pref * sw * ri2 * yhat * scale
618          duduz_i(3) = duduz_i(3) + pref * sw * ri2 * zhat * scale
619       endif
620
621       if (j_is_Dipole) then
622
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                
831            else
832 <             if (j_is_SplitDipole) then
833 <                BigR = sqrt(r2 + 0.25_dp * d_j * d_j)
832 >             if (i_is_SplitDipole) then
833 >                BigR = sqrt(r2 + 0.25_dp * d_i * d_i)
834                  ri = 1.0_dp / BigR
835 <                scale = rij * ri                            
836 <             else                
835 >                scale = rij * ri
836 >             else
837                  ri = riji
838                  scale = 1.0_dp
839               endif
840 +            
841 +             ri2 = ri * ri
842 +             ri3 = ri2 * ri
843 +             sc2 = scale * scale
844 +
845 +             pref = pre12 * q_j * mu_i
846 +             vterm = pref * ct_i * ri2 * scale
847 +             vpair = vpair + vterm
848 +             epot = epot + sw*vterm
849 +            
850 +             dudx = dudx + sw*pref * ri3 * ( uz_i(1) - 3.0d0 * ct_i * xhat*sc2)
851 +             dudy = dudy + sw*pref * ri3 * ( uz_i(2) - 3.0d0 * ct_i * yhat*sc2)
852 +             dudz = dudz + sw*pref * ri3 * ( uz_i(3) - 3.0d0 * ct_i * zhat*sc2)
853 +            
854 +             duduz_i(1) = duduz_i(1) + sw*pref * ri2 * xhat * scale
855 +             duduz_i(2) = duduz_i(2) + sw*pref * ri2 * yhat * scale
856 +             duduz_i(3) = duduz_i(3) + sw*pref * ri2 * zhat * scale
857            endif
858 +       endif
859 +      
860 +       if (j_is_Dipole) then
861  
862 <          ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
862 >          if (summationMethod .eq. UNDAMPED_WOLF) then
863 >             ri2 = riji * riji
864 >             ri3 = ri2 * riji
865 >             ri4 = ri2 * ri2
866  
867 <          ri2 = ri * ri
868 <          ri3 = ri2 * ri
869 <          ri4 = ri2 * ri2
870 <          sc2 = scale * scale
867 >             pref = pre22 * mu_i * mu_j
868 >             vterm = pref * (ri3 - rcuti3) * (ct_ij - 3.0d0 * ct_i * ct_j)
869 >             vpair = vpair + vterm
870 >             epot = epot + sw*vterm
871 >            
872 >             a1 = 5.0d0 * ct_i * ct_j - ct_ij
873 >            
874 >             dudx = dudx + sw*pref*3.0d0*ri4 &
875 >                             * (a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1)) &
876 >                         - sw*pref*3.0d0*rcuti4 &
877 >                             * (a1*rcuti*d(1)-ct_i*uz_j(1)-ct_j*uz_i(1))
878 >             dudy = dudy + sw*pref*3.0d0*ri4 &
879 >                             * (a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2)) &
880 >                         - sw*pref*3.0d0*rcuti4 &
881 >                             * (a1*rcuti*d(2)-ct_i*uz_j(2)-ct_j*uz_i(2))
882 >             dudz = dudz + sw*pref*3.0d0*ri4 &
883 >                             * (a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3)) &
884 >                         - sw*pref*3.0d0*rcuti4 &
885 >                             * (a1*rcuti*d(3)-ct_i*uz_j(3)-ct_j*uz_i(3))
886 >            
887 >             duduz_i(1) = duduz_i(1) + sw*pref*(ri3*(uz_j(1)-3.0d0*ct_j*xhat) &
888 >                  - rcuti3*(uz_j(1) - 3.0d0*ct_j*d(1)*rcuti))
889 >             duduz_i(2) = duduz_i(2) + sw*pref*(ri3*(uz_j(2)-3.0d0*ct_j*yhat) &
890 >                  - rcuti3*(uz_j(2) - 3.0d0*ct_j*d(2)*rcuti))
891 >             duduz_i(3) = duduz_i(3) + sw*pref*(ri3*(uz_j(3)-3.0d0*ct_j*zhat) &
892 >                  - rcuti3*(uz_j(3) - 3.0d0*ct_j*d(3)*rcuti))
893 >             duduz_j(1) = duduz_j(1) + sw*pref*(ri3*(uz_i(1)-3.0d0*ct_i*xhat) &
894 >                  - rcuti3*(uz_i(1) - 3.0d0*ct_i*d(1)*rcuti))
895 >             duduz_j(2) = duduz_j(2) + sw*pref*(ri3*(uz_i(2)-3.0d0*ct_i*yhat) &
896 >                  - rcuti3*(uz_i(2) - 3.0d0*ct_i*d(2)*rcuti))
897 >             duduz_j(3) = duduz_j(3) + sw*pref*(ri3*(uz_i(3)-3.0d0*ct_i*zhat) &
898 >                  - rcuti3*(uz_i(3) - 3.0d0*ct_i*d(3)*rcuti))
899  
900 <          pref = pre22 * mu_i * mu_j
901 <          vterm = pref * ri3 * (ct_ij - 3.0d0 * ct_i * ct_j * sc2)
902 <          vpair = vpair + vterm
903 <          epot = epot + sw * vterm
904 <          
905 <          a1 = 5.0d0 * ct_i * ct_j * sc2 - ct_ij
906 <
907 <          dudx=dudx+pref*sw*3.0d0*ri4*scale*(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
908 <          dudy=dudy+pref*sw*3.0d0*ri4*scale*(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
909 <          dudz=dudz+pref*sw*3.0d0*ri4*scale*(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
910 <
911 <          duduz_i(1) = duduz_i(1) + pref*sw*ri3*(uz_j(1) - 3.0d0*ct_j*xhat*sc2)
912 <          duduz_i(2) = duduz_i(2) + pref*sw*ri3*(uz_j(2) - 3.0d0*ct_j*yhat*sc2)
913 <          duduz_i(3) = duduz_i(3) + pref*sw*ri3*(uz_j(3) - 3.0d0*ct_j*zhat*sc2)
914 <
915 <          duduz_j(1) = duduz_j(1) + pref*sw*ri3*(uz_i(1) - 3.0d0*ct_i*xhat*sc2)
916 <          duduz_j(2) = duduz_j(2) + pref*sw*ri3*(uz_i(2) - 3.0d0*ct_i*yhat*sc2)
917 <          duduz_j(3) = duduz_j(3) + pref*sw*ri3*(uz_i(3) - 3.0d0*ct_i*zhat*sc2)
900 >          else
901 >             if (i_is_SplitDipole) then
902 >                if (j_is_SplitDipole) then
903 >                   BigR = sqrt(r2 + 0.25_dp * d_i * d_i + 0.25_dp * d_j * d_j)
904 >                else
905 >                   BigR = sqrt(r2 + 0.25_dp * d_i * d_i)
906 >                endif
907 >                ri = 1.0_dp / BigR
908 >                scale = rij * ri                
909 >             else
910 >                if (j_is_SplitDipole) then
911 >                   BigR = sqrt(r2 + 0.25_dp * d_j * d_j)
912 >                   ri = 1.0_dp / BigR
913 >                   scale = rij * ri                            
914 >                else                
915 >                   ri = riji
916 >                   scale = 1.0_dp
917 >                endif
918 >             endif
919 >            
920 >             ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
921 >            
922 >             ri2 = ri * ri
923 >             ri3 = ri2 * ri
924 >             ri4 = ri2 * ri2
925 >             sc2 = scale * scale
926 >            
927 >             pref = pre22 * mu_i * mu_j
928 >             vterm = pref * ri3 * (ct_ij - 3.0d0 * ct_i * ct_j * sc2)
929 >             vpair = vpair + vterm
930 >             epot = epot + sw*vterm
931 >            
932 >             a1 = 5.0d0 * ct_i * ct_j * sc2 - ct_ij
933 >            
934 >             dudx = dudx + sw*pref*3.0d0*ri4*scale &
935 >                             *(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
936 >             dudy = dudy + sw*pref*3.0d0*ri4*scale &
937 >                             *(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
938 >             dudz = dudz + sw*pref*3.0d0*ri4*scale &
939 >                             *(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
940 >            
941 >             duduz_i(1) = duduz_i(1) + sw*pref*ri3 &
942 >                                         *(uz_j(1) - 3.0d0*ct_j*xhat*sc2)
943 >             duduz_i(2) = duduz_i(2) + sw*pref*ri3 &
944 >                                         *(uz_j(2) - 3.0d0*ct_j*yhat*sc2)
945 >             duduz_i(3) = duduz_i(3) + sw*pref*ri3 &
946 >                                         *(uz_j(3) - 3.0d0*ct_j*zhat*sc2)
947 >            
948 >             duduz_j(1) = duduz_j(1) + sw*pref*ri3 &
949 >                                         *(uz_i(1) - 3.0d0*ct_i*xhat*sc2)
950 >             duduz_j(2) = duduz_j(2) + sw*pref*ri3 &
951 >                                         *(uz_i(2) - 3.0d0*ct_i*yhat*sc2)
952 >             duduz_j(3) = duduz_j(3) + sw*pref*ri3 &
953 >                                         *(uz_i(3) - 3.0d0*ct_i*zhat*sc2)
954 >          endif
955         endif
668
956      endif
957  
958      if (i_is_Quadrupole) then
959         if (j_is_Charge) then
960 <          
960 >
961            ri2 = riji * riji
962            ri3 = ri2 * riji
963            ri4 = ri2 * ri2
964            cx2 = cx_i * cx_i
965            cy2 = cy_i * cy_i
966            cz2 = cz_i * cz_i
967 <          
968 <          pref = pre14 * q_j / 3.0_dp
969 <          vterm = pref * ri3 * (qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
970 <               qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
971 <               qzz_i * (3.0_dp*cz2 - 1.0_dp))
972 <          vpair = vpair + vterm
973 <          epot = epot + sw * vterm
974 <          
975 <          dudx = dudx - 5.0_dp*sw*vterm*riji*xhat + pref * sw * ri4 * ( &
976 <               qxx_i*(6.0_dp*cx_i*ux_i(1) - 2.0_dp*xhat) + &
977 <               qyy_i*(6.0_dp*cy_i*uy_i(1) - 2.0_dp*xhat) + &
978 <               qzz_i*(6.0_dp*cz_i*uz_i(1) - 2.0_dp*xhat) )
979 <          dudy = dudy - 5.0_dp*sw*vterm*riji*yhat + pref * sw * ri4 * ( &
980 <               qxx_i*(6.0_dp*cx_i*ux_i(2) - 2.0_dp*yhat) + &
981 <               qyy_i*(6.0_dp*cy_i*uy_i(2) - 2.0_dp*yhat) + &
982 <               qzz_i*(6.0_dp*cz_i*uz_i(2) - 2.0_dp*yhat) )
983 <          dudz = dudz - 5.0_dp*sw*vterm*riji*zhat + pref * sw * ri4 * ( &
984 <               qxx_i*(6.0_dp*cx_i*ux_i(3) - 2.0_dp*zhat) + &
985 <               qyy_i*(6.0_dp*cy_i*uy_i(3) - 2.0_dp*zhat) + &
986 <               qzz_i*(6.0_dp*cz_i*uz_i(3) - 2.0_dp*zhat) )
987 <          
988 <          dudux_i(1) = dudux_i(1) + pref * sw * ri3 * (qxx_i*6.0_dp*cx_i*xhat)
989 <          dudux_i(2) = dudux_i(2) + pref * sw * ri3 * (qxx_i*6.0_dp*cx_i*yhat)
990 <          dudux_i(3) = dudux_i(3) + pref * sw * ri3 * (qxx_i*6.0_dp*cx_i*zhat)
991 <          
992 <          duduy_i(1) = duduy_i(1) + pref * sw * ri3 * (qyy_i*6.0_dp*cy_i*xhat)
993 <          duduy_i(2) = duduy_i(2) + pref * sw * ri3 * (qyy_i*6.0_dp*cy_i*yhat)
994 <          duduy_i(3) = duduy_i(3) + pref * sw * ri3 * (qyy_i*6.0_dp*cy_i*zhat)
995 <          
996 <          duduz_i(1) = duduz_i(1) + pref * sw * ri3 * (qzz_i*6.0_dp*cz_i*xhat)
997 <          duduz_i(2) = duduz_i(2) + pref * sw * ri3 * (qzz_i*6.0_dp*cz_i*yhat)
998 <          duduz_i(3) = duduz_i(3) + pref * sw * ri3 * (qzz_i*6.0_dp*cz_i*zhat)
967 >
968 >          if (summationMethod .eq. UNDAMPED_WOLF) then
969 >             pref = pre14 * q_j / 3.0_dp
970 >             vterm1 = pref * ri3*( qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
971 >                  qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
972 >                  qzz_i * (3.0_dp*cz2 - 1.0_dp) )
973 >             vterm2 = pref * rcuti3*( qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
974 >                  qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
975 >                  qzz_i * (3.0_dp*cz2 - 1.0_dp) )
976 >             vpair = vpair + ( vterm1 - vterm2 )
977 >             epot = epot + sw*( vterm1 - vterm2 )
978 >            
979 >             dudx = dudx - sw*(5.0_dp*(vterm1*riji*xhat-vterm2*rcuti2*d(1))) +&
980 >                  sw*pref * ( (ri4 - rcuti4)*(qxx_i*(6.0_dp*cx_i*ux_i(1)) - &
981 >                  qxx_i*2.0_dp*(xhat - rcuti*d(1))) + &
982 >                  (ri4 - rcuti4)*(qyy_i*(6.0_dp*cy_i*uy_i(1)) - &
983 >                  qyy_i*2.0_dp*(xhat - rcuti*d(1))) + &
984 >                  (ri4 - rcuti4)*(qzz_i*(6.0_dp*cz_i*uz_i(1)) - &
985 >                  qzz_i*2.0_dp*(xhat - rcuti*d(1))) )
986 >             dudy = dudy - sw*(5.0_dp*(vterm1*riji*yhat-vterm2*rcuti2*d(2))) +&
987 >                  sw*pref * ( (ri4 - rcuti4)*(qxx_i*(6.0_dp*cx_i*ux_i(2)) - &
988 >                  qxx_i*2.0_dp*(yhat - rcuti*d(2))) + &
989 >                  (ri4 - rcuti4)*(qyy_i*(6.0_dp*cy_i*uy_i(2)) - &
990 >                  qyy_i*2.0_dp*(yhat - rcuti*d(2))) + &
991 >                  (ri4 - rcuti4)*(qzz_i*(6.0_dp*cz_i*uz_i(2)) - &
992 >                  qzz_i*2.0_dp*(yhat - rcuti*d(2))) )
993 >             dudz = dudz - sw*(5.0_dp*(vterm1*riji*zhat-vterm2*rcuti2*d(3))) +&
994 >                  sw*pref * ( (ri4 - rcuti4)*(qxx_i*(6.0_dp*cx_i*ux_i(3)) - &
995 >                  qxx_i*2.0_dp*(zhat - rcuti*d(3))) + &
996 >                  (ri4 - rcuti4)*(qyy_i*(6.0_dp*cy_i*uy_i(3)) - &
997 >                  qyy_i*2.0_dp*(zhat - rcuti*d(3))) + &
998 >                  (ri4 - rcuti4)*(qzz_i*(6.0_dp*cz_i*uz_i(3)) - &
999 >                  qzz_i*2.0_dp*(zhat - rcuti*d(3))) )
1000 >            
1001 >             dudux_i(1) = dudux_i(1) + sw*pref*(ri3*(qxx_i*6.0_dp*cx_i*xhat) -&
1002 >                  rcuti4*(qxx_i*6.0_dp*cx_i*d(1)))
1003 >             dudux_i(2) = dudux_i(2) + sw*pref*(ri3*(qxx_i*6.0_dp*cx_i*yhat) -&
1004 >                  rcuti4*(qxx_i*6.0_dp*cx_i*d(2)))
1005 >             dudux_i(3) = dudux_i(3) + sw*pref*(ri3*(qxx_i*6.0_dp*cx_i*zhat) -&
1006 >                  rcuti4*(qxx_i*6.0_dp*cx_i*d(3)))
1007 >            
1008 >             duduy_i(1) = duduy_i(1) + sw*pref*(ri3*(qyy_i*6.0_dp*cy_i*xhat) -&
1009 >                  rcuti4*(qyy_i*6.0_dp*cx_i*d(1)))
1010 >             duduy_i(2) = duduy_i(2) + sw*pref*(ri3*(qyy_i*6.0_dp*cy_i*yhat) -&
1011 >                  rcuti4*(qyy_i*6.0_dp*cx_i*d(2)))
1012 >             duduy_i(3) = duduy_i(3) + sw*pref*(ri3*(qyy_i*6.0_dp*cy_i*zhat) -&
1013 >                  rcuti4*(qyy_i*6.0_dp*cx_i*d(3)))
1014 >            
1015 >             duduz_i(1) = duduz_i(1) + sw*pref*(ri3*(qzz_i*6.0_dp*cz_i*xhat) -&
1016 >                  rcuti4*(qzz_i*6.0_dp*cx_i*d(1)))
1017 >             duduz_i(2) = duduz_i(2) + sw*pref*(ri3*(qzz_i*6.0_dp*cz_i*yhat) -&
1018 >                  rcuti4*(qzz_i*6.0_dp*cx_i*d(2)))
1019 >             duduz_i(3) = duduz_i(3) + sw*pref*(ri3*(qzz_i*6.0_dp*cz_i*zhat) -&
1020 >                  rcuti4*(qzz_i*6.0_dp*cx_i*d(3)))
1021 >
1022 >          else
1023 >             pref = pre14 * q_j / 3.0_dp
1024 >             vterm = pref * ri3 * (qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1025 >                  qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1026 >                  qzz_i * (3.0_dp*cz2 - 1.0_dp))
1027 >             vpair = vpair + vterm
1028 >             epot = epot + sw*vterm
1029 >            
1030 >             dudx = dudx - 5.0_dp*sw*vterm*riji*xhat + sw*pref*ri4 * ( &
1031 >                  qxx_i*(6.0_dp*cx_i*ux_i(1) - 2.0_dp*xhat) + &
1032 >                  qyy_i*(6.0_dp*cy_i*uy_i(1) - 2.0_dp*xhat) + &
1033 >                  qzz_i*(6.0_dp*cz_i*uz_i(1) - 2.0_dp*xhat) )
1034 >             dudy = dudy - 5.0_dp*sw*vterm*riji*yhat + sw*pref*ri4 * ( &
1035 >                  qxx_i*(6.0_dp*cx_i*ux_i(2) - 2.0_dp*yhat) + &
1036 >                  qyy_i*(6.0_dp*cy_i*uy_i(2) - 2.0_dp*yhat) + &
1037 >                  qzz_i*(6.0_dp*cz_i*uz_i(2) - 2.0_dp*yhat) )
1038 >             dudz = dudz - 5.0_dp*sw*vterm*riji*zhat + sw*pref*ri4 * ( &
1039 >                  qxx_i*(6.0_dp*cx_i*ux_i(3) - 2.0_dp*zhat) + &
1040 >                  qyy_i*(6.0_dp*cy_i*uy_i(3) - 2.0_dp*zhat) + &
1041 >                  qzz_i*(6.0_dp*cz_i*uz_i(3) - 2.0_dp*zhat) )
1042 >            
1043 >             dudux_i(1) = dudux_i(1) + sw*pref*ri3*(qxx_i*6.0_dp*cx_i*xhat)
1044 >             dudux_i(2) = dudux_i(2) + sw*pref*ri3*(qxx_i*6.0_dp*cx_i*yhat)
1045 >             dudux_i(3) = dudux_i(3) + sw*pref*ri3*(qxx_i*6.0_dp*cx_i*zhat)
1046 >            
1047 >             duduy_i(1) = duduy_i(1) + sw*pref*ri3*(qyy_i*6.0_dp*cy_i*xhat)
1048 >             duduy_i(2) = duduy_i(2) + sw*pref*ri3*(qyy_i*6.0_dp*cy_i*yhat)
1049 >             duduy_i(3) = duduy_i(3) + sw*pref*ri3*(qyy_i*6.0_dp*cy_i*zhat)
1050 >            
1051 >             duduz_i(1) = duduz_i(1) + sw*pref*ri3*(qzz_i*6.0_dp*cz_i*xhat)
1052 >             duduz_i(2) = duduz_i(2) + sw*pref*ri3*(qzz_i*6.0_dp*cz_i*yhat)
1053 >             duduz_i(3) = duduz_i(3) + sw*pref*ri3*(qzz_i*6.0_dp*cz_i*zhat)
1054 >          endif
1055         endif
1056      endif
1057 <      
1058 <    
1057 >
1058 >
1059      if (do_pot) then
1060   #ifdef IS_MPI
1061         pot_row(atom1) = pot_row(atom1) + 0.5d0*epot
# Line 721 | Line 1064 | contains
1064         pot = pot + epot
1065   #endif
1066      endif
1067 <        
1067 >
1068   #ifdef IS_MPI
1069      f_Row(1,atom1) = f_Row(1,atom1) + dudx
1070      f_Row(2,atom1) = f_Row(2,atom1) + dudy
1071      f_Row(3,atom1) = f_Row(3,atom1) + dudz
1072 <    
1072 >
1073      f_Col(1,atom2) = f_Col(1,atom2) - dudx
1074      f_Col(2,atom2) = f_Col(2,atom2) - dudy
1075      f_Col(3,atom2) = f_Col(3,atom2) - dudz
1076 <    
1076 >
1077      if (i_is_Dipole .or. i_is_Quadrupole) then
1078         t_Row(1,atom1)=t_Row(1,atom1) - uz_i(2)*duduz_i(3) + uz_i(3)*duduz_i(2)
1079         t_Row(2,atom1)=t_Row(2,atom1) - uz_i(3)*duduz_i(1) + uz_i(1)*duduz_i(3)
# Line 765 | Line 1108 | contains
1108      f(1,atom1) = f(1,atom1) + dudx
1109      f(2,atom1) = f(2,atom1) + dudy
1110      f(3,atom1) = f(3,atom1) + dudz
1111 <    
1111 >
1112      f(1,atom2) = f(1,atom2) - dudx
1113      f(2,atom2) = f(2,atom2) - dudy
1114      f(3,atom2) = f(3,atom2) - dudz
1115 <    
1115 >
1116      if (i_is_Dipole .or. i_is_Quadrupole) then
1117         t(1,atom1)=t(1,atom1) - uz_i(2)*duduz_i(3) + uz_i(3)*duduz_i(2)
1118         t(2,atom1)=t(2,atom1) - uz_i(3)*duduz_i(1) + uz_i(1)*duduz_i(3)
# Line 801 | Line 1144 | contains
1144      endif
1145  
1146   #endif
1147 <    
1147 >
1148   #ifdef IS_MPI
1149      id1 = AtomRowToGlobal(atom1)
1150      id2 = AtomColToGlobal(atom2)
# Line 811 | Line 1154 | contains
1154   #endif
1155  
1156      if (molMembershipList(id1) .ne. molMembershipList(id2)) then
1157 <      
1157 >
1158         fpair(1) = fpair(1) + dudx
1159         fpair(2) = fpair(2) + dudy
1160         fpair(3) = fpair(3) + dudz
# Line 820 | Line 1163 | contains
1163  
1164      return
1165    end subroutine doElectrostaticPair
1166 <  
1166 >
1167 >  !! calculates the switching functions and their derivatives for a given
1168 >  subroutine calc_switch(r, mu, scale, dscale)
1169 >
1170 >    real (kind=dp), intent(in) :: r, mu
1171 >    real (kind=dp), intent(inout) :: scale, dscale
1172 >    real (kind=dp) :: rl, ru, mulow, minRatio, temp, scaleVal
1173 >
1174 >    ! distances must be in angstroms
1175 >    rl = 2.75d0
1176 >    ru = 3.75d0
1177 >    mulow = 0.0d0 !3.3856d0 ! 1.84 * 1.84
1178 >    minRatio = mulow / (mu*mu)
1179 >    scaleVal = 1.0d0 - minRatio
1180 >    
1181 >    if (r.lt.rl) then
1182 >       scale = minRatio
1183 >       dscale = 0.0d0
1184 >    elseif (r.gt.ru) then
1185 >       scale = 1.0d0
1186 >       dscale = 0.0d0
1187 >    else
1188 >       scale = 1.0d0 - scaleVal*((ru + 2.0d0*r - 3.0d0*rl) * (ru-r)**2) &
1189 >                        / ((ru - rl)**3)
1190 >       dscale = -scaleVal * 6.0d0 * (r-ru)*(r-rl)/((ru - rl)**3)    
1191 >    endif
1192 >        
1193 >    return
1194 >  end subroutine calc_switch
1195 >
1196 >  subroutine destroyElectrostaticTypes()
1197 >
1198 >    if(allocated(ElectrostaticMap)) deallocate(ElectrostaticMap)
1199 >
1200 >  end subroutine destroyElectrostaticTypes
1201 >
1202   end module electrostatic_module

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines