-
Notifications
You must be signed in to change notification settings - Fork 1
/
mm_collocate_potential.F
402 lines (374 loc) · 17.4 KB
/
mm_collocate_potential.F
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
!--------------------------------------------------------------------------------------------------!
! CP2K: A general program to perform molecular dynamics simulations !
! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
! !
! SPDX-License-Identifier: GPL-2.0-or-later !
!--------------------------------------------------------------------------------------------------!
! **************************************************************************************************
!> \brief Calculate the MM potential by collocating the primitive Gaussian
!> functions (pgf)
!> \par History
!> 7.2004 created [tlaino]
!> \author Teodoro Laino
! **************************************************************************************************
MODULE mm_collocate_potential
USE ao_util, ONLY: exp_radius
USE cell_types, ONLY: cell_type
USE cube_utils, ONLY: cube_info_type,&
return_cube
USE kinds, ONLY: dp
USE pw_types, ONLY: pw_r3d_rs_type
#include "./base/base_uses.f90"
IMPLICIT NONE
PRIVATE
LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .TRUE.
CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'mm_collocate_potential'
PUBLIC :: collocate_gf_rspace_NoPBC, &
integrate_gf_rspace_NoPBC
!***
CONTAINS
! **************************************************************************************************
!> \brief ...
!> \param grid ...
!> \param xdat ...
!> \param ydat ...
!> \param zdat ...
!> \param bo1 ...
!> \param bo2 ...
!> \param zlb ...
!> \param zub ...
!> \param ylb ...
!> \param yub ...
!> \param xlb ...
!> \param xub ...
! **************************************************************************************************
SUBROUTINE collocate_gf_npbc(grid, xdat, ydat, zdat, bo1, bo2, zlb, zub, ylb, yub, xlb, xub)
USE kinds, ONLY: dp
INTEGER, INTENT(IN) :: bo1(2, 3)
REAL(dp), INTENT(INOUT) :: &
grid(bo1(1, 1):bo1(2, 1), bo1(1, 2):bo1(2, 2), bo1(1, 3):bo1(2, 3))
INTEGER, INTENT(IN) :: bo2(2, 3)
REAL(dp), INTENT(IN) :: zdat(bo2(1, 3):bo2(2, 3)), &
ydat(bo2(1, 2):bo2(2, 2)), &
xdat(bo2(1, 1):bo2(2, 1))
INTEGER, INTENT(IN) :: zlb, zub, ylb, yub, xlb, xub
INTEGER :: ix, iy, iz
REAL(dp) :: tmp1
DO iz = zlb, zub
DO iy = ylb, yub
tmp1 = zdat(iz)*ydat(iy)
DO ix = xlb, xub
grid(ix, iy, iz) = grid(ix, iy, iz) + xdat(ix)*tmp1
END DO ! Loop on x
END DO ! Loop on y
END DO ! Loop on z
END SUBROUTINE collocate_gf_npbc
! **************************************************************************************************
!> \brief ...
!> \param grid ...
!> \param xdat ...
!> \param ydat ...
!> \param zdat ...
!> \param bo ...
!> \param zlb ...
!> \param zub ...
!> \param ylb ...
!> \param yub ...
!> \param xlb ...
!> \param xub ...
!> \param force ...
! **************************************************************************************************
SUBROUTINE integrate_gf_npbc(grid, xdat, ydat, zdat, bo, zlb, zub, ylb, yub, xlb, xub, force)
USE kinds, ONLY: dp
INTEGER, INTENT(IN) :: bo(2, 3)
REAL(dp), INTENT(IN) :: zdat(2, bo(1, 3):bo(2, 3)), &
ydat(2, bo(1, 2):bo(2, 2)), &
xdat(2, bo(1, 1):bo(2, 1))
REAL(dp), INTENT(INOUT) :: grid(bo(1, 1):bo(2, 1), bo(1, 2):bo(2, 2), bo(1, 3):bo(2, 3))
INTEGER, INTENT(IN) :: zlb, zub, ylb, yub, xlb, xub
REAL(dp), INTENT(INOUT) :: force(3)
INTEGER :: ix, iy, iy2, iz
REAL(dp) :: fx1, fx2, fyz1, fyz2, g1, g2, x1, x2
DO iz = zlb, zub
iy2 = HUGE(0)
! unroll by 2
DO iy = ylb, yub - 1, 2
iy2 = iy + 1
fx1 = 0.0_dp
fyz1 = 0.0_dp
fx2 = 0.0_dp
fyz2 = 0.0_dp
DO ix = xlb, xub
g1 = grid(ix, iy, iz)
g2 = grid(ix, iy2, iz)
x1 = xdat(1, ix)
x2 = xdat(2, ix)
fyz1 = fyz1 + g1*x1
fx1 = fx1 + g1*x2
fyz2 = fyz2 + g2*x1
fx2 = fx2 + g2*x2
END DO ! Loop on x
force(1) = force(1) + fx1*zdat(1, iz)*ydat(1, iy)
force(2) = force(2) + fyz1*zdat(1, iz)*ydat(2, iy)
force(3) = force(3) + fyz1*zdat(2, iz)*ydat(1, iy)
force(1) = force(1) + fx2*zdat(1, iz)*ydat(1, iy2)
force(2) = force(2) + fyz2*zdat(1, iz)*ydat(2, iy2)
force(3) = force(3) + fyz2*zdat(2, iz)*ydat(1, iy2)
END DO ! Loop on y
! cleanup loop: check if the last loop element has done
IF (iy2 .NE. yub) THEN
iy2 = yub
fx2 = 0.0_dp
fyz2 = 0.0_dp
DO ix = xlb, xub
g2 = grid(ix, iy2, iz)
x1 = xdat(1, ix)
x2 = xdat(2, ix)
fyz2 = fyz2 + g2*x1
fx2 = fx2 + g2*x2
END DO ! Loop on x
force(1) = force(1) + fx2*zdat(1, iz)*ydat(1, iy2)
force(2) = force(2) + fyz2*zdat(1, iz)*ydat(2, iy2)
force(3) = force(3) + fyz2*zdat(2, iz)*ydat(1, iy2)
END IF
END DO ! Loop on z
END SUBROUTINE integrate_gf_npbc
! **************************************************************************************************
!> \brief Main driver to collocate gaussian functions on grid
!> without using periodic boundary conditions (NoPBC)
!> \param zetp ...
!> \param rp ...
!> \param scale ...
!> \param W ...
!> \param pwgrid ...
!> \param cube_info ...
!> \param eps_mm_rspace ...
!> \param xdat ...
!> \param ydat ...
!> \param zdat ...
!> \param bo2 ...
!> \param n_rep_real ...
!> \param mm_cell ...
!> \par History
!> 07.2004 created [tlaino]
!> \author Teodoro Laino
! **************************************************************************************************
SUBROUTINE collocate_gf_rspace_NoPBC(zetp, rp, scale, W, pwgrid, cube_info, &
eps_mm_rspace, xdat, ydat, zdat, bo2, n_rep_real, mm_cell)
REAL(KIND=dp), INTENT(IN) :: zetp
REAL(KIND=dp), DIMENSION(3), INTENT(IN) :: rp
REAL(KIND=dp), INTENT(IN) :: scale, W
TYPE(pw_r3d_rs_type), INTENT(IN) :: pwgrid
TYPE(cube_info_type), INTENT(IN) :: cube_info
REAL(KIND=dp), INTENT(IN) :: eps_mm_rspace
REAL(KIND=dp), DIMENSION(:), POINTER :: xdat, ydat, zdat
INTEGER, DIMENSION(2, 3), INTENT(IN) :: bo2
INTEGER, DIMENSION(3), INTENT(IN) :: n_rep_real
TYPE(cell_type), POINTER :: mm_cell
INTEGER :: ig, ix, iy, iz, xlb, xub, ylb, yub, zlb, &
zub
INTEGER, DIMENSION(2, 3) :: bo, gbo
INTEGER, DIMENSION(3) :: cubecenter, lb_cube, ub_cube
INTEGER, DIMENSION(:), POINTER :: sphere_bounds
REAL(KIND=dp) :: radius, rpg, xap, yap, zap
REAL(KIND=dp), DIMENSION(3) :: dr, my_shift, rpl
REAL(KIND=dp), DIMENSION(:, :, :), POINTER :: grid
radius = exp_radius(0, zetp, eps_mm_rspace, scale*W)
IF (radius .EQ. 0.0_dp) THEN
RETURN
END IF
! *** properties of the grid ***
rpl = rp
dr(:) = pwgrid%pw_grid%dr(:)
grid => pwgrid%array
bo = pwgrid%pw_grid%bounds_local
gbo = pwgrid%pw_grid%bounds
! *** get the sub grid properties for the given radius ***
CALL return_cube(cube_info, radius, lb_cube, ub_cube, sphere_bounds)
IF (ALL(n_rep_real == 0)) THEN
cubecenter(:) = FLOOR(rpl(:)/dr(:)) + gbo(1, :)
zub = MIN(bo(2, 3), cubecenter(3) + ub_cube(3))
zlb = MAX(bo(1, 3), cubecenter(3) + lb_cube(3))
yub = MIN(bo(2, 2), cubecenter(2) + ub_cube(2))
ylb = MAX(bo(1, 2), cubecenter(2) + lb_cube(2))
xub = MIN(bo(2, 1), cubecenter(1) + ub_cube(1))
xlb = MAX(bo(1, 1), cubecenter(1) + lb_cube(1))
IF (zlb .GT. zub .OR. ylb .GT. yub .OR. xlb .GT. xub) RETURN
DO ig = zlb, zub
rpg = REAL(ig - gbo(1, 3), dp)*dr(3) - rpl(3)
zap = EXP(-zetp*rpg**2)
zdat(ig) = scale*W*zap
END DO
DO ig = ylb, yub
rpg = REAL(ig - gbo(1, 2), dp)*dr(2) - rpl(2)
yap = EXP(-zetp*rpg**2)
ydat(ig) = yap
END DO
DO ig = xlb, xub
rpg = REAL(ig - gbo(1, 1), dp)*dr(1) - rpl(1)
xap = EXP(-zetp*rpg**2)
xdat(ig) = xap
END DO
CALL collocate_gf_npbc(grid, xdat, ydat, zdat, bo, bo2, zlb, zub, ylb, yub, xlb, xub)
ELSE
DO iz = -n_rep_real(3), n_rep_real(3)
my_shift(3) = mm_cell%hmat(3, 3)*REAL(iz, KIND=dp)
DO iy = -n_rep_real(2), n_rep_real(2)
my_shift(2) = mm_cell%hmat(2, 2)*REAL(iy, KIND=dp)
DO ix = -n_rep_real(1), n_rep_real(1)
my_shift(1) = mm_cell%hmat(1, 1)*REAL(ix, KIND=dp)
rpl = rp + my_shift(:)
cubecenter(:) = FLOOR(rpl(:)/dr(:)) + gbo(1, :)
zub = MIN(bo(2, 3), cubecenter(3) + ub_cube(3))
zlb = MAX(bo(1, 3), cubecenter(3) + lb_cube(3))
yub = MIN(bo(2, 2), cubecenter(2) + ub_cube(2))
ylb = MAX(bo(1, 2), cubecenter(2) + lb_cube(2))
xub = MIN(bo(2, 1), cubecenter(1) + ub_cube(1))
xlb = MAX(bo(1, 1), cubecenter(1) + lb_cube(1))
IF (zlb .GT. zub .OR. ylb .GT. yub .OR. xlb .GT. xub) CYCLE
DO ig = zlb, zub
rpg = REAL(ig - gbo(1, 3), dp)*dr(3) - rpl(3)
zap = EXP(-zetp*rpg**2)
zdat(ig) = scale*W*zap
END DO
DO ig = ylb, yub
rpg = REAL(ig - gbo(1, 2), dp)*dr(2) - rpl(2)
yap = EXP(-zetp*rpg**2)
ydat(ig) = yap
END DO
DO ig = xlb, xub
rpg = REAL(ig - gbo(1, 1), dp)*dr(1) - rpl(1)
xap = EXP(-zetp*rpg**2)
xdat(ig) = xap
END DO
CALL collocate_gf_npbc(grid, xdat, ydat, zdat, bo, bo2, zlb, zub, ylb, yub, xlb, xub)
END DO
END DO
END DO
END IF
END SUBROUTINE collocate_gf_rspace_NoPBC
! **************************************************************************************************
!> \brief Main driver to integrate gaussian functions on a grid function
!> without using periodic boundary conditions (NoPBC)
!> Computes Forces.
!> \param zetp ...
!> \param rp ...
!> \param scale ...
!> \param W ...
!> \param pwgrid ...
!> \param cube_info ...
!> \param eps_mm_rspace ...
!> \param xdat ...
!> \param ydat ...
!> \param zdat ...
!> \param bo ...
!> \param force ...
!> \param n_rep_real ...
!> \param mm_cell ...
!> \par History
!> 07.2004 created [tlaino]
!> \author Teodoro Laino
! **************************************************************************************************
SUBROUTINE integrate_gf_rspace_NoPBC(zetp, rp, scale, W, pwgrid, cube_info, &
eps_mm_rspace, xdat, ydat, zdat, bo, force, n_rep_real, mm_cell)
REAL(KIND=dp), INTENT(IN) :: zetp
REAL(KIND=dp), DIMENSION(3), INTENT(IN) :: rp
REAL(KIND=dp), INTENT(IN) :: scale, W
TYPE(pw_r3d_rs_type), INTENT(IN) :: pwgrid
TYPE(cube_info_type), INTENT(IN) :: cube_info
REAL(KIND=dp), INTENT(IN) :: eps_mm_rspace
INTEGER, DIMENSION(2, 3), INTENT(IN) :: bo
REAL(KIND=dp), DIMENSION(2, bo(1, 3):bo(2, 3)) :: zdat
REAL(KIND=dp), DIMENSION(2, bo(1, 2):bo(2, 2)) :: ydat
REAL(KIND=dp), DIMENSION(2, bo(1, 1):bo(2, 1)) :: xdat
REAL(KIND=dp), DIMENSION(3), INTENT(OUT) :: force
INTEGER, DIMENSION(3), INTENT(IN) :: n_rep_real
TYPE(cell_type), POINTER :: mm_cell
INTEGER :: ig, ix, iy, iz, xlb, xub, ylb, yub, zlb, &
zub
INTEGER, DIMENSION(2, 3) :: gbo
INTEGER, DIMENSION(3) :: cubecenter, lb_cube, ub_cube
INTEGER, DIMENSION(:), POINTER :: sphere_bounds
REAL(KIND=dp) :: radius, rpg, xap, yap, zap
REAL(KIND=dp), DIMENSION(3) :: dr, my_shift, rpl
REAL(KIND=dp), DIMENSION(:, :, :), POINTER :: grid
force = 0.0_dp
radius = exp_radius(0, zetp, eps_mm_rspace, scale*W)
IF (radius .EQ. 0.0_dp) RETURN
! *** properties of the grid ***
rpl = rp
dr(:) = pwgrid%pw_grid%dr(:)
grid => pwgrid%array
gbo = pwgrid%pw_grid%bounds
! *** get the sub grid properties for the given radius ***
CALL return_cube(cube_info, radius, lb_cube, ub_cube, sphere_bounds)
IF (ALL(n_rep_real == 0)) THEN
cubecenter(:) = FLOOR(rpl(:)/dr(:)) + gbo(1, :)
zub = MIN(bo(2, 3), cubecenter(3) + ub_cube(3))
zlb = MAX(bo(1, 3), cubecenter(3) + lb_cube(3))
yub = MIN(bo(2, 2), cubecenter(2) + ub_cube(2))
ylb = MAX(bo(1, 2), cubecenter(2) + lb_cube(2))
xub = MIN(bo(2, 1), cubecenter(1) + ub_cube(1))
xlb = MAX(bo(1, 1), cubecenter(1) + lb_cube(1))
IF (zlb .GT. zub .OR. ylb .GT. yub .OR. xlb .GT. xub) RETURN
DO ig = zlb, zub
rpg = REAL(ig - gbo(1, 3), dp)*dr(3) - rpl(3)
zap = EXP(-zetp*rpg**2)
zdat(1, ig) = scale*W*zap
zdat(2, ig) = rpg*zdat(1, ig)*zetp*2.0_dp
END DO
DO ig = ylb, yub
rpg = REAL(ig - gbo(1, 2), dp)*dr(2) - rpl(2)
yap = EXP(-zetp*rpg**2)
ydat(1, ig) = yap
ydat(2, ig) = rpg*ydat(1, ig)*zetp*2.0_dp
END DO
DO ig = xlb, xub
rpg = REAL(ig - gbo(1, 1), dp)*dr(1) - rpl(1)
xap = EXP(-zetp*rpg**2)
xdat(1, ig) = xap
xdat(2, ig) = rpg*xdat(1, ig)*zetp*2.0_dp
END DO
CALL integrate_gf_npbc(grid, xdat, ydat, zdat, bo, zlb, zub, ylb, yub, xlb, xub, force)
ELSE
DO iz = -n_rep_real(3), n_rep_real(3)
my_shift(3) = mm_cell%hmat(3, 3)*REAL(iz, KIND=dp)
DO iy = -n_rep_real(2), n_rep_real(2)
my_shift(2) = mm_cell%hmat(2, 2)*REAL(iy, KIND=dp)
DO ix = -n_rep_real(1), n_rep_real(1)
my_shift(1) = mm_cell%hmat(1, 1)*REAL(ix, KIND=dp)
rpl = rp + my_shift(:)
cubecenter(:) = FLOOR(rpl(:)/dr(:)) + gbo(1, :)
zub = MIN(bo(2, 3), cubecenter(3) + ub_cube(3))
zlb = MAX(bo(1, 3), cubecenter(3) + lb_cube(3))
yub = MIN(bo(2, 2), cubecenter(2) + ub_cube(2))
ylb = MAX(bo(1, 2), cubecenter(2) + lb_cube(2))
xub = MIN(bo(2, 1), cubecenter(1) + ub_cube(1))
xlb = MAX(bo(1, 1), cubecenter(1) + lb_cube(1))
IF (zlb .GT. zub .OR. ylb .GT. yub .OR. xlb .GT. xub) CYCLE
DO ig = zlb, zub
rpg = REAL(ig - gbo(1, 3), dp)*dr(3) - rpl(3)
zap = EXP(-zetp*rpg**2)
zdat(1, ig) = scale*W*zap
zdat(2, ig) = rpg*zdat(1, ig)*zetp*2.0_dp
END DO
DO ig = ylb, yub
rpg = REAL(ig - gbo(1, 2), dp)*dr(2) - rpl(2)
yap = EXP(-zetp*rpg**2)
ydat(1, ig) = yap
ydat(2, ig) = rpg*ydat(1, ig)*zetp*2.0_dp
END DO
DO ig = xlb, xub
rpg = REAL(ig - gbo(1, 1), dp)*dr(1) - rpl(1)
xap = EXP(-zetp*rpg**2)
xdat(1, ig) = xap
xdat(2, ig) = rpg*xdat(1, ig)*zetp*2.0_dp
END DO
CALL integrate_gf_npbc(grid, xdat, ydat, zdat, bo, &
zlb, zub, ylb, yub, xlb, xub, force)
END DO
END DO
END DO
END IF
END SUBROUTINE integrate_gf_rspace_NoPBC
END MODULE mm_collocate_potential