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 2339 by chrisfen, Wed Sep 28 18:47:17 2005 UTC vs.
Revision 2399 by chrisfen, Wed Oct 26 23:31:40 2005 UTC

# Line 54 | Line 54 | module electrostatic_module
54  
55    PRIVATE
56  
57 +
58   #define __FORTRAN90
59 + #include "UseTheForce/DarkSide/fInteractionMap.h"
60   #include "UseTheForce/DarkSide/fElectrostaticSummationMethod.h"
61  
62 +
63    !! these prefactors convert the multipole interactions into kcal / mol
64    !! all were computed assuming distances are measured in angstroms
65    !! Charge-Charge, assuming charges are measured in electrons
# Line 75 | Line 78 | module electrostatic_module
78    integer, save :: summationMethod = NONE
79    logical, save :: summationMethodChecked = .false.
80    real(kind=DP), save :: defaultCutoff = 0.0_DP
81 +  real(kind=DP), save :: defaultCutoff2 = 0.0_DP
82    logical, save :: haveDefaultCutoff = .false.
83    real(kind=DP), save :: dampingAlpha = 0.0_DP
84    logical, save :: haveDampingAlpha = .false.
85 <  real(kind=DP), save :: dielectric = 0.0_DP
85 >  real(kind=DP), save :: dielectric = 1.0_DP
86    logical, save :: haveDielectric = .false.
87    real(kind=DP), save :: constERFC = 0.0_DP
88    real(kind=DP), save :: constEXP = 0.0_DP
89    logical, save :: haveDWAconstants = .false.
90 <  real(kind=dp), save :: rcuti = 0.0_dp
91 <  real(kind=dp), save :: rcuti2 = 0.0_dp
92 <  real(kind=dp), save :: rcuti3 = 0.0_dp
93 <  real(kind=dp), save :: rcuti4 = 0.0_dp
94 <  real(kind=dp), save :: alphaPi = 0.0_dp
95 <  real(kind=dp), save :: invRootPi = 0.0_dp
96 <  
90 >  real(kind=dp), save :: rcuti = 0.0_DP
91 >  real(kind=dp), save :: rcuti2 = 0.0_DP
92 >  real(kind=dp), save :: rcuti3 = 0.0_DP
93 >  real(kind=dp), save :: rcuti4 = 0.0_DP
94 >  real(kind=dp), save :: alphaPi = 0.0_DP
95 >  real(kind=dp), save :: invRootPi = 0.0_DP
96 >  real(kind=dp), save :: rrf = 1.0_DP
97 >  real(kind=dp), save :: rt = 1.0_DP
98 >  real(kind=dp), save :: rrfsq = 1.0_DP
99 >  real(kind=dp), save :: preRF = 0.0_DP
100 >  real(kind=dp), save :: preRF2 = 0.0_DP
101 >  logical, save :: preRFCalculated = .false.
102 >
103   #ifdef __IFC
104   ! error function for ifc version > 7.
105    double precision, external :: derfc
# Line 99 | Line 109 | module electrostatic_module
109    public :: setElectrostaticCutoffRadius
110    public :: setDampedWolfAlpha
111    public :: setReactionFieldDielectric
112 +  public :: setReactionFieldPrefactor
113    public :: newElectrostaticType
114    public :: setCharge
115    public :: setDipoleMoment
# Line 107 | Line 118 | module electrostatic_module
118    public :: doElectrostaticPair
119    public :: getCharge
120    public :: getDipoleMoment
110  public :: pre22
121    public :: destroyElectrostaticTypes
122 +  public :: rf_self_self
123 +  public :: rf_self_excludes
124  
125    type :: Electrostatic
126       integer :: c_ident
# Line 138 | Line 150 | contains
150  
151    end subroutine setElectrostaticSummationMethod
152  
153 <  subroutine setElectrostaticCutoffRadius(thisRcut)
153 >  subroutine setElectrostaticCutoffRadius(thisRcut, thisRsw)
154      real(kind=dp), intent(in) :: thisRcut
155 +    real(kind=dp), intent(in) :: thisRsw
156      defaultCutoff = thisRcut
157 +    rrf = defaultCutoff
158 +    rt = thisRsw
159      haveDefaultCutoff = .true.
160    end subroutine setElectrostaticCutoffRadius
161  
# Line 155 | Line 170 | contains
170      dielectric = thisDielectric
171      haveDielectric = .true.
172    end subroutine setReactionFieldDielectric
173 +
174 +  subroutine setReactionFieldPrefactor
175 +    if (haveDefaultCutoff .and. haveDielectric) then
176 +       defaultCutoff2 = defaultCutoff*defaultCutoff
177 +       preRF = (dielectric-1.0d0) / &
178 +            ((2.0d0*dielectric+1.0d0)*defaultCutoff2*defaultCutoff)
179 +       preRF2 = 2.0d0*preRF
180 +       preRFCalculated = .true.
181 +    else if (.not.haveDefaultCutoff) then
182 +       call handleError("setReactionFieldPrefactor", "Default cutoff not set")
183 +    else
184 +       call handleError("setReactionFieldPrefactor", "Dielectric not set")
185 +    endif
186 +  end subroutine setReactionFieldPrefactor
187  
188    subroutine newElectrostaticType(c_ident, is_Charge, is_Dipole, &
189         is_SplitDipole, is_Quadrupole, is_Tap, status)
# Line 392 | Line 421 | contains
421            constERFC = derfc(dampingAlpha*defaultCutoff)
422            invRootPi = 0.56418958354775628695d0
423            alphaPi = 2*dampingAlpha*invRootPi
424 <          
424 >  
425            haveDWAconstants = .true.
426         endif
427      endif
# Line 409 | Line 438 | contains
438  
439  
440    subroutine doElectrostaticPair(atom1, atom2, d, rij, r2, sw, &
441 <       vpair, fpair, pot, eFrame, f, t, do_pot)
441 >       vpair, fpair, pot, eFrame, f, t, do_pot, indirect_only)
442  
443 <    logical, intent(in) :: do_pot
443 >    logical, intent(in) :: do_pot, indirect_only
444  
445      integer, intent(in) :: atom1, atom2
446      integer :: localError
# Line 448 | Line 477 | contains
477      real (kind=dp) :: dudx, dudy, dudz
478      real (kind=dp) :: scale, sc2, bigR
479      real (kind=dp) :: varERFC, varEXP
480 +    real (kind=dp) :: limScale
481 +    real (kind=dp) :: preVal, rfVal
482  
483      if (.not.allocated(ElectrostaticMap)) then
484         call handleError("electrostatic", "no ElectrostaticMap was present before first call of do_electrostatic_pair!")
# Line 456 | Line 487 | contains
487  
488      if (.not.summationMethodChecked) then
489         call checkSummationMethod()
459      
490      endif
491  
492 +    if (.not.preRFCalculated) then
493 +       call setReactionFieldPrefactor()
494 +    endif
495  
496   #ifdef IS_MPI
497      me1 = atid_Row(atom1)
# Line 471 | Line 504 | contains
504      !! some variables we'll need independent of electrostatic type:
505  
506      riji = 1.0d0 / rij
507 <
507 >  
508      xhat = d(1) * riji
509      yhat = d(2) * riji
510      zhat = d(3) * riji
# Line 612 | Line 645 | contains
645         if (j_is_Charge) then
646  
647            if (summationMethod .eq. UNDAMPED_WOLF) then
615
648               vterm = pre11 * q_i * q_j * (riji - rcuti)
649               vpair = vpair + vterm
650               epot = epot + sw*vterm
651              
652 <             dudr  = -sw*pre11*q_i*q_j * (riji*riji*riji - rcuti2*rcuti)
652 >             dudr  = -sw*pre11*q_i*q_j * (riji*riji-rcuti2)*riji
653              
654               dudx = dudx + dudr * d(1)
655               dudy = dudy + dudr * d(2)
656               dudz = dudz + dudr * d(3)
657  
658            elseif (summationMethod .eq. DAMPED_WOLF) then
627
659               varERFC = derfc(dampingAlpha*rij)
660               varEXP = exp(-dampingAlpha*dampingAlpha*rij*rij)
661               vterm = pre11 * q_i * q_j * (varERFC*riji - constERFC*rcuti)
662               vpair = vpair + vterm
663               epot = epot + sw*vterm
664              
665 <             dudr  = -sw*pre11*q_i*q_j * ( riji*(varERFC*riji*riji &
666 <                                                 + alphaPi*varEXP) &
667 <                                         - rcuti*(constERFC*rcuti2 &
668 <                                                 + alphaPi*constEXP) )
665 >             dudr  = -sw*pre11*q_i*q_j * ( riji*((varERFC*riji*riji &
666 >                                                  + alphaPi*varEXP) &
667 >                                                 - (constERFC*rcuti2 &
668 >                                                    + alphaPi*constEXP)) )
669              
670               dudx = dudx + dudr * d(1)
671               dudy = dudy + dudr * d(2)
672               dudz = dudz + dudr * d(3)
673  
674 <          else
674 >          elseif (summationMethod .eq. REACTION_FIELD) then
675 >             preVal = pre11 * q_i * q_j
676 >             rfVal = preRF*rij*rij
677 >             vterm = preVal * ( riji + rfVal )
678 >            
679 >             vpair = vpair + vterm
680 >             epot = epot + sw*vterm
681 >            
682 >             dudr  = sw * preVal * ( 2.0d0*rfVal - riji )*riji
683 >            
684 >             dudx = dudx + dudr * xhat
685 >             dudy = dudy + dudr * yhat
686 >             dudz = dudz + dudr * zhat
687  
688 +          else
689               vterm = pre11 * q_i * q_j * riji
690               vpair = vpair + vterm
691               epot = epot + sw*vterm
# Line 684 | Line 728 | contains
728               duduz_j(2) = duduz_j(2) - sw*pref*( ri2*yhat - d(2)*rcuti3 )
729               duduz_j(3) = duduz_j(3) - sw*pref*( ri2*zhat - d(3)*rcuti3 )
730  
731 +          elseif (summationMethod .eq. REACTION_FIELD) then
732 +             ri2 = riji * riji
733 +             ri3 = ri2 * riji
734 +    
735 +             pref = pre12 * q_i * mu_j
736 +             vterm = - pref * ct_j * ( ri2 - preRF2*rij )
737 +             vpair = vpair + vterm
738 +             epot = epot + sw*vterm
739 +            
740 +             !! this has a + sign in the () because the rij vector is
741 +             !! r_j - r_i and the charge-dipole potential takes the origin
742 +             !! as the point dipole, which is atom j in this case.
743 +            
744 +             dudx = dudx - sw*pref*( ri3*(uz_j(1) - 3.0d0*ct_j*xhat) - &
745 +                                     preRF2*uz_j(1) )
746 +             dudy = dudy - sw*pref*( ri3*(uz_j(2) - 3.0d0*ct_j*yhat) - &
747 +                                     preRF2*uz_j(2) )
748 +             dudz = dudz - sw*pref*( ri3*(uz_j(3) - 3.0d0*ct_j*zhat) - &
749 +                                     preRF2*uz_j(3) )        
750 +             duduz_j(1) = duduz_j(1) - sw*pref * xhat * ( ri2 - preRF2*rij )
751 +             duduz_j(2) = duduz_j(2) - sw*pref * yhat * ( ri2 - preRF2*rij )
752 +             duduz_j(3) = duduz_j(3) - sw*pref * zhat * ( ri2 - preRF2*rij )
753 +
754            else
755               if (j_is_SplitDipole) then
756                  BigR = sqrt(r2 + 0.25_dp * d_j * d_j)
# Line 835 | Line 902 | contains
902               vpair = vpair + vterm
903               epot = epot + sw*vterm
904              
838             !! this has a + sign in the () because the rij vector is
839             !! r_j - r_i and the charge-dipole potential takes the origin
840             !! as the point dipole, which is atom j in this case.
841            
905               dudx = dudx + sw*pref * ( ri3*( uz_i(1) - 3.0d0*ct_i*xhat) &
906                    - rcuti3*( uz_i(1) - 3.0d0*ct_i*d(1)*rcuti ) )
907               dudy = dudy + sw*pref * ( ri3*( uz_i(2) - 3.0d0*ct_i*yhat) &
# Line 846 | Line 909 | contains
909               dudz = dudz + sw*pref * ( ri3*( uz_i(3) - 3.0d0*ct_i*zhat) &
910                    - rcuti3*( uz_i(3) - 3.0d0*ct_i*d(3)*rcuti ) )
911              
912 <             duduz_i(1) = duduz_i(1) - sw*pref*( ri2*xhat - d(1)*rcuti3 )
913 <             duduz_i(2) = duduz_i(2) - sw*pref*( ri2*yhat - d(2)*rcuti3 )
914 <             duduz_i(3) = duduz_i(3) - sw*pref*( ri2*zhat - d(3)*rcuti3 )
912 >             duduz_i(1) = duduz_i(1) + sw*pref*( ri2*xhat - d(1)*rcuti3 )
913 >             duduz_i(2) = duduz_i(2) + sw*pref*( ri2*yhat - d(2)*rcuti3 )
914 >             duduz_i(3) = duduz_i(3) + sw*pref*( ri2*zhat - d(3)*rcuti3 )
915  
916 +          elseif (summationMethod .eq. REACTION_FIELD) then
917 +             ri2 = riji * riji
918 +             ri3 = ri2 * riji
919 +
920 +             pref = pre12 * q_j * mu_i
921 +             vterm = pref * ct_i * ( ri2 - preRF2*rij )
922 +             vpair = vpair + vterm
923 +             epot = epot + sw*vterm
924 +            
925 +             dudx = dudx + sw*pref * ( ri3*(uz_i(1) - 3.0d0*ct_i*xhat) - &
926 +                  preRF2*uz_i(1) )
927 +             dudy = dudy + sw*pref * ( ri3*(uz_i(2) - 3.0d0*ct_i*yhat) - &
928 +                  preRF2*uz_i(2) )
929 +             dudz = dudz + sw*pref * ( ri3*(uz_i(3) - 3.0d0*ct_i*zhat) - &
930 +                  preRF2*uz_i(3) )
931 +            
932 +             duduz_i(1) = duduz_i(1) + sw*pref * xhat * ( ri2 - preRF2*rij )
933 +             duduz_i(2) = duduz_i(2) + sw*pref * yhat * ( ri2 - preRF2*rij )
934 +             duduz_i(3) = duduz_i(3) + sw*pref * zhat * ( ri2 - preRF2*rij )
935 +
936            else
937               if (i_is_SplitDipole) then
938                  BigR = sqrt(r2 + 0.25_dp * d_i * d_i)
# Line 919 | Line 1002 | contains
1002               duduz_j(3) = duduz_j(3) + sw*pref*(ri3*(uz_i(3)-3.0d0*ct_i*zhat) &
1003                    - rcuti3*(uz_i(3) - 3.0d0*ct_i*d(3)*rcuti))
1004  
1005 +         elseif (summationMethod .eq. REACTION_FIELD) then
1006 +             ct_ij = uz_i(1)*uz_j(1) + uz_i(2)*uz_j(2) + uz_i(3)*uz_j(3)
1007 +
1008 +             ri2 = riji * riji
1009 +             ri3 = ri2 * riji
1010 +             ri4 = ri2 * ri2
1011 +
1012 +             pref = pre22 * mu_i * mu_j
1013 +              
1014 +             vterm = pref*( ri3*(ct_ij - 3.0d0 * ct_i * ct_j) - &
1015 +                  preRF2*ct_ij )
1016 +             vpair = vpair + vterm
1017 +             epot = epot + sw*vterm
1018 +            
1019 +             a1 = 5.0d0 * ct_i * ct_j - ct_ij
1020 +            
1021 +             dudx = dudx + sw*pref*3.0d0*ri4 &
1022 +                             * (a1*xhat-ct_i*uz_j(1)-ct_j*uz_i(1))
1023 +             dudy = dudy + sw*pref*3.0d0*ri4 &
1024 +                             * (a1*yhat-ct_i*uz_j(2)-ct_j*uz_i(2))
1025 +             dudz = dudz + sw*pref*3.0d0*ri4 &
1026 +                             * (a1*zhat-ct_i*uz_j(3)-ct_j*uz_i(3))
1027 +            
1028 +             duduz_i(1) = duduz_i(1) + sw*pref*(ri3*(uz_j(1)-3.0d0*ct_j*xhat) &
1029 +                  - preRF2*uz_j(1))
1030 +             duduz_i(2) = duduz_i(2) + sw*pref*(ri3*(uz_j(2)-3.0d0*ct_j*yhat) &
1031 +                  - preRF2*uz_j(2))
1032 +             duduz_i(3) = duduz_i(3) + sw*pref*(ri3*(uz_j(3)-3.0d0*ct_j*zhat) &
1033 +                  - preRF2*uz_j(3))
1034 +             duduz_j(1) = duduz_j(1) + sw*pref*(ri3*(uz_i(1)-3.0d0*ct_i*xhat) &
1035 +                  - preRF2*uz_i(1))
1036 +             duduz_j(2) = duduz_j(2) + sw*pref*(ri3*(uz_i(2)-3.0d0*ct_i*yhat) &
1037 +                  - preRF2*uz_i(2))
1038 +             duduz_j(3) = duduz_j(3) + sw*pref*(ri3*(uz_i(3)-3.0d0*ct_i*zhat) &
1039 +                  - preRF2*uz_i(3))
1040 +
1041            else
1042               if (i_is_SplitDipole) then
1043                  if (j_is_SplitDipole) then
# Line 1080 | Line 1199 | contains
1199  
1200      if (do_pot) then
1201   #ifdef IS_MPI
1202 <       pot_row(atom1) = pot_row(atom1) + 0.5d0*epot
1203 <       pot_col(atom2) = pot_col(atom2) + 0.5d0*epot
1202 >       pot_row(ELECTROSTATIC_POT,atom1) = pot_row(ELECTROSTATIC_POT,atom1) + 0.5d0*epot
1203 >       pot_col(ELECTROSTATIC_POT,atom2) = pot_col(ELECTROSTATIC_POT,atom2) + 0.5d0*epot
1204   #else
1205         pot = pot + epot
1206   #endif
# Line 1186 | Line 1305 | contains
1305      return
1306    end subroutine doElectrostaticPair
1307  
1308 <  !! calculates the switching functions and their derivatives for a given
1309 <  subroutine calc_switch(r, mu, scale, dscale)
1310 <
1311 <    real (kind=dp), intent(in) :: r, mu
1312 <    real (kind=dp), intent(inout) :: scale, dscale
1313 <    real (kind=dp) :: rl, ru, mulow, minRatio, temp, scaleVal
1314 <
1315 <    ! distances must be in angstroms
1316 <    rl = 2.75d0
1317 <    ru = 3.75d0
1318 <    mulow = 0.0d0 !3.3856d0 ! 1.84 * 1.84
1319 <    minRatio = mulow / (mu*mu)
1320 <    scaleVal = 1.0d0 - minRatio
1308 >  subroutine destroyElectrostaticTypes()
1309 >
1310 >    if(allocated(ElectrostaticMap)) deallocate(ElectrostaticMap)
1311 >
1312 >  end subroutine destroyElectrostaticTypes
1313 >
1314 >  subroutine rf_self_self(atom1, eFrame, rfpot, t, do_pot)
1315 >    logical, intent(in) :: do_pot
1316 >    integer, intent(in) :: atom1
1317 >    integer :: atid1
1318 >    real(kind=dp), dimension(9,nLocal) :: eFrame
1319 >    real(kind=dp), dimension(3,nLocal) :: t
1320 >    real(kind=dp) :: mu1
1321 >    real(kind=dp) :: preVal, epot, rfpot
1322 >    real(kind=dp) :: eix, eiy, eiz
1323 >
1324 >    if (.not.preRFCalculated) then
1325 >       call setReactionFieldPrefactor()
1326 >    endif
1327 >
1328 >    ! this is a local only array, so we use the local atom type id's:
1329 >    atid1 = atid(atom1)
1330      
1331 <    if (r.lt.rl) then
1332 <       scale = minRatio
1333 <       dscale = 0.0d0
1334 <    elseif (r.gt.ru) then
1335 <       scale = 1.0d0
1336 <       dscale = 0.0d0
1337 <    else
1338 <       scale = 1.0d0 - scaleVal*((ru + 2.0d0*r - 3.0d0*rl) * (ru-r)**2) &
1339 <                        / ((ru - rl)**3)
1340 <       dscale = -scaleVal * 6.0d0 * (r-ru)*(r-rl)/((ru - rl)**3)    
1331 >    if (ElectrostaticMap(atid1)%is_Dipole) then
1332 >       mu1 = getDipoleMoment(atid1)
1333 >      
1334 >       preVal = pre22 * preRF2 * mu1*mu1
1335 >       rfpot = rfpot - 0.5d0*preVal
1336 >      
1337 >       ! The self-correction term adds into the reaction field vector
1338 >      
1339 >       eix = preVal * eFrame(3,atom1)
1340 >       eiy = preVal * eFrame(6,atom1)
1341 >       eiz = preVal * eFrame(9,atom1)
1342 >      
1343 >       ! once again, this is self-self, so only the local arrays are needed
1344 >       ! even for MPI jobs:
1345 >      
1346 >       t(1,atom1)=t(1,atom1) - eFrame(6,atom1)*eiz + &
1347 >            eFrame(9,atom1)*eiy
1348 >       t(2,atom1)=t(2,atom1) - eFrame(9,atom1)*eix + &
1349 >            eFrame(3,atom1)*eiz
1350 >       t(3,atom1)=t(3,atom1) - eFrame(3,atom1)*eiy + &
1351 >            eFrame(6,atom1)*eix
1352 >      
1353      endif
1354 <        
1354 >    
1355      return
1356 <  end subroutine calc_switch
1356 >  end subroutine rf_self_self
1357  
1358 <  subroutine destroyElectrostaticTypes()
1358 >  subroutine rf_self_excludes(atom1, atom2, sw, eFrame, d, rij, vpair, rfpot, &
1359 >       f, t, do_pot)
1360 >    logical, intent(in) :: do_pot
1361 >    integer, intent(in) :: atom1
1362 >    integer, intent(in) :: atom2
1363 >    logical :: i_is_Charge, j_is_Charge
1364 >    logical :: i_is_Dipole, j_is_Dipole
1365 >    integer :: atid1
1366 >    integer :: atid2
1367 >    real(kind=dp), intent(in) :: rij
1368 >    real(kind=dp), intent(in) :: sw
1369 >    real(kind=dp), intent(in), dimension(3) :: d
1370 >    real(kind=dp), intent(inout) :: vpair
1371 >    real(kind=dp), dimension(9,nLocal) :: eFrame
1372 >    real(kind=dp), dimension(3,nLocal) :: f
1373 >    real(kind=dp), dimension(3,nLocal) :: t
1374 >    real (kind = dp), dimension(3) :: duduz_i
1375 >    real (kind = dp), dimension(3) :: duduz_j
1376 >    real (kind = dp), dimension(3) :: uz_i
1377 >    real (kind = dp), dimension(3) :: uz_j
1378 >    real(kind=dp) :: q_i, q_j, mu_i, mu_j
1379 >    real(kind=dp) :: xhat, yhat, zhat
1380 >    real(kind=dp) :: ct_i, ct_j
1381 >    real(kind=dp) :: ri2, ri3, riji, vterm
1382 >    real(kind=dp) :: pref, preVal, rfVal, rfpot
1383 >    real(kind=dp) :: dudx, dudy, dudz, dudr
1384  
1385 <    if(allocated(ElectrostaticMap)) deallocate(ElectrostaticMap)
1385 >    if (.not.preRFCalculated) then
1386 >       call setReactionFieldPrefactor()
1387 >    endif
1388  
1389 <  end subroutine destroyElectrostaticTypes
1389 >    dudx = 0.0d0
1390 >    dudy = 0.0d0
1391 >    dudz = 0.0d0
1392  
1393 +    riji = 1.0d0/rij
1394 +
1395 +    xhat = d(1) * riji
1396 +    yhat = d(2) * riji
1397 +    zhat = d(3) * riji
1398 +
1399 +    ! this is a local only array, so we use the local atom type id's:
1400 +    atid1 = atid(atom1)
1401 +    atid2 = atid(atom2)
1402 +    i_is_Charge = ElectrostaticMap(atid1)%is_Charge
1403 +    j_is_Charge = ElectrostaticMap(atid2)%is_Charge
1404 +    i_is_Dipole = ElectrostaticMap(atid1)%is_Dipole
1405 +    j_is_Dipole = ElectrostaticMap(atid2)%is_Dipole
1406 +
1407 +    if (i_is_Charge.and.j_is_Charge) then
1408 +       q_i = ElectrostaticMap(atid1)%charge
1409 +       q_j = ElectrostaticMap(atid2)%charge
1410 +      
1411 +       preVal = pre11 * q_i * q_j
1412 +       rfVal = preRF*rij*rij
1413 +       vterm = preVal * rfVal
1414 +
1415 +       rfpot = rfpot + sw*vterm
1416 +      
1417 +       dudr  = sw*preVal * 2.0d0*rfVal*riji
1418 +              
1419 +       dudx = dudx + dudr * xhat
1420 +       dudy = dudy + dudr * yhat
1421 +       dudz = dudz + dudr * zhat
1422 +
1423 +    elseif (i_is_Charge.and.j_is_Dipole) then
1424 +       q_i = ElectrostaticMap(atid1)%charge
1425 +       mu_j = ElectrostaticMap(atid2)%dipole_moment
1426 +       uz_j(1) = eFrame(3,atom2)
1427 +       uz_j(2) = eFrame(6,atom2)
1428 +       uz_j(3) = eFrame(9,atom2)
1429 +       ct_j = uz_j(1)*xhat + uz_j(2)*yhat + uz_j(3)*zhat
1430 +
1431 +       ri2 = riji * riji
1432 +       ri3 = ri2 * riji
1433 +      
1434 +       pref = pre12 * q_i * mu_j
1435 +       vterm = - pref * ct_j * ( ri2 - preRF2*rij )
1436 +       rfpot = rfpot + sw*vterm
1437 +
1438 +       dudx = dudx - sw*pref*( ri3*(uz_j(1)-3.0d0*ct_j*xhat) - preRF2*uz_j(1) )
1439 +       dudy = dudy - sw*pref*( ri3*(uz_j(2)-3.0d0*ct_j*yhat) - preRF2*uz_j(2) )
1440 +       dudz = dudz - sw*pref*( ri3*(uz_j(3)-3.0d0*ct_j*zhat) - preRF2*uz_j(3) )
1441 +
1442 +       duduz_j(1) = duduz_j(1) - sw * pref * xhat * ( ri2 - preRF2*rij )
1443 +       duduz_j(2) = duduz_j(2) - sw * pref * yhat * ( ri2 - preRF2*rij )
1444 +       duduz_j(3) = duduz_j(3) - sw * pref * zhat * ( ri2 - preRF2*rij )
1445 +              
1446 +    elseif (i_is_Dipole.and.j_is_Charge) then
1447 +       mu_i = ElectrostaticMap(atid1)%dipole_moment
1448 +       q_j = ElectrostaticMap(atid2)%charge
1449 +       uz_i(1) = eFrame(3,atom1)
1450 +       uz_i(2) = eFrame(6,atom1)
1451 +       uz_i(3) = eFrame(9,atom1)
1452 +       ct_i = uz_i(1)*xhat + uz_i(2)*yhat + uz_i(3)*zhat
1453 +
1454 +       ri2 = riji * riji
1455 +       ri3 = ri2 * riji
1456 +      
1457 +       pref = pre12 * q_j * mu_i
1458 +       vterm = pref * ct_i * ( ri2 - preRF2*rij )
1459 +       rfpot = rfpot + sw*vterm
1460 +      
1461 +       dudx = dudx + sw*pref*( ri3*(uz_i(1)-3.0d0*ct_i*xhat) - preRF2*uz_i(1) )
1462 +       dudy = dudy + sw*pref*( ri3*(uz_i(2)-3.0d0*ct_i*yhat) - preRF2*uz_i(2) )
1463 +       dudz = dudz + sw*pref*( ri3*(uz_i(3)-3.0d0*ct_i*zhat) - preRF2*uz_i(3) )
1464 +      
1465 +       duduz_i(1) = duduz_i(1) + sw * pref * xhat * ( ri2 - preRF2*rij )
1466 +       duduz_i(2) = duduz_i(2) + sw * pref * yhat * ( ri2 - preRF2*rij )
1467 +       duduz_i(3) = duduz_i(3) + sw * pref * zhat * ( ri2 - preRF2*rij )
1468 +      
1469 +    endif
1470 +    
1471 +    ! accumulate the forces and torques resulting from the RF self term
1472 +    f(1,atom1) = f(1,atom1) + dudx
1473 +    f(2,atom1) = f(2,atom1) + dudy
1474 +    f(3,atom1) = f(3,atom1) + dudz
1475 +    
1476 +    f(1,atom2) = f(1,atom2) - dudx
1477 +    f(2,atom2) = f(2,atom2) - dudy
1478 +    f(3,atom2) = f(3,atom2) - dudz
1479 +    
1480 +    if (i_is_Dipole) then
1481 +       t(1,atom1)=t(1,atom1) - uz_i(2)*duduz_i(3) + uz_i(3)*duduz_i(2)
1482 +       t(2,atom1)=t(2,atom1) - uz_i(3)*duduz_i(1) + uz_i(1)*duduz_i(3)
1483 +       t(3,atom1)=t(3,atom1) - uz_i(1)*duduz_i(2) + uz_i(2)*duduz_i(1)
1484 +    elseif (j_is_Dipole) then
1485 +       t(1,atom2)=t(1,atom2) - uz_j(2)*duduz_j(3) + uz_j(3)*duduz_j(2)
1486 +       t(2,atom2)=t(2,atom2) - uz_j(3)*duduz_j(1) + uz_j(1)*duduz_j(3)
1487 +       t(3,atom2)=t(3,atom2) - uz_j(1)*duduz_j(2) + uz_j(2)*duduz_j(1)
1488 +    endif
1489 +
1490 +    return
1491 +  end subroutine rf_self_excludes
1492 +
1493   end module electrostatic_module

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines