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 2418 by chrisfen, Tue Nov 8 13:31:36 2005 UTC vs.
Revision 2722 by gezelter, Thu Apr 20 18:24:24 2006 UTC

# Line 47 | Line 47 | module electrostatic_module
47    use vector_class
48    use simulation
49    use status
50 +  use interpolation
51   #ifdef IS_MPI
52    use mpiSimulation
53   #endif
# Line 64 | Line 65 | module electrostatic_module
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
68 <  real(kind=dp), parameter :: pre11 = 332.0637778_dp
68 >  real(kind=dp), parameter :: pre11 = 332.0637778d0
69    !! Charge-Dipole, assuming charges are measured in electrons, and
70    !! dipoles are measured in debyes
71 <  real(kind=dp), parameter :: pre12 = 69.13373_dp
71 >  real(kind=dp), parameter :: pre12 = 69.13373d0
72    !! Dipole-Dipole, assuming dipoles are measured in debyes
73 <  real(kind=dp), parameter :: pre22 = 14.39325_dp
73 >  real(kind=dp), parameter :: pre22 = 14.39325d0
74    !! Charge-Quadrupole, assuming charges are measured in electrons, and
75    !! quadrupoles are measured in 10^-26 esu cm^2
76    !! This unit is also known affectionately as an esu centi-barn.
77 <  real(kind=dp), parameter :: pre14 = 69.13373_dp
77 >  real(kind=dp), parameter :: pre14 = 69.13373d0
78  
79 +  real(kind=dp), parameter :: zero = 0.0d0
80 +
81    !! variables to handle different summation methods for long-range
82    !! electrostatics:
83    integer, save :: summationMethod = NONE
# Line 103 | Line 106 | module electrostatic_module
106    real(kind=dp), save :: f0 = 1.0_DP
107    real(kind=dp), save :: f1 = 1.0_DP
108    real(kind=dp), save :: f2 = 0.0_DP
109 +  real(kind=dp), save :: f3 = 0.0_DP
110 +  real(kind=dp), save :: f4 = 0.0_DP
111    real(kind=dp), save :: f0c = 1.0_DP
112    real(kind=dp), save :: f1c = 1.0_DP
113    real(kind=dp), save :: f2c = 0.0_DP
114 +  real(kind=dp), save :: f3c = 0.0_DP
115 +  real(kind=dp), save :: f4c = 0.0_DP
116  
117 < #ifdef __IFC
117 > #if defined(__IFC) || defined(__PGI)
118   ! error function for ifc version > 7.
119    double precision, external :: derfc
120   #endif
# Line 117 | Line 124 | module electrostatic_module
124    public :: setElectrostaticCutoffRadius
125    public :: setDampingAlpha
126    public :: setReactionFieldDielectric
127 +  public :: buildElectroSplines
128    public :: newElectrostaticType
129    public :: setCharge
130    public :: setDipoleMoment
# Line 129 | Line 137 | module electrostatic_module
137    public :: self_self
138    public :: rf_self_excludes
139  
140 +
141    type :: Electrostatic
142       integer :: c_ident
143       logical :: is_Charge = .false.
# Line 144 | Line 153 | contains
153  
154    type(Electrostatic), dimension(:), allocatable :: ElectrostaticMap
155  
156 +  logical, save :: hasElectrostaticMap
157 +
158   contains
159  
160    subroutine setElectrostaticSummationMethod(the_ESM)
# Line 166 | Line 177 | contains
177      real(kind=dp), intent(in) :: thisRcut
178      real(kind=dp), intent(in) :: thisRsw
179      defaultCutoff = thisRcut
180 +    defaultCutoff2 = defaultCutoff*defaultCutoff
181      rrf = defaultCutoff
182      rt = thisRsw
183      haveDefaultCutoff = .true.
# Line 183 | Line 195 | contains
195      dielectric = thisDielectric
196      haveDielectric = .true.
197    end subroutine setReactionFieldDielectric
198 +
199 +  subroutine buildElectroSplines()
200 +  end subroutine buildElectroSplines
201  
202    subroutine newElectrostaticType(c_ident, is_Charge, is_Dipole, &
203         is_SplitDipole, is_Quadrupole, is_Tap, status)
# Line 211 | Line 226 | contains
226            return
227         end if
228  
229 <       if (.not. allocated(ElectrostaticMap)) then
215 <          allocate(ElectrostaticMap(nAtypes))
216 <       endif
229 >       allocate(ElectrostaticMap(nAtypes))
230  
231      end if
232  
# Line 231 | Line 244 | contains
244      ElectrostaticMap(myATID)%is_Quadrupole = is_Quadrupole
245      ElectrostaticMap(myATID)%is_Tap = is_Tap
246  
247 +    hasElectrostaticMap = .true.
248 +
249    end subroutine newElectrostaticType
250  
251    subroutine setCharge(c_ident, charge, status)
# Line 242 | Line 257 | contains
257      status = 0
258      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
259  
260 <    if (.not.allocated(ElectrostaticMap)) then
260 >    if (.not.hasElectrostaticMap) then
261         call handleError("electrostatic", "no ElectrostaticMap was present before first call of setCharge!")
262         status = -1
263         return
# Line 272 | Line 287 | contains
287      status = 0
288      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
289  
290 <    if (.not.allocated(ElectrostaticMap)) then
290 >    if (.not.hasElectrostaticMap) then
291         call handleError("electrostatic", "no ElectrostaticMap was present before first call of setDipoleMoment!")
292         status = -1
293         return
# Line 302 | Line 317 | contains
317      status = 0
318      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
319  
320 <    if (.not.allocated(ElectrostaticMap)) then
320 >    if (.not.hasElectrostaticMap) then
321         call handleError("electrostatic", "no ElectrostaticMap was present before first call of setSplitDipoleDistance!")
322         status = -1
323         return
# Line 332 | Line 347 | contains
347      status = 0
348      myATID = getFirstMatchingElement(atypes, "c_ident", c_ident)
349  
350 <    if (.not.allocated(ElectrostaticMap)) then
350 >    if (.not.hasElectrostaticMap) then
351         call handleError("electrostatic", "no ElectrostaticMap was present before first call of setQuadrupoleMoments!")
352         status = -1
353         return
# Line 363 | Line 378 | contains
378      integer :: localError
379      real(kind=dp) :: c
380  
381 <    if (.not.allocated(ElectrostaticMap)) then
381 >    if (.not.hasElectrostaticMap) then
382         call handleError("electrostatic", "no ElectrostaticMap was present before first call of getCharge!")
383         return
384      end if
# Line 381 | Line 396 | contains
396      integer :: localError
397      real(kind=dp) :: dm
398  
399 <    if (.not.allocated(ElectrostaticMap)) then
399 >    if (.not.hasElectrostaticMap) then
400         call handleError("electrostatic", "no ElectrostaticMap was present before first call of getDipoleMoment!")
401         return
402      end if
# Line 414 | Line 429 | contains
429            call handleError("checkSummationMethod", "no Default Cutoff set!")
430         endif
431  
432 <       constEXP = exp(-alpha2*defaultCutoff*defaultCutoff)
432 >       constEXP = exp(-alpha2*defaultCutoff2)
433         invRootPi = 0.56418958354775628695d0
434         alphaPi = 2.0d0*dampingAlpha*invRootPi
435         f0c = derfc(dampingAlpha*defaultCutoff)
436         f1c = alphaPi*defaultCutoff*constEXP + f0c
437 <       f2c = alphaPi*2.0d0*alpha2*constEXP*rcuti2
438 <
437 >       f2c = alphaPi*2.0d0*alpha2*constEXP
438 >       f3c = alphaPi*2.0d0*alpha2*constEXP*defaultCutoff2*defaultCutoff
439      endif
440  
441      if (summationMethod .eq. REACTION_FIELD) then
# Line 439 | Line 454 | contains
454    end subroutine checkSummationMethod
455  
456  
457 <  subroutine doElectrostaticPair(atom1, atom2, d, rij, r2, sw, &
457 >  subroutine doElectrostaticPair(atom1, atom2, d, rij, r2, rcut, sw, &
458         vpair, fpair, pot, eFrame, f, t, do_pot)
459  
460      logical, intent(in) :: do_pot
# Line 447 | Line 462 | contains
462      integer, intent(in) :: atom1, atom2
463      integer :: localError
464  
465 <    real(kind=dp), intent(in) :: rij, r2, sw
465 >    real(kind=dp), intent(in) :: rij, r2, sw, rcut
466      real(kind=dp), intent(in), dimension(3) :: d
467      real(kind=dp), intent(inout) :: vpair
468      real(kind=dp), intent(inout), dimension(3) :: fpair    
# Line 482 | Line 497 | contains
497      real (kind=dp) :: varEXP
498      real (kind=dp) :: pot_term
499      real (kind=dp) :: preVal, rfVal
500 +    real (kind=dp) :: f13, f134
501  
486    if (.not.allocated(ElectrostaticMap)) then
487       call handleError("electrostatic", "no ElectrostaticMap was present before first call of do_electrostatic_pair!")
488       return
489    end if
490
502      if (.not.summationMethodChecked) then
503         call checkSummationMethod()
504      endif
# Line 500 | Line 511 | contains
511      me2 = atid(atom2)
512   #endif
513  
503 !!$    if (rij .ge. defaultCutoff) then
504 !!$       write(*,*) 'warning: rij = ', rij, ' rcut = ', defaultCutoff, ' sw = ', sw
505 !!$    endif
506
514      !! some variables we'll need independent of electrostatic type:
515  
516      riji = 1.0d0 / rij
# Line 545 | Line 552 | contains
552         if (i_is_SplitDipole) then
553            d_i = ElectrostaticMap(me1)%split_dipole_distance
554         endif
555 <
555 >       duduz_i = zero
556      endif
557  
558      if (i_is_Quadrupole) then
# Line 576 | Line 583 | contains
583         cx_i = ux_i(1)*xhat + ux_i(2)*yhat + ux_i(3)*zhat
584         cy_i = uy_i(1)*xhat + uy_i(2)*yhat + uy_i(3)*zhat
585         cz_i = uz_i(1)*xhat + uz_i(2)*yhat + uz_i(3)*zhat
586 +       dudux_i = zero
587 +       duduy_i = zero
588 +       duduz_i = zero
589      endif
590  
591      if (j_is_Charge) then
# Line 598 | Line 608 | contains
608         if (j_is_SplitDipole) then
609            d_j = ElectrostaticMap(me2)%split_dipole_distance
610         endif
611 +       duduz_j = zero
612      endif
613  
614      if (j_is_Quadrupole) then
# Line 628 | Line 639 | contains
639         cx_j = ux_j(1)*xhat + ux_j(2)*yhat + ux_j(3)*zhat
640         cy_j = uy_j(1)*xhat + uy_j(2)*yhat + uy_j(3)*zhat
641         cz_j = uz_j(1)*xhat + uz_j(2)*yhat + uz_j(3)*zhat
642 +       dudux_j = zero
643 +       duduy_j = zero
644 +       duduz_j = zero
645      endif
646    
647 <    epot = 0.0_dp
648 <    dudx = 0.0_dp
649 <    dudy = 0.0_dp
650 <    dudz = 0.0_dp
647 >    epot = zero
648 >    dudx = zero
649 >    dudy = zero
650 >    dudz = zero  
651  
638    dudux_i = 0.0_dp
639    duduy_i = 0.0_dp
640    duduz_i = 0.0_dp
641
642    dudux_j = 0.0_dp
643    duduy_j = 0.0_dp
644    duduz_j = 0.0_dp
645
652      if (i_is_Charge) then
653  
654         if (j_is_Charge) then
655 +          if (screeningMethod .eq. DAMPED) then
656 +             f0 = derfc(dampingAlpha*rij)
657 +             varEXP = exp(-alpha2*rij*rij)
658 +             f1 = alphaPi*rij*varEXP + f0
659 +          endif
660  
661 +          preVal = pre11 * q_i * q_j
662 +
663            if (summationMethod .eq. SHIFTED_POTENTIAL) then
664 <             if (screeningMethod .eq. DAMPED) then
652 <                f0 = derfc(dampingAlpha*rij)
653 <                varEXP = exp(-alpha2*rij*rij)
654 <                f1 = alphaPi*rij*varEXP + f0c
655 <             endif
656 <
657 <             vterm = pre11 * q_i * q_j * (riji*f0 - rcuti*f0c)
658 <             vpair = vpair + vterm
659 <             epot = epot + sw*vterm
664 >             vterm = preVal * (riji*f0 - rcuti*f0c)
665              
666 <             dudr  = -sw*pre11*q_i*q_j * riji * riji * f1
667 <            
663 <             dudx = dudx + dudr * xhat
664 <             dudy = dudy + dudr * yhat
665 <             dudz = dudz + dudr * zhat
666 <
666 >             dudr  = -sw * preVal * riji * riji * f1
667 >  
668            elseif (summationMethod .eq. SHIFTED_FORCE) then
669 <             if (screeningMethod .eq. DAMPED) then
669 <                f0 = derfc(dampingAlpha*rij)
670 <                varEXP = exp(-alpha2*rij*rij)
671 <                f1 = alphaPi*rij*varEXP + f0
672 <             endif
673 <
674 <             vterm = pre11 * q_i * q_j * ( riji*f0 - rcuti*f0c + &
669 >             vterm = preVal * ( riji*f0 - rcuti*f0c + &
670                    f1c*rcuti2*(rij-defaultCutoff) )
671              
672 <             vpair = vpair + vterm
673 <             epot = epot + sw*vterm
679 <            
680 <             dudr  = -sw*pre11*q_i*q_j * (riji*riji*f1 - rcuti2*f1c)
681 <                          
682 <             dudx = dudx + dudr * xhat
683 <             dudy = dudy + dudr * yhat
684 <             dudz = dudz + dudr * zhat
685 <
672 >             dudr  = -sw*preVal * (riji*riji*f1 - rcuti2*f1c)
673 >  
674            elseif (summationMethod .eq. REACTION_FIELD) then
687             preVal = pre11 * q_i * q_j
675               rfVal = preRF*rij*rij
676               vterm = preVal * ( riji + rfVal )
677              
691             vpair = vpair + vterm
692             epot = epot + sw*vterm
693            
678               dudr  = sw * preVal * ( 2.0d0*rfVal - riji )*riji
679 <            
696 <             dudx = dudx + dudr * xhat
697 <             dudy = dudy + dudr * yhat
698 <             dudz = dudz + dudr * zhat
699 <
679 >  
680            else
681 <             vterm = pre11 * q_i * q_j * riji
702 <             vpair = vpair + vterm
703 <             epot = epot + sw*vterm
681 >             vterm = preVal * riji*f0
682              
683 <             dudr  = - sw * vterm * riji
684 <            
707 <             dudx = dudx + dudr * xhat
708 <             dudy = dudy + dudr * yhat
709 <             dudz = dudz + dudr * zhat
710 <
683 >             dudr  = - sw * preVal * riji*riji*f1
684 >  
685            endif
686  
687 +          vpair = vpair + vterm
688 +          epot = epot + sw*vterm
689 +
690 +          dudx = dudx + dudr * xhat
691 +          dudy = dudy + dudr * yhat
692 +          dudz = dudz + dudr * zhat
693 +
694         endif
695  
696         if (j_is_Dipole) then
697 +          if (screeningMethod .eq. DAMPED) then
698 +             f0 = derfc(dampingAlpha*rij)
699 +             varEXP = exp(-alpha2*rij*rij)
700 +             f1 = alphaPi*rij*varEXP + f0
701 +             f3 = alphaPi*2.0d0*alpha2*varEXP*rij*rij*rij
702 +          endif
703  
704            pref = pre12 * q_i * mu_j
705  
719 !!$          if (summationMethod .eq. UNDAMPED_WOLF) then
720 !!$             ri2 = riji * riji
721 !!$             ri3 = ri2 * riji
722 !!$
723 !!$             pref = pre12 * q_i * mu_j
724 !!$             vterm = - pref * ct_j * (ri2 - rcuti2)
725 !!$             vpair = vpair + vterm
726 !!$             epot = epot + sw*vterm
727 !!$            
728 !!$             !! this has a + sign in the () because the rij vector is
729 !!$             !! r_j - r_i and the charge-dipole potential takes the origin
730 !!$             !! as the point dipole, which is atom j in this case.
731 !!$            
732 !!$             dudx = dudx - sw*pref * ( ri3*( uz_j(1) - 3.0d0*ct_j*xhat) &
733 !!$                  - rcuti3*( uz_j(1) - 3.0d0*ct_j*d(1)*rcuti ) )
734 !!$             dudy = dudy - sw*pref * ( ri3*( uz_j(2) - 3.0d0*ct_j*yhat) &
735 !!$                  - rcuti3*( uz_j(2) - 3.0d0*ct_j*d(2)*rcuti ) )
736 !!$             dudz = dudz - sw*pref * ( ri3*( uz_j(3) - 3.0d0*ct_j*zhat) &
737 !!$                  - rcuti3*( uz_j(3) - 3.0d0*ct_j*d(3)*rcuti ) )
738 !!$            
739 !!$             duduz_j(1) = duduz_j(1) - sw*pref*( ri2*xhat - d(1)*rcuti3 )
740 !!$             duduz_j(2) = duduz_j(2) - sw*pref*( ri2*yhat - d(2)*rcuti3 )
741 !!$             duduz_j(3) = duduz_j(3) - sw*pref*( ri2*zhat - d(3)*rcuti3 )
742 !!$
743 !!$          elseif (summationMethod .eq. REACTION_FIELD) then
744
706            if (summationMethod .eq. REACTION_FIELD) then
707               ri2 = riji * riji
708               ri3 = ri2 * riji
709      
749             pref = pre12 * q_i * mu_j
710               vterm = - pref * ct_j * ( ri2 - preRF2*rij )
711               vpair = vpair + vterm
712               epot = epot + sw*vterm
# Line 767 | Line 727 | contains
727  
728            else
729               if (j_is_SplitDipole) then
730 <                BigR = sqrt(r2 + 0.25_dp * d_j * d_j)
731 <                ri = 1.0_dp / BigR
730 >                BigR = sqrt(r2 + 0.25d0 * d_j * d_j)
731 >                ri = 1.0d0 / BigR
732                  scale = rij * ri
733               else
734                  ri = riji
735 <                scale = 1.0_dp
735 >                scale = 1.0d0
736               endif
737              
738               ri2 = ri * ri
739               ri3 = ri2 * ri
740               sc2 = scale * scale
741  
742 <             pref = pre12 * q_i * mu_j
743 <             vterm = - pref * ct_j * ri2 * scale
742 >             pot_term =  ri2 * scale * f1
743 >             vterm = - pref * ct_j * pot_term
744               vpair = vpair + vterm
745               epot = epot + sw*vterm
746              
# Line 788 | Line 748 | contains
748               !! r_j - r_i and the charge-dipole potential takes the origin
749               !! as the point dipole, which is atom j in this case.
750              
751 <             dudx = dudx - sw*pref * ri3 * ( uz_j(1) - 3.0d0*ct_j*xhat*sc2)
752 <             dudy = dudy - sw*pref * ri3 * ( uz_j(2) - 3.0d0*ct_j*yhat*sc2)
753 <             dudz = dudz - sw*pref * ri3 * ( uz_j(3) - 3.0d0*ct_j*zhat*sc2)
754 <            
755 <             duduz_j(1) = duduz_j(1) - sw*pref * ri2 * xhat * scale
756 <             duduz_j(2) = duduz_j(2) - sw*pref * ri2 * yhat * scale
757 <             duduz_j(3) = duduz_j(3) - sw*pref * ri2 * zhat * scale
751 >             dudx = dudx - sw*pref * ri3 * ( uz_j(1)*f1 - &
752 >                  ct_j*xhat*sc2*( 3.0d0*f1 + f3 ) )
753 >             dudy = dudy - sw*pref * ri3 * ( uz_j(2)*f1 - &
754 >                  ct_j*yhat*sc2*( 3.0d0*f1 + f3 ) )
755 >             dudz = dudz - sw*pref * ri3 * ( uz_j(3)*f1 - &
756 >                  ct_j*zhat*sc2*( 3.0d0*f1 + f3 ) )
757 >                          
758 >             duduz_j(1) = duduz_j(1) - sw*pref * pot_term * xhat
759 >             duduz_j(2) = duduz_j(2) - sw*pref * pot_term * yhat
760 >             duduz_j(3) = duduz_j(3) - sw*pref * pot_term * zhat
761  
762            endif
763         endif
764  
765         if (j_is_Quadrupole) then
766 +          if (screeningMethod .eq. DAMPED) then
767 +             f0 = derfc(dampingAlpha*rij)
768 +             varEXP = exp(-alpha2*rij*rij)
769 +             f1 = alphaPi*rij*varEXP + f0
770 +             f2 = alphaPi*2.0d0*alpha2*varEXP
771 +             f3 = f2*rij*rij*rij
772 +             f4 = 2.0d0*alpha2*f2*rij
773 +          endif
774 +
775            ri2 = riji * riji
776            ri3 = ri2 * riji
777            ri4 = ri2 * ri2
# Line 807 | Line 779 | contains
779            cy2 = cy_j * cy_j
780            cz2 = cz_j * cz_j
781  
782 < !!$          if (summationMethod .eq. UNDAMPED_WOLF) then
783 < !!$             pref =  pre14 * q_i / 3.0_dp
784 < !!$             vterm1 = pref * ri3*( qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
785 < !!$                  qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
786 < !!$                  qzz_j * (3.0_dp*cz2 - 1.0_dp) )
787 < !!$             vterm2 = pref * rcuti3*( qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
788 < !!$                  qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
817 < !!$                  qzz_j * (3.0_dp*cz2 - 1.0_dp) )
818 < !!$             vpair = vpair + ( vterm1 - vterm2 )
819 < !!$             epot = epot + sw*( vterm1 - vterm2 )
820 < !!$            
821 < !!$             dudx = dudx - (5.0_dp * &
822 < !!$                  (vterm1*riji*xhat - vterm2*rcuti2*d(1))) + sw*pref * ( &
823 < !!$                  (ri4 - rcuti4)*(qxx_j*(6.0_dp*cx_j*ux_j(1)) - &
824 < !!$                  qxx_j*2.0_dp*(xhat - rcuti*d(1))) + &
825 < !!$                  (ri4 - rcuti4)*(qyy_j*(6.0_dp*cy_j*uy_j(1)) - &
826 < !!$                  qyy_j*2.0_dp*(xhat - rcuti*d(1))) + &
827 < !!$                  (ri4 - rcuti4)*(qzz_j*(6.0_dp*cz_j*uz_j(1)) - &
828 < !!$                  qzz_j*2.0_dp*(xhat - rcuti*d(1))) )
829 < !!$             dudy = dudy - (5.0_dp * &
830 < !!$                  (vterm1*riji*yhat - vterm2*rcuti2*d(2))) + sw*pref * ( &
831 < !!$                  (ri4 - rcuti4)*(qxx_j*(6.0_dp*cx_j*ux_j(2)) - &
832 < !!$                  qxx_j*2.0_dp*(yhat - rcuti*d(2))) + &
833 < !!$                  (ri4 - rcuti4)*(qyy_j*(6.0_dp*cy_j*uy_j(2)) - &
834 < !!$                  qyy_j*2.0_dp*(yhat - rcuti*d(2))) + &
835 < !!$                  (ri4 - rcuti4)*(qzz_j*(6.0_dp*cz_j*uz_j(2)) - &
836 < !!$                  qzz_j*2.0_dp*(yhat - rcuti*d(2))) )
837 < !!$             dudz = dudz - (5.0_dp * &
838 < !!$                  (vterm1*riji*zhat - vterm2*rcuti2*d(3))) + sw*pref * ( &
839 < !!$                  (ri4 - rcuti4)*(qxx_j*(6.0_dp*cx_j*ux_j(3)) - &
840 < !!$                  qxx_j*2.0_dp*(zhat - rcuti*d(3))) + &
841 < !!$                  (ri4 - rcuti4)*(qyy_j*(6.0_dp*cy_j*uy_j(3)) - &
842 < !!$                  qyy_j*2.0_dp*(zhat - rcuti*d(3))) + &
843 < !!$                  (ri4 - rcuti4)*(qzz_j*(6.0_dp*cz_j*uz_j(3)) - &
844 < !!$                  qzz_j*2.0_dp*(zhat - rcuti*d(3))) )
845 < !!$            
846 < !!$             dudux_j(1) = dudux_j(1) + sw*pref*(ri3*(qxx_j*6.0_dp*cx_j*xhat) -&
847 < !!$                  rcuti4*(qxx_j*6.0_dp*cx_j*d(1)))
848 < !!$             dudux_j(2) = dudux_j(2) + sw*pref*(ri3*(qxx_j*6.0_dp*cx_j*yhat) -&
849 < !!$                  rcuti4*(qxx_j*6.0_dp*cx_j*d(2)))
850 < !!$             dudux_j(3) = dudux_j(3) + sw*pref*(ri3*(qxx_j*6.0_dp*cx_j*zhat) -&
851 < !!$                  rcuti4*(qxx_j*6.0_dp*cx_j*d(3)))
852 < !!$            
853 < !!$             duduy_j(1) = duduy_j(1) + sw*pref*(ri3*(qyy_j*6.0_dp*cy_j*xhat) -&
854 < !!$                  rcuti4*(qyy_j*6.0_dp*cx_j*d(1)))
855 < !!$             duduy_j(2) = duduy_j(2) + sw*pref*(ri3*(qyy_j*6.0_dp*cy_j*yhat) -&
856 < !!$                  rcuti4*(qyy_j*6.0_dp*cx_j*d(2)))
857 < !!$             duduy_j(3) = duduy_j(3) + sw*pref*(ri3*(qyy_j*6.0_dp*cy_j*zhat) -&
858 < !!$                  rcuti4*(qyy_j*6.0_dp*cx_j*d(3)))
859 < !!$            
860 < !!$             duduz_j(1) = duduz_j(1) + sw*pref*(ri3*(qzz_j*6.0_dp*cz_j*xhat) -&
861 < !!$                  rcuti4*(qzz_j*6.0_dp*cx_j*d(1)))
862 < !!$             duduz_j(2) = duduz_j(2) + sw*pref*(ri3*(qzz_j*6.0_dp*cz_j*yhat) -&
863 < !!$                  rcuti4*(qzz_j*6.0_dp*cx_j*d(2)))
864 < !!$             duduz_j(3) = duduz_j(3) + sw*pref*(ri3*(qzz_j*6.0_dp*cz_j*zhat) -&
865 < !!$                  rcuti4*(qzz_j*6.0_dp*cx_j*d(3)))
866 < !!$        
867 < !!$          else
868 <             pref =  pre14 * q_i / 3.0_dp
869 <             vterm = pref * ri3 * (qxx_j * (3.0_dp*cx2 - 1.0_dp) + &
870 <                  qyy_j * (3.0_dp*cy2 - 1.0_dp) + &
871 <                  qzz_j * (3.0_dp*cz2 - 1.0_dp))
872 <             vpair = vpair + vterm
873 <             epot = epot + sw*vterm
874 <            
875 <             dudx = dudx - 5.0_dp*sw*vterm*riji*xhat + sw*pref * ri4 * ( &
876 <                  qxx_j*(6.0_dp*cx_j*ux_j(1) - 2.0_dp*xhat) + &
877 <                  qyy_j*(6.0_dp*cy_j*uy_j(1) - 2.0_dp*xhat) + &
878 <                  qzz_j*(6.0_dp*cz_j*uz_j(1) - 2.0_dp*xhat) )
879 <             dudy = dudy - 5.0_dp*sw*vterm*riji*yhat + sw*pref * ri4 * ( &
880 <                  qxx_j*(6.0_dp*cx_j*ux_j(2) - 2.0_dp*yhat) + &
881 <                  qyy_j*(6.0_dp*cy_j*uy_j(2) - 2.0_dp*yhat) + &
882 <                  qzz_j*(6.0_dp*cz_j*uz_j(2) - 2.0_dp*yhat) )
883 <             dudz = dudz - 5.0_dp*sw*vterm*riji*zhat + sw*pref * ri4 * ( &
884 <                  qxx_j*(6.0_dp*cx_j*ux_j(3) - 2.0_dp*zhat) + &
885 <                  qyy_j*(6.0_dp*cy_j*uy_j(3) - 2.0_dp*zhat) + &
886 <                  qzz_j*(6.0_dp*cz_j*uz_j(3) - 2.0_dp*zhat) )
887 <            
888 <             dudux_j(1) = dudux_j(1) + sw*pref * ri3*(qxx_j*6.0_dp*cx_j*xhat)
889 <             dudux_j(2) = dudux_j(2) + sw*pref * ri3*(qxx_j*6.0_dp*cx_j*yhat)
890 <             dudux_j(3) = dudux_j(3) + sw*pref * ri3*(qxx_j*6.0_dp*cx_j*zhat)
891 <            
892 <             duduy_j(1) = duduy_j(1) + sw*pref * ri3*(qyy_j*6.0_dp*cy_j*xhat)
893 <             duduy_j(2) = duduy_j(2) + sw*pref * ri3*(qyy_j*6.0_dp*cy_j*yhat)
894 <             duduy_j(3) = duduy_j(3) + sw*pref * ri3*(qyy_j*6.0_dp*cy_j*zhat)
895 <            
896 <             duduz_j(1) = duduz_j(1) + sw*pref * ri3*(qzz_j*6.0_dp*cz_j*xhat)
897 <             duduz_j(2) = duduz_j(2) + sw*pref * ri3*(qzz_j*6.0_dp*cz_j*yhat)
898 <             duduz_j(3) = duduz_j(3) + sw*pref * ri3*(qzz_j*6.0_dp*cz_j*zhat)
782 >          pref =  pre14 * q_i / 3.0d0
783 >          pot_term = ri3*(qxx_j * (3.0d0*cx2 - 1.0d0) + &
784 >               qyy_j * (3.0d0*cy2 - 1.0d0) + &
785 >               qzz_j * (3.0d0*cz2 - 1.0d0))
786 >          vterm = pref * (pot_term*f1 + (qxx_j*cx2 + qyy_j*cy2 + qzz_j*cz2)*f2)
787 >          vpair = vpair + vterm
788 >          epot = epot + sw*vterm
789            
790 < !!$          endif
790 >          dudx = dudx - sw*pref*pot_term*riji*xhat*(5.0d0*f1 + f3) + &
791 >               sw*pref*ri4 * ( &
792 >               qxx_j*(2.0d0*cx_j*ux_j(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) + &
793 >               qyy_j*(2.0d0*cy_j*uy_j(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) + &
794 >               qzz_j*(2.0d0*cz_j*uz_j(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) ) &
795 >               + (qxx_j*cx2 + qyy_j*cy2 + qzz_j*cz2)*f4
796 >          dudy = dudy - sw*pref*pot_term*riji*yhat*(5.0d0*f1 + f3) + &
797 >               sw*pref*ri4 * ( &
798 >               qxx_j*(2.0d0*cx_j*ux_j(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) + &
799 >               qyy_j*(2.0d0*cy_j*uy_j(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) + &
800 >               qzz_j*(2.0d0*cz_j*uz_j(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) ) &
801 >               + (qxx_j*cx2 + qyy_j*cy2 + qzz_j*cz2)*f4
802 >          dudz = dudz - sw*pref*pot_term*riji*zhat*(5.0d0*f1 + f3) + &
803 >               sw*pref*ri4 * ( &
804 >               qxx_j*(2.0d0*cx_j*ux_j(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) + &
805 >               qyy_j*(2.0d0*cy_j*uy_j(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) + &
806 >               qzz_j*(2.0d0*cz_j*uz_j(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) ) &
807 >               + (qxx_j*cx2 + qyy_j*cy2 + qzz_j*cz2)*f4
808 >          
809 >          dudux_j(1) = dudux_j(1) + sw*pref*ri3*( (qxx_j*2.0d0*cx_j*xhat) &
810 >               * (3.0d0*f1 + f3) )
811 >          dudux_j(2) = dudux_j(2) + sw*pref*ri3*( (qxx_j*2.0d0*cx_j*yhat) &
812 >               * (3.0d0*f1 + f3) )
813 >          dudux_j(3) = dudux_j(3) + sw*pref*ri3*( (qxx_j*2.0d0*cx_j*zhat) &
814 >               * (3.0d0*f1 + f3) )
815 >          
816 >          duduy_j(1) = duduy_j(1) + sw*pref*ri3*( (qyy_j*2.0d0*cy_j*xhat) &
817 >               * (3.0d0*f1 + f3) )
818 >          duduy_j(2) = duduy_j(2) + sw*pref*ri3*( (qyy_j*2.0d0*cy_j*yhat) &
819 >               * (3.0d0*f1 + f3) )
820 >          duduy_j(3) = duduy_j(3) + sw*pref*ri3*( (qyy_j*2.0d0*cy_j*zhat) &
821 >               * (3.0d0*f1 + f3) )
822 >          
823 >          duduz_j(1) = duduz_j(1) + sw*pref*ri3*( (qzz_j*2.0d0*cz_j*xhat) &
824 >               * (3.0d0*f1 + f3) )
825 >          duduz_j(2) = duduz_j(2) + sw*pref*ri3*( (qzz_j*2.0d0*cz_j*yhat) &
826 >               * (3.0d0*f1 + f3) )
827 >          duduz_j(3) = duduz_j(3) + sw*pref*ri3*( (qzz_j*2.0d0*cz_j*zhat) &
828 >               * (3.0d0*f1 + f3) )
829 >          
830         endif
831      endif
832 <
832 >    
833      if (i_is_Dipole) then
834  
835         if (j_is_Charge) then
836 +          if (screeningMethod .eq. DAMPED) then
837 +             f0 = derfc(dampingAlpha*rij)
838 +             varEXP = exp(-alpha2*rij*rij)
839 +             f1 = alphaPi*rij*varEXP + f0
840 +             f3 = alphaPi*2.0d0*alpha2*varEXP*rij*rij*rij
841 +          endif
842            
843 +          pref = pre12 * q_j * mu_i
844 +          
845            if (summationMethod .eq. SHIFTED_POTENTIAL) then
846               ri2 = riji * riji
847               ri3 = ri2 * riji
848              
849 <             pref = pre12 * q_j * mu_i
913 <             pot_term = ri2 - rcuti2
849 >             pot_term = ri2*f1 - rcuti2*f1c
850               vterm = pref * ct_i * pot_term
851               vpair = vpair + vterm
852               epot = epot + sw*vterm
853              
854 <             dudx = dudx + sw*pref * ( ri3*(uz_i(1)-3.0d0*ct_i*xhat) )
855 <             dudy = dudy + sw*pref * ( ri3*(uz_i(2)-3.0d0*ct_i*yhat) )
856 <             dudz = dudz + sw*pref * ( ri3*(uz_i(3)-3.0d0*ct_i*zhat) )
854 >             dudx = dudx + sw*pref*( ri3*(uz_i(1)*f1-ct_i*xhat*(3.0d0*f1+f3)) )
855 >             dudy = dudy + sw*pref*( ri3*(uz_i(2)*f1-ct_i*yhat*(3.0d0*f1+f3)) )
856 >             dudz = dudz + sw*pref*( ri3*(uz_i(3)*f1-ct_i*zhat*(3.0d0*f1+f3)) )
857              
858               duduz_i(1) = duduz_i(1) + sw*pref * xhat * pot_term
859               duduz_i(2) = duduz_i(2) + sw*pref * yhat * pot_term
# Line 927 | Line 863 | contains
863               ri2 = riji * riji
864               ri3 = ri2 * riji
865  
866 <             pref = pre12 * q_j * mu_i
867 <             pot_term = ri2 - rcuti2 + 2.0d0*rcuti3*( rij - defaultCutoff )
866 >             !! might need a -(f1c-f0c) or dct_i/dr in the derivative term...
867 >             pot_term = ri2*f1 - rcuti2*f1c + &
868 >                  (2.0d0*rcuti3*f1c + f2c)*( rij - defaultCutoff )
869               vterm = pref * ct_i * pot_term
870               vpair = vpair + vterm
871               epot = epot + sw*vterm
872              
873 <             dudx = dudx + sw*pref * ( (ri3-rcuti3)*(uz_i(1)-3.0d0*ct_i*xhat) )
874 <             dudy = dudy + sw*pref * ( (ri3-rcuti3)*(uz_i(2)-3.0d0*ct_i*yhat) )
875 <             dudz = dudz + sw*pref * ( (ri3-rcuti3)*(uz_i(3)-3.0d0*ct_i*zhat) )
873 >             dudx = dudx + sw*pref*( ri3*(uz_i(1)*f1-ct_i*xhat*(3.0d0*f1+f3)) &
874 >                  - rcuti3*(uz_i(1)*f1c-ct_i*xhat*(3.0d0*f1c+f3c)) )
875 >             dudy = dudy + sw*pref*( ri3*(uz_i(2)*f1-ct_i*yhat*(3.0d0*f1+f3)) &
876 >                  - rcuti3*(uz_i(1)*f1c-ct_i*xhat*(3.0d0*f1c+f3c)) )
877 >             dudz = dudz + sw*pref*( ri3*(uz_i(3)*f1-ct_i*zhat*(3.0d0*f1+f3)) &
878 >                  - rcuti3*(uz_i(1)*f1c-ct_i*xhat*(3.0d0*f1c+f3c)) )
879              
880               duduz_i(1) = duduz_i(1) + sw*pref * xhat * pot_term
881               duduz_i(2) = duduz_i(2) + sw*pref * yhat * pot_term
882               duduz_i(3) = duduz_i(3) + sw*pref * zhat * pot_term
883 <
883 >
884            elseif (summationMethod .eq. REACTION_FIELD) then
885               ri2 = riji * riji
886               ri3 = ri2 * riji
887  
948             pref = pre12 * q_j * mu_i
888               vterm = pref * ct_i * ( ri2 - preRF2*rij )
889               vpair = vpair + vterm
890               epot = epot + sw*vterm
# Line 963 | Line 902 | contains
902  
903            else
904               if (i_is_SplitDipole) then
905 <                BigR = sqrt(r2 + 0.25_dp * d_i * d_i)
906 <                ri = 1.0_dp / BigR
905 >                BigR = sqrt(r2 + 0.25d0 * d_i * d_i)
906 >                ri = 1.0d0 / BigR
907                  scale = rij * ri
908               else
909                  ri = riji
910 <                scale = 1.0_dp
910 >                scale = 1.0d0
911               endif
912              
913               ri2 = ri * ri
914               ri3 = ri2 * ri
915               sc2 = scale * scale
916  
917 <             pref = pre12 * q_j * mu_i
918 <             vterm = pref * ct_i * ri2 * scale
917 >             pot_term = ri2 * f1 * scale
918 >             vterm = pref * ct_i * pot_term
919               vpair = vpair + vterm
920               epot = epot + sw*vterm
921              
922 <             dudx = dudx + sw*pref * ri3 * ( uz_i(1) - 3.0d0 * ct_i * xhat*sc2)
923 <             dudy = dudy + sw*pref * ri3 * ( uz_i(2) - 3.0d0 * ct_i * yhat*sc2)
924 <             dudz = dudz + sw*pref * ri3 * ( uz_i(3) - 3.0d0 * ct_i * zhat*sc2)
922 >             dudx = dudx + sw*pref * ri3 * ( uz_i(1)*f1 - &
923 >                  ct_i*xhat*sc2*( 3.0d0*f1 + f3 ) )
924 >             dudy = dudy + sw*pref * ri3 * ( uz_i(2)*f1 - &
925 >                  ct_i*yhat*sc2*( 3.0d0*f1 + f3 ) )
926 >             dudz = dudz + sw*pref * ri3 * ( uz_i(3)*f1 - &
927 >                  ct_i*zhat*sc2*( 3.0d0*f1 + f3 ) )
928              
929 <             duduz_i(1) = duduz_i(1) + sw*pref * ri2 * xhat * scale
930 <             duduz_i(2) = duduz_i(2) + sw*pref * ri2 * yhat * scale
931 <             duduz_i(3) = duduz_i(3) + sw*pref * ri2 * zhat * scale
929 >             duduz_i(1) = duduz_i(1) + sw*pref * pot_term * xhat
930 >             duduz_i(2) = duduz_i(2) + sw*pref * pot_term * yhat
931 >             duduz_i(3) = duduz_i(3) + sw*pref * pot_term * zhat
932            endif
933         endif
934        
935         if (j_is_Dipole) then
936 +          if (screeningMethod .eq. DAMPED) then
937 +             f0 = derfc(dampingAlpha*rij)
938 +             varEXP = exp(-alpha2*rij*rij)
939 +             f1 = alphaPi*rij*varEXP + f0
940 +             f2 = alphaPi*2.0d0*alpha2*varEXP
941 +             f3 = f2*rij*rij*rij
942 +             f4 = 2.0d0*alpha2*f3*rij*rij
943 +          endif
944 +
945            ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
946            
947            ri2 = riji * riji
# Line 999 | Line 950 | contains
950            
951            pref = pre22 * mu_i * mu_j
952  
1002 !!$          if (summationMethod .eq. SHIFTED_POTENTIAL) then
1003 !!$             a0 = ct_ij - 3.0d0 * ct_i * ct_j
1004 !!$             pot_term = ri3 - rcuti3
1005 !!$            
1006 !!$             vterm = pref*pot_term*a0
1007 !!$             vpair = vpair + vterm
1008 !!$             epot = epot + sw*vterm
1009 !!$            
1010 !!$             a1 = 5.0d0 * ct_i * ct_j - ct_ij
1011 !!$            
1012 !!$             dudx = dudx + sw*pref*3.0d0*ri4 &
1013 !!$                  * (a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
1014 !!$             dudy = dudy + sw*pref*3.0d0*ri4 &
1015 !!$                  * (a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
1016 !!$             dudz = dudz + sw*pref*3.0d0*ri4 &
1017 !!$                  * (a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
1018 !!$            
1019 !!$             duduz_i(1) = duduz_i(1) + sw*pref*( pot_term &
1020 !!$                  * (uz_j(1) - 3.0d0*ct_j*xhat) )
1021 !!$             duduz_i(2) = duduz_i(2) + sw*pref*( pot_term &
1022 !!$                  * (uz_j(2) - 3.0d0*ct_j*yhat) )
1023 !!$             duduz_i(3) = duduz_i(3) + sw*pref*( pot_term &
1024 !!$                  * (uz_j(3) - 3.0d0*ct_j*zhat) )
1025 !!$             duduz_j(1) = duduz_j(1) + sw*pref*( pot_term &
1026 !!$                  * (uz_i(1) - 3.0d0*ct_i*xhat) )
1027 !!$             duduz_j(2) = duduz_j(2) + sw*pref*( pot_term &
1028 !!$                  * (uz_i(2) - 3.0d0*ct_i*yhat) )
1029 !!$             duduz_j(3) = duduz_j(3) + sw*pref*( pot_term &
1030 !!$                  * (uz_i(3) - 3.0d0*ct_i*zhat) )
1031 !!$
1032 !!$          elseif (summationMethod .eq. SHIFTED_FORCE) then
1033 !!$             a0 = ct_ij - 3.0d0 * ct_i * ct_j
1034 !!$             pot_term = ri3 - rcuti3 + 3.0d0*rcuti4*( rij - defaultCutoff )
1035 !!$            
1036 !!$             vterm = pref*pot_term*a0
1037 !!$             vpair = vpair + vterm
1038 !!$             epot = epot + sw*vterm
1039 !!$            
1040 !!$             a1 = 5.0d0 * ct_i * ct_j - ct_ij
1041 !!$            
1042 !!$             dudx = dudx + sw*pref*3.0d0*( ri4 - rcuti4 ) &
1043 !!$                             * (a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
1044 !!$             dudy = dudy + sw*pref*3.0d0*( ri4 - rcuti4 ) &
1045 !!$                             * (a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
1046 !!$             dudz = dudz + sw*pref*3.0d0*( ri4 - rcuti4 ) &
1047 !!$                             * (a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
1048 !!$            
1049 !!$             duduz_i(1) = duduz_i(1) + sw*pref*( pot_term &
1050 !!$                  * (uz_j(1) - 3.0d0*ct_j*xhat) )
1051 !!$             duduz_i(2) = duduz_i(2) + sw*pref*( pot_term &
1052 !!$                  * (uz_j(2) - 3.0d0*ct_j*yhat) )
1053 !!$             duduz_i(3) = duduz_i(3) + sw*pref*( pot_term &
1054 !!$                  * (uz_j(3) - 3.0d0*ct_j*zhat) )
1055 !!$             duduz_j(1) = duduz_j(1) + sw*pref*( pot_term &
1056 !!$                  * (uz_i(1) - 3.0d0*ct_i*xhat) )
1057 !!$             duduz_j(2) = duduz_j(2) + sw*pref*( pot_term &
1058 !!$                  * (uz_i(2) - 3.0d0*ct_i*yhat) )
1059 !!$             duduz_j(3) = duduz_j(3) + sw*pref*( pot_term &
1060 !!$                  * (uz_i(3) - 3.0d0*ct_i*zhat) )
1061 !!$            
1062 !!$          elseif (summationMethod .eq. REACTION_FIELD) then
953            if (summationMethod .eq. REACTION_FIELD) then
954               vterm = pref*( ri3*(ct_ij - 3.0d0 * ct_i * ct_j) - &
955                    preRF2*ct_ij )
# Line 1091 | Line 981 | contains
981            else
982               if (i_is_SplitDipole) then
983                  if (j_is_SplitDipole) then
984 <                   BigR = sqrt(r2 + 0.25_dp * d_i * d_i + 0.25_dp * d_j * d_j)
984 >                   BigR = sqrt(r2 + 0.25d0 * d_i * d_i + 0.25d0 * d_j * d_j)
985                  else
986 <                   BigR = sqrt(r2 + 0.25_dp * d_i * d_i)
986 >                   BigR = sqrt(r2 + 0.25d0 * d_i * d_i)
987                  endif
988 <                ri = 1.0_dp / BigR
988 >                ri = 1.0d0 / BigR
989                  scale = rij * ri                
990               else
991                  if (j_is_SplitDipole) then
992 <                   BigR = sqrt(r2 + 0.25_dp * d_j * d_j)
993 <                   ri = 1.0_dp / BigR
992 >                   BigR = sqrt(r2 + 0.25d0 * d_j * d_j)
993 >                   ri = 1.0d0 / BigR
994                     scale = rij * ri                            
995                  else                
996                     ri = riji
997 <                   scale = 1.0_dp
997 >                   scale = 1.0d0
998                  endif
999               endif
1000              
1001               sc2 = scale * scale
1002  
1003 <             vterm = pref * ri3 * (ct_ij - 3.0d0 * ct_i * ct_j * sc2)
1003 >             pot_term = (ct_ij - 3.0d0 * ct_i * ct_j * sc2)
1004 >             vterm = pref * ( ri3*pot_term*f1 + (ct_i * ct_j)*f2 )
1005               vpair = vpair + vterm
1006               epot = epot + sw*vterm
1007              
1008 <             a1 = 5.0d0 * ct_i * ct_j * sc2 - ct_ij
1008 >             f13 = f1+f3
1009 >             f134 = f13 + f4
1010              
1011 <             dudx = dudx + sw*pref*3.0d0*ri4*scale &
1012 <                             *(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
1013 <             dudy = dudy + sw*pref*3.0d0*ri4*scale &
1014 <                             *(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
1015 <             dudz = dudz + sw*pref*3.0d0*ri4*scale &
1016 <                             *(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
1017 <            
1018 <             duduz_i(1) = duduz_i(1) + sw*pref*ri3 &
1019 <                                         *(uz_j(1) - 3.0d0*ct_j*xhat*sc2)
1020 <             duduz_i(2) = duduz_i(2) + sw*pref*ri3 &
1021 <                                         *(uz_j(2) - 3.0d0*ct_j*yhat*sc2)
1022 <             duduz_i(3) = duduz_i(3) + sw*pref*ri3 &
1023 <                                         *(uz_j(3) - 3.0d0*ct_j*zhat*sc2)
1011 > !!$             dudx = dudx + sw*pref * ( ri4*scale*( &
1012 > !!$                  3.0d0*(a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))*f1 &
1013 > !!$                  - pot_term*f3) &
1014 > !!$                  + 2.0d0*ct_i*ct_j*xhat*(ct_i*uz_j(1)+ct_j*uz_i(1))*f3 &
1015 > !!$                  + (ct_i * ct_j)*f4 )
1016 > !!$             dudy = dudy + sw*pref * ( ri4*scale*( &
1017 > !!$                  3.0d0*(a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))*f1 &
1018 > !!$                  - pot_term*f3) &
1019 > !!$                  + 2.0d0*ct_i*ct_j*yhat*(ct_i*uz_j(2)+ct_j*uz_i(2))*f3 &
1020 > !!$                  + (ct_i * ct_j)*f4 )
1021 > !!$             dudz = dudz + sw*pref * ( ri4*scale*( &
1022 > !!$                  3.0d0*(a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))*f1 &
1023 > !!$                  - pot_term*f3) &
1024 > !!$                  + 2.0d0*ct_i*ct_j*zhat*(ct_i*uz_j(3)+ct_j*uz_i(3))*f3 &
1025 > !!$                  + (ct_i * ct_j)*f4 )
1026 >
1027 >             dudx = dudx + sw*pref * ( ri4*scale*( &
1028 >                  15.0d0*(ct_i * ct_j * sc2)*xhat*f134 - &
1029 >                  3.0d0*(ct_i*uz_j(1) + ct_j*uz_i(1) + ct_ij*xhat)*f134) )
1030 >             dudy = dudy + sw*pref * ( ri4*scale*( &
1031 >                  15.0d0*(ct_i * ct_j * sc2)*yhat*f134 - &
1032 >                  3.0d0*(ct_i*uz_j(2) + ct_j*uz_i(2) + ct_ij*yhat)*f134) )
1033 >             dudz = dudz + sw*pref * ( ri4*scale*( &
1034 >                  15.0d0*(ct_i * ct_j * sc2)*zhat*f134 - &
1035 >                  3.0d0*(ct_i*uz_j(3) + ct_j*uz_i(3) + ct_ij*zhat)*f134) )
1036              
1037 <             duduz_j(1) = duduz_j(1) + sw*pref*ri3 &
1038 <                                         *(uz_i(1) - 3.0d0*ct_i*xhat*sc2)
1039 <             duduz_j(2) = duduz_j(2) + sw*pref*ri3 &
1040 <                                         *(uz_i(2) - 3.0d0*ct_i*yhat*sc2)
1041 <             duduz_j(3) = duduz_j(3) + sw*pref*ri3 &
1042 <                                         *(uz_i(3) - 3.0d0*ct_i*zhat*sc2)
1037 >             duduz_i(1) = duduz_i(1) + sw*pref * &
1038 >                  ( ri3*(uz_j(1) - 3.0d0*ct_j*xhat*sc2)*f1 + (ct_j*xhat)*f2 )
1039 >             duduz_i(2) = duduz_i(2) + sw*pref * &
1040 >                  ( ri3*(uz_j(2) - 3.0d0*ct_j*yhat*sc2)*f1 + (ct_j*yhat)*f2 )
1041 >             duduz_i(3) = duduz_i(3) + sw*pref * &
1042 >                  ( ri3*(uz_j(3) - 3.0d0*ct_j*zhat*sc2)*f1 + (ct_j*zhat)*f2 )
1043 >            
1044 >             duduz_j(1) = duduz_j(1) + sw*pref * &
1045 >                  ( ri3*(uz_i(1) - 3.0d0*ct_i*xhat*sc2)*f1 + (ct_i*xhat)*f2 )
1046 >             duduz_j(2) = duduz_j(2) + sw*pref * &
1047 >                  ( ri3*(uz_i(2) - 3.0d0*ct_i*yhat*sc2)*f1 + (ct_i*yhat)*f2 )
1048 >             duduz_j(3) = duduz_j(3) + sw*pref * &
1049 >                  ( ri3*(uz_i(3) - 3.0d0*ct_i*zhat*sc2)*f1 + (ct_i*zhat)*f2 )
1050            endif
1051         endif
1052      endif
1053  
1054      if (i_is_Quadrupole) then
1055         if (j_is_Charge) then
1056 +          if (screeningMethod .eq. DAMPED) then
1057 +             f0 = derfc(dampingAlpha*rij)
1058 +             varEXP = exp(-alpha2*rij*rij)
1059 +             f1 = alphaPi*rij*varEXP + f0
1060 +             f2 = alphaPi*2.0d0*alpha2*varEXP
1061 +             f3 = f2*rij*rij*rij
1062 +             f4 = 2.0d0*alpha2*f2*rij
1063 +          endif
1064  
1065            ri2 = riji * riji
1066            ri3 = ri2 * riji
# Line 1150 | Line 1069 | contains
1069            cy2 = cy_i * cy_i
1070            cz2 = cz_i * cz_i
1071  
1072 < !!$          if (summationMethod .eq. UNDAMPED_WOLF) then
1073 < !!$             pref = pre14 * q_j / 3.0_dp
1074 < !!$             vterm1 = pref * ri3*( qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1075 < !!$                  qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1076 < !!$                  qzz_i * (3.0_dp*cz2 - 1.0_dp) )
1077 < !!$             vterm2 = pref * rcuti3*( qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1078 < !!$                  qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1079 < !!$                  qzz_i * (3.0_dp*cz2 - 1.0_dp) )
1080 < !!$             vpair = vpair + ( vterm1 - vterm2 )
1081 < !!$             epot = epot + sw*( vterm1 - vterm2 )
1082 < !!$            
1083 < !!$             dudx = dudx - sw*(5.0_dp*(vterm1*riji*xhat-vterm2*rcuti2*d(1))) +&
1084 < !!$                  sw*pref * ( (ri4 - rcuti4)*(qxx_i*(6.0_dp*cx_i*ux_i(1)) - &
1085 < !!$                  qxx_i*2.0_dp*(xhat - rcuti*d(1))) + &
1086 < !!$                  (ri4 - rcuti4)*(qyy_i*(6.0_dp*cy_i*uy_i(1)) - &
1087 < !!$                  qyy_i*2.0_dp*(xhat - rcuti*d(1))) + &
1088 < !!$                  (ri4 - rcuti4)*(qzz_i*(6.0_dp*cz_i*uz_i(1)) - &
1089 < !!$                  qzz_i*2.0_dp*(xhat - rcuti*d(1))) )
1090 < !!$             dudy = dudy - sw*(5.0_dp*(vterm1*riji*yhat-vterm2*rcuti2*d(2))) +&
1091 < !!$                  sw*pref * ( (ri4 - rcuti4)*(qxx_i*(6.0_dp*cx_i*ux_i(2)) - &
1092 < !!$                  qxx_i*2.0_dp*(yhat - rcuti*d(2))) + &
1093 < !!$                  (ri4 - rcuti4)*(qyy_i*(6.0_dp*cy_i*uy_i(2)) - &
1094 < !!$                  qyy_i*2.0_dp*(yhat - rcuti*d(2))) + &
1095 < !!$                  (ri4 - rcuti4)*(qzz_i*(6.0_dp*cz_i*uz_i(2)) - &
1096 < !!$                  qzz_i*2.0_dp*(yhat - rcuti*d(2))) )
1097 < !!$             dudz = dudz - sw*(5.0_dp*(vterm1*riji*zhat-vterm2*rcuti2*d(3))) +&
1098 < !!$                  sw*pref * ( (ri4 - rcuti4)*(qxx_i*(6.0_dp*cx_i*ux_i(3)) - &
1099 < !!$                  qxx_i*2.0_dp*(zhat - rcuti*d(3))) + &
1100 < !!$                  (ri4 - rcuti4)*(qyy_i*(6.0_dp*cy_i*uy_i(3)) - &
1101 < !!$                  qyy_i*2.0_dp*(zhat - rcuti*d(3))) + &
1102 < !!$                  (ri4 - rcuti4)*(qzz_i*(6.0_dp*cz_i*uz_i(3)) - &
1103 < !!$                  qzz_i*2.0_dp*(zhat - rcuti*d(3))) )
1104 < !!$            
1105 < !!$             dudux_i(1) = dudux_i(1) + sw*pref*(ri3*(qxx_i*6.0_dp*cx_i*xhat) -&
1106 < !!$                  rcuti4*(qxx_i*6.0_dp*cx_i*d(1)))
1107 < !!$             dudux_i(2) = dudux_i(2) + sw*pref*(ri3*(qxx_i*6.0_dp*cx_i*yhat) -&
1108 < !!$                  rcuti4*(qxx_i*6.0_dp*cx_i*d(2)))
1109 < !!$             dudux_i(3) = dudux_i(3) + sw*pref*(ri3*(qxx_i*6.0_dp*cx_i*zhat) -&
1110 < !!$                  rcuti4*(qxx_i*6.0_dp*cx_i*d(3)))
1111 < !!$            
1112 < !!$             duduy_i(1) = duduy_i(1) + sw*pref*(ri3*(qyy_i*6.0_dp*cy_i*xhat) -&
1113 < !!$                  rcuti4*(qyy_i*6.0_dp*cx_i*d(1)))
1114 < !!$             duduy_i(2) = duduy_i(2) + sw*pref*(ri3*(qyy_i*6.0_dp*cy_i*yhat) -&
1115 < !!$                  rcuti4*(qyy_i*6.0_dp*cx_i*d(2)))
1116 < !!$             duduy_i(3) = duduy_i(3) + sw*pref*(ri3*(qyy_i*6.0_dp*cy_i*zhat) -&
1117 < !!$                  rcuti4*(qyy_i*6.0_dp*cx_i*d(3)))
1118 < !!$            
1119 < !!$             duduz_i(1) = duduz_i(1) + sw*pref*(ri3*(qzz_i*6.0_dp*cz_i*xhat) -&
1201 < !!$                  rcuti4*(qzz_i*6.0_dp*cx_i*d(1)))
1202 < !!$             duduz_i(2) = duduz_i(2) + sw*pref*(ri3*(qzz_i*6.0_dp*cz_i*yhat) -&
1203 < !!$                  rcuti4*(qzz_i*6.0_dp*cx_i*d(2)))
1204 < !!$             duduz_i(3) = duduz_i(3) + sw*pref*(ri3*(qzz_i*6.0_dp*cz_i*zhat) -&
1205 < !!$                  rcuti4*(qzz_i*6.0_dp*cx_i*d(3)))
1206 < !!$
1207 < !!$          else
1208 <             pref = pre14 * q_j / 3.0_dp
1209 <             vterm = pref * ri3 * (qxx_i * (3.0_dp*cx2 - 1.0_dp) + &
1210 <                  qyy_i * (3.0_dp*cy2 - 1.0_dp) + &
1211 <                  qzz_i * (3.0_dp*cz2 - 1.0_dp))
1212 <             vpair = vpair + vterm
1213 <             epot = epot + sw*vterm
1214 <            
1215 <             dudx = dudx - 5.0_dp*sw*vterm*riji*xhat + sw*pref*ri4 * ( &
1216 <                  qxx_i*(6.0_dp*cx_i*ux_i(1) - 2.0_dp*xhat) + &
1217 <                  qyy_i*(6.0_dp*cy_i*uy_i(1) - 2.0_dp*xhat) + &
1218 <                  qzz_i*(6.0_dp*cz_i*uz_i(1) - 2.0_dp*xhat) )
1219 <             dudy = dudy - 5.0_dp*sw*vterm*riji*yhat + sw*pref*ri4 * ( &
1220 <                  qxx_i*(6.0_dp*cx_i*ux_i(2) - 2.0_dp*yhat) + &
1221 <                  qyy_i*(6.0_dp*cy_i*uy_i(2) - 2.0_dp*yhat) + &
1222 <                  qzz_i*(6.0_dp*cz_i*uz_i(2) - 2.0_dp*yhat) )
1223 <             dudz = dudz - 5.0_dp*sw*vterm*riji*zhat + sw*pref*ri4 * ( &
1224 <                  qxx_i*(6.0_dp*cx_i*ux_i(3) - 2.0_dp*zhat) + &
1225 <                  qyy_i*(6.0_dp*cy_i*uy_i(3) - 2.0_dp*zhat) + &
1226 <                  qzz_i*(6.0_dp*cz_i*uz_i(3) - 2.0_dp*zhat) )
1227 <            
1228 <             dudux_i(1) = dudux_i(1) + sw*pref*ri3*(qxx_i*6.0_dp*cx_i*xhat)
1229 <             dudux_i(2) = dudux_i(2) + sw*pref*ri3*(qxx_i*6.0_dp*cx_i*yhat)
1230 <             dudux_i(3) = dudux_i(3) + sw*pref*ri3*(qxx_i*6.0_dp*cx_i*zhat)
1231 <            
1232 <             duduy_i(1) = duduy_i(1) + sw*pref*ri3*(qyy_i*6.0_dp*cy_i*xhat)
1233 <             duduy_i(2) = duduy_i(2) + sw*pref*ri3*(qyy_i*6.0_dp*cy_i*yhat)
1234 <             duduy_i(3) = duduy_i(3) + sw*pref*ri3*(qyy_i*6.0_dp*cy_i*zhat)
1235 <            
1236 <             duduz_i(1) = duduz_i(1) + sw*pref*ri3*(qzz_i*6.0_dp*cz_i*xhat)
1237 <             duduz_i(2) = duduz_i(2) + sw*pref*ri3*(qzz_i*6.0_dp*cz_i*yhat)
1238 <             duduz_i(3) = duduz_i(3) + sw*pref*ri3*(qzz_i*6.0_dp*cz_i*zhat)
1239 < !!$          endif
1072 >          pref = pre14 * q_j / 3.0d0
1073 >          pot_term = ri3 * (qxx_i * (3.0d0*cx2 - 1.0d0) + &
1074 >                            qyy_i * (3.0d0*cy2 - 1.0d0) + &
1075 >                            qzz_i * (3.0d0*cz2 - 1.0d0))
1076 >          vterm = pref * (pot_term*f1 + (qxx_i*cx2 + qyy_i*cy2 + qzz_i*cz2)*f2)
1077 >          vpair = vpair + vterm
1078 >          epot = epot + sw*vterm
1079 >          
1080 >          dudx = dudx - sw*pref*pot_term*riji*xhat*(5.0d0*f1 + f3) + &
1081 >               sw*pref*ri4 * ( &
1082 >               qxx_i*(2.0d0*cx_i*ux_i(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) + &
1083 >               qyy_i*(2.0d0*cy_i*uy_i(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) + &
1084 >               qzz_i*(2.0d0*cz_i*uz_i(1)*(3.0d0*f1 + f3) - 2.0d0*xhat*f1) ) &
1085 >               + (qxx_i*cx2 + qyy_i*cy2 + qzz_i*cz2)*f4
1086 >          dudy = dudy - sw*pref*pot_term*riji*yhat*(5.0d0*f1 + f3) + &
1087 >               sw*pref*ri4 * ( &
1088 >               qxx_i*(2.0d0*cx_i*ux_i(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) + &
1089 >               qyy_i*(2.0d0*cy_i*uy_i(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) + &
1090 >               qzz_i*(2.0d0*cz_i*uz_i(2)*(3.0d0*f1 + f3) - 2.0d0*yhat*f1) ) &
1091 >               + (qxx_i*cx2 + qyy_i*cy2 + qzz_i*cz2)*f4
1092 >          dudz = dudz - sw*pref*pot_term*riji*zhat*(5.0d0*f1 + f3) + &
1093 >               sw*pref*ri4 * ( &
1094 >               qxx_i*(2.0d0*cx_i*ux_i(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) + &
1095 >               qyy_i*(2.0d0*cy_i*uy_i(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) + &
1096 >               qzz_i*(2.0d0*cz_i*uz_i(3)*(3.0d0*f1 + f3) - 2.0d0*zhat*f1) ) &
1097 >               + (qxx_i*cx2 + qyy_i*cy2 + qzz_i*cz2)*f4
1098 >          
1099 >          dudux_i(1) = dudux_i(1) + sw*pref*( ri3*(qxx_i*2.0d0*cx_i*xhat) &
1100 >               * (3.0d0*f1 + f3) )
1101 >          dudux_i(2) = dudux_i(2) + sw*pref*( ri3*(qxx_i*2.0d0*cx_i*yhat) &
1102 >               * (3.0d0*f1 + f3) )
1103 >          dudux_i(3) = dudux_i(3) + sw*pref*( ri3*(qxx_i*2.0d0*cx_i*zhat) &
1104 >               * (3.0d0*f1 + f3) )
1105 >          
1106 >          duduy_i(1) = duduy_i(1) + sw*pref*( ri3*(qyy_i*2.0d0*cy_i*xhat) &
1107 >               * (3.0d0*f1 + f3) )
1108 >          duduy_i(2) = duduy_i(2) + sw*pref*( ri3*(qyy_i*2.0d0*cy_i*yhat) &
1109 >               * (3.0d0*f1 + f3) )
1110 >          duduy_i(3) = duduy_i(3) + sw*pref*( ri3*(qyy_i*2.0d0*cy_i*zhat) &
1111 >               * (3.0d0*f1 + f3) )
1112 >          
1113 >          duduz_i(1) = duduz_i(1) + sw*pref*( ri3*(qzz_i*2.0d0*cz_i*xhat) &
1114 >               * (3.0d0*f1 + f3) )
1115 >          duduz_i(2) = duduz_i(2) + sw*pref*( ri3*(qzz_i*2.0d0*cz_i*yhat) &
1116 >               * (3.0d0*f1 + f3) )
1117 >          duduz_i(3) = duduz_i(3) + sw*pref*( ri3*(qzz_i*2.0d0*cz_i*zhat) &
1118 >               * (3.0d0*f1 + f3) )
1119 >
1120         endif
1121      endif
1122  
# Line 1397 | Line 1277 | contains
1277            
1278         endif
1279  
1280 <    elseif (summationMethod .eq. SHIFTED_FORCE) then
1280 >    elseif ( (summationMethod .eq. SHIFTED_FORCE) .or. &
1281 >         (summationMethod .eq. SHIFTED_POTENTIAL) ) then
1282         if (ElectrostaticMap(atid1)%is_Charge) then
1283            c1 = getCharge(atid1)
1284            
1285            if (screeningMethod .eq. DAMPED) then
1286 <             mypot = mypot - (f0c * rcuti * 0.5_dp + &
1286 >             mypot = mypot - (f0c * rcuti * 0.5d0 + &
1287                    dampingAlpha*invRootPi) * c1 * c1    
1288              
1289            else            
1290 <             mypot = mypot - (rcuti * 0.5_dp * c1 * c1)
1290 >             mypot = mypot - (rcuti * 0.5d0 * c1 * c1)
1291              
1292            endif
1293         endif
# Line 1446 | Line 1327 | contains
1327         call checkSummationMethod()
1328      endif
1329  
1330 <    dudx = 0.0d0
1331 <    dudy = 0.0d0
1332 <    dudz = 0.0d0
1330 >    dudx = zero
1331 >    dudy = zero
1332 >    dudz = zero
1333  
1334      riji = 1.0d0/rij
1335  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines