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 |
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 |
> |
logical, save :: preRFCalculated = .false. |
101 |
> |
|
102 |
|
#ifdef __IFC |
103 |
|
! error function for ifc version > 7. |
104 |
|
double precision, external :: derfc |
108 |
|
public :: setElectrostaticCutoffRadius |
109 |
|
public :: setDampedWolfAlpha |
110 |
|
public :: setReactionFieldDielectric |
111 |
+ |
public :: setReactionFieldPrefactor |
112 |
|
public :: newElectrostaticType |
113 |
|
public :: setCharge |
114 |
|
public :: setDipoleMoment |
119 |
|
public :: getDipoleMoment |
120 |
|
public :: pre22 |
121 |
|
public :: destroyElectrostaticTypes |
122 |
+ |
public :: accumulate_rf |
123 |
+ |
public :: accumulate_self_rf |
124 |
+ |
public :: reaction_field_final |
125 |
+ |
public :: rf_correct_forces |
126 |
|
|
127 |
|
type :: Electrostatic |
128 |
|
integer :: c_ident |
152 |
|
|
153 |
|
end subroutine setElectrostaticSummationMethod |
154 |
|
|
155 |
< |
subroutine setElectrostaticCutoffRadius(thisRcut) |
155 |
> |
subroutine setElectrostaticCutoffRadius(thisRcut, thisRsw) |
156 |
|
real(kind=dp), intent(in) :: thisRcut |
157 |
+ |
real(kind=dp), intent(in) :: thisRsw |
158 |
|
defaultCutoff = thisRcut |
159 |
+ |
rrf = defaultCutoff |
160 |
+ |
rt = thisRsw |
161 |
|
haveDefaultCutoff = .true. |
162 |
|
end subroutine setElectrostaticCutoffRadius |
163 |
|
|
173 |
|
haveDielectric = .true. |
174 |
|
end subroutine setReactionFieldDielectric |
175 |
|
|
176 |
+ |
subroutine setReactionFieldPrefactor |
177 |
+ |
if (haveDefaultCutoff .and. haveDielectric) then |
178 |
+ |
defaultCutoff2 = defaultCutoff*defaultCutoff |
179 |
+ |
preRF = pre22 * 2.0d0*(dielectric-1.0d0) / & |
180 |
+ |
((2.0d0*dielectric+1.0d0)*defaultCutoff2*defaultCutoff) |
181 |
+ |
preRFCalculated = .true. |
182 |
+ |
else if (.not.haveDefaultCutoff) then |
183 |
+ |
call handleError("setReactionFieldPrefactor", "Default cutoff not set") |
184 |
+ |
else |
185 |
+ |
call handleError("setReactionFieldPrefactor", "Dielectric not set") |
186 |
+ |
endif |
187 |
+ |
end subroutine setReactionFieldPrefactor |
188 |
+ |
|
189 |
|
subroutine newElectrostaticType(c_ident, is_Charge, is_Dipole, & |
190 |
|
is_SplitDipole, is_Quadrupole, is_Tap, status) |
191 |
|
|
422 |
|
constERFC = derfc(dampingAlpha*defaultCutoff) |
423 |
|
invRootPi = 0.56418958354775628695d0 |
424 |
|
alphaPi = 2*dampingAlpha*invRootPi |
425 |
< |
|
425 |
> |
|
426 |
|
haveDWAconstants = .true. |
427 |
|
endif |
428 |
|
endif |
478 |
|
real (kind=dp) :: dudx, dudy, dudz |
479 |
|
real (kind=dp) :: scale, sc2, bigR |
480 |
|
real (kind=dp) :: varERFC, varEXP |
481 |
+ |
real (kind=dp) :: limScale |
482 |
|
|
483 |
|
if (.not.allocated(ElectrostaticMap)) then |
484 |
|
call handleError("electrostatic", "no ElectrostaticMap was present before first call of do_electrostatic_pair!") |
502 |
|
!! some variables we'll need independent of electrostatic type: |
503 |
|
|
504 |
|
riji = 1.0d0 / rij |
505 |
< |
|
505 |
> |
|
506 |
|
xhat = d(1) * riji |
507 |
|
yhat = d(2) * riji |
508 |
|
zhat = d(3) * riji |
648 |
|
vpair = vpair + vterm |
649 |
|
epot = epot + sw*vterm |
650 |
|
|
651 |
< |
dudr = -sw*pre11*q_i*q_j * (riji*riji*riji - rcuti2*rcuti) |
651 |
> |
dudr = -sw*pre11*q_i*q_j * (riji*riji-rcuti2)*riji |
652 |
|
|
653 |
|
dudx = dudx + dudr * d(1) |
654 |
|
dudy = dudy + dudr * d(2) |
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) |
1111 |
|
|
1112 |
|
if (do_pot) then |
1113 |
|
#ifdef IS_MPI |
1114 |
< |
pot_row(atom1) = pot_row(atom1) + 0.5d0*epot |
1115 |
< |
pot_col(atom2) = pot_col(atom2) + 0.5d0*epot |
1114 |
> |
pot_row(ELECTROSTATIC_POT,atom1) = pot_row(ELECTROSTATIC_POT,atom1) + 0.5d0*epot |
1115 |
> |
pot_col(ELECTROSTATIC_POT,atom2) = pot_col(ELECTROSTATIC_POT,atom2) + 0.5d0*epot |
1116 |
|
#else |
1117 |
|
pot = pot + epot |
1118 |
|
#endif |
1251 |
|
if(allocated(ElectrostaticMap)) deallocate(ElectrostaticMap) |
1252 |
|
|
1253 |
|
end subroutine destroyElectrostaticTypes |
1254 |
+ |
|
1255 |
+ |
subroutine accumulate_rf(atom1, atom2, rij, eFrame, taper) |
1256 |
+ |
|
1257 |
+ |
integer, intent(in) :: atom1, atom2 |
1258 |
+ |
real (kind = dp), intent(in) :: rij |
1259 |
+ |
real (kind = dp), dimension(9,nLocal) :: eFrame |
1260 |
+ |
|
1261 |
+ |
integer :: me1, me2 |
1262 |
+ |
real (kind = dp), intent(in) :: taper |
1263 |
+ |
real (kind = dp):: mu1, mu2 |
1264 |
+ |
real (kind = dp), dimension(3) :: ul1 |
1265 |
+ |
real (kind = dp), dimension(3) :: ul2 |
1266 |
+ |
|
1267 |
+ |
integer :: localError |
1268 |
+ |
|
1269 |
+ |
#ifdef IS_MPI |
1270 |
+ |
me1 = atid_Row(atom1) |
1271 |
+ |
ul1(1) = eFrame_Row(3,atom1) |
1272 |
+ |
ul1(2) = eFrame_Row(6,atom1) |
1273 |
+ |
ul1(3) = eFrame_Row(9,atom1) |
1274 |
+ |
|
1275 |
+ |
me2 = atid_Col(atom2) |
1276 |
+ |
ul2(1) = eFrame_Col(3,atom2) |
1277 |
+ |
ul2(2) = eFrame_Col(6,atom2) |
1278 |
+ |
ul2(3) = eFrame_Col(9,atom2) |
1279 |
+ |
#else |
1280 |
+ |
me1 = atid(atom1) |
1281 |
+ |
ul1(1) = eFrame(3,atom1) |
1282 |
+ |
ul1(2) = eFrame(6,atom1) |
1283 |
+ |
ul1(3) = eFrame(9,atom1) |
1284 |
+ |
|
1285 |
+ |
me2 = atid(atom2) |
1286 |
+ |
ul2(1) = eFrame(3,atom2) |
1287 |
+ |
ul2(2) = eFrame(6,atom2) |
1288 |
+ |
ul2(3) = eFrame(9,atom2) |
1289 |
+ |
#endif |
1290 |
+ |
|
1291 |
+ |
mu1 = getDipoleMoment(me1) |
1292 |
+ |
mu2 = getDipoleMoment(me2) |
1293 |
+ |
|
1294 |
+ |
#ifdef IS_MPI |
1295 |
+ |
rf_Row(1,atom1) = rf_Row(1,atom1) + ul2(1)*mu2*taper |
1296 |
+ |
rf_Row(2,atom1) = rf_Row(2,atom1) + ul2(2)*mu2*taper |
1297 |
+ |
rf_Row(3,atom1) = rf_Row(3,atom1) + ul2(3)*mu2*taper |
1298 |
+ |
|
1299 |
+ |
rf_Col(1,atom2) = rf_Col(1,atom2) + ul1(1)*mu1*taper |
1300 |
+ |
rf_Col(2,atom2) = rf_Col(2,atom2) + ul1(2)*mu1*taper |
1301 |
+ |
rf_Col(3,atom2) = rf_Col(3,atom2) + ul1(3)*mu1*taper |
1302 |
+ |
#else |
1303 |
+ |
rf(1,atom1) = rf(1,atom1) + ul2(1)*mu2*taper |
1304 |
+ |
rf(2,atom1) = rf(2,atom1) + ul2(2)*mu2*taper |
1305 |
+ |
rf(3,atom1) = rf(3,atom1) + ul2(3)*mu2*taper |
1306 |
+ |
|
1307 |
+ |
rf(1,atom2) = rf(1,atom2) + ul1(1)*mu1*taper |
1308 |
+ |
rf(2,atom2) = rf(2,atom2) + ul1(2)*mu1*taper |
1309 |
+ |
rf(3,atom2) = rf(3,atom2) + ul1(3)*mu1*taper |
1310 |
+ |
#endif |
1311 |
+ |
return |
1312 |
+ |
end subroutine accumulate_rf |
1313 |
+ |
|
1314 |
+ |
subroutine accumulate_self_rf(atom1, mu1, eFrame) |
1315 |
+ |
|
1316 |
+ |
integer, intent(in) :: atom1 |
1317 |
+ |
real(kind=dp), intent(in) :: mu1 |
1318 |
+ |
real(kind=dp), dimension(9,nLocal) :: eFrame |
1319 |
+ |
|
1320 |
+ |
!! should work for both MPI and non-MPI version since this is not pairwise. |
1321 |
+ |
rf(1,atom1) = rf(1,atom1) + eFrame(3,atom1)*mu1 |
1322 |
+ |
rf(2,atom1) = rf(2,atom1) + eFrame(6,atom1)*mu1 |
1323 |
+ |
rf(3,atom1) = rf(3,atom1) + eFrame(9,atom1)*mu1 |
1324 |
+ |
|
1325 |
+ |
return |
1326 |
+ |
end subroutine accumulate_self_rf |
1327 |
|
|
1328 |
+ |
subroutine reaction_field_final(a1, mu1, eFrame, rfpot, t, do_pot) |
1329 |
+ |
|
1330 |
+ |
integer, intent(in) :: a1 |
1331 |
+ |
real (kind=dp), intent(in) :: mu1 |
1332 |
+ |
real (kind=dp), intent(inout) :: rfpot |
1333 |
+ |
logical, intent(in) :: do_pot |
1334 |
+ |
real (kind = dp), dimension(9,nLocal) :: eFrame |
1335 |
+ |
real (kind = dp), dimension(3,nLocal) :: t |
1336 |
+ |
|
1337 |
+ |
integer :: localError |
1338 |
+ |
|
1339 |
+ |
if (.not.preRFCalculated) then |
1340 |
+ |
call setReactionFieldPrefactor() |
1341 |
+ |
endif |
1342 |
+ |
|
1343 |
+ |
! compute torques on dipoles: |
1344 |
+ |
! pre converts from mu in units of debye to kcal/mol |
1345 |
+ |
|
1346 |
+ |
! The torque contribution is dipole cross reaction_field |
1347 |
+ |
|
1348 |
+ |
t(1,a1) = t(1,a1) + preRF*mu1*(eFrame(6,a1)*rf(3,a1) - & |
1349 |
+ |
eFrame(9,a1)*rf(2,a1)) |
1350 |
+ |
t(2,a1) = t(2,a1) + preRF*mu1*(eFrame(9,a1)*rf(1,a1) - & |
1351 |
+ |
eFrame(3,a1)*rf(3,a1)) |
1352 |
+ |
t(3,a1) = t(3,a1) + preRF*mu1*(eFrame(3,a1)*rf(2,a1) - & |
1353 |
+ |
eFrame(6,a1)*rf(1,a1)) |
1354 |
+ |
|
1355 |
+ |
! the potential contribution is -1/2 dipole dot reaction_field |
1356 |
+ |
|
1357 |
+ |
if (do_pot) then |
1358 |
+ |
rfpot = rfpot - 0.5d0 * preRF * mu1 * & |
1359 |
+ |
(rf(1,a1)*eFrame(3,a1) + rf(2,a1)*eFrame(6,a1) + & |
1360 |
+ |
rf(3,a1)*eFrame(9,a1)) |
1361 |
+ |
endif |
1362 |
+ |
|
1363 |
+ |
return |
1364 |
+ |
end subroutine reaction_field_final |
1365 |
+ |
|
1366 |
+ |
subroutine rf_correct_forces(atom1, atom2, d, rij, eFrame, taper, f, fpair) |
1367 |
+ |
|
1368 |
+ |
integer, intent(in) :: atom1, atom2 |
1369 |
+ |
real(kind=dp), dimension(3), intent(in) :: d |
1370 |
+ |
real(kind=dp), intent(in) :: rij, taper |
1371 |
+ |
real( kind = dp ), dimension(9,nLocal) :: eFrame |
1372 |
+ |
real( kind = dp ), dimension(3,nLocal) :: f |
1373 |
+ |
real( kind = dp ), dimension(3), intent(inout) :: fpair |
1374 |
+ |
|
1375 |
+ |
real (kind = dp), dimension(3) :: ul1 |
1376 |
+ |
real (kind = dp), dimension(3) :: ul2 |
1377 |
+ |
real (kind = dp) :: dtdr |
1378 |
+ |
real (kind = dp) :: dudx, dudy, dudz, u1dotu2 |
1379 |
+ |
integer :: me1, me2, id1, id2 |
1380 |
+ |
real (kind = dp) :: mu1, mu2 |
1381 |
+ |
|
1382 |
+ |
integer :: localError |
1383 |
+ |
|
1384 |
+ |
if (.not.preRFCalculated) then |
1385 |
+ |
call setReactionFieldPrefactor() |
1386 |
+ |
endif |
1387 |
+ |
|
1388 |
+ |
if (rij.le.rrf) then |
1389 |
+ |
|
1390 |
+ |
if (rij.lt.rt) then |
1391 |
+ |
dtdr = 0.0d0 |
1392 |
+ |
else |
1393 |
+ |
! write(*,*) 'rf correct in taper region' |
1394 |
+ |
dtdr = 6.0d0*(rij*rij - rij*rt - rij*rrf +rrf*rt)/((rrf-rt)**3) |
1395 |
+ |
endif |
1396 |
+ |
|
1397 |
+ |
#ifdef IS_MPI |
1398 |
+ |
me1 = atid_Row(atom1) |
1399 |
+ |
ul1(1) = eFrame_Row(3,atom1) |
1400 |
+ |
ul1(2) = eFrame_Row(6,atom1) |
1401 |
+ |
ul1(3) = eFrame_Row(9,atom1) |
1402 |
+ |
|
1403 |
+ |
me2 = atid_Col(atom2) |
1404 |
+ |
ul2(1) = eFrame_Col(3,atom2) |
1405 |
+ |
ul2(2) = eFrame_Col(6,atom2) |
1406 |
+ |
ul2(3) = eFrame_Col(9,atom2) |
1407 |
+ |
#else |
1408 |
+ |
me1 = atid(atom1) |
1409 |
+ |
ul1(1) = eFrame(3,atom1) |
1410 |
+ |
ul1(2) = eFrame(6,atom1) |
1411 |
+ |
ul1(3) = eFrame(9,atom1) |
1412 |
+ |
|
1413 |
+ |
me2 = atid(atom2) |
1414 |
+ |
ul2(1) = eFrame(3,atom2) |
1415 |
+ |
ul2(2) = eFrame(6,atom2) |
1416 |
+ |
ul2(3) = eFrame(9,atom2) |
1417 |
+ |
#endif |
1418 |
+ |
|
1419 |
+ |
mu1 = getDipoleMoment(me1) |
1420 |
+ |
mu2 = getDipoleMoment(me2) |
1421 |
+ |
|
1422 |
+ |
u1dotu2 = ul1(1)*ul2(1) + ul1(2)*ul2(2) + ul1(3)*ul2(3) |
1423 |
+ |
|
1424 |
+ |
dudx = - preRF*mu1*mu2*u1dotu2*dtdr*d(1)/rij |
1425 |
+ |
dudy = - preRF*mu1*mu2*u1dotu2*dtdr*d(2)/rij |
1426 |
+ |
dudz = - preRF*mu1*mu2*u1dotu2*dtdr*d(3)/rij |
1427 |
+ |
|
1428 |
+ |
#ifdef IS_MPI |
1429 |
+ |
f_Row(1,atom1) = f_Row(1,atom1) + dudx |
1430 |
+ |
f_Row(2,atom1) = f_Row(2,atom1) + dudy |
1431 |
+ |
f_Row(3,atom1) = f_Row(3,atom1) + dudz |
1432 |
+ |
|
1433 |
+ |
f_Col(1,atom2) = f_Col(1,atom2) - dudx |
1434 |
+ |
f_Col(2,atom2) = f_Col(2,atom2) - dudy |
1435 |
+ |
f_Col(3,atom2) = f_Col(3,atom2) - dudz |
1436 |
+ |
#else |
1437 |
+ |
f(1,atom1) = f(1,atom1) + dudx |
1438 |
+ |
f(2,atom1) = f(2,atom1) + dudy |
1439 |
+ |
f(3,atom1) = f(3,atom1) + dudz |
1440 |
+ |
|
1441 |
+ |
f(1,atom2) = f(1,atom2) - dudx |
1442 |
+ |
f(2,atom2) = f(2,atom2) - dudy |
1443 |
+ |
f(3,atom2) = f(3,atom2) - dudz |
1444 |
+ |
#endif |
1445 |
+ |
|
1446 |
+ |
#ifdef IS_MPI |
1447 |
+ |
id1 = AtomRowToGlobal(atom1) |
1448 |
+ |
id2 = AtomColToGlobal(atom2) |
1449 |
+ |
#else |
1450 |
+ |
id1 = atom1 |
1451 |
+ |
id2 = atom2 |
1452 |
+ |
#endif |
1453 |
+ |
|
1454 |
+ |
if (molMembershipList(id1) .ne. molMembershipList(id2)) then |
1455 |
+ |
|
1456 |
+ |
fpair(1) = fpair(1) + dudx |
1457 |
+ |
fpair(2) = fpair(2) + dudy |
1458 |
+ |
fpair(3) = fpair(3) + dudz |
1459 |
+ |
|
1460 |
+ |
endif |
1461 |
+ |
|
1462 |
+ |
end if |
1463 |
+ |
return |
1464 |
+ |
end subroutine rf_correct_forces |
1465 |
+ |
|
1466 |
|
end module electrostatic_module |