Debian Codegraph @

contrib/iapbs/modules/CHARMM/apbs.f

raw
1 CHARMM Element source/misc/apbs.src
2 SUBROUTINE APBS
3 c
4 c
5 c APBS module for CHARMM/APBS integration
6 c
7 c-----------------------------------------------------------------------
8 ##IFN APBS
9 CALL WRNDIE(-1,'<CHARMM>','iAPBS module was not compiled.')
10 ##ELSE
11 c
12 c implicit none
13 ##INCLUDE '~/charmm_fcm/impnon.fcm'
14 c
15 c maxa (max # of atoms), maxaim (including image atoms)
16 ##INCLUDE '~/charmm_fcm/dimens.fcm'
17 c
18 c numbers definitions
19 ##INCLUDE '~/charmm_fcm/number.fcm'
20 c
21 ##INCLUDE '~/charmm_fcm/exfunc.fcm'
22 c
23 ##INCLUDE '~/charmm_fcm/comand.fcm'
24 c
25 c natom, cg (charge)
26 ##INCLUDE '~/charmm_fcm/psf.fcm'
27 c
28 ##INCLUDE '~/charmm_fcm/stream.fcm'
29 c
30 c x, y, z coords, wmain
31 ##INCLUDE '~/charmm_fcm/coord.fcm'
32 c
33 ##INCLUDE '~/charmm_fcm/stack.fcm'
34 ##INCLUDE '~/charmm_fcm/heap.fcm'
35 ##INCLUDE '~/charmm_fcm/pbeq.fcm'
36 ##INCLUDE '~/charmm_fcm/timer.fcm'
37 c
38 c forces common block: dx, dy, dz
39 c##INCLUDE '~/charmm_fcm/deriv.fcm'
40 c
41 c-----------------------------------------------------------------
42 c apbs include
43 c
44 ##INCLUDE '~/charmm_fcm/apbs.fcm'
45 ##INCLUDE '~/charmm_fcm/parallel.fcm'
46 c-----------------------------------------------------------------
47 c local variables
48 integer*4 rc, apbsdrv
49 ! integer ncalc(1)
50 logical skip, sp_apbs
51
52 INTEGER*4 nonlin, bcfl, nion, srfm, calcenergy, calcforce
53 INTEGER*4 calc_type, nlev, cmeth, ccmeth, fcmeth, chgm
54 INTEGER*4 calcnpenergy, wpot, wchg, wsmol, wkappa, wdiel
55 INTEGER*4 watompot, rpot
56 INTEGER*4 calcnpforce
57 INTEGER*4 rchg, rkappa, rdiel
58 INTEGER*4 apbs_print, radiopt
59
60 double precision pdie, sdie, srad, swinapbs, tempapbs, gamma
61 double precision sdens,smvolume, smsize
62 double precision maxx, minx, maxy, miny, maxz, minz
63
64 double precision esenerg(15), npenerg(15)
65 double precision apbsdx(NATOM), apbsdy(NATOM), apbsdz(NATOM)
66 double precision apbsqfx(NATOM), apbsqfy(NATOM), apbsqfz(NATOM)
67 double precision apbsibx(NATOM), apbsiby(NATOM), apbsibz(NATOM)
68 double precision apbsnpx(NATOM), apbsnpy(NATOM), apbsnpz(NATOM)
69 double precision apbsdbx(NATOM), apbsdby(NATOM), apbsdbz(NATOM)
70
71 double precision apbsgrid_meta(13), apbsgrid(3*NATOM)
72
73 c character*80 rcsid
74 c data rcsid /'$Id: apbs.f rok $'/
75 c-----------------------------------------------------------------
76 INTEGER ISLCT, lstpbi, ntpbi
77 C Local variables
78 INTEGER IMODE, I, LISTR, OLDUSD, NN
79 SAVE
80 c
81 IF (TIMER.GT.1)
82 $ CALL WRTTIM('PBEQ/APBS solver times:')
83 OLDUSD = LSTUSD
84 ISLCT = ALLSTK(INTEG4(NATOM))
85 lstpbi = allstk(integ4(NATOM))
86
87 c
88 c Atom Selection
89 c ==============
90
91 IMODE=0 !implies default = all atoms selected
92 CALL SELRPN(COMLYN,COMLEN,stack(ISLCT),NATOM,1,IMODE,
93 $ .FALSE.,1,' ',0,RESID,RES,IBASE,SEGID,NICTOT,NSEG,
94 $ .TRUE.,X,Y,Z,.TRUE.,1,HEAP(PBRAD))
95
96 IF(IMODE.NE.0)THEN
97 Write(outu,'(/,3x,a)')
98 $ 'PREP WARNING: Not all atoms selected, is this what you want?'
99 c CALL WRNDIE(-1,'<PREP>','ATOM SELECTION PARSING ERROR')
100 ENDIF
101
102 CALL STPRP(NATOM,stack(ISLCT),stack(lstpbi),NTpbi)
103 WRITE(OUTU,101)
104 WRITE(OUTU,101) 'Calculation with ',NTpbi,' atoms'
105 101 FORMAT(3X,A,I6,A)
106
107 call frestk(lstusd-oldusd)
108
109 c-----------------------------------------------------------------
110 c
111 c start of APBS section
112 c
113 c-----------------------------------------------------------------
114
115 c we are in APBS module so set qapbs to .T.
116 qapbs = .true.
117
118 c get the keywords and assign apbs parameters
119 qaparsed = .false.
120
121 c natom - current number of atoms
122
123 c-----------------------------------------------------------------
124 c
125 c CHARMM/APBS commands parsing section
126 c
127 c-----------------------------------------------------------------
128
129 ! rokFIXME: also add centering-related (center) keywords
130
131 ! Default values
132 ! PBEparm
133 ! ispara = 0
134 ! i_pbeparm(1) = 1 ! molid
135 nonlin = 0
136 bcfl = 1
137 nion = 0
138 srfm = 2
139 pdie = 2.0D0
140 sdie = 78.4D0
141 srad = 1.4D0
142 swinapbs = 0.3D0
143 tempapbs = 298.15D0
144 gamma = 0.105D0
145 sdens = 10.0D0
146 calcenergy = 2
147 calcforce = 2
148 calcnpenergy = 1
149 calcnpforce = 2
150 wpot = 0
151 wchg = 0
152 wsmol = 0
153 wkappa = 0
154 wdiel= 0
155 watompot = 0
156 rchg = 0
157 rkappa = 0
158 rdiel = 0
159 rpot = 0
160
161 ! MGparm
162 calc_type = 1 ! 0 - manual MG, 1- autoMG, 2- parallel MG
163 nlev = 4
164 cmeth = 1
165 ccmeth = 1
166 fcmeth = 1
167 chgm = 1
168
169 ofrac = 0.1D0
170
171 ! ionq = (/ 1.0, -1.0 /)
172 ! ionc = (/ 0.15, 0.15 /)
173 ! ionrr = (/ 2.0, 2.0 /)
174
175 do i = 1,3
176 pdime(i) = 0
177 dime(i) = 0
178 end do
179 do i = 1, 3
180 grid(i) = 0.5D0
181 glen(i) = 0.0D0
182 center(i) = 0.0D0
183 cglen(i) = 0.0D0
184 fglen(i) = 0.0D0
185 ccenter(i) = 0.0D0
186 fcenter(i) = 0.0D0
187 end do
188
189 do i = 1, 13
190 apbsgrid_meta(i) = 0.0
191 end do
192 do i = 1, 3*NATOM
193 apbsgrid(i) = 0.0
194 end do
195
196 ! is this a single point energy calculation?
197 ! default is no
198 sp_apbs = .FALSE.
199 ! printing verbosity
200 apbs_print = 1
201 ! debuging flag
202 apbs_debug = 0
203 ! radii optimization option
204 radiopt = 0
205 ! grid dimension recalculation
206 qdime_updates = .FALSE.
207 ! number of PB steps
208 napbs = 0
209
210 c-----------------------------------------------------------------
211 c PBEparm
212 c-----------------------------------------------------------------
213
214 c do we need molID?? probably not
215 ! i_pbeparm(1) = 1
216
217 c pbetype :: LPBE/NPBE
218 if (indxa(comlyn, comlen, 'LPBE') .gt. 0) then
219 nonlin = 0
220 endif
221 if (indxa(comlyn, comlen, 'NPBE') .gt. 0) then
222 nonlin = 1
223 endif
224
225 c bcfl :: boundary condition
226 c defaults to sdh (single Debye-Huckel sphere)
227 bcfl = gtrmi(comlyn, comlen, 'BCFL', bcfl)
228
229 c pdie :: solute dielectric
230 c defaults to 2.0
231 pdie = gtrmf(comlyn, comlen, 'PDIE', pdie)
232
233 c sdie :; solvent dielectric
234 c defaults to 78.54
235 sdie = gtrmf(comlyn, comlen, 'SDIE', sdie)
236
237 c srfm :: surface calculation method
238 c defaults to smol (molecular surface with smoothed harmonic average)
239 srfm = gtrmi(comlyn, comlen, 'SRFM', srfm)
240
241 c srad :: solvent radius
242 c defaults to 1.4
243 srad = gtrmf(comlyn, comlen, 'SRAD', srad)
244
245 c swinapbs :: cubic spline window
246 c defaults to 0.3
247 swinapbs = gtrmf(comlyn, comlen, 'SWIN', swinapbs)
248
249 c tempapbs :: temperature (in K)
250 c defaults to 298.15
251 tempapbs = gtrmf(comlyn, comlen, 'TEMP', tempapbs)
252
253 c gamma :: surface tension for apolar energies/forces (in kJ/mol/A^2)
254 c defaults to 0.105
255 gamma = gtrmf(comlyn, comlen, 'GAMMA', gamma)
256
257 c sdens :: number of grid points per square-angstrom to use in Vacc object
258 c defaults to 10.0
259 sdens = gtrmf(comlyn, comlen, 'SDENS', sdens)
260
261 c calcenergy :: energy calculation
262 c defaults to per atom energy calculation
263 calcenergy = gtrmi(comlyn, comlen, 'CALCE', calcenergy)
264
265 c calcforce :: atomic forces I/O
266 c defaults to per atom forces calculation
267 calcforce = gtrmi(comlyn, comlen, 'CALCF', calcforce)
268
269 c calcnpenergy :: NP energy calculation
270 c defaults to per atom energy calculation
271 calcnpenergy = gtrmi(comlyn, comlen, 'CALNE', calcnpenergy)
272
273 c calcnpforce :: NP atomic forces I/O
274 c defaults to per atom forces calculation
275 calcnpforce = gtrmi(comlyn, comlen, 'CALNF', calcnpforce)
276
277 c dielMap :: read dielectric maps (x, y and z)
278 if (indxa(comlyn, comlen, 'RDIEL') .gt. 0) then
279 rdiel = 1
280 endif
281
282 c kappaMap :: read Kappa map
283 if (indxa(comlyn, comlen, 'RKAPPA') .gt. 0) then
284 rkappa = 1
285 endif
286
287 c chargeMap :: read charge map
288 if (indxa(comlyn, comlen, 'RCHG') .gt. 0) then
289 rchg = 1
290 endif
291
292 c get ions parameters and set nion (i_pbeparm(4))
293 c (we are considering 2 ions only - this should be enough for
294 c most applications)
295 if (indx(comlyn, comlen, 'IONQ1', 5) .gt. 0) then
296 ionq(1) = gtrmf(comlyn, comlen, 'IONQ1', zero)
297 ionc(1) = gtrmf(comlyn, comlen, 'IONC1', zero)
298 ionrr(1) = gtrmf(comlyn, comlen, 'IONR1', zero)
299 nion = 1
300 endif
301 if (indx(comlyn, comlen, 'IONQ2', 5) .gt. 0) then
302 ionq(2) = gtrmf(comlyn, comlen, 'IONQ2', zero)
303 ionc(2) = gtrmf(comlyn, comlen, 'IONC2', zero)
304 ionrr(2) = gtrmf(comlyn, comlen, 'IONR2', zero)
305 nion = 2
306 endif
307
308
309 c-----------------------------------------------------------------
310 c external files write section
311 c-----------------------------------------------------------------
312 c write potential DX file
313 if (indxa(comlyn, comlen, 'WPOT') .gt. 0) then
314 wpot = 1
315 endif
316 c write charge DX file
317 if (indxa(comlyn, comlen, 'WCHG') .gt. 0) then
318 wchg = 1
319 endif
320 c write smol DX file
321 if (indxa(comlyn, comlen, 'WSMOL') .gt. 0) then
322 wsmol = 1
323 endif
324 c write kappa DX file
325 if (indxa(comlyn, comlen, 'WKAPPA') .gt. 0) then
326 wkappa = 1
327 endif
328 c write diel DX files (x, y and z)
329 if (indxa(comlyn, comlen, 'WDIEL') .gt. 0) then
330 wdiel = 1
331 endif
332 c-----------------------------------------------------------------
333 c MGparm
334 c-----------------------------------------------------------------
335
336 c type mgmanual/mgauto
337 if (indxa(comlyn, comlen, 'MGMANUAL') .gt. 0) then
338 calc_type = 0
339 endif
340 if (indxa(comlyn, comlen, 'MGAUTO') .gt. 0) then
341 calc_type = 1
342 endif
343
344 c mg-para
345 if (indxa(comlyn, comlen, 'MGPARA') .gt. 0) then
346 calc_type = 2
347 ! ispara = 1
348 endif
349
350 c nlev :: levels in multigrid hierarchy
351 c used in mg-manual only, no default
352 nlev = gtrmi(comlyn, comlen, 'NLEV', 4)
353
354 c centering methods - defaults to centering on molecule
355 c 0 is centering on point, 1 is on molecule
356 c if centering on a point - needs CNT, CCN, FCN
357
358 c cmeth for manual only (needs cnt also)
359 cmeth = gtrmi(comlyn, comlen, 'CMET', 1)
360
361 c ccmeth and fcmeth for auto (need ccn and fcn also)
362 c defaults to 1 (centered on molecule)
363 ccmeth = gtrmi(comlyn, comlen, 'CCME', 1)
364 fcmeth = gtrmi(comlyn, comlen, 'FCME', 1)
365
366 c dime :: grid dimensions
367 c no default
368 dime(1) = gtrmi(comlyn, comlen, 'DIMX', dime(1))
369 dime(2) = gtrmi(comlyn, comlen, 'DIMY', dime(2))
370 dime(3) = gtrmi(comlyn, comlen, 'DIMZ', dime(3))
371
372 c grid center
373 if ((indx(comlyn, comlen, 'CNTX', 4) .gt. 0) .and.
374 + (indx(comlyn, comlen, 'CNTY', 4) .gt. 0) .and.
375 + (indx(comlyn, comlen, 'CNTZ', 4) .gt. 0)) then
376 center(1) = gtrmf(comlyn, comlen, 'CNTX', zero)
377 center(2) = gtrmf(comlyn, comlen, 'CNTY', zero)
378 center(3) = gtrmf(comlyn, comlen, 'CNTZ', zero)
379 endif
380
381 c ccenter
382 if ((indx(comlyn, comlen, 'CCNX', 4) .gt. 0) .and.
383 + (indx(comlyn, comlen, 'CCNY', 4) .gt. 0) .and.
384 + (indx(comlyn, comlen, 'CCNZ', 4) .gt. 0))then
385 ccenter(1) = gtrmf(comlyn, comlen, 'CCNX', zero)
386 ccenter(2) = gtrmf(comlyn, comlen, 'CCNY', zero)
387 ccenter(3) = gtrmf(comlyn, comlen, 'CCNZ', zero)
388 endif
389
390 c fcenter
391 if ((indx(comlyn, comlen, 'FCNX', 4) .gt. 0) .and.
392 + (indx(comlyn, comlen, 'FCNY', 4) .gt. 0) .and.
393 + (indx(comlyn, comlen, 'FCNZ', 4) .gt. 0)) then
394 fcenter(1) = gtrmf(comlyn, comlen, 'FCNX', zero)
395 fcenter(2) = gtrmf(comlyn, comlen, 'FCNY', zero)
396 fcenter(3) = gtrmf(comlyn, comlen, 'FCNZ', zero)
397 endif
398
399 c cglen
400 if ((indx(comlyn, comlen, 'CGLX', 4) .gt. 0) .and.
401 + (indx(comlyn, comlen, 'CGLY', 4) .gt. 0) .and.
402 + (indx(comlyn, comlen, 'CGLZ', 4) .gt. 0)) then
403 cglen(1) = gtrmf(comlyn, comlen, 'CGLX', zero)
404 cglen(2) = gtrmf(comlyn, comlen, 'CGLY', zero)
405 cglen(3) = gtrmf(comlyn, comlen, 'CGLZ', zero)
406 endif
407
408 c fglen
409 if ((indx(comlyn, comlen, 'FGLX', 4) .gt. 0) .and.
410 + (indx(comlyn, comlen, 'FGLY', 4) .gt. 0) .and.
411 + (indx(comlyn, comlen, 'FGLZ', 4) .gt. 0)) then
412 fglen(1) = gtrmf(comlyn, comlen, 'FGLX', zero)
413 fglen(2) = gtrmf(comlyn, comlen, 'FGLY', zero)
414 fglen(3) = gtrmf(comlyn, comlen, 'FGLZ', zero)
415 endif
416
417 c glen
418 if ((indx(comlyn, comlen, 'GLNX', 4) .gt. 0) .and.
419 + (indx(comlyn, comlen, 'GLNY', 4) .gt. 0) .and.
420 + (indx(comlyn, comlen, 'GLNZ', 4) .gt. 0)) then
421 glen(1) = gtrmf(comlyn, comlen, 'GLNX', zero)
422 glen(2) = gtrmf(comlyn, comlen, 'GLNY', zero)
423 glen(3) = gtrmf(comlyn, comlen, 'GLNZ', zero)
424 endif
425
426 c grid
427 if ((indx(comlyn, comlen, 'GRDX', 4) .gt. 0) .and.
428 + (indx(comlyn, comlen, 'GRDY', 4) .gt. 0) .and.
429 + (indx(comlyn, comlen, 'GRDZ', 4) .gt. 0)) then
430 grid(1) = gtrmf(comlyn, comlen, 'GRDX', zero)
431 grid(2) = gtrmf(comlyn, comlen, 'GRDY', zero)
432 grid(3) = gtrmf(comlyn, comlen, 'GRDZ', zero)
433 endif
434
435 c chgm/setchgm
436 c defaults to spl2 (1)
437 chgm = gtrmi(comlyn, comlen, 'CHGM', 1)
438
439 c setup for mg-para
440 c pdime ::
441 c defaults to 0 which is not correct
442 pdime(1) = gtrmi(comlyn, comlen, 'PDIX', pdime(1))
443 pdime(2) = gtrmi(comlyn, comlen, 'PDIY', pdime(2))
444 pdime(3) = gtrmi(comlyn, comlen, 'PDIZ', pdime(3))
445
446 c ofrac :: overlap fraction between procs
447 c defaults to 0.1
448 ofrac = gtrmf(comlyn, comlen, 'OFRA', ofrac)
449
450 c do we calculate solvation forces?
451 qfapbs = (indxa(comlyn, comlen, 'SFORCE') .gt. 0)
452
453 c if yes, skip the first APBS calculation, just set up all variables
454 if (qfapbs) then
455 skip = .true.
456 endif
457
458 c how often do we calculate forces in md?
459 c default is 1 (every step)
460 napbs = gtrmi(comlyn, comlen, 'UPDATE', 1)
461
462 c forces update method
463 umeth = gtrmi(comlyn, comlen, 'UMETHOD', 1)
464
465 c get atom positions, radius and charge from a common block (coord.fcm)
466 c
467 c positionx = x
468 c positiony = y
469 c positionz = z
470 c radius = wmain
471 c charge = cg
472
473 c save wmain radii to a_radius
474 do i=1, natom
475 a_radius(i) = wmain(i)
476 end do
477
478 c debug
479 apbs_debug = gtrmi(comlyn, comlen, 'DEBUG', apbs_debug)
480
481 c ok, we now have all user switches
482 qaparsed = .true.
483
484 i_param(1) = calc_type
485 i_param(2) = nlev
486 i_param(3) = cmeth
487 i_param(4) = ccmeth
488 i_param(5) = fcmeth
489 i_param(6) = chgm
490 i_param(7) = nonlin
491 i_param(8) = bcfl
492 i_param(9) = srfm
493 i_param(10) = calcenergy
494 i_param(11) = calcforce
495 i_param(12) = wpot
496 i_param(13) = wchg
497 i_param(14) = wsmol
498 i_param(15) = wkappa
499 i_param(16) = wdiel
500 i_param(17) = watompot
501 i_param(18) = rpot
502 i_param(19) = 0
503 i_param(20) = calcnpforce
504 i_param(21) = calcnpenergy
505 i_param(22) = nion
506 i_param(23) = rchg
507 i_param(24) = rkappa
508 i_param(25) = rdiel
509
510 r_param(1) = pdie
511 r_param(2) = sdie
512 r_param(3) = srad
513 r_param(4) = swinapbs
514 r_param(5) = tempapbs
515 r_param(6) = sdens
516 r_param(7) = gamma
517 r_param(8) = smvolume
518 r_param(9) = smsize
519
520 c go over atomic coordinates and figure out optimal grid size
521 maxx = x(1)
522 minx = x(1)
523 maxy = y(1)
524 miny = y(1)
525 maxz = z(1)
526 minz = z(1)
527 do i = 1, natom
528 if(maxx < x(i)+a_radius(i)) maxx = x(i)+a_radius(i)
529 if(minx > x(i)-a_radius(i)) minx = x(i)-a_radius(i)
530 if(maxy < y(i)+a_radius(i)) maxy = y(i)+a_radius(i)
531 if(miny > y(i)-a_radius(i)) miny = y(i)-a_radius(i)
532 if(maxz < z(i)+a_radius(i)) maxz = z(i)+a_radius(i)
533 if(minz > z(i)-a_radius(i)) minz = z(i)-a_radius(i)
534 end do
535
536 write(outu,'(3x, a, 3f8.3)') 'APBS> Molecular dimensions: ',
537 + maxx-minx, maxy-miny, maxz-minz
538
539 ! for mg-manual calculate missing grid parameters
540 if ((i_param(1)==0 .OR. i_param(1)==1) .and. dime(1)==0) then
541 cglen(1) = 1.7 * (maxx-minx)
542 cglen(2) = 1.7 * (maxy-miny)
543 cglen(3) = 1.7 * (maxz-minz)
544 fglen(1) = 20.0 + (maxx-minx)
545 fglen(2) = 20.0 + (maxy-miny)
546 fglen(3) = 20.0 + (maxz-minz)
547
548 do i = 1, 3
549 if (fglen(i) > cglen(i)) cglen(i) = fglen(i)
550 end do
551 write(outu, '(3x, a)')
552 + 'APBS> Grid dime not specified, calculating ...'
553 write(outu, '(3x, a)')
554 + 'APBS> Requesting dime re-calculation on the fly'
555 qdime_updates = .TRUE.
556
557 do i = 1, 3
558 dime(i) =
559 + 32*(int((int(fglen(i)/grid(i) + 0.5) - 1)/32.0 + 0.5)) + 1
560 if (dime(i) < 33) dime(i) = 33
561 end do
562 end if
563
564 if (apbs_debug .gt. 0) then
565 write(outu, '(3x, a)') 'APBS> Grid values: '
566 write(outu, '(3x, a, 3f8.3)') 'APBS> fglen: ', fglen(1),
567 + fglen(2), fglen(3)
568 write(outu, '(3x, a, 3f8.3)') 'APBS> cglen: ', cglen(1),
569 + cglen(2), cglen(3)
570 write(outu, '(3x, a, 3i4)') 'APBS> dime: ', dime(1),
571 + dime(2),dime(3)
572 write(outu, '(3x, a, 3f8.3)') 'APBS> grid: ', grid(1),
573 + grid(2),grid(3)
574 write(outu, '(3x, a, f10.3)')
575 + 'APBS> Required memory (in MB): ',dime(1)*dime(2)
576 + *dime(3)*200.0/1024/1024
577 end if
578
579 c sanity checks
580 do i = 1, natom
581 if (ABS(a_radius(i)) .gt. 4.0) then
582 write(outu, '(3x, 2a, i6 , a, f8.3)')
583 + 'APBS> WARNING: ',
584 + 'Radius of this atom is larger than 4.0 A. Atom: ',
585 + i, ' Radius: ', a_radius(i)
586 end if
587 if (ABS(cg(i)) .gt. 5.0) then
588 write(outu, '(3x, 2a, i6 ,a, f8.3)')
589 + 'APBS> WARNING: ',
590 + 'Charge of this atom is larger than 5 e. Atom: ',
591 + i, ' Charge: ', cg(i)
592 end if
593 if (apbs_debug .gt. 10) then
594 write(outu, '(3x, i6, 5f8.3)')
595 + i, x(i), y(i), z(i), cg(i), a_radius(i)
596 end if
597 end do
598
599 if (apbs_debug .gt. 5) then
600 do i = 1, 25
601 write(outu, '(3x, a, i4, i4)') 'iAPBS debug i_param(): ',
602 + i, i_param(i)
603 end do
604 end if
605
606 do i = 1, 3
607 if (grid(i) * dime(i) < fglen(i)) then
608 write(outu, '(3x, a)')
609 + 'APBS> WARNING: caclulated grid spacing is larger than
610 + requested:'
611 write(outu, '(3x, a, i1, a, f5.3, a, f5.3)')
612 + 'APBS> grid(', i, '): requested: ', grid(i), ' actual: ',
613 + fglen(i)/dime(i)
614 c write(outu, '(3x, a)')
615 c + 'APBS> To fix this decrease grd value'
616 c call wrndie(-1, '<APBS>',
617 c + 'Requested and calculated grid spacing discrapancy')
618 end if
619 end do
620
621 c OK, now we are ready to call the apbs_driver and start the show
622
623 if (skip) then
624 write(outu, '(3x, a)')
625 + "APBS> Skiping the first APBS calculation, "
626 write(outu, '(3x, a)')
627 + "APBS> Initializing parameters only."
628 else
629 rc = apbsdrv(natom, x, y, z, a_radius, cg,
630 + r_param, i_param,
631 + grid, dime, pdime, glen, center,
632 + cglen, fglen, ccenter, fcenter,
633 + ofrac, apbs_debug,
634 + ionq, ionc, ionrr,
635 + esenerg, npenerg,
636 + apbsdx, apbsdy, apbsdz,
637 + apbsqfx, apbsqfy, apbsqfz, apbsibx, apbsiby, apbsibz,
638 + apbsnpx, apbsnpy, apbsnpz, apbsdbx, apbsdby, apbsdbz,
639 + apbsgrid_meta, apbsgrid)
640
641 if (apbs_debug .gt. 0) then
642 write(outu, '(3x, a, i3)') "APBS> APBS return code: ", rc
643 end if
644
645 if ((apbs_debug .gt. 3) .and. (calcforce .gt. 0)) then
646 do i = 1, natom
647 write(outu, '(3x, a, i8, 3f13.5, a)')
648 + "APBS> Total force on atom", i, apbsdx(i), apbsdy(i)
649 + , apbsdz(i), " kJ/(mol/A)"
650 end do
651 endif
652
653 if (apbs_debug .gt. 0) then
654 write(outu, '(3x, a, f13.5, a)') "APBS> esEnergy: ",
655 + esenerg(1)/ 4.2D0, " kcal/mol"
656 write(outu, '(3x, a, f13.5, a)') "APBS> npEnergy: ",
657 + npenerg(1)/ 4.2D0, " kcal/mol"
658 write(outu, '(3x, a, f13.5, a)') "APBS> Total Energy: ",
659 + (esenerg(1) + npenerg(1))/ 4.2D0, " kcal/mol"
660 endif
661
662
663 c pass the electrostatic energy value back (in kcal/mol)
664 call setmsr('ENPB', esenerg(1) / 4.2D0)
665 call setmsr('ENNP', npenerg(1) / 4.2D0)
666 endif
667
668 ##ENDIF ifn/else APBS
669 RETURN
670 END
671
672 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
673 c
674 subroutine apbsfrc(f_natom, x, y, z, f_cg, enelec, ennp,
675 + dx, dy, dz, icall, qprin)
676 c
677 c calculates forces by doing two apbs calculation (vacuum/solvent)
678 c
679 c this is called by energy.src (SP APBS calculation must be done
680 c first, before starting MD to initialize all values)
681 c-----------------------------------------------------------------------
682 ##IFN APBS
683 CALL WRNDIE(-1,'<CHARMM>','APBS module was not compiled.')
684 ##ELSE
685 c
686 c implicit none
687 ##INCLUDE '~/charmm_fcm/impnon.fcm'
688 c maxa (max # of atoms), maxaim (including image atoms)
689 ##INCLUDE '~/charmm_fcm/dimens.fcm'
690 c numbers definitions
691 ##INCLUDE '~/charmm_fcm/number.fcm'
692 ##INCLUDE '~/charmm_fcm/exfunc.fcm'
693 ##INCLUDE '~/charmm_fcm/comand.fcm'
694 c natom, cg (charge)
695 ##INCLUDE '~/charmm_fcm/psf.fcm'
696 ##INCLUDE '~/charmm_fcm/stream.fcm'
697 ##INCLUDE '~/charmm_fcm/stack.fcm'
698 ##INCLUDE '~/charmm_fcm/heap.fcm'
699 ##INCLUDE '~/charmm_fcm/pbeq.fcm'
700 ##INCLUDE '~/charmm_fcm/timer.fcm'
701 c apbs include
702 ##INCLUDE '~/charmm_fcm/apbs.fcm'
703 ##INCLUDE '~/charmm_fcm/parallel.fcm'
704 c-----------------------------------------------------------------
705 c local variables
706 double precision apbsdx(natom), apbsdy(natom), apbsdz(natom)
707 double precision solvdx(natom), solvdy(natom), solvdz(natom)
708 double precision vacdx(natom), vacdy(natom), vacdz(natom)
709 double precision dx(natom), dy(natom), dz(natom)
710 double precision x(natom), y(natom), z(natom)
711 double precision enelec, ennp, f_cg(natom)
712 double precision esenvac, esensolv, npenvac, npensolv
713 double precision esenerg(15), npenerg(15)
714 double precision sdie, gamma, ionc1, ionc2
715 double precision maxx, minx, maxy, miny, maxz, minz
716 double precision apbsqfx(natom), apbsqfy(natom), apbsqfz(natom)
717 double precision apbsibx(natom), apbsiby(natom), apbsibz(natom)
718 double precision apbsnpx(natom), apbsnpy(natom), apbsnpz(natom)
719 double precision apbsdbx(natom), apbsdby(natom), apbsdbz(natom)
720 double precision solvqfx(natom), solvqfy(natom), solvqfz(natom)
721 double precision solvibx(natom), solviby(natom), solvibz(natom)
722 double precision solvnpx(natom), solvnpy(natom), solvnpz(natom)
723 double precision solvdbx(natom), solvdby(natom), solvdbz(natom)
724 double precision vacqfx(natom), vacqfy(natom), vacqfz(natom)
725 double precision vacibx(natom), vaciby(natom), vacibz(natom)
726 double precision vacnpx(natom), vacnpy(natom), vacnpz(natom)
727 double precision vacdbx(natom), vacdby(natom), vacdbz(natom)
728
729 double precision apbsgrid_meta(13), apbsgrid(3*natom)
730
731 integer*4 f_natom, i, apbsdrv, icall, rc
732 logical qprin
733 c--------------------------------------------------------------------
734 c
735 c forces: two apbs calculations (one in solvent, the other in vacuum),
736 c solvation force is the difference
737 c
738
739 c did we parse options first?
740 if (.not. qaparsed) then
741 call wrndie(-5, '<APBSFRC>', 'Must have APBS options first!')
742 endif
743
744 c initialization
745
746 do i = 1, 13
747 apbsgrid_meta(i) = 0.0
748 end do
749 do i = 1, 3*NATOM
750 apbsgrid(i) = 0.0
751 end do
752
753 c we're doing this calculation only every icall/napbs step
754 if (mod(icall, napbs) .eq. 0) then
755
756 c must turn on forces in apbs!
757 if (i_param(11) .ne. 2 ) then
758 call wrndie(-5, '<APBSFRC>',
759 + 'Set CALCF to 2 for solvation forces calculation!')
760 end if
761
762 if (qdime_updates) then
763 maxx = x(1)
764 minx = x(1)
765 maxy = y(1)
766 miny = y(1)
767 maxz = z(1)
768 minz = z(1)
769 do i = 1, natom
770 if(maxx < x(i)+a_radius(i)) maxx = x(i)+a_radius(i)
771 if(minx > x(i)-a_radius(i)) minx = x(i)-a_radius(i)
772 if(maxy < y(i)+a_radius(i)) maxy = y(i)+a_radius(i)
773 if(miny > y(i)-a_radius(i)) miny = y(i)-a_radius(i)
774 if(maxz < z(i)+a_radius(i)) maxz = z(i)+a_radius(i)
775 if(minz > z(i)-a_radius(i)) minz = z(i)-a_radius(i)
776 end do
777
778 cglen(1) = 1.7 * (maxx-minx)
779 cglen(2) = 1.7 * (maxy-miny)
780 cglen(3) = 1.7 * (maxz-minz)
781 fglen(1) = 20.0 + (maxx-minx)
782 fglen(2) = 20.0 + (maxy-miny)
783 fglen(3) = 20.0 + (maxz-minz)
784
785 do i = 1, 3
786 if (fglen(i) > cglen(i)) cglen(i) = fglen(i)
787 end do
788
789 if (apbs_debug .gt. 0) then
790 write(outu,'(3x, a, 3f8.3)')
791 + 'APBS> Molecular dimensions: ',maxx-minx, maxy-miny,
792 + maxz-minz
793 write(outu, '(3x, a)')
794 + 'APBS> Re-calculating grid dimensions ...'
795 end if
796
797 do i = 1, 3
798 dime(i) =
799 + 32*(int((int(fglen(i)/grid(i) + 0.5) - 1)/32.0 + 0.5)) + 1
800 if (dime(i) < 33) dime(i) = 33
801 end do
802 end if
803
804 if (apbs_debug .gt. 0) then
805 write(outu, '(3x, a)') 'APBS> Grid values: '
806 write(outu, '(3x, a, 3f8.3)') 'APBS> fglen: ', fglen(1),
807 + fglen(2), fglen(3)
808 write(outu, '(3x, a, 3f8.3)') 'APBS> cglen: ', cglen(1),
809 + cglen(2), cglen(3)
810 write(outu, '(3x, a, 3i4)') 'APBS> dime: ', dime(1),
811 + dime(2),dime(3)
812 write(outu, '(3x, a, 3f8.3)') 'APBS> grid: ', grid(1),
813 + grid(2),grid(3)
814 write(outu, '(3x, a, f10.3)')
815 + 'APBS> Required memory (in MB): ',dime(1)*dime(2)
816 + *dime(3)*200.0/1024/1024
817 end if
818
819
820 c write(*,*)'APBSFRC> before apbsdrv...'
821 c first calculation - in solvent
822 rc = apbsdrv(f_natom, x, y, z, a_radius, f_cg,
823 + r_param, i_param,
824 + grid, dime, pdime, glen, center,
825 + cglen, fglen, ccenter, fcenter,
826 + ofrac, apbs_debug,
827 + ionq, ionc, ionrr,
828 + esenerg, npenerg,
829 + apbsdx, apbsdy, apbsdz,
830 + apbsqfx, apbsqfy, apbsqfz, apbsibx, apbsiby, apbsibz,
831 + apbsnpx, apbsnpy, apbsnpz, apbsdbx, apbsdby, apbsdbz,
832 + apbsgrid_meta, apbsgrid)
833
834 c write(*,*)'APBSFRC> after apbsdrv...,ncalc=',ncalc(1)
835
836 c total energy in solvent (in kcal/mol)
837 esensolv = esenerg(1) / 4.2D0
838 npensolv = npenerg(1) / 4.2D0
839 c write(*,*)'APBSFRC>after energy...'
840 if (apbs_debug .gt. 0) then
841 write(outu, '(3x, a, f8.3, a)')
842 + "APBSFRC> Electrostatic energy in solvent: ",
843 + esensolv, " kcal/mol"
844 write(outu, '(3x, a, f8.3, a)')
845 + "APBSFRC> Nonpolar energy in solvent: ",
846 + npensolv, " kcal/mol"
847 end if
848
849 c get the total forces from the solvent calculation
850 do i = 1, f_natom
851 solvdx(i) = apbsdx(i) / 4.2D0
852 solvdy(i) = apbsdy(i) / 4.2D0
853 solvdz(i) = apbsdz(i) / 4.2D0
854
855 solvqfx(i) = apbsqfx(i) / 4.2D0
856 solvqfy(i) = apbsqfy(i) / 4.2D0
857 solvqfz(i) = apbsqfz(i) / 4.2D0
858
859 solvibx(i) = apbsibx(i) / 4.2D0
860 solviby(i) = apbsiby(i) / 4.2D0
861 solvibz(i) = apbsibz(i) / 4.2D0
862
863 solvnpx(i) = apbsnpx(i) / 4.2D0
864 solvnpy(i) = apbsnpy(i) / 4.2D0
865 solvnpz(i) = apbsnpz(i) / 4.2D0
866
867 solvdbx(i) = apbsdbx(i) / 4.2D0
868 solvdby(i) = apbsdby(i) / 4.2D0
869 solvdbz(i) = apbsdbz(i) / 4.2D0
870 end do
871
872 c-----------------------------------------------------------------
873
874 c save sdie and ion concentration
875 sdie = r_param(2)
876 ionc1 = ionc(1)
877 ionc2 = ionc(2)
878 c set sdie = 1.0
879 c salt concentration should be 0.0
880 r_param(2) = 1.0D0 ! sdie
881 ionc(1) = 0.0D0
882 ionc(2) = 0.0D0
883
884 c second calculation, now in vacuum
885 rc = apbsdrv(f_natom, x, y, z, a_radius, f_cg,
886 + r_param, i_param,
887 + grid, dime, pdime, glen, center,
888 + cglen, fglen, ccenter, fcenter,
889 + ofrac, apbs_debug,
890 + ionq, ionc, ionrr,
891 + esenerg, npenerg,
892 + apbsdx, apbsdy, apbsdz,
893 + apbsqfx, apbsqfy, apbsqfz, apbsibx, apbsiby, apbsibz,
894 + apbsnpx, apbsnpy, apbsnpz, apbsdbx, apbsdby, apbsdbz,
895 + apbsgrid_meta, apbsgrid)
896
897
898
899 c return back the original sdie and ionc concentration values
900 r_param(2) = sdie
901 ionc(1) = ionc1
902 ionc(2) = ionc2
903
904 c total energy in vacuum (in kcal/mol)
905 esenvac = esenerg(1) / 4.2D0
906 c npenvac = npenerg(1) / 4.2D0
907 c no NP energy in vacuum
908 npenvac = 0.0D0
909 if (apbs_debug .gt. 0) then
910 print *, "APBSFRC> Electrostatic energy in vacuum: ",
911 + esenvac, " kcal/mol"
912 print *, "APBSFRC> Nonpolar energy in vacuum: ",
913 + npenvac, " kcal/mol"
914 end if
915
916 c get the total forces from the vacuum calculation
917 do i = 1, f_natom
918 vacdx(i) = apbsdx(i) / 4.2D0
919 vacdy(i) = apbsdy(i) / 4.2D0
920 vacdz(i) = apbsdz(i) / 4.2D0
921
922 vacqfx(i) = apbsqfx(i) / 4.2D0
923 vacqfy(i) = apbsqfy(i) / 4.2D0
924 vacqfz(i) = apbsqfz(i) / 4.2D0
925
926 vacibx(i) = apbsibx(i) / 4.2D0
927 vaciby(i) = apbsiby(i) / 4.2D0
928 vacibz(i) = apbsibz(i) / 4.2D0
929
930 c the following are zero in vacuum
931
932 vacnpx(i) = 0.0D0
933 vacnpy(i) = 0.0D0
934 vacnpz(i) = 0.0D0
935
936 vacdbx(i) = 0.0D0
937 vacdby(i) = 0.0D0
938 vacdbz(i) = 0.0D0
939
940 end do
941
942 c-----------------------------------------------------------------
943
944 c add calulated total forces to dx, dy, dz in common block
945 c
946 do i = 1, f_natom
947 dx(i) = dx(i) - (solvdx(i) - vacdx(i))
948 dy(i) = dy(i) - (solvdy(i) - vacdy(i))
949 dz(i) = dz(i) - (solvdz(i) - vacdz(i))
950 end do
951
952 if (apbs_debug .gt. 1) then
953 do i = 1, f_natom
954 print *, "APBSFRC> TotalForces:", i, dx(i), dy(i), dz(i)
955 end do
956 do i = 1, f_natom
957 print *, "APBSFRC> SolventForces:", i, solvdx(i) ,
958 + solvdy(i) , solvdz(i)
959 end do
960 do i = 1, f_natom
961 print *, "APBSFRC> VacuumForces:", i, vacdx(i),
962 + vacdy(i), vacdz(i)
963 end do
964 do i = 1, f_natom
965 print *, "APBSFRC> SolvForces:", i, solvdx(i) - vacdx(i),
966 + solvdy(i) - vacdy(i), solvdz(i) - vacdz(i)
967 end do
968 do i = 1, f_natom
969 print *, "APBSFRC> qfForces:", i, solvqfx(i) - vacqfx(i),
970 + solvqfy(i) - vacqfy(i), solvqfz(i) - vacqfz(i)
971 end do
972 do i = 1, f_natom
973 print *, "APBSFRC> ibForces:", i, solvibx(i) - vacibx(i),
974 + solviby(i) - vaciby(i), solvibz(i) - vacibz(i)
975 end do
976 do i = 1, f_natom
977 print *, "APBSFRC> npForces:", i, solvnpx(i) - vacnpx(i),
978 + solvnpy(i) - vacnpy(i), solvnpz(i) - vacnpz(i)
979 end do
980 do i = 1, f_natom
981 print *, "APBSFRC> dbForces:", i, solvdbx(i) - vacdbx(i),
982 + solvdby(i) - vacdby(i), solvdbz(i) - vacdbz(i)
983 end do
984
985 endif
986
987 c total, solvatation energy (in kcal/mol)
988 enelec = esensolv - esenvac
989 if (apbs_debug .gt. 0) then
990 print *, "APBSFRC> Total solvation energy: ",
991 + enelec, " kcal/mol"
992 end if
993
994 c total, non-polar energy (in kcal/mol)
995 c ennp = npensolv - npenvac
996 ennp = npensolv
997 if (apbs_debug .gt. 0) then
998 print *, "APBSFRC> Total non-polar energy: ",
999 + ennp, " kcal/mol"
1000 print *, "APBSFRC> Total non-polar energy (vacuum): ",
1001 + npenvac, " kcal/mol"
1002
1003 end if
1004
1005 if (qprin) then
1006 WRITE(outu,'(3X,A,F13.5,A)')
1007 + 'The Free Energy of Charging in Solvent = ',
1008 + esensolv,' [KCAL/MOL]'
1009 WRITE(outu,'(3X,A,F13.5,A)')
1010 + 'The Free Energy of Charging in vacuum = ',
1011 + esenvac,' [KCAL/MOL]'
1012 WRITE(outu,'(3X,A,F13.5,A)')
1013 + 'The Electrostatic Solvation Free Energy = ',
1014 + enelec,' [KCAL/MOL]'
1015
1016 WRITE(outu,'(3X,A,F13.5,A)')
1017 + 'The Nonpolar Solvation Free Energy = ',
1018 + ennp,' [KCAL/MOL]'
1019 end if
1020
1021 c pass the electrostatic energy value back (in kcal/mol)
1022 c but this doesn't make too much sense in here, does it?
1023 c call setmsr('ENPB', enelec)
1024
1025 c save solvation forces for different update schemes
1026 do i = 1, f_natom
1027 solvfrcx(i) = solvdx(i) - vacdx(i)
1028 solvfrcy(i) = solvdy(i) - vacdy(i)
1029 solvfrcz(i) = solvdz(i) - vacdz(i)
1030 end do
1031
1032 c save ennp and enelec
1033 senelec = enelec
1034 sennp = ennp
1035
1036 c end if section for napbs==icall
1037 c if we don't do APBS calculation just use the old APBS calculated forces
1038 c or update it accordingly
1039 else
1040 if (apbs_debug .gt. 0) then
1041 print *, "APBSFRC> Reusing solvation forces in this step:",
1042 + icall
1043 end if
1044 c select force update method
1045 if (umeth .eq. 0) then
1046 c this just uses zero for solvation forces and energies
1047 c between updates
1048 enelec = 0.0
1049 ennp = 0.0
1050 else if (umeth .eq. 1) then
1051 c this method uses forces from previous APBS step between updates
1052 do i = 1, f_natom
1053 dx(i) = dx(i) - solvfrcx(i)
1054 dy(i) = dy(i) - solvfrcy(i)
1055 dz(i) = dz(i) - solvfrcz(i)
1056 end do
1057 enelec = senelec
1058 ennp = sennp
1059 else
1060 write(outu, '(3x, a)')
1061 + "APBSFRC> This method of force updates is not implemented"
1062 end if
1063
1064 c endif section for napbs/icall comparison
1065 end if
1066
1067 ##ENDIF ifn/else APBS
1068 RETURN
1069 END
1070
1071 c $Id: apbs.f rok $