1 c-------------------------------------------------------------------------------
2 subroutine velverlet_step(itime)
3 c-------------------------------------------------------------------------------
4 c Perform a single velocity Verlet step; the time step can be rescaled if
5 c increments in accelerations exceed the threshold
6 c-------------------------------------------------------------------------------
7 implicit real*8 (a-h,o-z)
9 include 'COMMON.CONTROL'
12 include 'COMMON.LANGEVIN'
13 include 'COMMON.CHAIN'
14 include 'COMMON.DERIV'
16 include 'COMMON.LOCAL'
17 include 'COMMON.INTERACT'
18 include 'COMMON.IOUNITS'
19 include 'COMMON.NAMES'
20 include 'COMMON.TIME1'
22 double precision energia(0:n_ene),vcm(3),incr(3)
23 double precision cm(3),L(3)
24 integer ilen,count,rstcount
27 integer maxcount_scale /20/
28 common /gucio/ cm, energia
29 double precision stochforcvec(MAXRES6)
30 common /stochcalc/ stochforcvec
33 double precision HNose1,HNose,HNose_nh,H,vtnp(maxres6)
34 double precision vtnp_(maxres6),vtnp_a(maxres6)
40 else if (lang.eq.2 .or. lang.eq.3) then
41 call stochastic_force(stochforcvec)
45 icount_scale=icount_scale+1
46 if (icount_scale.gt.maxcount_scale) then
48 & "ERROR: too many attempts at scaling down the time step. ",
49 & "amax=",amax,"epdrift=",epdrift,
50 & "damax=",damax,"edriftmax=",edriftmax,
54 c First step of the velocity Verlet algorithm
57 else if (lang.eq.3) then
58 call sd_verlet1_ciccotti
59 else if (lang.eq.1) then
68 call nhcint(EK,scale_nh,wdti,wdti2,wdti4,wdti8)
72 d_t_old(j,i)=d_t_old(j,i)*scale_nh
78 c Build the chain from the newly calculated coordinates
80 if (rattle) call rattle1
81 if (large.and. mod(itime,ntwe).eq.0) then
82 write (iout,*) "Cartesian and internal coordinates: step 1"
85 write (iout,*) "Accelerations"
87 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),
88 & (d_a(j,i+nres),j=1,3)
90 write (iout,*) "Velocities, step 1"
92 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),
93 & (d_t(j,i+nres),j=1,3)
97 c Calculate energy and forces
101 potE=energia(0)-energia(20)
103 c Get the new accelerations
105 t_enegrad=t_enegrad+tcpu()-tt0
106 c Determine maximum acceleration and scale down the timestep if needed
108 call predict_edrift(epdrift)
109 if (amax.gt.damax .or. epdrift.gt.edriftmax) then
110 c Maximum acceleration or maximum predicted energy drift exceeded, rescale the time step
112 ifac_time=dmax1(dlog(amax/damax),dlog(epdrift/edriftmax))
114 itime_scal=itime_scal+ifac_time
115 c fac_time=dmin1(damax/amax,0.5d0)
116 fac_time=0.5d0**ifac_time
117 d_time=d_time*fac_time
118 if (lang.eq.2 .or. lang.eq.3) then
119 c write (iout,*) "Calling sd_verlet_setup: 1"
120 c Rescale the stochastic forces and recalculate or restore
121 c the matrices of tinker integrator
122 if (itime_scal.gt.maxflag_stoch) then
123 if (large) write (iout,'(a,i5,a)')
124 & "Calculate matrices for stochastic step;",
125 & " itime_scal ",itime_scal
127 call sd_verlet_p_setup
129 call sd_verlet_ciccotti_setup
131 write (iout,'(2a,i3,a,i3,1h.)')
132 & "Warning: cannot store matrices for stochastic",
133 & " integration because the index",itime_scal,
134 & " is greater than",maxflag_stoch
135 write (iout,'(2a)')"Increase MAXFLAG_STOCH or use direct",
136 & " integration Langevin algorithm for better efficiency."
137 else if (flag_stoch(itime_scal)) then
138 if (large) write (iout,'(a,i5,a,l1)')
139 & "Restore matrices for stochastic step; itime_scal ",
140 & itime_scal," flag ",flag_stoch(itime_scal)
143 pfric_mat(i,j)=pfric0_mat(i,j,itime_scal)
144 afric_mat(i,j)=afric0_mat(i,j,itime_scal)
145 vfric_mat(i,j)=vfric0_mat(i,j,itime_scal)
146 prand_mat(i,j)=prand0_mat(i,j,itime_scal)
147 vrand_mat1(i,j)=vrand0_mat1(i,j,itime_scal)
148 vrand_mat2(i,j)=vrand0_mat2(i,j,itime_scal)
152 if (large) write (iout,'(2a,i5,a,l1)')
153 & "Calculate & store matrices for stochastic step;",
154 & " itime_scal ",itime_scal," flag ",flag_stoch(itime_scal)
156 call sd_verlet_p_setup
158 call sd_verlet_ciccotti_setup
160 flag_stoch(ifac_time)=.true.
163 pfric0_mat(i,j,itime_scal)=pfric_mat(i,j)
164 afric0_mat(i,j,itime_scal)=afric_mat(i,j)
165 vfric0_mat(i,j,itime_scal)=vfric_mat(i,j)
166 prand0_mat(i,j,itime_scal)=prand_mat(i,j)
167 vrand0_mat1(i,j,itime_scal)=vrand_mat1(i,j)
168 vrand0_mat2(i,j,itime_scal)=vrand_mat2(i,j)
172 fac_time=1.0d0/dsqrt(fac_time)
174 stochforcvec(i)=fac_time*stochforcvec(i)
176 else if (lang.eq.1) then
177 c Rescale the accelerations due to stochastic forces
178 fac_time=1.0d0/dsqrt(fac_time)
180 d_as_work(i)=d_as_work(i)*fac_time
183 if (large) write (iout,'(a,i10,a,f8.6,a,i3,a,i3)')
184 & "itime",itime," Timestep scaled down to ",
185 & d_time," ifac_time",ifac_time," itime_scal",itime_scal
187 c Second step of the velocity Verlet algorithm
190 else if (lang.eq.3) then
191 call sd_verlet2_ciccotti
192 else if (lang.eq.1) then
202 call nhcint(EK,scale_nh,wdti,wdti2,wdti4,wdti8)
205 d_t(j,i)=d_t(j,i)*scale_nh
210 if (rattle) call rattle2
212 if (d_time.ne.d_time0) then
214 if (lang.eq.2 .or. lang.eq.3) then
215 if (large) write (iout,'(a)')
216 & "Restore original matrices for stochastic step"
217 c write (iout,*) "Calling sd_verlet_setup: 2"
218 c Restore the matrices of tinker integrator if the time step has been restored
221 pfric_mat(i,j)=pfric0_mat(i,j,0)
222 afric_mat(i,j)=afric0_mat(i,j,0)
223 vfric_mat(i,j)=vfric0_mat(i,j,0)
224 prand_mat(i,j)=prand0_mat(i,j,0)
225 vrand_mat1(i,j)=vrand0_mat1(i,j,0)
226 vrand_mat2(i,j)=vrand0_mat2(i,j,0)
234 c Calculate the kinetic and the total energy and the kinetic temperature
235 if (tnp .or. tnp1) then
238 d_t_old(j,i)=d_t(j,i)
239 d_t(j,i)=d_t(j,i)/s_np
247 c write (iout,*) "step",itime," EK",EK," EK1",EK1
249 c Couple the system to Berendsen bath if needed
250 if (tbf .and. lang.eq.0) then
253 kinetic_T=2.0d0/(dimen*Rb)*EK
254 c Backup the coordinates, velocities, and accelerations
258 if(.not.(tnp .or. tnp1)) d_t_old(j,i)=d_t(j,i)
259 d_a_old(j,i)=d_a(j,i)
262 c if (mod(itime,ntwe).eq.0 .and. large) then
263 if (mod(itime,ntwe).eq.0) then
265 if(tnp .or. tnp1) then
266 HNose1=Hnose(EK,s_np,potE,pi_np,Q_np,t_bath,dimen)
268 cd write (iout,'(a,10f)') "hhh",EK,s_np,potE,pi_np,H0
269 cd & ,EK+potE+pi_np**2/(2*Q_np)+dimen*0.001986d0*t_bath*log(s_np)
270 write (iout,*) "HHH H=",H,abs(HNose1-H0)/H0
274 HNose1=Hnose_nh(EK,potE)
276 write (iout,*) "HHH H=",H,abs(HNose1-H0)/H0
292 if (itype(i).ne.10) then
296 vtnp(itnp)=d_t(j,inres)
301 c Transform velocities from UNRES coordinate space to cartesian and Gvec
308 vtnp_(i)=vtnp_(i)+Gvec(j,i)*vtnp(j)
309 vtnp_a(i)=vtnp_a(i)+A(i,j)*vtnp(j)
311 vtnp_(i)=vtnp_(i)*dsqrt(geigen(i))
315 write (iout,'("WWW",i3,3f10.5)') i,vtnp(i),vtnp_(i),vtnp_a(i)