-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqc_neigh.f90
590 lines (505 loc) · 20.8 KB
/
qc_neigh.f90
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
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
module triple_type
type triple
integer :: a, b, c
end type triple
end module triple_type
module lat_queue
use triple_type, QUEUE_DATA => triple
logical, dimension(:,:,:), allocatable :: vis
include "queues.f90"
function visited(newvec)
type(QUEUE_DATA), intent(in) :: newvec
logical :: visited
visited = vis(newvec%a, newvec%b, newvec%c)
vis(newvec%a, newvec%b, newvec%c) = .true.
end function visited
end module lat_queue
module qc_neigh
use qc_system
use consts
use lat_queue
implicit none
type, public :: neigh_typ
integer :: jm, ja, jb, jc
logical :: qm
end type neigh_typ
type, public :: pair_typ
integer :: jm, ja, jb, jc
real*8 :: scale
end type pair_typ
integer, dimension(:), allocatable :: npair(:)
integer, dimension(:), allocatable :: nbq(:), nlr(:)
integer :: num_pairs
integer :: nbq2
type(pair_typ), dimension(:,:), allocatable, target :: pair_list
type(neigh_typ), dimension(:,:), allocatable, target :: bq_list
type(neigh_typ), dimension(:), allocatable :: bq2_list
contains
subroutine qc_get_lists (overflow)
use qc_mpi
type(QUEUE_STRUCT), pointer :: lat_vecs
type(QUEUE_DATA) :: vec, nvec
logical, intent(out) :: overflow
logical :: success
integer :: nhits
num_pairs = 0
npair = 0
nbq = 0
!---BREADTH-FIRST-SEARCH: NEIGHBOR CELLS
call queue_create( lat_vecs, 10000 )
allocate ( vis(-100:100,-100:100,-100:100) )
vis = .false.
vec%a = 0; vec%b = 0; vec%c = 0
call queue_append_data(lat_vecs, vec, success)
vis(0,0,0) = .true.
do while (.not. queue_empty(lat_vecs))
vec = queue_retrieve_data(lat_vecs)
call build_pairs(vec, nhits, overflow)
if (overflow) exit
if (nhits .gt. 0) then
if (a_dim) then
nvec%a = vec%a+1; nvec%b = vec%b; nvec%c = vec%c
if (.not. visited(nvec)) call queue_append_data(lat_vecs, nvec, success)
if (.not. success) STOP "***QUEUE OVERFLOW***"
nvec%a = vec%a-1; nvec%b = vec%b; nvec%c = vec%c
if (.not. visited(nvec)) call queue_append_data(lat_vecs, nvec, success)
if (.not. success) STOP "***QUEUE OVERFLOW***"
end if
if (b_dim) then
nvec%a = vec%a; nvec%b = vec%b+1; nvec%c = vec%c
if (.not. visited(nvec)) call queue_append_data(lat_vecs, nvec, success)
if (.not. success) STOP "***QUEUE OVERFLOW***"
nvec%a = vec%a; nvec%b = vec%b-1; nvec%c = vec%c
if (.not. visited(nvec)) call queue_append_data(lat_vecs, nvec, success)
if (.not. success) STOP "***QUEUE OVERFLOW***"
end if
if (c_dim) then
nvec%a = vec%a; nvec%b = vec%b; nvec%c = vec%c+1
if (.not. visited(nvec)) call queue_append_data(lat_vecs, nvec, success)
if (.not. success) STOP "***QUEUE OVERFLOW***"
nvec%a = vec%a; nvec%b = vec%b; nvec%c = vec%c-1
if (.not. visited(nvec)) call queue_append_data(lat_vecs, nvec, success)
if (.not. success) STOP "***QUEUE OVERFLOW***"
end if
end if
end do
deallocate (vis)
call queue_destroy (lat_vecs)
if (overflow .and. sys_master) then
write(*,*) "Detected neighbor list overflow"
end if
end subroutine qc_get_lists
subroutine qc_allocate_lists
use qc_mpi
type(QUEUE_STRUCT), pointer :: lat_vecs
type(QUEUE_DATA) :: vec, nvec
logical :: success
integer :: nhits
if (sys_master) write(*,'(A,/)') "(Re)allocating neighbor lists..."
num_pairs = 0
npair = 0
nbq = 0
if (allocated(pair_list)) deallocate(pair_list)
if (allocated(bq_list)) deallocate(bq_list)
if (allocated(bq2_list)) deallocate(bq2_list)
if (allocated(d_bq0)) deallocate (d_bq0)
if (allocated(d_mbqi)) deallocate (d_mbqi)
if (allocated(d_mbqj)) deallocate (d_mbqj)
if (allocated(d_mr)) deallocate (d_mr)
!---BREADTH-FIRST-SEARCH: NEIGHBOR CELLS
call queue_create( lat_vecs, 10000 )
allocate ( vis(-100:100,-100:100,-100:100) )
vis = .false.
vec%a = 0; vec%b = 0; vec%c = 0
call queue_append_data(lat_vecs, vec, success)
vis(0,0,0) = .true.
do while (.not. queue_empty(lat_vecs))
vec = queue_retrieve_data(lat_vecs)
call count_pairs(vec, nhits)
if (nhits .gt. 0) then
if (a_dim) then
nvec%a = vec%a+1; nvec%b = vec%b; nvec%c = vec%c
if (.not. visited(nvec)) call queue_append_data(lat_vecs, nvec, success)
if (.not. success) STOP "***QUEUE OVERFLOW***"
nvec%a = vec%a-1; nvec%b = vec%b; nvec%c = vec%c
if (.not. visited(nvec)) call queue_append_data(lat_vecs, nvec, success)
if (.not. success) STOP "***QUEUE OVERFLOW***"
end if
if (b_dim) then
nvec%a = vec%a; nvec%b = vec%b+1; nvec%c = vec%c
if (.not. visited(nvec)) call queue_append_data(lat_vecs, nvec, success)
if (.not. success) STOP "***QUEUE OVERFLOW***"
nvec%a = vec%a; nvec%b = vec%b-1; nvec%c = vec%c
if (.not. visited(nvec)) call queue_append_data(lat_vecs, nvec, success)
if (.not. success) STOP "***QUEUE OVERFLOW***"
end if
if (c_dim) then
nvec%a = vec%a; nvec%b = vec%b; nvec%c = vec%c+1
if (.not. visited(nvec)) call queue_append_data(lat_vecs, nvec, success)
if (.not. success) STOP "***QUEUE OVERFLOW***"
nvec%a = vec%a; nvec%b = vec%b; nvec%c = vec%c-1
if (.not. visited(nvec)) call queue_append_data(lat_vecs, nvec, success)
if (.not. success) STOP "***QUEUE OVERFLOW***"
end if
end if
end do
deallocate (vis)
call queue_destroy (lat_vecs)
maxnum_pair = maxval(npair) + 10
maxnum_bq = maxval(nbq) + 10
allocate (pair_list(maxnum_pair,nmol))
allocate (bq_list(maxnum_bq,nmol))
allocate (bq2_list(2*maxnum_bq))
allocate (d_bq0(3,2*maxnum_bq*3))
allocate (d_mbqi(3,2*maxnum_bq*3))
allocate (d_mbqj(3,2*maxnum_bq*3))
allocate (d_mr (3,natom))
end subroutine qc_allocate_lists
subroutine get_lr_interaction (u_lr, im, l_old_neigh)
integer, intent(in) :: im
real*8, intent(out) :: u_lr
logical, intent(in) :: l_old_neigh
type(QUEUE_STRUCT), pointer :: lat_vecs
type(QUEUE_DATA) :: vec, nvec
logical :: success
integer :: nhits
nlr(im) = 0
u_lr = 0.0d0
call queue_create( lat_vecs, 200000 )
allocate ( vis(-100:100,-100:100,-100:100) )
vis = .false.
vec%a = 0; vec%b = 0; vec%c = 0
call queue_append_data(lat_vecs, vec, success)
vis(0,0,0) = .true.
do while (.not. queue_empty(lat_vecs))
vec = queue_retrieve_data(lat_vecs)
call accumulate_lr(im, u_lr, vec, nhits, l_old_neigh)
if (nhits .gt. 0) then
if (a_dim) then
nvec%a = vec%a+1; nvec%b = vec%b; nvec%c = vec%c
if (.not. visited(nvec)) call queue_append_data(lat_vecs, nvec, success)
if (.not. success) STOP "***QUEUE OVERFLOW***"
nvec%a = vec%a-1; nvec%b = vec%b; nvec%c = vec%c
if (.not. visited(nvec)) call queue_append_data(lat_vecs, nvec, success)
if (.not. success) STOP "***QUEUE OVERFLOW***"
end if
if (b_dim) then
nvec%a = vec%a; nvec%b = vec%b+1; nvec%c = vec%c
if (.not. visited(nvec)) call queue_append_data(lat_vecs, nvec, success)
if (.not. success) STOP "***QUEUE OVERFLOW***"
nvec%a = vec%a; nvec%b = vec%b-1; nvec%c = vec%c
if (.not. visited(nvec)) call queue_append_data(lat_vecs, nvec, success)
if (.not. success) STOP "***QUEUE OVERFLOW***"
end if
if (c_dim) then
nvec%a = vec%a; nvec%b = vec%b; nvec%c = vec%c+1
if (.not. visited(nvec)) call queue_append_data(lat_vecs, nvec, success)
if (.not. success) STOP "***QUEUE OVERFLOW***"
nvec%a = vec%a; nvec%b = vec%b; nvec%c = vec%c-1
if (.not. visited(nvec)) call queue_append_data(lat_vecs, nvec, success)
if (.not. success) STOP "***QUEUE OVERFLOW***"
end if
end if
end do
deallocate (vis)
call queue_destroy (lat_vecs)
end subroutine get_lr_interaction
subroutine count_pairs(vec, nhits)
TYPE(QUEUE_DATA), intent(in) :: vec
integer, intent(out) :: nhits
integer :: im, ia
integer :: jm, na, nb, nc, ja
real*8 :: ri(3), rj(3), dcel(3), dr(3), r2
na = vec%a; nb = vec%b; nc = vec%c
dcel(:) = na*lat(:,1)+nb*lat(:,2)+nc*lat(:,3)
nhits = 0
do im = 1, nmol
ia = mol_iatom(im)
ri = gm_pos(1:3,ia+1)
do jm = 1, nmol
if (im .eq. jm .and. na .eq. 0 .and. nb .eq. 0 .and. nc .eq. 0) cycle
ja = mol_iatom(jm)
rj = gm_pos(1:3,ja+1) + dcel
dr = ri - rj
r2 = dot_product(dr, dr)
!-- within QM and BQ
if (r2 < rcut_qq2) then
nhits = nhits + 1
nbq(im) = nbq(im) + 1
if (jm .gt. im) then
npair(im) = npair(im) + 1
num_pairs = num_pairs + 1
else if ( (jm.eq.im) .and. cell_gt_zero(na,nb,nc) ) then
npair(im) = npair(im) + 1
num_pairs = num_pairs + 1
end if
!-- within BQ, outside QM
else if (r2 < rcut_bq2) then
nhits = nhits + 1
nbq(im) = nbq(im) + 1
end if
end do
end do
end subroutine count_pairs
subroutine build_pairs(vec, nhits, overflow)
!use qc_mpi
TYPE(QUEUE_DATA), intent(in) :: vec
integer, intent(out) :: nhits
logical, intent(out) :: overflow
integer :: im, ia
integer :: jm, na, nb, nc, ja
real*8 :: ri(3), rj(3), dcel(3), dr(3), r2
na = vec%a; nb = vec%b; nc = vec%c
dcel(:) = na*lat(:,1)+nb*lat(:,2)+nc*lat(:,3)
nhits = 0
overflow = .false.
do im = 1, nmol
ia = mol_iatom(im)
ri = gm_pos(1:3,ia+1)
do jm = 1, nmol
if (im .eq. jm .and. na .eq. 0 .and. nb .eq. 0 .and. nc .eq. 0) cycle
ja = mol_iatom(jm)
rj = gm_pos(1:3,ja+1) + dcel
dr = ri - rj
r2 = dot_product(dr, dr)
!-- within QM and BQ
if (r2 < rcut_qq2) then
nhits = nhits + 1
nbq(im) = nbq(im) + 1
if (nbq(im) > maxnum_bq) then
overflow = .true.
exit
end if
bq_list(nbq(im),im)%jm = jm
bq_list(nbq(im),im)%ja = na
bq_list(nbq(im),im)%jb = nb
bq_list(nbq(im),im)%jc = nc
bq_list(nbq(im),im)%qm = .true.
if (jm .gt. im) then
npair(im) = npair(im) + 1
num_pairs = num_pairs + 1
!if (sys_master) write(*,*) im, 'has', npair(im)
if (npair(im) > maxnum_pair) then
overflow = .true.
exit
end if
pair_list(npair(im),im)%jm = jm
pair_list(npair(im),im)%ja = na
pair_list(npair(im),im)%jb = nb
pair_list(npair(im),im)%jc = nc
pair_list(npair(im),im)%scale = 1.0d0
else if ( (jm.eq.im) .and. cell_gt_zero(na,nb,nc) ) then
npair(im) = npair(im) + 1
num_pairs = num_pairs + 1
!if (sys_master) write(*,*) im, 'has', npair(im)
if (npair(im) > maxnum_pair) then
overflow = .true.
exit
end if
pair_list(npair(im),im)%jm = jm
pair_list(npair(im),im)%ja = na
pair_list(npair(im),im)%jb = nb
pair_list(npair(im),im)%jc = nc
pair_list(npair(im),im)%scale = 1.0d0
end if
!-- within BQ, outside QM
else if (r2 < rcut_bq2) then
nhits = nhits + 1
nbq(im) = nbq(im) + 1
if (nbq(im) > maxnum_bq) then
overflow = .true.
exit
end if
bq_list(nbq(im),im)%jm = jm
bq_list(nbq(im),im)%ja = na
bq_list(nbq(im),im)%jb = nb
bq_list(nbq(im),im)%jc = nc
bq_list(nbq(im),im)%qm = .false.
end if
end do
if (overflow) exit
end do
end subroutine build_pairs
subroutine qc_bq2_list_get(im, ip, l_old_neigh)
integer, intent(in) :: im, ip
logical, intent(in) :: l_old_neigh
integer :: jm, ka, kb, na, nb, nc
real*8 :: ri(3), rk(3), dr(3), r2, dcel(3)
! monomer im and its bq's (this will include monomers i and j)
if (l_old_neigh) then
ri = gm_pos_old(1:3,mol_iatom(im)+1)
else
ri = gm_pos(1:3,mol_iatom(im)+1)
end if
bq2_list(1)%jm = im
bq2_list(1)%ja = 0
bq2_list(1)%jb = 0
bq2_list(1)%jc = 0
nbq2 = 1
do kb=1,nbq(im)
nbq2 = nbq2 + 1
bq2_list(nbq2)%jm = bq_list(kb,im)%jm
bq2_list(nbq2)%ja = bq_list(kb,im)%ja
bq2_list(nbq2)%jb = bq_list(kb,im)%jb
bq2_list(nbq2)%jc = bq_list(kb,im)%jc
end do
! bq's of jm not within bq cutoff of im (will NOT include monomers i or j)
jm = pair_list(ip,im)%jm
na = pair_list(ip,im)%ja
nb = pair_list(ip,im)%jb
nc = pair_list(ip,im)%jc
if (l_old_neigh) then
dcel(:) = na*lat_old(:,1)+nb*lat_old(:,2)+nc*lat_old(:,3)
else
dcel(:) = na*lat(:,1)+nb*lat(:,2)+nc*lat(:,3)
end if
do kb=1,nbq(jm)
ka = mol_iatom(bq_list(kb,jm)%jm)
if (l_old_neigh) then
rk = gm_pos_old(1:3,ka+1) + bq_list(kb,jm)%ja*lat_old(:,1) + bq_list(kb,jm)%jb*lat_old(:,2) &
+ bq_list(kb,jm)%jc*lat_old(:,3)
else
rk = gm_pos(1:3,ka+1) + bq_list(kb,jm)%ja*lat(:,1) + bq_list(kb,jm)%jb*lat(:,2) &
+ bq_list(kb,jm)%jc*lat(:,3)
end if
rk = rk + dcel
dr = rk - ri
r2 = dot_product(dr, dr)
if (r2 < rcut_bq2) then
cycle !-- already got from im
else
nbq2 = nbq2 + 1
bq2_list(nbq2)%jm = bq_list(kb,jm)%jm
bq2_list(nbq2)%ja = bq_list(kb,jm)%ja + na
bq2_list(nbq2)%jb = bq_list(kb,jm)%jb + nb
bq2_list(nbq2)%jc = bq_list(kb,jm)%jc + nc
end if
end do
end subroutine qc_bq2_list_get
subroutine accumulate_lr(im, u_lr, vec, nhits, l_old_neigh)
integer, intent(in) :: im
real*8, intent(inout) :: u_lr
TYPE(QUEUE_DATA), intent(in) :: vec
integer, intent(out) :: nhits
logical, intent(in) :: l_old_neigh
logical :: completeLRcell, outOfRange
integer :: ia, is, i, j, nchg_i, ichg_i, nchg_j, ichg_j
integer :: jm, na, nb, nc, ja, js, at_i, at_j
real*8 :: ri(3), rj(3), qi, qj, dcel(3), rij(3), rij2, rij_norm
real*8 :: d_ri(3)
completeLRcell = .false.
outOfRange = .false.
na = vec%a; nb = vec%b; nc = vec%c
dcel(:) = na*lat(:,1)+nb*lat(:,2)+nc*lat(:,3)
nhits = 0
ia = mol_iatom(im)
nchg_i = mol_nchg(im)
ichg_i = mol_ichg(im)
do jm = 1, nmol
if (im .eq. jm .and. na .eq. 0 .and. nb .eq. 0 .and. nc .eq. 0) cycle
ja = mol_iatom(jm)
nchg_j = mol_nchg(jm)
ichg_j = mol_ichg(jm)
if (l_old_neigh) then
ri = gm_pos_old(1:3,ia+1)
rj = gm_pos_old(1:3,ja+1) + na*lat_old(:,1)+nb*lat_old(:,2)+nc*lat_old(:,3)
else
ri = gm_pos(1:3,ia+1)
rj = gm_pos(1:3,ja+1) + dcel
end if
rij = rj - ri
rij2 = dot_product(rij, rij)
if (rij2 < rcut_qq2) then
nhits = nhits + 1
else if (rij2 < rcut_bq2) then
nhits = nhits + 1
else if (rij2 < rcut_lr2) then
nhits = nhits + 1
nlr(im) = nlr(im) + 1
completeLRcell = .true.
do is=1, nchg_i
ri = chg_pos(1:3,ichg_i+is)
qi = chg_pos(0, ichg_i+is)
do js = 1, nchg_j
rj = chg_pos(1:3,ichg_j+js) + dcel
qj = chg_pos(0, ichg_j+js)
rij = (rj - ri)*ang2bohr ! points from i to j
rij_norm = sqrt(dot_product(rij,rij))
u_lr = u_lr + 0.5d0*qi*qj/rij_norm
if (l_grd) then
d_ri = 0.5d0 * rij * (qi*qj/(rij_norm**3))
do at_i = 1, mol_nsite(im)
d_mr(1:3,ia+at_i) = d_mr(1:3,ia+at_i) + d_ri(1:3)*chg_coef(at_i, ichg_i+is) ! why are we doing this???
end do
do at_j = 1, mol_nsite(jm)
d_mr(1:3,ja+at_j) = d_mr(1:3,ja+at_j) - d_ri(1:3)*chg_coef(at_j, ichg_j+js)
end do
!--LR Contribution to Virial Tensor
do j = 1, 3
do i = 1, 3
m_virt(i,j) = m_virt(i,j) - gm_pos(i,ia+1)*ang2bohr*d_ri(j) ! force on i is -d_ri
m_virt(i,j) = m_virt(i,j) + (gm_pos(i,ja+1)+dcel(i))*ang2bohr*d_ri(j) ! force on k is +d_ri
end do
end do
end if
end do
end do
else
outOfRange = .true.
end if
end do
if (completeLRcell .and. outOfRange) then
do jm = 1, nmol
if (im .eq. jm .and. na .eq. 0 .and. nb .eq. 0 .and. nc .eq. 0) cycle
ja = mol_iatom(jm)
nchg_j = mol_nchg(jm)
ichg_j = mol_ichg(jm)
if (l_old_neigh) then
ri = gm_pos_old(1:3,ia+1)
rj = gm_pos_old(1:3,ja+1) + na*lat_old(:,1)+nb*lat_old(:,2)+nc*lat_old(:,3)
else
ri = gm_pos(1:3,ia+1)
rj = gm_pos(1:3,ja+1) + dcel
end if
rij = rj - ri
rij2 = dot_product(rij, rij)
if (rij2 >= rcut_lr2) then
nhits = nhits + 1
nlr(im) = nlr(im) + 1
do is=1, nchg_i
ri = chg_pos(1:3,ichg_i+is)
qi = chg_pos(0, ichg_i+is)
do js = 1, nchg_j
rj = chg_pos(1:3,ichg_j+js) + dcel
qj = chg_pos(0, ichg_j+js)
rij = (rj - ri)*ang2bohr ! points from i to j
rij_norm = sqrt(dot_product(rij,rij))
u_lr = u_lr + 0.5d0*qi*qj/rij_norm
if (l_grd) then
d_ri = 0.5d0 * rij * (qi*qj/(rij_norm**3))
do at_i = 1, mol_nsite(im)
d_mr(1:3,ia+at_i) = d_mr(1:3,ia+at_i) + d_ri(1:3)*chg_coef(at_i, ichg_i+is)
end do
do at_j = 1, mol_nsite(jm)
d_mr(1:3,ja+at_j) = d_mr(1:3,ja+at_j) - d_ri(1:3)*chg_coef(at_j, ichg_j+js)
end do
!--LR Contribution to Virial Tensor
do j = 1, 3
do i = 1, 3
m_virt(i,j) = m_virt(i,j) - gm_pos(i,ia+1)*ang2bohr*d_ri(j) ! force on i is -d_ri
m_virt(i,j) = m_virt(i,j) + (gm_pos(i,ja+1)+dcel(i))*ang2bohr*d_ri(j) ! force on k is +d_ri
end do
end do
end if
end do
end do
end if
end do
end if
end subroutine accumulate_lr
function cell_gt_zero (na, nb, nc)
integer, intent(in) :: na, nb, nc
logical :: cell_gt_zero
cell_gt_zero = (na.gt.0).or.(na.eq.0 .and. nb.gt.0).or.(na.eq.0 .and. nb.eq.0 .and. nc.gt.0)
end function cell_gt_zero
end module qc_neigh