43 |
|
!! Calculates Long Range forces Lennard-Jones interactions. |
44 |
|
!! @author Charles F. Vardeman II |
45 |
|
!! @author Matthew Meineke |
46 |
< |
!! @version $Id: LJ.F90,v 1.8 2005-02-25 21:22:00 tim Exp $, $Date: 2005-02-25 21:22:00 $, $Name: not supported by cvs2svn $, $Revision: 1.8 $ |
46 |
> |
!! @version $Id: LJ.F90,v 1.12 2005-05-19 15:49:53 tim Exp $, $Date: 2005-05-19 15:49:53 $, $Name: not supported by cvs2svn $, $Revision: 1.12 $ |
47 |
|
|
48 |
|
|
49 |
|
module lj |
59 |
|
|
60 |
|
implicit none |
61 |
|
PRIVATE |
62 |
< |
|
62 |
> |
|
63 |
|
integer, parameter :: DP = selected_real_kind(15) |
64 |
< |
|
64 |
> |
|
65 |
|
type, private :: LjType |
66 |
|
integer :: c_ident |
67 |
|
integer :: atid |
69 |
|
real(kind=dp) :: epsilon |
70 |
|
logical :: soft_pot |
71 |
|
end type LjType |
72 |
< |
|
72 |
> |
|
73 |
|
type(LjType), dimension(:), allocatable :: ParameterMap |
74 |
< |
|
74 |
> |
|
75 |
|
logical, save :: haveMixingMap = .false. |
76 |
< |
|
76 |
> |
|
77 |
|
type :: MixParameters |
78 |
|
real(kind=DP) :: sigma |
79 |
|
real(kind=DP) :: epsilon |
83 |
|
real(kind=dp) :: delta |
84 |
|
logical :: soft_pot |
85 |
|
end type MixParameters |
86 |
< |
|
86 |
> |
|
87 |
|
type(MixParameters), dimension(:,:), allocatable :: MixingMap |
88 |
< |
|
88 |
> |
|
89 |
|
real(kind=DP), save :: LJ_rcut |
90 |
|
logical, save :: have_rcut = .false. |
91 |
|
logical, save :: LJ_do_shift = .false. |
92 |
|
logical, save :: useGeometricDistanceMixing = .false. |
93 |
< |
|
93 |
> |
|
94 |
|
!! Public methods and data |
95 |
< |
|
95 |
> |
|
96 |
|
public :: setCutoffLJ |
97 |
|
public :: useGeometricMixing |
98 |
|
public :: do_lj_pair |
99 |
|
public :: newLJtype |
100 |
|
public :: getSigma |
101 |
|
public :: getEpsilon |
102 |
< |
|
102 |
> |
public :: destroyLJTypes |
103 |
> |
|
104 |
|
contains |
105 |
|
|
106 |
|
subroutine newLJtype(c_ident, sigma, epsilon, soft_pot, status) |
113 |
|
integer, pointer :: MatchList(:) => null() |
114 |
|
|
115 |
|
status = 0 |
116 |
< |
|
116 |
> |
|
117 |
|
myATID = getFirstMatchingElement(atypes, "c_ident", c_ident) |
118 |
|
|
119 |
|
if (.not.allocated(ParameterMap)) then |
120 |
< |
|
120 |
> |
|
121 |
|
!call getMatchingElementList(atypes, "is_LennardJones", .true., & |
122 |
|
! nLJTypes, MatchList) |
123 |
|
nAtypes = getSize(atypes) |
125 |
|
status = -1 |
126 |
|
return |
127 |
|
end if |
128 |
< |
|
128 |
> |
|
129 |
|
if (.not. allocated(ParameterMap)) then |
130 |
|
allocate(ParameterMap(nAtypes)) |
131 |
|
endif |
132 |
< |
|
132 |
> |
|
133 |
|
end if |
134 |
|
|
135 |
|
if (myATID .gt. size(ParameterMap)) then |
136 |
|
status = -1 |
137 |
|
return |
138 |
|
endif |
139 |
< |
|
139 |
> |
|
140 |
|
! set the values for ParameterMap for this atom type: |
141 |
|
|
142 |
|
ParameterMap(myATID)%c_ident = c_ident |
144 |
|
ParameterMap(myATID)%epsilon = epsilon |
145 |
|
ParameterMap(myATID)%sigma = sigma |
146 |
|
if (soft_pot == 1) then |
147 |
< |
ParameterMap(myATID)%soft_pot = .true. |
147 |
> |
ParameterMap(myATID)%soft_pot = .true. |
148 |
|
else |
149 |
< |
ParameterMap(myATID)%soft_pot = .false. |
149 |
> |
ParameterMap(myATID)%soft_pot = .false. |
150 |
|
endif |
151 |
|
end subroutine newLJtype |
152 |
|
|
154 |
|
integer, intent(in) :: atid |
155 |
|
integer :: localError |
156 |
|
real(kind=dp) :: s |
157 |
< |
|
157 |
> |
|
158 |
|
if (.not.allocated(ParameterMap)) then |
159 |
|
call handleError("LJ", "no ParameterMap was present before first call of getSigma!") |
160 |
|
return |
161 |
|
end if |
162 |
< |
|
162 |
> |
|
163 |
|
s = ParameterMap(atid)%sigma |
164 |
|
end function getSigma |
165 |
|
|
167 |
|
integer, intent(in) :: atid |
168 |
|
integer :: localError |
169 |
|
real(kind=dp) :: e |
170 |
< |
|
170 |
> |
|
171 |
|
if (.not.allocated(ParameterMap)) then |
172 |
|
call handleError("LJ", "no ParameterMap was present before first call of getEpsilon!") |
173 |
|
return |
174 |
|
end if |
175 |
< |
|
175 |
> |
|
176 |
|
e = ParameterMap(atid)%epsilon |
177 |
|
end function getEpsilon |
178 |
|
|
191 |
|
LJ_do_shift = do_shift |
192 |
|
call set_switch(LJ_SWITCH, rcut, rcut) |
193 |
|
have_rcut = .true. |
194 |
< |
|
194 |
> |
|
195 |
|
return |
196 |
|
end subroutine setCutoffLJ |
197 |
|
|
200 |
|
haveMixingMap = .false. |
201 |
|
return |
202 |
|
end subroutine useGeometricMixing |
203 |
< |
|
203 |
> |
|
204 |
|
subroutine createMixingMap(status) |
205 |
|
integer :: nATIDs |
206 |
|
integer :: status |
209 |
|
real ( kind = dp ) :: Sigma_i, Sigma_j |
210 |
|
real ( kind = dp ) :: Epsilon_i, Epsilon_j |
211 |
|
real ( kind = dp ) :: rcut6 |
212 |
+ |
logical :: i_is_LJ, j_is_LJ |
213 |
|
|
214 |
|
status = 0 |
215 |
< |
|
215 |
> |
|
216 |
> |
if (.not. allocated(ParameterMap)) then |
217 |
> |
call handleError("LJ", "no ParameterMap was present before call of createMixingMap!") |
218 |
> |
status = -1 |
219 |
> |
return |
220 |
> |
endif |
221 |
> |
|
222 |
|
nATIDs = size(ParameterMap) |
223 |
< |
|
223 |
> |
|
224 |
|
if (nATIDs == 0) then |
225 |
|
status = -1 |
226 |
|
return |
227 |
|
end if |
228 |
|
|
229 |
+ |
if (.not. allocated(MixingMap)) then |
230 |
+ |
allocate(MixingMap(nATIDs, nATIDs)) |
231 |
+ |
endif |
232 |
+ |
|
233 |
|
if (.not.have_rcut) then |
234 |
|
status = -1 |
235 |
|
return |
236 |
|
endif |
237 |
< |
|
226 |
< |
if (.not. allocated(MixingMap)) then |
227 |
< |
allocate(MixingMap(nATIDs, nATIDs)) |
228 |
< |
endif |
229 |
< |
|
237 |
> |
|
238 |
|
rcut6 = LJ_rcut**6 |
239 |
< |
|
239 |
> |
|
240 |
|
! This loops through all atypes, even those that don't support LJ forces. |
241 |
|
do i = 1, nATIDs |
242 |
< |
|
243 |
< |
Epsilon_i = ParameterMap(i)%epsilon |
244 |
< |
Sigma_i = ParameterMap(i)%sigma |
245 |
< |
|
238 |
< |
! do self mixing rule |
239 |
< |
MixingMap(i,i)%sigma = Sigma_i |
240 |
< |
MixingMap(i,i)%sigma6 = Sigma_i ** 6 |
241 |
< |
MixingMap(i,i)%tp6 = (MixingMap(i,i)%sigma6)/rcut6 |
242 |
< |
MixingMap(i,i)%tp12 = (MixingMap(i,i)%tp6) ** 2 |
243 |
< |
MixingMap(i,i)%epsilon = Epsilon_i |
244 |
< |
MixingMap(i,i)%delta = -4.0_DP * MixingMap(i,i)%epsilon * & |
245 |
< |
(MixingMap(i,i)%tp12 - MixingMap(i,i)%tp6) |
246 |
< |
MixingMap(i,i)%soft_pot = ParameterMap(i)%soft_pot |
247 |
< |
|
248 |
< |
do j = i + 1, nATIDs |
249 |
< |
|
250 |
< |
Epsilon_j = ParameterMap(j)%epsilon |
251 |
< |
Sigma_j = ParameterMap(j)%sigma |
252 |
< |
|
253 |
< |
! only the distance parameter uses different mixing policies |
254 |
< |
if (useGeometricDistanceMixing) then |
255 |
< |
! only for OPLS as far as we can tell |
256 |
< |
MixingMap(i,j)%sigma = dsqrt(Sigma_i * Sigma_j) |
257 |
< |
else |
258 |
< |
! everyone else |
259 |
< |
MixingMap(i,j)%sigma = 0.5_dp * (Sigma_i + Sigma_j) |
260 |
< |
endif |
261 |
< |
|
262 |
< |
! energy parameter is always geometric mean: |
263 |
< |
MixingMap(i,j)%epsilon = dsqrt(Epsilon_i * Epsilon_j) |
264 |
< |
|
265 |
< |
MixingMap(i,j)%sigma6 = (MixingMap(i,j)%sigma)**6 |
266 |
< |
MixingMap(i,j)%tp6 = MixingMap(i,j)%sigma6/rcut6 |
267 |
< |
MixingMap(i,j)%tp12 = (MixingMap(i,j)%tp6) ** 2 |
268 |
< |
|
269 |
< |
MixingMap(i,j)%delta = -4.0_DP * MixingMap(i,j)%epsilon * & |
270 |
< |
(MixingMap(i,j)%tp12 - MixingMap(i,j)%tp6) |
242 |
> |
call getElementProperty(atypes, i, "is_LennardJones", i_is_LJ) |
243 |
> |
if (i_is_LJ) then |
244 |
> |
Epsilon_i = ParameterMap(i)%epsilon |
245 |
> |
Sigma_i = ParameterMap(i)%sigma |
246 |
|
|
247 |
< |
MixingMap(i,j)%soft_pot = ParameterMap(i)%soft_pot .or. ParameterMap(j)%soft_pot |
247 |
> |
! do self mixing rule |
248 |
> |
MixingMap(i,i)%sigma = Sigma_i |
249 |
> |
MixingMap(i,i)%sigma6 = Sigma_i ** 6 |
250 |
> |
MixingMap(i,i)%tp6 = (MixingMap(i,i)%sigma6)/rcut6 |
251 |
> |
MixingMap(i,i)%tp12 = (MixingMap(i,i)%tp6) ** 2 |
252 |
> |
MixingMap(i,i)%epsilon = Epsilon_i |
253 |
> |
MixingMap(i,i)%delta = -4.0_DP * MixingMap(i,i)%epsilon * & |
254 |
> |
(MixingMap(i,i)%tp12 - MixingMap(i,i)%tp6) |
255 |
> |
MixingMap(i,i)%soft_pot = ParameterMap(i)%soft_pot |
256 |
|
|
257 |
< |
|
258 |
< |
MixingMap(j,i)%sigma = MixingMap(i,j)%sigma |
259 |
< |
MixingMap(j,i)%sigma6 = MixingMap(i,j)%sigma6 |
260 |
< |
MixingMap(j,i)%tp6 = MixingMap(i,j)%tp6 |
261 |
< |
MixingMap(j,i)%tp12 = MixingMap(i,j)%tp12 |
262 |
< |
MixingMap(j,i)%epsilon = MixingMap(i,j)%epsilon |
263 |
< |
MixingMap(j,i)%delta = MixingMap(i,j)%delta |
264 |
< |
MixingMap(j,i)%soft_pot = MixingMap(i,j)%soft_pot |
265 |
< |
|
266 |
< |
end do |
257 |
> |
do j = i + 1, nATIDs |
258 |
> |
call getElementProperty(atypes, j, "is_LennardJones", j_is_LJ) |
259 |
> |
|
260 |
> |
if (j_is_LJ) then |
261 |
> |
Epsilon_j = ParameterMap(j)%epsilon |
262 |
> |
Sigma_j = ParameterMap(j)%sigma |
263 |
> |
|
264 |
> |
! only the distance parameter uses different mixing policies |
265 |
> |
if (useGeometricDistanceMixing) then |
266 |
> |
! only for OPLS as far as we can tell |
267 |
> |
MixingMap(i,j)%sigma = dsqrt(Sigma_i * Sigma_j) |
268 |
> |
else |
269 |
> |
! everyone else |
270 |
> |
MixingMap(i,j)%sigma = 0.5_dp * (Sigma_i + Sigma_j) |
271 |
> |
endif |
272 |
> |
|
273 |
> |
! energy parameter is always geometric mean: |
274 |
> |
MixingMap(i,j)%epsilon = dsqrt(Epsilon_i * Epsilon_j) |
275 |
> |
|
276 |
> |
MixingMap(i,j)%sigma6 = (MixingMap(i,j)%sigma)**6 |
277 |
> |
MixingMap(i,j)%tp6 = MixingMap(i,j)%sigma6/rcut6 |
278 |
> |
MixingMap(i,j)%tp12 = (MixingMap(i,j)%tp6) ** 2 |
279 |
> |
|
280 |
> |
MixingMap(i,j)%delta = -4.0_DP * MixingMap(i,j)%epsilon * & |
281 |
> |
(MixingMap(i,j)%tp12 - MixingMap(i,j)%tp6) |
282 |
> |
|
283 |
> |
MixingMap(i,j)%soft_pot = ParameterMap(i)%soft_pot .or. ParameterMap(j)%soft_pot |
284 |
> |
|
285 |
> |
|
286 |
> |
MixingMap(j,i)%sigma = MixingMap(i,j)%sigma |
287 |
> |
MixingMap(j,i)%sigma6 = MixingMap(i,j)%sigma6 |
288 |
> |
MixingMap(j,i)%tp6 = MixingMap(i,j)%tp6 |
289 |
> |
MixingMap(j,i)%tp12 = MixingMap(i,j)%tp12 |
290 |
> |
MixingMap(j,i)%epsilon = MixingMap(i,j)%epsilon |
291 |
> |
MixingMap(j,i)%delta = MixingMap(i,j)%delta |
292 |
> |
MixingMap(j,i)%soft_pot = MixingMap(i,j)%soft_pot |
293 |
> |
endif |
294 |
> |
end do |
295 |
> |
endif |
296 |
|
end do |
297 |
< |
|
297 |
> |
|
298 |
|
haveMixingMap = .true. |
299 |
|
|
300 |
|
end subroutine createMixingMap |
301 |
< |
|
301 |
> |
|
302 |
|
subroutine do_lj_pair(atom1, atom2, d, rij, r2, sw, vpair, fpair, & |
303 |
|
pot, f, do_pot) |
304 |
|
|
346 |
|
#endif |
347 |
|
|
348 |
|
r6 = r2 * r2 * r2 |
349 |
< |
|
349 |
> |
|
350 |
|
t6 = sigma6/ r6 |
351 |
|
t12 = t6 * t6 |
352 |
|
|
353 |
|
if (soft_pot) then |
354 |
< |
pot_temp = 4.0E0_DP * epsilon * t12 |
354 |
> |
|
355 |
> |
pot_temp = 4.0E0_DP * epsilon * t6 |
356 |
|
if (LJ_do_shift) then |
357 |
|
pot_temp = pot_temp + delta |
358 |
|
endif |
359 |
< |
|
359 |
> |
|
360 |
|
vpair = vpair + pot_temp |
348 |
– |
|
349 |
– |
dudr = sw * 24.0E0_DP * epsilon * (-2.0E0_DP)*t12 / rij |
361 |
|
|
362 |
+ |
dudr = -sw * 24.0E0_DP * epsilon * t6 / rij |
363 |
+ |
|
364 |
|
else |
365 |
< |
pot_temp = 4.0E0_DP * epsilon * (t12 - t6) |
366 |
< |
if (LJ_do_shift) then |
367 |
< |
pot_temp = pot_temp + delta |
368 |
< |
endif |
369 |
< |
|
370 |
< |
vpair = vpair + pot_temp |
371 |
< |
|
372 |
< |
dudr = sw * 24.0E0_DP * epsilon * (t6 - 2.0E0_DP*t12) / rij |
365 |
> |
pot_temp = 4.0E0_DP * epsilon * (t12 - t6) |
366 |
> |
if (LJ_do_shift) then |
367 |
> |
pot_temp = pot_temp + delta |
368 |
> |
endif |
369 |
> |
|
370 |
> |
vpair = vpair + pot_temp |
371 |
> |
|
372 |
> |
dudr = sw * 24.0E0_DP * epsilon * (t6 - 2.0E0_DP*t12) / rij |
373 |
|
endif |
374 |
< |
|
374 |
> |
|
375 |
|
drdx = d(1) / rij |
376 |
|
drdy = d(2) / rij |
377 |
|
drdz = d(3) / rij |
378 |
< |
|
378 |
> |
|
379 |
|
fx = dudr * drdx |
380 |
|
fy = dudr * drdy |
381 |
|
fz = dudr * drdz |
382 |
< |
|
383 |
< |
|
382 |
> |
|
383 |
> |
|
384 |
|
#ifdef IS_MPI |
385 |
|
if (do_pot) then |
386 |
|
pot_Row(atom1) = pot_Row(atom1) + sw*pot_temp*0.5 |
387 |
|
pot_Col(atom2) = pot_Col(atom2) + sw*pot_temp*0.5 |
388 |
|
endif |
389 |
< |
|
389 |
> |
|
390 |
|
f_Row(1,atom1) = f_Row(1,atom1) + fx |
391 |
|
f_Row(2,atom1) = f_Row(2,atom1) + fy |
392 |
|
f_Row(3,atom1) = f_Row(3,atom1) + fz |
393 |
< |
|
393 |
> |
|
394 |
|
f_Col(1,atom2) = f_Col(1,atom2) - fx |
395 |
|
f_Col(2,atom2) = f_Col(2,atom2) - fy |
396 |
|
f_Col(3,atom2) = f_Col(3,atom2) - fz |
397 |
< |
|
397 |
> |
|
398 |
|
#else |
399 |
|
if (do_pot) pot = pot + sw*pot_temp |
400 |
|
|
401 |
|
f(1,atom1) = f(1,atom1) + fx |
402 |
|
f(2,atom1) = f(2,atom1) + fy |
403 |
|
f(3,atom1) = f(3,atom1) + fz |
404 |
< |
|
404 |
> |
|
405 |
|
f(1,atom2) = f(1,atom2) - fx |
406 |
|
f(2,atom2) = f(2,atom2) - fy |
407 |
|
f(3,atom2) = f(3,atom2) - fz |
408 |
|
#endif |
409 |
< |
|
409 |
> |
|
410 |
|
#ifdef IS_MPI |
411 |
|
id1 = AtomRowToGlobal(atom1) |
412 |
|
id2 = AtomColToGlobal(atom2) |
416 |
|
#endif |
417 |
|
|
418 |
|
if (molMembershipList(id1) .ne. molMembershipList(id2)) then |
419 |
< |
|
419 |
> |
|
420 |
|
fpair(1) = fpair(1) + fx |
421 |
|
fpair(2) = fpair(2) + fy |
422 |
|
fpair(3) = fpair(3) + fz |
424 |
|
endif |
425 |
|
|
426 |
|
return |
427 |
< |
|
427 |
> |
|
428 |
|
end subroutine do_lj_pair |
429 |
< |
|
430 |
< |
|
431 |
< |
!! Calculates the mixing for sigma or epslon |
432 |
< |
|
429 |
> |
|
430 |
> |
subroutine destroyLJTypes() |
431 |
> |
if(allocated(ParameterMap)) deallocate(ParameterMap) |
432 |
> |
if(allocated(MixingMap)) deallocate(MixingMap) |
433 |
> |
haveMixingMap = .false. |
434 |
> |
end subroutine destroyLJTypes |
435 |
> |
|
436 |
> |
|
437 |
|
end module lj |