2 c------------------------------------------------
3 c The driver for molecular dynamics subroutines
4 c------------------------------------------------
5 implicit real*8 (a-h,o-z)
10 include 'COMMON.CONTROL'
14 include 'COMMON.LANGEVIN'
16 include 'COMMON.LANGEVIN.lang0'
18 include 'COMMON.CHAIN'
19 include 'COMMON.DERIV'
21 include 'COMMON.LOCAL'
22 include 'COMMON.INTERACT'
23 include 'COMMON.IOUNITS'
24 include 'COMMON.NAMES'
25 include 'COMMON.TIME1'
26 include 'COMMON.HAIRPIN'
27 double precision cm(3),L(3),vcm(3)
29 double precision v_work(maxres6),v_transf(maxres6)
38 if (ilen(tmpdir).gt.0)
39 & call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_"
40 & //liczba(:ilen(liczba))//'.rst')
42 if (ilen(tmpdir).gt.0)
43 & call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_"//'.rst')
50 write (iout,'(20(1h=),a20,20(1h=))') "MD calculation started"
56 c Determine the inverse of the inertia matrix.
57 call setup_MD_matrices
61 t_MDsetup = MPI_Wtime()-tt0
63 t_MDsetup = tcpu()-tt0
66 c Entering the MD loop
72 if (lang.eq.2 .or. lang.eq.3) then
75 call sd_verlet_p_setup
77 call sd_verlet_ciccotti_setup
82 pfric0_mat(i,j,0)=pfric_mat(i,j)
83 afric0_mat(i,j,0)=afric_mat(i,j)
84 vfric0_mat(i,j,0)=vfric_mat(i,j)
85 prand0_mat(i,j,0)=prand_mat(i,j)
86 vrand0_mat1(i,j,0)=vrand_mat1(i,j)
87 vrand0_mat2(i,j,0)=vrand_mat2(i,j)
95 else if (lang.eq.1 .or. lang.eq.4) then
99 t_langsetup=MPI_Wtime()-tt0
102 t_langsetup=tcpu()-tt0
105 do itime=1,n_timestep
106 if (ovrtim()) goto 100
108 if (lang.gt.0 .and. surfarea .and.
109 & mod(itime,reset_fricmat).eq.0) then
110 if (lang.eq.2 .or. lang.eq.3) then
113 call sd_verlet_p_setup
115 call sd_verlet_ciccotti_setup
120 pfric0_mat(i,j,0)=pfric_mat(i,j)
121 afric0_mat(i,j,0)=afric_mat(i,j)
122 vfric0_mat(i,j,0)=vfric_mat(i,j)
123 prand0_mat(i,j,0)=prand_mat(i,j)
124 vrand0_mat1(i,j,0)=vrand_mat1(i,j)
125 vrand0_mat2(i,j,0)=vrand_mat2(i,j)
131 flag_stoch(i)=.false.
133 else if (lang.eq.1 .or. lang.eq.4) then
136 write (iout,'(a,i10)')
137 & "Friction matrix reset based on surface area, itime",itime
139 if (reset_vel .and. tbf .and. lang.eq.0
140 & .and. mod(itime,count_reset_vel).eq.0) then
142 write(iout,'(a,f20.2)')
143 & "Velocities reset to random values, time",totT
146 d_t_old(j,i)=d_t(j,i)
150 if (reset_moment .and. mod(itime,count_reset_moment).eq.0) then
154 d_t(j,0)=d_t(j,0)-vcm(j)
157 kinetic_T=2.0d0/(dimen*Rb)*EK
158 scalfac=dsqrt(T_bath/kinetic_T)
159 write(iout,'(a,f20.2)') "Momenta zeroed out, time",totT
162 d_t_old(j,i)=scalfac*d_t(j,i)
168 c Time-reversible RESPA algorithm
169 c (Tuckerman et al., J. Chem. Phys., 97, 1990, 1992)
170 call RESPA_step(itime)
172 c Variable time step algorithm.
173 call velverlet_step(itime)
176 call brown_step(itime)
179 if (mod(itime,ntwe).eq.0) call statout(itime)
192 if (itype(i).ne.10 .and. itype(i).ne.21) then
195 v_work(ind)=d_t(j,i+nres)
200 write (66,'(80f10.5)')
201 & ((d_t(j,i),j=1,3),i=0,nres-1),((d_t(j,i+nres),j=1,3),i=1,nres)
205 v_transf(i)=v_transf(i)+gvec(j,i)*v_work(j)
207 v_transf(i)= v_transf(i)*dsqrt(geigen(i))
209 write (67,'(80f10.5)') (v_transf(i),i=1,ind)
212 if (mod(itime,ntwx).eq.0) then
213 write (tytul,'("time",f8.2)') totT
215 call hairpin(.true.,nharp,iharp)
216 call secondary2(.true.)
217 call pdbout(potE,tytul,ipdb)
222 if (rstcount.eq.1000.or.itime.eq.n_timestep) then
223 open(irest2,file=rest2name,status='unknown')
224 write(irest2,*) totT,EK,potE,totE,t_bath
226 write (irest2,'(3e15.5)') (d_t(j,i),j=1,3)
229 write (irest2,'(3e15.5)') (dc(j,i),j=1,3)
241 write (iout,'(//35(1h=),a10,35(1h=)/10(/a40,1pe15.5))')
243 & 'MD calculations setup:',t_MDsetup,
244 & 'Energy & gradient evaluation:',t_enegrad,
245 & 'Stochastic MD setup:',t_langsetup,
246 & 'Stochastic MD step setup:',t_sdsetup,
248 write (iout,'(/28(1h=),a25,27(1h=))')
249 & ' End of MD calculation '
252 c-------------------------------------------------------------------------------
253 subroutine brown_step(itime)
254 c------------------------------------------------
255 c Perform a single Euler integration step of Brownian dynamics
256 c------------------------------------------------
257 implicit real*8 (a-h,o-z)
262 include 'COMMON.CONTROL'
266 include 'COMMON.LANGEVIN'
268 include 'COMMON.LANGEVIN.lang0'
270 include 'COMMON.CHAIN'
271 include 'COMMON.DERIV'
273 include 'COMMON.LOCAL'
274 include 'COMMON.INTERACT'
275 include 'COMMON.IOUNITS'
276 include 'COMMON.NAMES'
277 include 'COMMON.TIME1'
278 double precision zapas(MAXRES6)
279 integer ilen,rstcount
281 double precision stochforcvec(MAXRES6)
282 double precision Bmat(MAXRES6,MAXRES2),Cmat(maxres2,maxres2),
283 & Cinv(maxres2,maxres2),GBmat(MAXRES6,MAXRES2),
284 & Tmat(MAXRES6,MAXRES2),Pmat(maxres6,maxres6),Td(maxres6),
286 common /stochcalc/ stochforcvec
289 logical lprn /.false./,lprn1 /.false./
291 double precision difftol /1.0d-5/
294 if (itype(i).ne.10 .and. itype(i).ne.21) nbond=nbond+1
298 write (iout,*) "Generalized inverse of fricmat"
299 call matout(dimen,dimen,MAXRES6,MAXRES6,fricmat)
311 Bmat(ind+j,ind1)=dC_norm(j,i)
316 if (itype(i).ne.10 .and. itype(i).ne.21) then
319 Bmat(ind+j,ind1)=dC_norm(j,i+nres)
325 write (iout,*) "Matrix Bmat"
326 call MATOUT(nbond,dimen,MAXRES6,MAXRES2,Bmat)
332 GBmat(i,j)=GBmat(i,j)+fricmat(i,k)*Bmat(k,j)
337 write (iout,*) "Matrix GBmat"
338 call MATOUT(nbond,dimen,MAXRES6,MAXRES2,Gbmat)
344 Cmat(i,j)=Cmat(i,j)+Bmat(k,i)*GBmat(k,j)
349 write (iout,*) "Matrix Cmat"
350 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,Cmat)
352 call matinvert(nbond,MAXRES2,Cmat,Cinv)
354 write (iout,*) "Matrix Cinv"
355 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,Cinv)
361 Tmat(i,j)=Tmat(i,j)+GBmat(i,k)*Cinv(k,j)
366 write (iout,*) "Matrix Tmat"
367 call MATOUT(nbond,dimen,MAXRES6,MAXRES2,Tmat)
377 Pmat(i,j)=Pmat(i,j)-Tmat(i,k)*Bmat(j,k)
382 write (iout,*) "Matrix Pmat"
383 call MATOUT(dimen,dimen,MAXRES6,MAXRES6,Pmat)
390 Td(i)=Td(i)+vbl*Tmat(i,ind)
393 if (itype(k).ne.10 .and. itype(i).ne.21) then
395 Td(i)=Td(i)+vbldsc0(1,itype(k))*Tmat(i,ind)
400 write (iout,*) "Vector Td"
402 write (iout,'(i5,f10.5)') i,Td(i)
405 call stochastic_force(stochforcvec)
407 write (iout,*) "stochforcvec"
409 write (iout,*) i,stochforcvec(i)
413 zapas(j)=-gcart(j,0)+stochforcvec(j)
415 dC_work(j)=dC_old(j,0)
421 zapas(ind)=-gcart(j,i)+stochforcvec(ind)
422 dC_work(ind)=dC_old(j,i)
426 if (itype(i).ne.10 .and. itype(i).ne.21) then
429 zapas(ind)=-gxcart(j,i)+stochforcvec(ind)
430 dC_work(ind)=dC_old(j,i+nres)
436 write (iout,*) "Initial d_t_work"
438 write (iout,*) i,d_t_work(i)
445 d_t_work(i)=d_t_work(i)+fricmat(i,j)*zapas(j)
452 zapas(i)=zapas(i)+Pmat(i,j)*(dC_work(j)+d_t_work(j)*d_time)
456 write (iout,*) "Final d_t_work and zapas"
458 write (iout,*) i,d_t_work(i),zapas(i)
472 dc_work(ind+j)=dc(j,i)
478 d_t(j,i+nres)=d_t_work(ind+j)
479 dc(j,i+nres)=zapas(ind+j)
480 dc_work(ind+j)=dc(j,i+nres)
486 write (iout,*) "Before correction for rotational lengthening"
487 write (iout,*) "New coordinates",
488 & " and differences between actual and standard bond lengths"
493 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)')
494 & i,(dC(j,i),j=1,3),xx
497 if (itype(i).ne.10 .and. itype(i).ne.21) then
499 xx=vbld(i+nres)-vbldsc0(1,itype(i))
500 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)')
501 & i,(dC(j,i+nres),j=1,3),xx
505 c Second correction (rotational lengthening)
511 blen2 = scalar(dc(1,i),dc(1,i))
512 ppvec(ind)=2*vbl**2-blen2
513 diffbond=dabs(vbl-dsqrt(blen2))
514 if (diffbond.gt.diffmax) diffmax=diffbond
515 if (ppvec(ind).gt.0.0d0) then
516 ppvec(ind)=dsqrt(ppvec(ind))
521 write (iout,'(i5,3f10.5)') ind,diffbond,ppvec(ind)
525 if (itype(i).ne.10 .and. itype(i).ne.21) then
527 blen2 = scalar(dc(1,i+nres),dc(1,i+nres))
528 ppvec(ind)=2*vbldsc0(1,itype(i))**2-blen2
529 diffbond=dabs(vbldsc0(1,itype(i))-dsqrt(blen2))
530 if (diffbond.gt.diffmax) diffmax=diffbond
531 if (ppvec(ind).gt.0.0d0) then
532 ppvec(ind)=dsqrt(ppvec(ind))
537 write (iout,'(i5,3f10.5)') ind,diffbond,ppvec(ind)
541 if (lprn) write (iout,*) "iter",iter," diffmax",diffmax
542 if (diffmax.lt.difftol) goto 10
546 Td(i)=Td(i)+ppvec(j)*Tmat(i,j)
552 zapas(i)=zapas(i)+Pmat(i,j)*dc_work(j)
563 dc_work(ind+j)=zapas(ind+j)
568 if (itype(i).ne.10 .and. itype(i).ne.21) then
570 dc(j,i+nres)=zapas(ind+j)
571 dc_work(ind+j)=zapas(ind+j)
576 c Building the chain from the newly calculated coordinates
579 if (large.and. mod(itime,ntwe).eq.0) then
580 write (iout,*) "Cartesian and internal coordinates: step 1"
583 write (iout,'(a)') "Potential forces"
585 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(-gcart(j,i),j=1,3),
586 & (-gxcart(j,i),j=1,3)
588 write (iout,'(a)') "Stochastic forces"
590 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(stochforc(j,i),j=1,3),
591 & (stochforc(j,i+nres),j=1,3)
593 write (iout,'(a)') "Velocities"
595 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),
596 & (d_t(j,i+nres),j=1,3)
601 write (iout,*) "After correction for rotational lengthening"
602 write (iout,*) "New coordinates",
603 & " and differences between actual and standard bond lengths"
608 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)')
609 & i,(dC(j,i),j=1,3),xx
612 if (itype(i).ne.10 .and. itype(i).ne.21) then
614 xx=vbld(i+nres)-vbldsc0(1,itype(i))
615 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)')
616 & i,(dC(j,i+nres),j=1,3),xx
621 c write (iout,*) "Too many attempts at correcting the bonds"
629 c Calculate energy and forces
631 call etotal(potEcomp)
632 potE=potEcomp(0)-potEcomp(20)
635 c Calculate the kinetic and total energy and the kinetic temperature
638 t_enegrad=t_enegrad+MPI_Wtime()-tt0
640 t_enegrad=t_enegrad+tcpu()-tt0
643 kinetic_T=2.0d0/(dimen*Rb)*EK
646 c-------------------------------------------------------------------------------
647 subroutine velverlet_step(itime)
648 c-------------------------------------------------------------------------------
649 c Perform a single velocity Verlet step; the time step can be rescaled if
650 c increments in accelerations exceed the threshold
651 c-------------------------------------------------------------------------------
652 implicit real*8 (a-h,o-z)
656 integer ierror,ierrcode
658 include 'COMMON.CONTROL'
662 include 'COMMON.LANGEVIN'
664 include 'COMMON.LANGEVIN.lang0'
666 include 'COMMON.CHAIN'
667 include 'COMMON.DERIV'
669 include 'COMMON.LOCAL'
670 include 'COMMON.INTERACT'
671 include 'COMMON.IOUNITS'
672 include 'COMMON.NAMES'
673 include 'COMMON.TIME1'
674 include 'COMMON.MUCA'
675 double precision vcm(3),incr(3)
676 double precision cm(3),L(3)
677 integer ilen,count,rstcount
680 integer maxcount_scale /20/
682 double precision stochforcvec(MAXRES6)
683 common /stochcalc/ stochforcvec
691 else if (lang.eq.2 .or. lang.eq.3) then
692 call stochastic_force(stochforcvec)
696 icount_scale=icount_scale+1
697 if (icount_scale.gt.maxcount_scale) then
699 & "ERROR: too many attempts at scaling down the time step. ",
700 & "amax=",amax,"epdrift=",epdrift,
701 & "damax=",damax,"edriftmax=",edriftmax,
705 call MPI_Abort(MPI_COMM_WORLD,IERROR,IERRCODE)
709 c First step of the velocity Verlet algorithm
712 else if (lang.eq.3) then
713 call sd_verlet1_ciccotti
714 else if (lang.eq.1) then
719 c Build the chain from the newly calculated coordinates
721 if (rattle) call rattle1
723 if (large.and. mod(itime,ntwe).eq.0) then
724 write (iout,*) "Cartesian and internal coordinates: step 1"
729 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(dc(j,i),j=1,3),
730 & (dc(j,i+nres),j=1,3)
732 write (iout,*) "Accelerations"
734 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),
735 & (d_a(j,i+nres),j=1,3)
737 write (iout,*) "Velocities, step 1"
739 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),
740 & (d_t(j,i+nres),j=1,3)
749 c Calculate energy and forces
751 call etotal(potEcomp)
752 potE=potEcomp(0)-potEcomp(20)
754 c Get the new accelerations
757 t_enegrad=t_enegrad+MPI_Wtime()-tt0
759 t_enegrad=t_enegrad+tcpu()-tt0
761 c Determine maximum acceleration and scale down the timestep if needed
763 call predict_edrift(epdrift)
764 if (amax.gt.damax .or. epdrift.gt.edriftmax) then
765 c Maximum acceleration or maximum predicted energy drift exceeded, rescale the time step
767 ifac_time=dmax1(dlog(amax/damax),dlog(epdrift/edriftmax))
769 itime_scal=itime_scal+ifac_time
770 c fac_time=dmin1(damax/amax,0.5d0)
771 fac_time=0.5d0**ifac_time
772 d_time=d_time*fac_time
773 if (lang.eq.2 .or. lang.eq.3) then
774 c write (iout,*) "Calling sd_verlet_setup: 1"
775 c Rescale the stochastic forces and recalculate or restore
776 c the matrices of tinker integrator
777 if (itime_scal.gt.maxflag_stoch) then
778 if (large) write (iout,'(a,i5,a)')
779 & "Calculate matrices for stochastic step;",
780 & " itime_scal ",itime_scal
782 call sd_verlet_p_setup
784 call sd_verlet_ciccotti_setup
786 write (iout,'(2a,i3,a,i3,1h.)')
787 & "Warning: cannot store matrices for stochastic",
788 & " integration because the index",itime_scal,
789 & " is greater than",maxflag_stoch
790 write (iout,'(2a)')"Increase MAXFLAG_STOCH or use direct",
791 & " integration Langevin algorithm for better efficiency."
792 else if (flag_stoch(itime_scal)) then
793 if (large) write (iout,'(a,i5,a,l1)')
794 & "Restore matrices for stochastic step; itime_scal ",
795 & itime_scal," flag ",flag_stoch(itime_scal)
799 pfric_mat(i,j)=pfric0_mat(i,j,itime_scal)
800 afric_mat(i,j)=afric0_mat(i,j,itime_scal)
801 vfric_mat(i,j)=vfric0_mat(i,j,itime_scal)
802 prand_mat(i,j)=prand0_mat(i,j,itime_scal)
803 vrand_mat1(i,j)=vrand0_mat1(i,j,itime_scal)
804 vrand_mat2(i,j)=vrand0_mat2(i,j,itime_scal)
809 if (large) write (iout,'(2a,i5,a,l1)')
810 & "Calculate & store matrices for stochastic step;",
811 & " itime_scal ",itime_scal," flag ",flag_stoch(itime_scal)
813 call sd_verlet_p_setup
815 call sd_verlet_ciccotti_setup
817 flag_stoch(ifac_time)=.true.
821 pfric0_mat(i,j,itime_scal)=pfric_mat(i,j)
822 afric0_mat(i,j,itime_scal)=afric_mat(i,j)
823 vfric0_mat(i,j,itime_scal)=vfric_mat(i,j)
824 prand0_mat(i,j,itime_scal)=prand_mat(i,j)
825 vrand0_mat1(i,j,itime_scal)=vrand_mat1(i,j)
826 vrand0_mat2(i,j,itime_scal)=vrand_mat2(i,j)
831 fac_time=1.0d0/dsqrt(fac_time)
833 stochforcvec(i)=fac_time*stochforcvec(i)
835 else if (lang.eq.1) then
836 c Rescale the accelerations due to stochastic forces
837 fac_time=1.0d0/dsqrt(fac_time)
839 d_as_work(i)=d_as_work(i)*fac_time
842 if (large) write (iout,'(a,i10,a,f8.6,a,i3,a,i3)')
843 & "itime",itime," Timestep scaled down to ",
844 & d_time," ifac_time",ifac_time," itime_scal",itime_scal
846 c Second step of the velocity Verlet algorithm
849 else if (lang.eq.3) then
850 call sd_verlet2_ciccotti
851 else if (lang.eq.1) then
856 if (rattle) call rattle2
858 if (d_time.ne.d_time0) then
860 if (lang.eq.2 .or. lang.eq.3) then
861 if (large) write (iout,'(a)')
862 & "Restore original matrices for stochastic step"
863 c write (iout,*) "Calling sd_verlet_setup: 2"
864 c Restore the matrices of tinker integrator if the time step has been restored
868 pfric_mat(i,j)=pfric0_mat(i,j,0)
869 afric_mat(i,j)=afric0_mat(i,j,0)
870 vfric_mat(i,j)=vfric0_mat(i,j,0)
871 prand_mat(i,j)=prand0_mat(i,j,0)
872 vrand_mat1(i,j)=vrand0_mat1(i,j,0)
873 vrand_mat2(i,j)=vrand0_mat2(i,j,0)
882 c Calculate the kinetic and the total energy and the kinetic temperature
887 c write (iout,*) "step",itime," EK",EK," EK1",EK1
889 c Couple the system to Berendsen bath if needed
890 if (tbf .and. lang.eq.0) then
893 kinetic_T=2.0d0/(dimen*Rb)*EK
894 c Backup the coordinates, velocities, and accelerations
898 d_t_old(j,i)=d_t(j,i)
899 d_a_old(j,i)=d_a(j,i)
903 if (mod(itime,ntwe).eq.0 .and. large) then
904 write (iout,*) "Velocities, step 2"
906 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),
907 & (d_t(j,i+nres),j=1,3)
913 c-------------------------------------------------------------------------------
914 subroutine RESPA_step(itime)
915 c-------------------------------------------------------------------------------
916 c Perform a single RESPA step.
917 c-------------------------------------------------------------------------------
918 implicit real*8 (a-h,o-z)
923 include 'COMMON.CONTROL'
927 include 'COMMON.LANGEVIN'
929 include 'COMMON.LANGEVIN.lang0'
931 include 'COMMON.CHAIN'
932 include 'COMMON.DERIV'
934 include 'COMMON.LOCAL'
935 include 'COMMON.INTERACT'
936 include 'COMMON.IOUNITS'
937 include 'COMMON.NAMES'
938 include 'COMMON.TIME1'
939 double precision energia_short(0:n_ene),
940 & energia_long(0:n_ene)
941 double precision cm(3),L(3),vcm(3),incr(3)
942 integer ilen,count,rstcount
945 integer maxcount_scale /10/
947 double precision stochforcvec(MAXRES6)
948 common /stochcalc/ stochforcvec
951 common /cipiszcze/ itt
953 large=(itime.gt.14600 .and. itime.lt.14700)
955 if (large.and. mod(itime,ntwe).eq.0) then
956 write (iout,*) "***************** RESPA itime",itime
957 write (iout,*) "Cartesian and internal coordinates: step 0"
959 call pdbout(0.0d0,"cipiszcze",iout)
961 write (iout,*) "Accelerations"
963 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),
964 & (d_a(j,i+nres),j=1,3)
966 write (iout,*) "Velocities, step 0"
968 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),
969 & (d_t(j,i+nres),j=1,3)
974 c Perform the initial RESPA step (increment velocities)
975 c write (iout,*) "*********************** RESPA ini"
978 if (mod(itime,ntwe).eq.0 .and. large) then
979 write (iout,*) "Velocities, end"
981 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),
982 & (d_t(j,i+nres),j=1,3)
986 c Compute the short-range forces
993 call etotal_short(energia_short)
994 if (large) write (iout,*) "energia_short",energia_short(0)
998 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1000 t_enegrad=t_enegrad+tcpu()-tt0
1005 d_t_old(j,i)=d_t(j,i)
1006 d_a_old(j,i)=d_a(j,i)
1010 c Split the time step
1011 d_time=d_time/ntime_split
1012 c Perform the short-range RESPSA steps (velocity Verlet increments of
1013 c positions and velocities using short-range forces)
1014 c write (iout,*) "*********************** RESPA split"
1015 do itsplit=1,ntime_split
1018 else if (lang.eq.2 .or. lang.eq.3) then
1019 call stochastic_force(stochforcvec)
1021 c First step of the velocity Verlet algorithm
1024 else if (lang.eq.3) then
1025 call sd_verlet1_ciccotti
1026 else if (lang.eq.1) then
1031 c Build the chain from the newly calculated coordinates
1032 call chainbuild_cart
1033 if (rattle) call rattle1
1035 if (large.and. mod(itime,ntwe).eq.0) then
1036 write (iout,*) "Cartesian and internal coordinates: step 1"
1037 call pdbout(0.0d0,"cipiszcze",iout)
1040 write (iout,*) "Accelerations"
1042 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),
1043 & (d_a(j,i+nres),j=1,3)
1045 write (iout,*) "Velocities, step 1"
1047 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),
1048 & (d_t(j,i+nres),j=1,3)
1057 c Calculate energy and forces
1059 call etotal_short(energia_short)
1060 if (large) write (iout,*) "energia_short",energia_short(0)
1062 c Get the new accelerations
1065 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1067 t_enegrad=t_enegrad+tcpu()-tt0
1069 c Second step of the velocity Verlet algorithm
1072 else if (lang.eq.3) then
1073 call sd_verlet2_ciccotti
1074 else if (lang.eq.1) then
1079 if (rattle) call rattle2
1080 c Backup the coordinates, velocities, and accelerations
1084 d_t_old(j,i)=d_t(j,i)
1085 d_a_old(j,i)=d_a(j,i)
1089 c Restore the time step
1091 c Compute long-range forces
1098 call etotal_long(energia_long)
1099 if (large) write (iout,*) "energia_long",energia_long(0)
1103 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1105 t_enegrad=t_enegrad+tcpu()-tt0
1107 c Compute accelerations from long-range forces
1109 if (large.and. mod(itime,ntwe).eq.0) then
1110 write (iout,*) "Cartesian and internal coordinates: step 2"
1112 call pdbout(0.0d0,"cipiszcze",iout)
1114 write (iout,*) "Accelerations"
1116 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),
1117 & (d_a(j,i+nres),j=1,3)
1119 write (iout,*) "Velocities, step 2"
1121 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),
1122 & (d_t(j,i+nres),j=1,3)
1126 c Compute the final RESPA step (increment velocities)
1127 c write (iout,*) "*********************** RESPA fin"
1129 c Compute the complete potential energy
1131 potEcomp(i)=energia_short(i)+energia_long(i)
1133 potE=potEcomp(0)-potEcomp(20)
1134 c potE=energia_short(0)+energia_long(0)
1136 c Calculate the kinetic and the total energy and the kinetic temperature
1139 c Couple the system to Berendsen bath if needed
1140 if (tbf .and. lang.eq.0) then
1143 kinetic_T=2.0d0/(dimen*Rb)*EK
1144 c Backup the coordinates, velocities, and accelerations
1146 if (mod(itime,ntwe).eq.0 .and. large) then
1147 write (iout,*) "Velocities, end"
1149 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),
1150 & (d_t(j,i+nres),j=1,3)
1156 c---------------------------------------------------------------------
1157 subroutine RESPA_vel
1158 c First and last RESPA step (incrementing velocities using long-range
1160 implicit real*8 (a-h,o-z)
1161 include 'DIMENSIONS'
1162 include 'COMMON.CONTROL'
1163 include 'COMMON.VAR'
1165 include 'COMMON.CHAIN'
1166 include 'COMMON.DERIV'
1167 include 'COMMON.GEO'
1168 include 'COMMON.LOCAL'
1169 include 'COMMON.INTERACT'
1170 include 'COMMON.IOUNITS'
1171 include 'COMMON.NAMES'
1173 d_t(j,0)=d_t(j,0)+0.5d0*d_a(j,0)*d_time
1177 d_t(j,i)=d_t(j,i)+0.5d0*d_a(j,i)*d_time
1181 if (itype(i).ne.10 .and. itype(i).ne.21) then
1184 d_t(j,inres)=d_t(j,inres)+0.5d0*d_a(j,inres)*d_time
1190 c-----------------------------------------------------------------
1192 c Applying velocity Verlet algorithm - step 1 to coordinates
1193 implicit real*8 (a-h,o-z)
1194 include 'DIMENSIONS'
1195 include 'COMMON.CONTROL'
1196 include 'COMMON.VAR'
1198 include 'COMMON.CHAIN'
1199 include 'COMMON.DERIV'
1200 include 'COMMON.GEO'
1201 include 'COMMON.LOCAL'
1202 include 'COMMON.INTERACT'
1203 include 'COMMON.IOUNITS'
1204 include 'COMMON.NAMES'
1205 double precision adt,adt2
1208 adt=d_a_old(j,0)*d_time
1210 dc(j,0)=dc_old(j,0)+(d_t_old(j,0)+adt2)*d_time
1211 d_t_new(j,0)=d_t_old(j,0)+adt2
1212 d_t(j,0)=d_t_old(j,0)+adt
1216 adt=d_a_old(j,i)*d_time
1218 dc(j,i)=dc_old(j,i)+(d_t_old(j,i)+adt2)*d_time
1219 d_t_new(j,i)=d_t_old(j,i)+adt2
1220 d_t(j,i)=d_t_old(j,i)+adt
1224 if (itype(i).ne.10 .and. itype(i).ne.21) then
1227 adt=d_a_old(j,inres)*d_time
1229 dc(j,inres)=dc_old(j,inres)+(d_t_old(j,inres)+adt2)*d_time
1230 d_t_new(j,inres)=d_t_old(j,inres)+adt2
1231 d_t(j,inres)=d_t_old(j,inres)+adt
1237 c---------------------------------------------------------------------
1239 c Step 2 of the velocity Verlet algorithm: update velocities
1240 implicit real*8 (a-h,o-z)
1241 include 'DIMENSIONS'
1242 include 'COMMON.CONTROL'
1243 include 'COMMON.VAR'
1245 include 'COMMON.CHAIN'
1246 include 'COMMON.DERIV'
1247 include 'COMMON.GEO'
1248 include 'COMMON.LOCAL'
1249 include 'COMMON.INTERACT'
1250 include 'COMMON.IOUNITS'
1251 include 'COMMON.NAMES'
1253 d_t(j,0)=d_t_new(j,0)+0.5d0*d_a(j,0)*d_time
1257 d_t(j,i)=d_t_new(j,i)+0.5d0*d_a(j,i)*d_time
1261 if (itype(i).ne.10 .and. itype(i).ne.21) then
1264 d_t(j,inres)=d_t_new(j,inres)+0.5d0*d_a(j,inres)*d_time
1270 c-----------------------------------------------------------------
1271 subroutine sddir_precalc
1272 c Applying velocity Verlet algorithm - step 1 to coordinates
1273 implicit real*8 (a-h,o-z)
1274 include 'DIMENSIONS'
1275 include 'COMMON.CONTROL'
1276 include 'COMMON.VAR'
1279 include 'COMMON.LANGEVIN'
1281 include 'COMMON.LANGEVIN.lang0'
1283 include 'COMMON.CHAIN'
1284 include 'COMMON.DERIV'
1285 include 'COMMON.GEO'
1286 include 'COMMON.LOCAL'
1287 include 'COMMON.INTERACT'
1288 include 'COMMON.IOUNITS'
1289 include 'COMMON.NAMES'
1290 double precision stochforcvec(MAXRES6)
1291 common /stochcalc/ stochforcvec
1293 c Compute friction and stochastic forces
1296 call stochastic_force(stochforcvec)
1298 c Compute the acceleration due to friction forces (d_af_work) and stochastic
1299 c forces (d_as_work)
1306 d_af_work(i)=d_af_work(i)+Ginv(i,j)*fric_work(j)
1307 d_as_work(i)=d_as_work(i)+Ginv(i,j)*stochforcvec(j)
1311 call ginv_mult(fric_work, d_af_work)
1312 call ginv_mult(stochforcvec, d_as_work)
1316 c---------------------------------------------------------------------
1317 subroutine sddir_verlet1
1318 c Applying velocity Verlet algorithm - step 1 to velocities
1319 implicit real*8 (a-h,o-z)
1320 include 'DIMENSIONS'
1321 include 'COMMON.CONTROL'
1322 include 'COMMON.VAR'
1325 include 'COMMON.LANGEVIN'
1327 include 'COMMON.LANGEVIN.lang0'
1329 include 'COMMON.CHAIN'
1330 include 'COMMON.DERIV'
1331 include 'COMMON.GEO'
1332 include 'COMMON.LOCAL'
1333 include 'COMMON.INTERACT'
1334 include 'COMMON.IOUNITS'
1335 include 'COMMON.NAMES'
1336 c Revised 3/31/05 AL: correlation between random contributions to
1337 c position and velocity increments included.
1338 double precision sqrt13 /0.57735026918962576451d0/ ! 1/sqrt(3)
1339 double precision adt,adt2
1341 c Add the contribution from BOTH friction and stochastic force to the
1342 c coordinates, but ONLY the contribution from the friction forces to velocities
1345 adt=(d_a_old(j,0)+d_af_work(j))*d_time
1346 adt2=0.5d0*adt+sqrt13*d_as_work(j)*d_time
1347 dc(j,0)=dc_old(j,0)+(d_t_old(j,0)+adt2)*d_time
1348 d_t_new(j,0)=d_t_old(j,0)+0.5d0*adt
1349 d_t(j,0)=d_t_old(j,0)+adt
1354 adt=(d_a_old(j,i)+d_af_work(ind+j))*d_time
1355 adt2=0.5d0*adt+sqrt13*d_as_work(ind+j)*d_time
1356 dc(j,i)=dc_old(j,i)+(d_t_old(j,i)+adt2)*d_time
1357 d_t_new(j,i)=d_t_old(j,i)+0.5d0*adt
1358 d_t(j,i)=d_t_old(j,i)+adt
1363 if (itype(i).ne.10 .and. itype(i).ne.21) then
1366 adt=(d_a_old(j,inres)+d_af_work(ind+j))*d_time
1367 adt2=0.5d0*adt+sqrt13*d_as_work(ind+j)*d_time
1368 dc(j,inres)=dc_old(j,inres)+(d_t_old(j,inres)+adt2)*d_time
1369 d_t_new(j,inres)=d_t_old(j,inres)+0.5d0*adt
1370 d_t(j,inres)=d_t_old(j,inres)+adt
1377 c---------------------------------------------------------------------
1378 subroutine sddir_verlet2
1379 c Calculating the adjusted velocities for accelerations
1380 implicit real*8 (a-h,o-z)
1381 include 'DIMENSIONS'
1382 include 'COMMON.CONTROL'
1383 include 'COMMON.VAR'
1386 include 'COMMON.LANGEVIN'
1388 include 'COMMON.LANGEVIN.lang0'
1390 include 'COMMON.CHAIN'
1391 include 'COMMON.DERIV'
1392 include 'COMMON.GEO'
1393 include 'COMMON.LOCAL'
1394 include 'COMMON.INTERACT'
1395 include 'COMMON.IOUNITS'
1396 include 'COMMON.NAMES'
1397 double precision stochforcvec(MAXRES6),d_as_work1(MAXRES6)
1398 double precision cos60 /0.5d0/, sin60 /0.86602540378443864676d0/
1399 c Revised 3/31/05 AL: correlation between random contributions to
1400 c position and velocity increments included.
1401 c The correlation coefficients are calculated at low-friction limit.
1402 c Also, friction forces are now not calculated with new velocities.
1404 c call friction_force
1405 call stochastic_force(stochforcvec)
1407 c Compute the acceleration due to friction forces (d_af_work) and stochastic
1408 c forces (d_as_work)
1412 c d_af_work(i)=0.0d0
1415 c d_af_work(i)=d_af_work(i)+Ginv(i,j)*fric_work(j)
1416 d_as_work1(i)=d_as_work1(i)+Ginv(i,j)*stochforcvec(j)
1420 call ginv_mult(stochforcvec, d_as_work1)
1427 d_t(j,0)=d_t_new(j,0)+(0.5d0*(d_a(j,0)+d_af_work(j))
1428 & +sin60*d_as_work(j)+cos60*d_as_work1(j))*d_time
1433 d_t(j,i)=d_t_new(j,i)+(0.5d0*(d_a(j,i)+d_af_work(ind+j))
1434 & +sin60*d_as_work(ind+j)+cos60*d_as_work1(ind+j))*d_time
1439 if (itype(i).ne.10 .and. itype(i).ne.21) then
1442 d_t(j,inres)=d_t_new(j,inres)+(0.5d0*(d_a(j,inres)
1443 & +d_af_work(ind+j))+sin60*d_as_work(ind+j)
1444 & +cos60*d_as_work1(ind+j))*d_time
1451 c---------------------------------------------------------------------
1452 subroutine max_accel
1454 c Find the maximum difference in the accelerations of the the sites
1455 c at the beginning and the end of the time step.
1457 implicit real*8 (a-h,o-z)
1458 include 'DIMENSIONS'
1459 include 'COMMON.CONTROL'
1460 include 'COMMON.VAR'
1462 include 'COMMON.CHAIN'
1463 include 'COMMON.DERIV'
1464 include 'COMMON.GEO'
1465 include 'COMMON.LOCAL'
1466 include 'COMMON.INTERACT'
1467 include 'COMMON.IOUNITS'
1468 double precision aux(3),accel(3)
1470 aux(j)=d_a(j,0)-d_a_old(j,0)
1477 accel(j)=aux(j)+0.5d0*(d_a(j,i)-d_a_old(j,i))
1478 if (dabs(accel(j)).gt.amax) amax=dabs(accel(j))
1485 if (itype(i).ne.10 .and. itype(i).ne.21) then
1487 accel(j)=accel(j)+d_a(j,i+nres)-d_a_old(j,i+nres)
1491 if (dabs(accel(j)).gt.amax) amax=dabs(accel(j))
1494 aux(j)=aux(j)+d_a(j,i)-d_a_old(j,i)
1499 c---------------------------------------------------------------------
1500 subroutine predict_edrift(epdrift)
1502 c Predict the drift of the potential energy
1504 implicit real*8 (a-h,o-z)
1505 include 'DIMENSIONS'
1506 include 'COMMON.CONTROL'
1507 include 'COMMON.VAR'
1509 include 'COMMON.CHAIN'
1510 include 'COMMON.DERIV'
1511 include 'COMMON.GEO'
1512 include 'COMMON.LOCAL'
1513 include 'COMMON.INTERACT'
1514 include 'COMMON.IOUNITS'
1515 include 'COMMON.MUCA'
1516 double precision epdrift,epdriftij
1517 c Drift of the potential energy
1523 epdriftij=dabs((d_a(j,i)-d_a_old(j,i))*gcart(j,i))
1524 if (lmuca) epdriftij=epdriftij*factor
1525 c write (iout,*) "back",i,j,epdriftij
1526 if (epdriftij.gt.epdrift) epdrift=epdriftij
1530 if (itype(i).ne.10 .and. itype(i).ne.21) then
1533 & dabs((d_a(j,i+nres)-d_a_old(j,i+nres))*gxcart(j,i))
1534 if (lmuca) epdriftij=epdriftij*factor
1535 c write (iout,*) "side",i,j,epdriftij
1536 if (epdriftij.gt.epdrift) epdrift=epdriftij
1540 epdrift=0.5d0*epdrift*d_time*d_time
1541 c write (iout,*) "epdrift",epdrift
1544 c-----------------------------------------------------------------------
1545 subroutine verlet_bath
1547 c Coupling to the thermostat by using the Berendsen algorithm
1549 implicit real*8 (a-h,o-z)
1550 include 'DIMENSIONS'
1551 include 'COMMON.CONTROL'
1552 include 'COMMON.VAR'
1554 include 'COMMON.CHAIN'
1555 include 'COMMON.DERIV'
1556 include 'COMMON.GEO'
1557 include 'COMMON.LOCAL'
1558 include 'COMMON.INTERACT'
1559 include 'COMMON.IOUNITS'
1560 include 'COMMON.NAMES'
1561 double precision T_half,fact
1563 T_half=2.0d0/(dimen*Rb)*EK
1564 fact=dsqrt(1.0d0+(d_time/tau_bath)*(t_bath/T_half-1.0d0))
1565 c write(iout,*) "T_half", T_half
1566 c write(iout,*) "EK", EK
1567 c write(iout,*) "fact", fact
1569 d_t(j,0)=fact*d_t(j,0)
1573 d_t(j,i)=fact*d_t(j,i)
1577 if (itype(i).ne.10 .and. itype(i).ne.21) then
1580 d_t(j,inres)=fact*d_t(j,inres)
1586 c---------------------------------------------------------
1588 c Set up the initial conditions of a MD simulation
1589 implicit real*8 (a-h,o-z)
1590 include 'DIMENSIONS'
1593 include 'COMMON.SETUP'
1596 include 'COMMON.CONTROL'
1597 include 'COMMON.VAR'
1600 include 'COMMON.LANGEVIN'
1602 include 'COMMON.LANGEVIN.lang0'
1604 include 'COMMON.CHAIN'
1605 include 'COMMON.DERIV'
1606 include 'COMMON.GEO'
1607 include 'COMMON.LOCAL'
1608 include 'COMMON.INTERACT'
1609 include 'COMMON.IOUNITS'
1610 include 'COMMON.NAMES'
1611 include 'COMMON.REMD'
1612 real*8 energia_long(0:n_ene),
1613 & energia_short(0:n_ene),vcm(3),incr(3)
1614 double precision cm(3),L(3),xv,sigv,lowb,highb
1615 double precision varia(maxvar)
1623 c write(iout,*) "d_time", d_time
1624 c Compute the standard deviations of stochastic forces for Langevin dynamics
1625 c if the friction coefficients do not depend on surface area
1626 if (lang.gt.0 .and. .not.surfarea) then
1628 stdforcp(i)=stdfp*dsqrt(gamp)
1631 stdforcsc(i)=stdfsc(itype(i))*dsqrt(gamsc(iabs(itype(i))))
1634 c Open the pdb file for snapshotshots
1637 if (ilen(tmpdir).gt.0)
1638 & call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD"//
1639 & liczba(:ilen(liczba))//".pdb")
1641 & file=prefix(:ilen(prefix))//"_MD"//liczba(:ilen(liczba))
1645 if (ilen(tmpdir).gt.0 .and. (me.eq.king .or. .not.traj1file))
1646 & call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD"//
1647 & liczba(:ilen(liczba))//".x")
1648 cartname=prefix(:ilen(prefix))//"_MD"//liczba(:ilen(liczba))
1651 if (ilen(tmpdir).gt.0 .and. (me.eq.king .or. .not.traj1file))
1652 & call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD"//
1653 & liczba(:ilen(liczba))//".cx")
1654 cartname=prefix(:ilen(prefix))//"_MD"//liczba(:ilen(liczba))
1660 if (ilen(tmpdir).gt.0)
1661 & call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD.pdb")
1662 open(ipdb,file=prefix(:ilen(prefix))//"_MD.pdb")
1664 if (ilen(tmpdir).gt.0)
1665 & call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD.cx")
1666 cartname=prefix(:ilen(prefix))//"_MD.cx"
1670 write (qstr,'(256(1h ))')
1673 iq = qinfrag(i,iset)*10
1674 iw = wfrag(i,iset)/100
1676 if(me.eq.king.or..not.out1file)
1677 & write (iout,*) "Frag",qinfrag(i,iset),wfrag(i,iset),iq,iw
1678 write (qstr(ipos:ipos+6),'(2h_f,i1,1h_,i1,1h_,i1)') i,iq,iw
1683 iq = qinpair(i,iset)*10
1684 iw = wpair(i,iset)/100
1686 if(me.eq.king.or..not.out1file)
1687 & write (iout,*) "Pair",i,qinpair(i,iset),wpair(i,iset),iq,iw
1688 write (qstr(ipos:ipos+6),'(2h_p,i1,1h_,i1,1h_,i1)') i,iq,iw
1692 c pdbname=pdbname(:ilen(pdbname)-4)//qstr(:ipos-1)//'.pdb'
1694 c cartname=cartname(:ilen(cartname)-2)//qstr(:ipos-1)//'.x'
1696 c cartname=cartname(:ilen(cartname)-3)//qstr(:ipos-1)//'.cx'
1698 c statname=statname(:ilen(statname)-5)//qstr(:ipos-1)//'.stat'
1702 if (restart1file) then
1704 & inquire(file=mremd_rst_name,exist=file_exist)
1705 write (*,*) me," Before broadcast: file_exist",file_exist
1706 call MPI_Bcast(file_exist,1,MPI_LOGICAL,king,CG_COMM,
1708 write (*,*) me," After broadcast: file_exist",file_exist
1709 c inquire(file=mremd_rst_name,exist=file_exist)
1710 if(me.eq.king.or..not.out1file)
1711 & write(iout,*) "Initial state read by master and distributed"
1713 if (ilen(tmpdir).gt.0)
1714 & call copy_to_tmp(pref_orig(:ilen(pref_orig))//'_'
1715 & //liczba(:ilen(liczba))//'.rst')
1716 inquire(file=rest2name,exist=file_exist)
1719 if(.not.restart1file) then
1720 if(me.eq.king.or..not.out1file)
1721 & write(iout,*) "Initial state will be read from file ",
1722 & rest2name(:ilen(rest2name))
1725 call rescale_weights(t_bath)
1727 if(me.eq.king.or..not.out1file)then
1728 if (restart1file) then
1729 write(iout,*) "File ",mremd_rst_name(:ilen(mremd_rst_name)),
1732 write(iout,*) "File ",rest2name(:ilen(rest2name)),
1735 write(iout,*) "Initial velocities randomly generated"
1741 c Generate initial velocities
1742 if(me.eq.king.or..not.out1file)
1743 & write(iout,*) "Initial velocities randomly generated"
1747 c rest2name = prefix(:ilen(prefix))//'.rst'
1748 if(me.eq.king.or..not.out1file)then
1749 write(iout,*) "Initial backbone velocities"
1751 write(iout,*) (d_t(j,i),j=1,3)
1753 write(iout,*) "Initial side-chain velocities"
1755 write(iout,*) (d_t(j,i+nres),j=1,3)
1757 c Zeroing the total angular momentum of the system
1758 write(iout,*) "Calling the zero-angular
1759 & momentum subroutine"
1762 c Getting the potential energy and forces and velocities and accelerations
1764 c write (iout,*) "velocity of the center of the mass:"
1765 c write (iout,*) (vcm(j),j=1,3)
1767 d_t(j,0)=d_t(j,0)-vcm(j)
1769 c Removing the velocity of the center of mass
1771 if(me.eq.king.or..not.out1file)then
1772 write (iout,*) "vcm right after adjustment:"
1773 write (iout,*) (vcm(j),j=1,3)
1777 if(iranconf.ne.0) then
1779 print *, 'Calling OVERLAP_SC'
1780 call overlap_sc(fail)
1784 call sc_move(2,nres-1,10,1d10,nft_sc,etot)
1785 print *,'SC_move',nft_sc,etot
1786 if(me.eq.king.or..not.out1file)
1787 & write(iout,*) 'SC_move',nft_sc,etot
1791 print *, 'Calling MINIM_DC'
1792 call minim_dc(etot,iretcode,nfun)
1794 call geom_to_var(nvar,varia)
1795 print *,'Calling MINIMIZE.'
1796 call minimize(etot,varia,iretcode,nfun)
1797 call var_to_geom(nvar,varia)
1799 if(me.eq.king.or..not.out1file)
1800 & write(iout,*) 'SUMSL return code is',iretcode,' eval ',nfun
1803 call chainbuild_cart
1806 call verlet_bath(EK)
1808 kinetic_T=2.0d0/(dimen*Rb)*EK
1809 if(me.eq.king.or..not.out1file)then
1814 call etotal(potEcomp)
1819 if (amax*d_time .gt. dvmax) d_time=d_time*dvmax/amax
1820 if(me.eq.king.or..not.out1file)then
1821 write(iout,*) "Potential energy and its components"
1822 write(iout,*) (potEcomp(i),i=0,n_ene)
1824 potE=potEcomp(0)-potEcomp(20)
1827 if (ntwe.ne.0) call statout(itime)
1828 if(me.eq.king.or..not.out1file)
1829 & write (iout,*) "Initial:",
1830 & " Kinetic energy",EK," potential energy",potE,
1831 & " total energy",totE," maximum acceleration ",
1834 write (iout,*) "Initial coordinates"
1836 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(c(j,i),j=1,3),
1837 & (c(j,i+nres),j=1,3)
1839 write (iout,*) "Initial dC"
1841 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(dc(j,i),j=1,3),
1842 & (dc(j,i+nres),j=1,3)
1844 write (iout,*) "Initial velocities"
1846 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),
1847 & (d_t(j,i+nres),j=1,3)
1849 write (iout,*) "Initial accelerations"
1851 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),
1852 & (d_a(j,i+nres),j=1,3)
1858 d_t_old(j,i)=d_t(j,i)
1859 d_a_old(j,i)=d_a(j,i)
1861 c write (iout,*) "dc_old",i,(dc_old(j,i),j=1,3)
1870 call etotal_long(energia_long)
1871 if (large) write (iout,*) "energia_long",energia_long(0)
1875 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1877 t_enegrad=t_enegrad+tcpu()-tt0
1879 c call etotal_short(energia_short)
1880 c write (iout,*) "energia_long",energia_long(0),
1881 c & " energia_short",energia_short(0),
1882 c & " total",energia_long(0)+energia_short(0)
1886 c-----------------------------------------------------------
1887 subroutine random_vel
1888 implicit real*8 (a-h,o-z)
1889 include 'DIMENSIONS'
1890 include 'COMMON.CONTROL'
1891 include 'COMMON.VAR'
1894 include 'COMMON.LANGEVIN'
1896 include 'COMMON.LANGEVIN.lang0'
1898 include 'COMMON.CHAIN'
1899 include 'COMMON.DERIV'
1900 include 'COMMON.GEO'
1901 include 'COMMON.LOCAL'
1902 include 'COMMON.INTERACT'
1903 include 'COMMON.IOUNITS'
1904 include 'COMMON.NAMES'
1905 include 'COMMON.TIME1'
1906 double precision xv,sigv,lowb,highb
1907 c Generate random velocities from Gaussian distribution of mean 0 and std of KT/m
1908 c First generate velocities in the eigenspace of the G matrix
1909 c write (iout,*) "Calling random_vel"
1912 sigv=dsqrt((Rb*t_bath)/geigen(i))
1915 d_t_work_new(i)=anorm_distr(xv,sigv,lowb,highb)
1919 c Ek1=Ek1+0.5d0*geigen(i)*d_t_work_new(i)**2
1921 c Transform velocities to UNRES coordinate space
1925 d_t_work(i)=d_t_work(i)+Gvec(i,j)*d_t_work_new(j)
1928 c Transfer to the d_t vector
1930 d_t(j,0)=d_t_work(j)
1936 if (itype(i).ne.21 .and. itype(i+1).ne.21) then
1937 d_t(j,i)=d_t_work(ind)
1944 if (itype(i).ne.10 .and. itype(i).ne.21) then
1947 d_t(j,i+nres)=d_t_work(ind)
1952 c write (iout,*) "Kinetic energy",Ek,EK1," kinetic temperature",
1953 c & 2.0d0/(dimen*Rb)*EK,2.0d0/(dimen*Rb)*EK1
1956 c-----------------------------------------------------------
1957 subroutine sd_verlet_p_setup
1958 c Sets up the parameters of stochastic Verlet algorithm
1959 implicit real*8 (a-h,o-z)
1960 include 'DIMENSIONS'
1964 include 'COMMON.CONTROL'
1965 include 'COMMON.VAR'
1968 include 'COMMON.LANGEVIN'
1970 include 'COMMON.LANGEVIN.lang0'
1972 include 'COMMON.CHAIN'
1973 include 'COMMON.DERIV'
1974 include 'COMMON.GEO'
1975 include 'COMMON.LOCAL'
1976 include 'COMMON.INTERACT'
1977 include 'COMMON.IOUNITS'
1978 include 'COMMON.NAMES'
1979 include 'COMMON.TIME1'
1980 double precision emgdt(MAXRES6),
1981 & pterm,vterm,rho,rhoc,vsig,
1982 & pfric_vec(MAXRES6),vfric_vec(MAXRES6),
1983 & afric_vec(MAXRES6),prand_vec(MAXRES6),
1984 & vrand_vec1(MAXRES6),vrand_vec2(MAXRES6)
1985 logical lprn /.false./
1986 double precision zero /1.0d-8/, gdt_radius /0.05d0/
1987 double precision ktm
1994 c AL 8/17/04 Code adapted from tinker
1996 c Get the frictional and random terms for stochastic dynamics in the
1997 c eigenspace of mass-scaled UNRES friction matrix
2000 gdt = fricgam(i) * d_time
2002 c Stochastic dynamics reduces to simple MD for zero friction
2004 if (gdt .le. zero) then
2005 pfric_vec(i) = 1.0d0
2006 vfric_vec(i) = d_time
2007 afric_vec(i) = 0.5d0 * d_time * d_time
2008 prand_vec(i) = 0.0d0
2009 vrand_vec1(i) = 0.0d0
2010 vrand_vec2(i) = 0.0d0
2012 c Analytical expressions when friction coefficient is large
2015 if (gdt .ge. gdt_radius) then
2018 vfric_vec(i) = (1.0d0-egdt) / fricgam(i)
2019 afric_vec(i) = (d_time-vfric_vec(i)) / fricgam(i)
2020 pterm = 2.0d0*gdt - 3.0d0 + (4.0d0-egdt)*egdt
2021 vterm = 1.0d0 - egdt**2
2022 rho = (1.0d0-egdt)**2 / sqrt(pterm*vterm)
2024 c Use series expansions when friction coefficient is small
2035 afric_vec(i) = (gdt2/2.0d0 - gdt3/6.0d0 + gdt4/24.0d0
2036 & - gdt5/120.0d0 + gdt6/720.0d0
2037 & - gdt7/5040.0d0 + gdt8/40320.0d0
2038 & - gdt9/362880.0d0) / fricgam(i)**2
2039 vfric_vec(i) = d_time - fricgam(i)*afric_vec(i)
2040 pfric_vec(i) = 1.0d0 - fricgam(i)*vfric_vec(i)
2041 pterm = 2.0d0*gdt3/3.0d0 - gdt4/2.0d0
2042 & + 7.0d0*gdt5/30.0d0 - gdt6/12.0d0
2043 & + 31.0d0*gdt7/1260.0d0 - gdt8/160.0d0
2044 & + 127.0d0*gdt9/90720.0d0
2045 vterm = 2.0d0*gdt - 2.0d0*gdt2 + 4.0d0*gdt3/3.0d0
2046 & - 2.0d0*gdt4/3.0d0 + 4.0d0*gdt5/15.0d0
2047 & - 4.0d0*gdt6/45.0d0 + 8.0d0*gdt7/315.0d0
2048 & - 2.0d0*gdt8/315.0d0 + 4.0d0*gdt9/2835.0d0
2049 rho = sqrt(3.0d0) * (0.5d0 - 3.0d0*gdt/16.0d0
2050 & - 17.0d0*gdt2/1280.0d0
2051 & + 17.0d0*gdt3/6144.0d0
2052 & + 40967.0d0*gdt4/34406400.0d0
2053 & - 57203.0d0*gdt5/275251200.0d0
2054 & - 1429487.0d0*gdt6/13212057600.0d0)
2057 c Compute the scaling factors of random terms for the nonzero friction case
2059 ktm = 0.5d0*d_time/fricgam(i)
2060 psig = dsqrt(ktm*pterm) / fricgam(i)
2061 vsig = dsqrt(ktm*vterm)
2062 rhoc = dsqrt(1.0d0 - rho*rho)
2064 vrand_vec1(i) = vsig * rho
2065 vrand_vec2(i) = vsig * rhoc
2070 & "pfric_vec, vfric_vec, afric_vec, prand_vec, vrand_vec1,",
2073 write (iout,'(i5,6e15.5)') i,pfric_vec(i),vfric_vec(i),
2074 & afric_vec(i),prand_vec(i),vrand_vec1(i),vrand_vec2(i)
2078 c Transform from the eigenspace of mass-scaled friction matrix to UNRES variables
2081 call eigtransf(dimen,maxres6,mt3,mt2,pfric_vec,pfric_mat)
2082 call eigtransf(dimen,maxres6,mt3,mt2,vfric_vec,vfric_mat)
2083 call eigtransf(dimen,maxres6,mt3,mt2,afric_vec,afric_mat)
2084 call eigtransf(dimen,maxres6,mt3,mt1,prand_vec,prand_mat)
2085 call eigtransf(dimen,maxres6,mt3,mt1,vrand_vec1,vrand_mat1)
2086 call eigtransf(dimen,maxres6,mt3,mt1,vrand_vec2,vrand_mat2)
2088 c call eigtransf1(dimen,maxres6,mt3mt2,pfric_vec,pfric_mat)
2089 c call eigtransf1(dimen,maxres6,mt3mt2,vfric_vec,vfric_mat)
2090 c call eigtransf1(dimen,maxres6,mt3mt2,afric_vec,afric_mat)
2091 c call eigtransf1(dimen,maxres6,mt3mt1,prand_vec,prand_mat)
2092 c call eigtransf1(dimen,maxres6,mt3mt1,vrand_vec1,vrand_mat1)
2093 c call eigtransf1(dimen,maxres6,mt3mt1,vrand_vec2,vrand_mat2)
2095 t_sdsetup=t_sdsetup+MPI_Wtime()
2097 t_sdsetup=t_sdsetup+tcpu()-tt0
2101 c-------------------------------------------------------------
2102 subroutine eigtransf1(n,ndim,ab,d,c)
2105 double precision ab(ndim,ndim,n),c(ndim,n),d(ndim)
2111 c(i,j)=c(i,j)+ab(k,j,i)*d(k)
2117 c-------------------------------------------------------------
2118 subroutine eigtransf(n,ndim,a,b,d,c)
2121 double precision a(ndim,n),b(ndim,n),c(ndim,n),d(ndim)
2127 c(i,j)=c(i,j)+a(i,k)*b(k,j)*d(k)
2133 c-------------------------------------------------------------
2134 subroutine sd_verlet1
2135 c Applying stochastic velocity Verlet algorithm - step 1 to velocities
2136 implicit real*8 (a-h,o-z)
2137 include 'DIMENSIONS'
2138 include 'COMMON.CONTROL'
2139 include 'COMMON.VAR'
2142 include 'COMMON.LANGEVIN'
2144 include 'COMMON.LANGEVIN.lang0'
2146 include 'COMMON.CHAIN'
2147 include 'COMMON.DERIV'
2148 include 'COMMON.GEO'
2149 include 'COMMON.LOCAL'
2150 include 'COMMON.INTERACT'
2151 include 'COMMON.IOUNITS'
2152 include 'COMMON.NAMES'
2153 double precision stochforcvec(MAXRES6)
2154 common /stochcalc/ stochforcvec
2155 logical lprn /.false./
2157 c write (iout,*) "dc_old"
2159 c write (iout,'(i5,3f10.5,5x,3f10.5)')
2160 c & i,(dc_old(j,i),j=1,3),(dc_old(j,i+nres),j=1,3)
2163 dc_work(j)=dc_old(j,0)
2164 d_t_work(j)=d_t_old(j,0)
2165 d_a_work(j)=d_a_old(j,0)
2170 dc_work(ind+j)=dc_old(j,i)
2171 d_t_work(ind+j)=d_t_old(j,i)
2172 d_a_work(ind+j)=d_a_old(j,i)
2177 if (itype(i).ne.10 .and. itype(i).ne.21) then
2179 dc_work(ind+j)=dc_old(j,i+nres)
2180 d_t_work(ind+j)=d_t_old(j,i+nres)
2181 d_a_work(ind+j)=d_a_old(j,i+nres)
2189 & "pfric_mat, vfric_mat, afric_mat, prand_mat, vrand_mat1,",
2193 write (iout,'(2i5,6e15.5)') i,j,pfric_mat(i,j),
2194 & vfric_mat(i,j),afric_mat(i,j),
2195 & prand_mat(i,j),vrand_mat1(i,j),vrand_mat2(i,j)
2203 dc_work(i)=dc_work(i)+vfric_mat(i,j)*d_t_work(j)
2204 & +afric_mat(i,j)*d_a_work(j)+prand_mat(i,j)*stochforcvec(j)
2205 ddt1=ddt1+pfric_mat(i,j)*d_t_work(j)
2206 ddt2=ddt2+vfric_mat(i,j)*d_a_work(j)
2208 d_t_work_new(i)=ddt1+0.5d0*ddt2
2209 d_t_work(i)=ddt1+ddt2
2214 d_t(j,0)=d_t_work(j)
2219 dc(j,i)=dc_work(ind+j)
2220 d_t(j,i)=d_t_work(ind+j)
2225 if (itype(i).ne.10 .and. itype(i).ne.21) then
2228 dc(j,inres)=dc_work(ind+j)
2229 d_t(j,inres)=d_t_work(ind+j)
2236 c--------------------------------------------------------------------------
2237 subroutine sd_verlet2
2238 c Calculating the adjusted velocities for accelerations
2239 implicit real*8 (a-h,o-z)
2240 include 'DIMENSIONS'
2241 include 'COMMON.CONTROL'
2242 include 'COMMON.VAR'
2245 include 'COMMON.LANGEVIN'
2247 include 'COMMON.LANGEVIN.lang0'
2249 include 'COMMON.CHAIN'
2250 include 'COMMON.DERIV'
2251 include 'COMMON.GEO'
2252 include 'COMMON.LOCAL'
2253 include 'COMMON.INTERACT'
2254 include 'COMMON.IOUNITS'
2255 include 'COMMON.NAMES'
2256 double precision stochforcvec(MAXRES6),stochforcvecV(MAXRES6)
2257 common /stochcalc/ stochforcvec
2259 c Compute the stochastic forces which contribute to velocity change
2261 call stochastic_force(stochforcvecV)
2268 ddt1=ddt1+vfric_mat(i,j)*d_a_work(j)
2269 ddt2=ddt2+vrand_mat1(i,j)*stochforcvec(j)+
2270 & vrand_mat2(i,j)*stochforcvecV(j)
2272 d_t_work(i)=d_t_work_new(i)+0.5d0*ddt1+ddt2
2276 d_t(j,0)=d_t_work(j)
2281 d_t(j,i)=d_t_work(ind+j)
2286 if (itype(i).ne.10 .and. itype(i).ne.21) then
2289 d_t(j,inres)=d_t_work(ind+j)
2296 c-----------------------------------------------------------
2297 subroutine sd_verlet_ciccotti_setup
2298 c Sets up the parameters of stochastic velocity Verlet algorithmi; Ciccotti's
2300 implicit real*8 (a-h,o-z)
2301 include 'DIMENSIONS'
2305 include 'COMMON.CONTROL'
2306 include 'COMMON.VAR'
2309 include 'COMMON.LANGEVIN'
2311 include 'COMMON.LANGEVIN.lang0'
2313 include 'COMMON.CHAIN'
2314 include 'COMMON.DERIV'
2315 include 'COMMON.GEO'
2316 include 'COMMON.LOCAL'
2317 include 'COMMON.INTERACT'
2318 include 'COMMON.IOUNITS'
2319 include 'COMMON.NAMES'
2320 include 'COMMON.TIME1'
2321 double precision emgdt(MAXRES6),
2322 & pterm,vterm,rho,rhoc,vsig,
2323 & pfric_vec(MAXRES6),vfric_vec(MAXRES6),
2324 & afric_vec(MAXRES6),prand_vec(MAXRES6),
2325 & vrand_vec1(MAXRES6),vrand_vec2(MAXRES6)
2326 logical lprn /.false./
2327 double precision zero /1.0d-8/, gdt_radius /0.05d0/
2328 double precision ktm
2335 c AL 8/17/04 Code adapted from tinker
2337 c Get the frictional and random terms for stochastic dynamics in the
2338 c eigenspace of mass-scaled UNRES friction matrix
2341 write (iout,*) "i",i," fricgam",fricgam(i)
2342 gdt = fricgam(i) * d_time
2344 c Stochastic dynamics reduces to simple MD for zero friction
2346 if (gdt .le. zero) then
2347 pfric_vec(i) = 1.0d0
2348 vfric_vec(i) = d_time
2349 afric_vec(i) = 0.5d0*d_time*d_time
2350 prand_vec(i) = afric_vec(i)
2351 vrand_vec2(i) = vfric_vec(i)
2353 c Analytical expressions when friction coefficient is large
2358 vfric_vec(i) = dexp(-0.5d0*gdt)*d_time
2359 afric_vec(i) = 0.5d0*dexp(-0.25d0*gdt)*d_time*d_time
2360 prand_vec(i) = afric_vec(i)
2361 vrand_vec2(i) = vfric_vec(i)
2363 c Compute the scaling factors of random terms for the nonzero friction case
2365 c ktm = 0.5d0*d_time/fricgam(i)
2366 c psig = dsqrt(ktm*pterm) / fricgam(i)
2367 c vsig = dsqrt(ktm*vterm)
2368 c prand_vec(i) = psig*afric_vec(i)
2369 c vrand_vec2(i) = vsig*vfric_vec(i)
2374 & "pfric_vec, vfric_vec, afric_vec, prand_vec, vrand_vec1,",
2377 write (iout,'(i5,6e15.5)') i,pfric_vec(i),vfric_vec(i),
2378 & afric_vec(i),prand_vec(i),vrand_vec1(i),vrand_vec2(i)
2382 c Transform from the eigenspace of mass-scaled friction matrix to UNRES variables
2384 call eigtransf(dimen,maxres6,mt3,mt2,pfric_vec,pfric_mat)
2385 call eigtransf(dimen,maxres6,mt3,mt2,vfric_vec,vfric_mat)
2386 call eigtransf(dimen,maxres6,mt3,mt2,afric_vec,afric_mat)
2387 call eigtransf(dimen,maxres6,mt3,mt1,prand_vec,prand_mat)
2388 call eigtransf(dimen,maxres6,mt3,mt1,vrand_vec2,vrand_mat2)
2390 t_sdsetup=t_sdsetup+MPI_Wtime()
2392 t_sdsetup=t_sdsetup+tcpu()-tt0
2396 c-------------------------------------------------------------
2397 subroutine sd_verlet1_ciccotti
2398 c Applying stochastic velocity Verlet algorithm - step 1 to velocities
2399 implicit real*8 (a-h,o-z)
2400 include 'DIMENSIONS'
2404 include 'COMMON.CONTROL'
2405 include 'COMMON.VAR'
2408 include 'COMMON.LANGEVIN'
2410 include 'COMMON.LANGEVIN.lang0'
2412 include 'COMMON.CHAIN'
2413 include 'COMMON.DERIV'
2414 include 'COMMON.GEO'
2415 include 'COMMON.LOCAL'
2416 include 'COMMON.INTERACT'
2417 include 'COMMON.IOUNITS'
2418 include 'COMMON.NAMES'
2419 double precision stochforcvec(MAXRES6)
2420 common /stochcalc/ stochforcvec
2421 logical lprn /.false./
2423 c write (iout,*) "dc_old"
2425 c write (iout,'(i5,3f10.5,5x,3f10.5)')
2426 c & i,(dc_old(j,i),j=1,3),(dc_old(j,i+nres),j=1,3)
2429 dc_work(j)=dc_old(j,0)
2430 d_t_work(j)=d_t_old(j,0)
2431 d_a_work(j)=d_a_old(j,0)
2436 dc_work(ind+j)=dc_old(j,i)
2437 d_t_work(ind+j)=d_t_old(j,i)
2438 d_a_work(ind+j)=d_a_old(j,i)
2443 if (itype(i).ne.10 .and. itype(i).ne.21) then
2445 dc_work(ind+j)=dc_old(j,i+nres)
2446 d_t_work(ind+j)=d_t_old(j,i+nres)
2447 d_a_work(ind+j)=d_a_old(j,i+nres)
2456 & "pfric_mat, vfric_mat, afric_mat, prand_mat, vrand_mat1,",
2460 write (iout,'(2i5,6e15.5)') i,j,pfric_mat(i,j),
2461 & vfric_mat(i,j),afric_mat(i,j),
2462 & prand_mat(i,j),vrand_mat1(i,j),vrand_mat2(i,j)
2470 dc_work(i)=dc_work(i)+vfric_mat(i,j)*d_t_work(j)
2471 & +afric_mat(i,j)*d_a_work(j)+prand_mat(i,j)*stochforcvec(j)
2472 ddt1=ddt1+pfric_mat(i,j)*d_t_work(j)
2473 ddt2=ddt2+vfric_mat(i,j)*d_a_work(j)
2475 d_t_work_new(i)=ddt1+0.5d0*ddt2
2476 d_t_work(i)=ddt1+ddt2
2481 d_t(j,0)=d_t_work(j)
2486 dc(j,i)=dc_work(ind+j)
2487 d_t(j,i)=d_t_work(ind+j)
2492 if (itype(i).ne.10 .and. itype(i).ne.21) then
2495 dc(j,inres)=dc_work(ind+j)
2496 d_t(j,inres)=d_t_work(ind+j)
2503 c--------------------------------------------------------------------------
2504 subroutine sd_verlet2_ciccotti
2505 c Calculating the adjusted velocities for accelerations
2506 implicit real*8 (a-h,o-z)
2507 include 'DIMENSIONS'
2508 include 'COMMON.CONTROL'
2509 include 'COMMON.VAR'
2512 include 'COMMON.LANGEVIN'
2514 include 'COMMON.LANGEVIN.lang0'
2516 include 'COMMON.CHAIN'
2517 include 'COMMON.DERIV'
2518 include 'COMMON.GEO'
2519 include 'COMMON.LOCAL'
2520 include 'COMMON.INTERACT'
2521 include 'COMMON.IOUNITS'
2522 include 'COMMON.NAMES'
2523 double precision stochforcvec(MAXRES6),stochforcvecV(MAXRES6)
2524 common /stochcalc/ stochforcvec
2526 c Compute the stochastic forces which contribute to velocity change
2528 call stochastic_force(stochforcvecV)
2535 ddt1=ddt1+vfric_mat(i,j)*d_a_work(j)
2536 c ddt2=ddt2+vrand_mat2(i,j)*stochforcvecV(j)
2537 ddt2=ddt2+vrand_mat2(i,j)*stochforcvec(j)
2539 d_t_work(i)=d_t_work_new(i)+0.5d0*ddt1+ddt2
2543 d_t(j,0)=d_t_work(j)
2548 d_t(j,i)=d_t_work(ind+j)
2553 if (itype(i).ne.10 .and. itype(i).ne.21) then
2556 d_t(j,inres)=d_t_work(ind+j)