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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines