10
15
#include "mafdecls.fh"
15
22
* **** local variables ****
16
logical value, newchain, svalue,verlet,oprint
23
logical value,newchain,svalue,verlet,oprint,done,converged,found
24
logical ostress,finishedstep,converged1
25
character*9 cvg1,cvg2,cvg3,cvg4
18
character*50 bead_list
20
integer i,it,nbeads,nion,ng,iterNEB,nebsteps
27
character*50 bead_list,filename
28
character*80 title,neb_movecs
30
character*255 full_filename,full_filename2,filename2
32
integer ii,shift,print_shift,print_count,jj,manyjj,itm,goodjj
33
integer i,it,nbeads,nion,ng,m,nebsteps,neb_algorithm
34
integer nbeads1,nbeads2
21
35
integer e1(2),g0(2),g1(2),s(2),t1(2),v1(2),c0(2),c1(2)
22
integer mass(2),dti(2)
23
real*8 path_energy,path_distance,norm,norm0,time_step
24
real*8 Gmax,Grms,Xmax,Xrms,dE,path_energy0
36
integer mass(2),dti(2),cs(2),gs(2)
37
real*8 path_energy,path_distance,norm,norm0,time_step,kbeads
38
real*8 Gmax,Grms,Xmax,Xrms,dE,path_energy0,emid,emax,emin,trust
39
real*8 nebGmax,nebGrms,nebXmax,nebXrms,nebdE,sum,sum2,t,alpha
40
real*8 alphamin,deltaE,sum0,sum0_old,time_step0
41
real*8 emid0,emin0,emax0
26
43
* **** external functions ****
27
44
logical task_gradient
30
47
real*8 energy_bead_list
31
48
external size_bead_list,nion_bead_list
32
49
external energy_bead_list
50
character*7 bead_index_name
51
external bead_index_name
34
54
oprint = ga_nodeid() .eq. 0
59
call util_print_centered(luout,
60
> 'NWChem Minimum Energy Pathway Program (NEB)',
66
if (rtdb_cget(rtdb,'title',1,title)) then
70
call util_print_centered(6, title, 40, .false.)
75
if (.not. rtdb_get(rtdb,'neb:gmax',mt_dbl,1,nebgmax))
77
if (.not. rtdb_get(rtdb,'neb:grms',mt_dbl,1,nebgrms))
79
if (.not. rtdb_get(rtdb,'neb:xmax',mt_dbl,1,nebxmax))
80
> nebxmax = 0.000180d0
81
if (.not. rtdb_get(rtdb,'neb:xrms',mt_dbl,1,nebxrms))
82
> nebxrms = 0.000120d0
36
84
if (.not.rtdb_get(rtdb,'neb:stepsize',mt_dbl,1,time_step))
86
if (.not.rtdb_get(rtdb,'neb:trust',mt_dbl,1,trust))
88
if (.not.rtdb_get(rtdb,'neb:kbeads',mt_dbl,1,kbeads))
90
if (.not.rtdb_get(rtdb,'neb:steps',mt_int,1,nebsteps))
93
if (.not.rtdb_cget(rtdb,'neb:movecs',1,neb_movecs)) then
94
call util_file_prefix('movecs',neb_movecs)
97
* *** neb_algorithm ***
98
if (.not.rtdb_get(rtdb,'neb:algorithm',mt_int,1,neb_algorithm))
100
if (.not.rtdb_get(rtdb,'neb:m',mt_int,1,m)) m = 5
102
if (.not.rtdb_get(rtdb,'neb:print_shift',mt_int,1,print_shift))
105
* **** neb_epath filename ****
106
call util_file_prefix('neb_epath',filename)
107
call util_file_name_noprefix(filename,.false.,
111
* **** includestress? ****
112
if (.not. rtdb_get(rtdb,'includestress',mt_log,1,ostress))
40
117
* RRR only initialize if this is a new neb chain!
41
118
* **** initialize neb list ****
42
bead_list = 'neb_list'
119
bead_list = 'bead_list'
43
120
newchain = .false.
44
if (.not.rtdb_get(rtdb,'neb:nebnew',mt_log,1,newchain))
121
if (.not.rtdb_get(rtdb,'bead_list:new',mt_log,1,newchain))
45
122
> newchain = .true.
49
> write(*,*)'NEW NEB CHAIN, INITIALIZING'
125
if (oprint) write(*,*)'NEW NEB CHAIN, INITIALIZING'
51
126
call neb_initialize(rtdb,bead_list)
54
> write(*,*)'EXISTING NEB CHAIN? RESTARTING'
129
if (oprint) write(*,*)'EXISTING NEB CHAIN? RESTARTING'
130
call set_rtdb_bead_list(rtdb)
131
nbeads1 = size_bead_list(bead_list)
132
if (.not.rtdb_get(rtdb,'neb:nbeads',mt_int,1,nbeads2))
134
if (nbeads1.ne.nbeads2) then
135
if (oprint) write(*,*) 'RESIZING NEB CHAIN'
136
call neb_resize_path(rtdb,bead_list,nbeads1,nbeads2)
138
if (.not.rtdb_get(rtdb,'neb:print_count',mt_int,1,print_count))
57
141
newchain = .false.
59
143
nbeads = size_bead_list(bead_list)
60
144
nion = nion_bead_list(bead_list,1)
61
145
ng = 3*nion*nbeads
63
* *** is verlet algorithm used ***
64
if (.not.rtdb_get(rtdb,'neb:verlet',mt_log,1,verlet))
149
if (neb_algorithm.eq.0) then
151
else if (neb_algorithm.eq.1) then
153
else if (neb_algorithm.eq.2) then
154
tmp = "refining conjugate gradient"
156
tmp = "not implemented"
160
write(luout,1) nebgmax,nebgrms,nebxmax,nebxrms,
161
> time_step,trust,nebsteps,nbeads,m,nion,kbeads,
165
> write(luout,*) ' INCLUDING STRESS !!!!!!!!!!!!!!!!'
169
> ' maximum gradient threshold (gmax) = ', f10.6,/,
170
> ' rms gradient threshold (grms) = ', f10.6,/,
171
> ' maximum cartesian step threshold (xmax) = ', f10.6,/,
172
> ' rms cartesian step threshold (xrms) = ', f10.6,/,
174
> ' step size (stepsize) = ', f10.6,/,
175
> ' fixed trust radius (trust) = ', f10.6,/,
176
> ' maximum number of steps (maxiter) = ', i4,/,
177
> ' number of images in path (nbeads) = ', i4,/,
178
> ' number of histories (nhist) = ', i4,/,
179
> ' number of atoms = ', i4,/,
180
> ' NEB spring constant in a.u. (kbeads) = ', f10.6,/,
181
> ' NEB algorithm (algorithm) = ', i4,
183
> ' NEB movecs filename = ', a)
68
187
* **** allocate space for gradients and coordinates ****
109
237
* **** initial step ****
110
if (ga_nodeid().eq.0)
111
> write(*,*) "neb: Calculating Initial Path Energy "
238
if (oprint) write(luout,*) "neb: Calculating Initial Path Energy"
239
call neb_coords_get(bead_list,dbl_mb(c1(1)))
112
240
call runall_bead_list(bead_list,task_gradient)
113
241
call neb_energies_get(bead_list,dbl_mb(e1(1)))
114
call neb_coords_get(bead_list,dbl_mb(c1(1)))
115
call neb_gradient_get(bead_list,
242
call dcopy(ng,0.0d0,0,dbl_mb(t1(1)),1)
243
call dcopy(ng,0.0d0,0,dbl_mb(g1(1)),1)
244
call neb_gradient_get(bead_list,kbeads,
249
sum0 = ddot(ng,dbl_mb(g1(1)),1,dbl_mb(g1(1)),1)
253
time_step0 = time_step
121
256
call neb_path_energy(bead_list,
125
IF (ga_nodeid().eq.0) THEN
127
write(*,*) "neb: Initial Path Energy "
128
write(*,*) "neb: -----------------------"
130
write(*,*) "neb: ",i,dbl_mb(e1(1)+i-1)
134
call create_xyz_file_bead_list(bead_list)
261
write(luout,*) "neb: sum0=",sum0,ng
263
write(luout,*) "neb: Initial Path Energy "
264
write(luout,*) "neb: -----------------------"
266
write(luout,*) "neb: ",i,dbl_mb(e1(1)+i-1)
270
call create_xyz_file_bead_list(luout,bead_list,.true.)
136
272
norm = dsqrt(ddot(ng,dbl_mb(g1(1)),1,dbl_mb(g1(1)),1))
137
IF (ga_nodeid().eq.0)
138
> write(*,*) "Path Energy, Path Distance, |G_neb|:",
273
if (oprint) write(luout,*) "Path Energy, Path Distance, |G_neb|:",
139
274
> path_energy,path_distance,norm
143
svalue = rtdb_get(rtdb,'neb:steps',mt_int,1,nebsteps)
146
IF (ga_nodeid().eq.0)
147
> write(*,*)'NEB iterations =',iterNEB
150
IF (ga_nodeid().eq.0)
151
> write(*,*)'SHORTRUN, NEB iterations =',iterNEB
154
276
call dcopy(ng,dbl_mb(g1(1)),1,dbl_mb(s(1)),1)
284
if (oprint) write(luout,*) 'neb: iteration #',it,itm
158
IF (ga_nodeid().eq.0)
159
> write(*,*)'neb: iteration #',it
160
286
* *** save old forces and coordinates ***
161
287
call dcopy(ng,dbl_mb(c1(1)),1,dbl_mb(c0(1)),1)
162
288
call dcopy(ng,dbl_mb(g1(1)),1,dbl_mb(g0(1)),1)
167
IF (ga_nodeid().eq.0)
168
> write(*,*)'neb: using verlet algroithm'
293
* ***** fixed point iteration ****
294
if (neb_algorithm.eq.0) then
295
if (oprint) write(luout,*)'neb: using fixed point'
299
call dcopy(ng,dbl_mb(c0(1)),1,dbl_mb(cs(1)+shift),1)
300
call dcopy(ng,dbl_mb(g0(1)),1,dbl_mb(gs(1)+shift),1)
302
call neb_lmbfgs(ng,itm,
307
call dcopy(ng,dbl_mb(g0(1)),1,dbl_mb(s(1)),1)
312
call dcopy(ng,dbl_mb(cs(1)+shift+ng),1,
313
> dbl_mb(cs(1)+shift), 1)
314
call dcopy(ng,dbl_mb(gs(1)+shift+ng),1,
315
> dbl_mb(gs(1)+shift), 1)
319
call dcopy(ng,dbl_mb(c0(1)),1,dbl_mb(cs(1)+shift),1)
320
call dcopy(ng,dbl_mb(g0(1)),1,dbl_mb(gs(1)+shift),1)
321
call neb_lmbfgs(ng,m,
326
c call neb_project_gradient(nion,nbeads,
330
finishedstep = .false.
333
do while ((.not.finishedstep).and.(jj.lt.9))
335
sum = ddot(ng,dbl_mb(g0(1)),1,dbl_mb(s(1)),1)
337
if ((sum.le.0.0d0).or.(sum0.gt.sum0_old)) then
338
call dcopy(ng,dbl_mb(g0(1)),1,dbl_mb(s(1)),1)
340
if (oprint) write(*,*) "neb: s=g and itm reset to 0"
343
sum2 = dsqrt(ddot(ng,dbl_mb(s(1)),1,dbl_mb(s(1)),1))
346
> write(*,*) "neb: |<s|s>|,<g|s>=",sum2,sum
353
call neb_coords_set(bead_list,dbl_mb(c1(1)))
355
if (oprint) write(luout,*) "neb: running internal beads"
356
call runmid_bead_list(bead_list,task_gradient)
358
call neb_energies_get(bead_list,dbl_mb(e1(1)))
359
call neb_gradient_get(bead_list,kbeads,
364
sum0 = ddot(ng,dbl_mb(g1(1)),1,dbl_mb(g1(1)),1)
366
finishedstep = (sum0.le.sum0_old)
367
if (.not.finishedstep) then
371
if (manyjj.gt.2) then
372
time_step = 0.5d0*time_step
375
> write(*,*) "neb: reducing timestep=",time_step
378
if (finishedstep.and.(jj.eq.1)) then
380
if (goodjj.gt.10) then
381
time_step = 2.0d0*time_step
382
if (time_step.gt.time_step0) time_step = time_step0
388
> write(*,*) "neb: sum0,sum0_old=",
389
> sum0,sum0_old,jj,finishedstep,alpha
391
c if (finishedstep) sum0_old = sum0
397
* ***** Verlet iteration ****
398
else if (neb_algorithm.eq.1) then
399
IF (oprint) write(luout,*)'neb: using verlet algroithm'
169
400
call neb_verlet_update(ng,
201
433
call neb_coords_set(bead_list,dbl_mb(c1(1)))
202
if(oprint) write(*,*) "neb: running internal beads"
434
if (oprint) write(luout,*) "neb: running internal beads"
203
435
call runmid_bead_list(bead_list,task_gradient)
204
436
call neb_energies_get(bead_list,dbl_mb(e1(1)))
205
call neb_gradient_get(bead_list,
437
call neb_gradient_get(bead_list,kbeads,
211
443
norm = dsqrt(ddot(ng,dbl_mb(g1(1)),1,dbl_mb(g1(1)),1))
212
if(oprint) write(*,*) "neb: new gnorm=",norm
213
if(oprint) write(*,*) "neb: old gnorm0=",norm0
444
if(oprint) write(luout,*) "neb: new gnorm=",norm
445
if(oprint) write(luout,*) "neb: old gnorm0=",norm0
214
446
if(norm.gt.norm0) then
215
447
time_step=time_step/2.0d0
217
> write(*,*) "neb: reducing time step",time_step
449
> write(luout,*) "neb: reducing time step ",time_step
219
451
call dscal(ng,time_step,dbl_mb(s(1)),1)
221
> write(*,*) "neb: accepting time step"
453
> write(luout,*) "neb: accepting time step ",time_step
461
inquire(file=full_filename,exist=found)
462
* **** CIF FILE already exists - parse to EOF ****
464
open(unit=19,file=full_filename,form='formatted',
467
read(19,*,ERR=30,END=30) ch_tmp
470
#if defined(FUJITSU_SOLARIS) || defined(PSCALE) || defined(SOLARIS) || defined(__crayx1) || defined(GCC46)
474
* **** .neb_epath FILE does not exist ****
476
open(unit=19,file=full_filename,form='formatted')
479
> "#-------------------------------------------------------"
480
write(19,*) "# NEB Path iteration = ",it
481
write(19,*) "# algorithm = ",neb_algorithm
482
write(19,*) "# nbeads = ",nbeads
483
write(19,*) "# nhist = ",m
484
write(19,*) "# natoms = ",nion
485
write(19,*) "# kbeads = ",kbeads
486
write(19,*) "# stepsize = ",time_step
487
write(19,*) "# trust = ",trust
488
write(19,*) "# path energy = ",path_energy
489
write(19,*) "# path distance = ",path_distance
490
write(19,*) "# dE = ",dE
491
write(19,*) "# Gmax = ",Gmax
492
write(19,*) "# Grms = ",Grms
493
write(19,*) "# Xmax = ",Xmax
494
write(19,*) "# Xrms = ",Xrms
496
> "#-------------------------------------------------------"
498
t = (i-1)/dble(nbeads-1)
499
write(19,*) t,dbl_mb(e1(1)+i-1)
231
505
* *** RRR write out cumulative path energy
232
IF (ga_nodeid().eq.0) THEN
234
write(*,*) "neb: Path Energy #",it
235
write(*,*) "----------------------------"
237
write(*,*) "neb: ",i,dbl_mb(e1(1)+i-1)
241
call create_xyz_file_bead_list(bead_list)
243
path_energy0 = path_energy
508
write(luout,*) "neb: Path Energy #",it
509
write(luout,*) "----------------------------"
511
write(luout,*) "neb: ",i,dbl_mb(e1(1)+i-1)
515
call create_xyz_file_bead_list(luout,bead_list,.true.)
517
* **** write out current xyz file ***
518
print_count = print_count + 1
519
if (print_shift.gt.0) then
520
if (mod(print_count,print_shift).eq.0) then
521
call util_file_prefix(
522
> 'nebpath'//bead_index_name(print_count)//'.xyz',
524
call util_file_name_noprefix(filename2,.false.,
528
> open(unit=23,file=full_filename2,form='formatted')
529
call create_xyz_file_bead_list(23,bead_list,.false.)
530
if (oprint) close(23)
533
if (.not.rtdb_put(rtdb,'neb:print_count',mt_int,1,print_count))
534
> call errquit('setting neb:print_count failed',4,RTDB_ERR)
536
emid0 = path_energy/path_distance
244
537
call neb_path_energy(bead_list,
247
dE = path_energy - path_energy0
540
dE = dabs((path_energy/path_distance) - emid0)
248
541
call neb_calc_convergence(ng,dbl_mb(g1(1)),
251
544
> Gmax,Grms,Xmax,Xrms)
253
! IF (ga_nodeid().eq.0) THEN
254
! write(*,*) "@ Iteration#:",it
255
! write(*,*) "@ Path Energy:",path_energy
256
! write(*,*) "@ Path Distance:",path_distance
257
! write(*,*) "@ |G_neb|:",norm
553
if (dbl_mb(e1(1)+i-1)>emax)
554
> emax = dbl_mb(e1(1)+i-1)
555
if (dbl_mb(e1(1)+i-1)<emin)
556
> emin = dbl_mb(e1(1)+i-1)
560
emid = dbl_mb(e1(1)+i-1)
562
dE = dE + dabs(emid-emid0)
563
dE = dE + dabs(emin-emin0)
564
dE = dE + dabs(emax-emax0)
571
if (gmax .lt. nebGmax) cvg1 = ' ok '
572
if (grms .lt. nebGrms) cvg2 = ' ok '
573
if (xrms .lt. nebXrms) cvg3 = ' ok '
574
if (xmax .lt. nebXmax) cvg4 = ' ok '
262
577
if (it .gt. 1) mark = ' '
263
write(6,1) mark, mark
579
write(luout,12) mark," "
580
write(luout,12) mark,"NEB Method"
581
write(luout,13) mark,"algorithm = ",neb_algorithm
582
write(luout,13) mark,"maxiter = ",nebsteps
583
write(luout,13) mark,"nbeads = ",nbeads
584
write(luout,13) mark,"nhist = ",m
585
write(luout,13) mark,"natoms = ",nion
586
write(luout,14) mark,"stepsize = ",time_step
587
write(luout,14) mark,"trust = ",trust
588
write(luout,14) mark,"kbeads = ",kbeads
589
write(luout,14) mark,"Gmax tolerance = ",nebGmax
590
write(luout,14) mark,"Grms tolerance = ",nebGrms
591
write(luout,14) mark,"Xmax tolerance = ",nebXmax
592
write(luout,14) mark,"Xrms tolerance = ",nebXrms
593
write(luout,12) mark," "
595
write(luout,10) mark, mark
265
write(6,2) mark, it-1, path_energy, dE,
266
$ Gmax, Grms, Xrms, Xmax, util_wallsec()
268
$ /,a4,' Step Path Energy Delta E Gmax',
269
$ ' Grms Xrms Xmax Walltime',
270
$ /,a4,' ---- ---------------- -------- --------',
271
$ ' -------- -------- -------- --------')
273
$ a4,i5,f17.8,1p,d9.1,0p,4f9.5,f9.1,/,
274
$ 1x,5x,17x,9x,4a9,/)
598
write(luout,11) mark, it, path_energy/path_distance,
600
> Gmax, Grms, Xrms, Xmax, util_wallsec(),
601
> cvg1,cvg2,cvg3,cvg4
603
> /,a4,' Step Intrinsic E Mid-Point E ',
604
> ' Minimum E Maximum E Gmax',
605
> ' Grms Xrms Xmax Walltime',
606
> /,a4,' ---- -------------- -------------- --------------',
608
> ' -------- -------- -------- -------- --------')
610
> a4,i5,4f15.6,1p,4f9.5,f9.1,/,
611
> 1x,5x,17x,9x,4a9,/)
613
13 format(a4,1x,a,i9)
614
14 format(a4,1x,a,e9.3)
618
converged1 = (Gmax.le.nebgmax)
619
converged = (Grms.le.nebgrms)
620
converged = converged.and.(Xmax.le.nebxmax)
621
converged = converged.and.(Xrms.le.nebxrms)
622
if (dE.gt.1.0d-6) converged = converged.and.converged1
624
done = converged.or.(it.ge.nebsteps)
629
write(luout,'(a)') "@neb NEB calculation converged"
631
> write(luout,'(2a)')
632
> "@neb However NEB Gmax not converged",
633
> "...Try increasing the number of beads."
635
write(luout,'(a)') "@neb NEB calculation not converged"
641
* **** write out final path energies ****
642
call util_file_prefix('neb_final_epath',filename)
643
call util_file_name_noprefix(filename,.false.,
647
open(unit=19,file=full_filename,form='formatted')
649
> "#-------------------------------------------------------"
650
write(19,*) "# NEB Path"
651
write(19,*) "# algorithm = ",neb_algorithm
652
write(19,*) "# nbeads = ",nbeads
653
write(19,*) "# nhist = ",m
654
write(19,*) "# natoms = ",nion
655
write(19,*) "# kbeads = ",kbeads
656
write(19,*) "# stepsize = ",time_step
657
write(19,*) "# trust = ",trust
658
write(19,*) "# path energy = ",path_energy
659
write(19,*) "# path distance = ",path_distance
660
write(19,*) "# dE = ",dE
661
write(19,*) "# Gmax = ",Gmax
662
write(19,*) "# Grms = ",Grms
663
write(19,*) "# Xmax = ",Xmax
664
write(19,*) "# Xrms = ",Xrms
666
> "#-------------------------------------------------------"
668
t = (i-1)/dble(nbeads-1)
669
write(19,*) t,dbl_mb(e1(1)+i-1)
674
* **** write out final xyz movies energies ****
675
call util_file_prefix('neb_final.xyz',filename)
676
call util_file_name_noprefix(filename,.false.,
679
if (oprint) open(unit=19,file=full_filename,form='formatted')
680
call create_xyz_file_bead_list(19,bead_list,.false.)
681
if (oprint) close(19)
684
value = value.and.MA_free_heap(cs(2))
685
value = value.and.MA_free_heap(gs(2))
280
686
value = value.and.MA_free_heap(dti(2))
281
687
value = value.and.MA_free_heap(c1(2))
282
688
value = value.and.MA_free_heap(c0(2))