1 subroutine gradient(n,x,nf,g,uiparm,urparm,ufparm)
2 implicit real*8 (a-h,o-z)
7 include 'COMMON.INTERACT'
8 include 'COMMON.FFIELD'
10 include 'COMMON.IOUNITS'
13 double precision urparm(1)
14 dimension x(maxvar),g(maxvar)
16 c This subroutine calculates total internal coordinate gradient.
17 c Depending on the number of function evaluations, either whole energy
18 c is evaluated beforehand, Cartesian coordinates and their derivatives in
19 c internal coordinates are reevaluated or only the cartesian-in-internal
20 c coordinate derivatives are evaluated. The subroutine was designed to work
26 cd print *,'grad',nf,icg
27 if (nf-nfl+1) 20,30,40
28 20 call func(n,x,nf,f,uiparm,urparm,ufparm)
29 c write (iout,*) 'grad 20'
32 30 call var_to_geom(n,x)
34 c write (iout,*) 'grad 30'
36 C Evaluate the derivatives of virtual bond lengths and SC vectors in variables.
39 c write (iout,*) 'grad 40'
40 c print *,'GRADIENT: nnt=',nnt,' nct=',nct,' expon=',expon
42 C Convert the Cartesian gradient into internal-coordinate gradient.
52 c print *,'GRAD: i=',i,' jc=',j,' ind=',ind
54 gthetai=gthetai+dcdv(k,ind)*gradc(k,j,icg)
57 gphii=gphii+dcdv(k+3,ind)*gradc(k,j,icg)
63 c print *,'GRAD: i=',i,' jx=',j,' ind1=',ind1
65 gthetai=gthetai+dxdv(k,ind1)*gradx(k,j,icg)
66 gphii=gphii+dxdv(k+3,ind1)*gradx(k,j,icg)
69 if (i.gt.1) g(i-1)=gphii
70 if (n.gt.nphi) g(nphi+i)=gthetai
72 if (n.le.nphi+ntheta) goto 10
74 if (itype(i).ne.10) then
78 galphai=galphai+dxds(k,i)*gradx(k,i,icg)
81 gomegai=gomegai+dxds(k+3,i)*gradx(k,i,icg)
84 g(ialph(i,1)+nside)=gomegai
88 C Add the components corresponding to local energy terms.
92 cd write (iout,*) 'i=',i,'g=',g(i),' gloc=',gloc(i,icg)
95 C Uncomment following three lines for diagnostics.
97 cd call briefout(0,0.0d0)
98 cd write (iout,'(i3,1pe15.5)') (k,g(k),k=1,n)
101 C-------------------------------------------------------------------------
102 subroutine grad_restr(n,x,nf,g,uiparm,urparm,ufparm)
103 implicit real*8 (a-h,o-z)
105 include 'COMMON.CHAIN'
106 include 'COMMON.DERIV'
108 include 'COMMON.INTERACT'
109 include 'COMMON.FFIELD'
110 include 'COMMON.IOUNITS'
113 double precision urparm(1)
114 dimension x(maxvar),g(maxvar)
117 if (nf-nfl+1) 20,30,40
118 20 call func_restr(n,x,nf,f,uiparm,urparm,ufparm)
119 c write (iout,*) 'grad 20'
124 c Intercept NaNs in the coordinates
125 c write(iout,*) (var(i),i=1,nvar)
130 if (x_sum.ne.x_sum) then
131 write(iout,*)" *** grad_restr : Found NaN in coordinates"
133 print *," *** grad_restr : Found NaN in coordinates"
137 call var_to_geom_restr(n,x)
140 C Evaluate the derivatives of virtual bond lengths and SC vectors in variables.
144 C Convert the Cartesian gradient into internal-coordinate gradient.
150 IF (mask_phi(i+2).eq.1) THEN
155 gphii=gphii+dcdv(k+3,ind)*gradc(k,j,icg)
156 gphii=gphii+dxdv(k+3,ind)*gradx(k,j,icg)
169 IF (mask_theta(i+2).eq.1) THEN
175 gthetai=gthetai+dcdv(k,ind)*gradc(k,j,icg)
176 gthetai=gthetai+dxdv(k,ind)*gradx(k,j,icg)
186 if (itype(i).ne.10) then
187 IF (mask_side(i).eq.1) THEN
191 galphai=galphai+dxds(k,i)*gradx(k,i,icg)
200 if (itype(i).ne.10) then
201 IF (mask_side(i).eq.1) THEN
205 gomegai=gomegai+dxds(k+3,i)*gradx(k,i,icg)
213 C Add the components corresponding to local energy terms.
220 if (mask_phi(i).eq.1) then
222 g(ig)=g(ig)+gloc(igall,icg)
228 if (mask_theta(i).eq.1) then
230 g(ig)=g(ig)+gloc(igall,icg)
236 if (itype(i).ne.10) then
238 if (mask_side(i).eq.1) then
240 g(ig)=g(ig)+gloc(igall,icg)
247 cd write (iout,'(a2,i5,a3,f25.8)') 'i=',i,' g=',g(i)
251 C-------------------------------------------------------------------------
253 implicit real*8 (a-h,o-z)
258 include 'COMMON.CHAIN'
259 include 'COMMON.DERIV'
261 include 'COMMON.INTERACT'
262 include 'COMMON.FFIELD'
264 include 'COMMON.IOUNITS'
265 include 'COMMON.TIME1'
267 c This subrouting calculates total Cartesian coordinate gradient.
268 c The subroutine chainbuild_cart and energy MUST be called beforehand.
277 cd write (iout,*) "After sum_gradient"
279 cd write (iout,*) i," gradc ",(gradc(j,i,icg),j=1,3)
280 cd write (iout,*) i," gradx ",(gradx(j,i,icg),j=1,3)
282 c If performing constraint dynamics, add the gradients of the constraint energy
283 if(usampl.and.totT.gt.eq_time) then
286 gradc(j,i,icg)=gradc(j,i,icg)+dudconst(j,i)+duscdiff(j,i)
287 gradx(j,i,icg)=gradx(j,i,icg)+dudxconst(j,i)+duscdiffx(j,i)
291 gloc(i,icg)=gloc(i,icg)+dugamma(i)
294 gloc(nphi+i,icg)=gloc(nphi+i,icg)+dutheta(i)
302 time_intcartderiv=time_intcartderiv+MPI_Wtime()-time01
304 cd call checkintcartgrad
305 cd write(iout,*) 'calling int_to_cart'
306 cd write (iout,*) "gcart, gxcart, gloc before int_to_cart"
309 gcart(j,i)=gradc(j,i,icg)
310 gxcart(j,i)=gradx(j,i,icg)
312 cd write (iout,'(i5,2(3f10.5,5x),f10.5)') i,(gcart(j,i),j=1,3),
313 cd & (gxcart(j,i),j=1,3),gloc(i,icg)
320 time_inttocart=time_inttocart+MPI_Wtime()-time01
322 cd write (iout,*) "gcart and gxcart after int_to_cart"
324 cd write (iout,'(i5,3f10.5,5x,3f10.5)') i,(gcart(j,i),j=1,3),
325 cd & (gxcart(j,i),j=1,3)
328 time_cartgrad=time_cartgrad+MPI_Wtime()-time00
332 C-------------------------------------------------------------------------
334 implicit real*8 (a-h,o-z)
336 include 'COMMON.DERIV'
337 include 'COMMON.CHAIN'
341 C Initialize Cartesian-coordinate gradient
351 gvdwc_scpp(j,i)=0.0d0
358 gel_loc_long(j,i)=0.0d0
361 gcorr3_turn(j,i)=0.0d0
362 gcorr4_turn(j,i)=0.0d0
364 gradcorr_long(j,i)=0.0d0
365 gradcorr5_long(j,i)=0.0d0
366 gradcorr6_long(j,i)=0.0d0
367 gcorr6_turn_long(j,i)=0.0d0
370 gcorr6_turn(j,i)=0.0d0
380 C Initialize the gradient of local energy terms.
390 gel_loc_turn3(i)=0.0d0
391 gel_loc_turn4(i)=0.0d0
392 gel_loc_turn6(i)=0.0d0
395 c initialize gcart and gxcart
404 c-------------------------------------------------------------------------
405 double precision function fdum()