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) then
195 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
198 v_work(ind)=d_t(j,i+nres)
203 write (66,'(80f10.5)')
204 & ((d_t(j,i),j=1,3),i=0,nres-1),((d_t(j,i+nres),j=1,3),i=1,nres)
208 v_transf(i)=v_transf(i)+gvec(j,i)*v_work(j)
210 v_transf(i)= v_transf(i)*dsqrt(geigen(i))
212 write (67,'(80f10.5)') (v_transf(i),i=1,ind)
215 if (mod(itime,ntwx).eq.0) then
216 write (tytul,'("time",f8.2)') totT
218 call hairpin(.true.,nharp,iharp)
219 call secondary2(.true.)
220 call pdbout(potE,tytul,ipdb)
225 if (rstcount.eq.1000.or.itime.eq.n_timestep) then
226 open(irest2,file=rest2name,status='unknown')
227 write(irest2,*) totT,EK,potE,totE,t_bath
229 write (irest2,'(3e15.5)') (d_t(j,i),j=1,3)
232 write (irest2,'(3e15.5)') (dc(j,i),j=1,3)
244 write (iout,'(//35(1h=),a10,35(1h=)/10(/a40,1pe15.5))')
246 & 'MD calculations setup:',t_MDsetup,
247 & 'Energy & gradient evaluation:',t_enegrad,
248 & 'Stochastic MD setup:',t_langsetup,
249 & 'Stochastic MD step setup:',t_sdsetup,
251 write (iout,'(/28(1h=),a25,27(1h=))')
252 & ' End of MD calculation '
255 c-------------------------------------------------------------------------------
256 subroutine brown_step(itime)
257 c------------------------------------------------
258 c Perform a single Euler integration step of Brownian dynamics
259 c------------------------------------------------
260 implicit real*8 (a-h,o-z)
265 include 'COMMON.CONTROL'
269 include 'COMMON.LANGEVIN'
271 include 'COMMON.LANGEVIN.lang0'
273 include 'COMMON.CHAIN'
274 include 'COMMON.DERIV'
276 include 'COMMON.LOCAL'
277 include 'COMMON.INTERACT'
278 include 'COMMON.IOUNITS'
279 include 'COMMON.NAMES'
280 include 'COMMON.TIME1'
281 double precision zapas(MAXRES6)
282 integer ilen,rstcount
284 double precision stochforcvec(MAXRES6)
285 double precision Bmat(MAXRES6,MAXRES2),Cmat(maxres2,maxres2),
286 & Cinv(maxres2,maxres2),GBmat(MAXRES6,MAXRES2),
287 & Tmat(MAXRES6,MAXRES2),Pmat(maxres6,maxres6),Td(maxres6),
289 common /stochcalc/ stochforcvec
292 logical lprn /.false./,lprn1 /.false./
294 double precision difftol /1.0d-5/
297 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) nbond=nbond+1
301 write (iout,*) "Generalized inverse of fricmat"
302 call matout(dimen,dimen,MAXRES6,MAXRES6,fricmat)
314 Bmat(ind+j,ind1)=dC_norm(j,i)
319 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
322 Bmat(ind+j,ind1)=dC_norm(j,i+nres)
328 write (iout,*) "Matrix Bmat"
329 call MATOUT(nbond,dimen,MAXRES6,MAXRES2,Bmat)
335 GBmat(i,j)=GBmat(i,j)+fricmat(i,k)*Bmat(k,j)
340 write (iout,*) "Matrix GBmat"
341 call MATOUT(nbond,dimen,MAXRES6,MAXRES2,Gbmat)
347 Cmat(i,j)=Cmat(i,j)+Bmat(k,i)*GBmat(k,j)
352 write (iout,*) "Matrix Cmat"
353 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,Cmat)
355 call matinvert(nbond,MAXRES2,Cmat,Cinv)
357 write (iout,*) "Matrix Cinv"
358 call MATOUT(nbond,nbond,MAXRES2,MAXRES2,Cinv)
364 Tmat(i,j)=Tmat(i,j)+GBmat(i,k)*Cinv(k,j)
369 write (iout,*) "Matrix Tmat"
370 call MATOUT(nbond,dimen,MAXRES6,MAXRES2,Tmat)
380 Pmat(i,j)=Pmat(i,j)-Tmat(i,k)*Bmat(j,k)
385 write (iout,*) "Matrix Pmat"
386 call MATOUT(dimen,dimen,MAXRES6,MAXRES6,Pmat)
393 Td(i)=Td(i)+vbl*Tmat(i,ind)
396 if (itype(k).ne.10 .and. itype(i).ne.ntyp1) then
398 Td(i)=Td(i)+vbldsc0(1,itype(k))*Tmat(i,ind)
403 write (iout,*) "Vector Td"
405 write (iout,'(i5,f10.5)') i,Td(i)
408 call stochastic_force(stochforcvec)
410 write (iout,*) "stochforcvec"
412 write (iout,*) i,stochforcvec(i)
416 zapas(j)=-gcart(j,0)+stochforcvec(j)
418 dC_work(j)=dC_old(j,0)
424 zapas(ind)=-gcart(j,i)+stochforcvec(ind)
425 dC_work(ind)=dC_old(j,i)
429 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
432 zapas(ind)=-gxcart(j,i)+stochforcvec(ind)
433 dC_work(ind)=dC_old(j,i+nres)
439 write (iout,*) "Initial d_t_work"
441 write (iout,*) i,d_t_work(i)
448 d_t_work(i)=d_t_work(i)+fricmat(i,j)*zapas(j)
455 zapas(i)=zapas(i)+Pmat(i,j)*(dC_work(j)+d_t_work(j)*d_time)
459 write (iout,*) "Final d_t_work and zapas"
461 write (iout,*) i,d_t_work(i),zapas(i)
475 dc_work(ind+j)=dc(j,i)
481 d_t(j,i+nres)=d_t_work(ind+j)
482 dc(j,i+nres)=zapas(ind+j)
483 dc_work(ind+j)=dc(j,i+nres)
489 write (iout,*) "Before correction for rotational lengthening"
490 write (iout,*) "New coordinates",
491 & " and differences between actual and standard bond lengths"
496 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)')
497 & i,(dC(j,i),j=1,3),xx
500 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
502 xx=vbld(i+nres)-vbldsc0(1,itype(i))
503 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)')
504 & i,(dC(j,i+nres),j=1,3),xx
508 c Second correction (rotational lengthening)
514 blen2 = scalar(dc(1,i),dc(1,i))
515 ppvec(ind)=2*vbl**2-blen2
516 diffbond=dabs(vbl-dsqrt(blen2))
517 if (diffbond.gt.diffmax) diffmax=diffbond
518 if (ppvec(ind).gt.0.0d0) then
519 ppvec(ind)=dsqrt(ppvec(ind))
524 write (iout,'(i5,3f10.5)') ind,diffbond,ppvec(ind)
528 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
530 blen2 = scalar(dc(1,i+nres),dc(1,i+nres))
531 ppvec(ind)=2*vbldsc0(1,itype(i))**2-blen2
532 diffbond=dabs(vbldsc0(1,itype(i))-dsqrt(blen2))
533 if (diffbond.gt.diffmax) diffmax=diffbond
534 if (ppvec(ind).gt.0.0d0) then
535 ppvec(ind)=dsqrt(ppvec(ind))
540 write (iout,'(i5,3f10.5)') ind,diffbond,ppvec(ind)
544 if (lprn) write (iout,*) "iter",iter," diffmax",diffmax
545 if (diffmax.lt.difftol) goto 10
549 Td(i)=Td(i)+ppvec(j)*Tmat(i,j)
555 zapas(i)=zapas(i)+Pmat(i,j)*dc_work(j)
566 dc_work(ind+j)=zapas(ind+j)
571 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
573 dc(j,i+nres)=zapas(ind+j)
574 dc_work(ind+j)=zapas(ind+j)
579 c Building the chain from the newly calculated coordinates
582 if (large.and. mod(itime,ntwe).eq.0) then
583 write (iout,*) "Cartesian and internal coordinates: step 1"
586 write (iout,'(a)') "Potential forces"
588 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(-gcart(j,i),j=1,3),
589 & (-gxcart(j,i),j=1,3)
591 write (iout,'(a)') "Stochastic forces"
593 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(stochforc(j,i),j=1,3),
594 & (stochforc(j,i+nres),j=1,3)
596 write (iout,'(a)') "Velocities"
598 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),
599 & (d_t(j,i+nres),j=1,3)
604 write (iout,*) "After correction for rotational lengthening"
605 write (iout,*) "New coordinates",
606 & " and differences between actual and standard bond lengths"
611 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)')
612 & i,(dC(j,i),j=1,3),xx
615 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
617 xx=vbld(i+nres)-vbldsc0(1,itype(i))
618 write (iout,'(i5,3f10.5,5x,f10.5,e15.5)')
619 & i,(dC(j,i+nres),j=1,3),xx
624 c write (iout,*) "Too many attempts at correcting the bonds"
632 c Calculate energy and forces
634 call etotal(potEcomp)
635 potE=potEcomp(0)-potEcomp(20)
638 c Calculate the kinetic and total energy and the kinetic temperature
641 t_enegrad=t_enegrad+MPI_Wtime()-tt0
643 t_enegrad=t_enegrad+tcpu()-tt0
646 kinetic_T=2.0d0/(dimen*Rb)*EK
649 c-------------------------------------------------------------------------------
650 subroutine velverlet_step(itime)
651 c-------------------------------------------------------------------------------
652 c Perform a single velocity Verlet step; the time step can be rescaled if
653 c increments in accelerations exceed the threshold
654 c-------------------------------------------------------------------------------
655 implicit real*8 (a-h,o-z)
659 integer ierror,ierrcode
661 include 'COMMON.CONTROL'
665 include 'COMMON.LANGEVIN'
667 include 'COMMON.LANGEVIN.lang0'
669 include 'COMMON.CHAIN'
670 include 'COMMON.DERIV'
672 include 'COMMON.LOCAL'
673 include 'COMMON.INTERACT'
674 include 'COMMON.IOUNITS'
675 include 'COMMON.NAMES'
676 include 'COMMON.TIME1'
677 include 'COMMON.MUCA'
678 double precision vcm(3),incr(3)
679 double precision cm(3),L(3)
680 integer ilen,count,rstcount
683 integer maxcount_scale /20/
685 double precision stochforcvec(MAXRES6)
686 common /stochcalc/ stochforcvec
694 else if (lang.eq.2 .or. lang.eq.3) then
695 call stochastic_force(stochforcvec)
699 icount_scale=icount_scale+1
700 if (icount_scale.gt.maxcount_scale) then
702 & "ERROR: too many attempts at scaling down the time step. ",
703 & "amax=",amax,"epdrift=",epdrift,
704 & "damax=",damax,"edriftmax=",edriftmax,
708 call MPI_Abort(MPI_COMM_WORLD,IERROR,IERRCODE)
712 c First step of the velocity Verlet algorithm
715 else if (lang.eq.3) then
716 call sd_verlet1_ciccotti
717 else if (lang.eq.1) then
722 c Build the chain from the newly calculated coordinates
724 if (rattle) call rattle1
726 if (large.and. mod(itime,ntwe).eq.0) then
727 write (iout,*) "Cartesian and internal coordinates: step 1"
732 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(dc(j,i),j=1,3),
733 & (dc(j,i+nres),j=1,3)
735 write (iout,*) "Accelerations"
737 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),
738 & (d_a(j,i+nres),j=1,3)
740 write (iout,*) "Velocities, step 1"
742 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),
743 & (d_t(j,i+nres),j=1,3)
752 c Calculate energy and forces
754 call etotal(potEcomp)
755 potE=potEcomp(0)-potEcomp(20)
757 c Get the new accelerations
760 t_enegrad=t_enegrad+MPI_Wtime()-tt0
762 t_enegrad=t_enegrad+tcpu()-tt0
764 c Determine maximum acceleration and scale down the timestep if needed
766 call predict_edrift(epdrift)
767 if (amax.gt.damax .or. epdrift.gt.edriftmax) then
768 c Maximum acceleration or maximum predicted energy drift exceeded, rescale the time step
770 ifac_time=dmax1(dlog(amax/damax),dlog(epdrift/edriftmax))
772 itime_scal=itime_scal+ifac_time
773 c fac_time=dmin1(damax/amax,0.5d0)
774 fac_time=0.5d0**ifac_time
775 d_time=d_time*fac_time
776 if (lang.eq.2 .or. lang.eq.3) then
777 c write (iout,*) "Calling sd_verlet_setup: 1"
778 c Rescale the stochastic forces and recalculate or restore
779 c the matrices of tinker integrator
780 if (itime_scal.gt.maxflag_stoch) then
781 if (large) write (iout,'(a,i5,a)')
782 & "Calculate matrices for stochastic step;",
783 & " itime_scal ",itime_scal
785 call sd_verlet_p_setup
787 call sd_verlet_ciccotti_setup
789 write (iout,'(2a,i3,a,i3,1h.)')
790 & "Warning: cannot store matrices for stochastic",
791 & " integration because the index",itime_scal,
792 & " is greater than",maxflag_stoch
793 write (iout,'(2a)')"Increase MAXFLAG_STOCH or use direct",
794 & " integration Langevin algorithm for better efficiency."
795 else if (flag_stoch(itime_scal)) then
796 if (large) write (iout,'(a,i5,a,l1)')
797 & "Restore matrices for stochastic step; itime_scal ",
798 & itime_scal," flag ",flag_stoch(itime_scal)
802 pfric_mat(i,j)=pfric0_mat(i,j,itime_scal)
803 afric_mat(i,j)=afric0_mat(i,j,itime_scal)
804 vfric_mat(i,j)=vfric0_mat(i,j,itime_scal)
805 prand_mat(i,j)=prand0_mat(i,j,itime_scal)
806 vrand_mat1(i,j)=vrand0_mat1(i,j,itime_scal)
807 vrand_mat2(i,j)=vrand0_mat2(i,j,itime_scal)
812 if (large) write (iout,'(2a,i5,a,l1)')
813 & "Calculate & store matrices for stochastic step;",
814 & " itime_scal ",itime_scal," flag ",flag_stoch(itime_scal)
816 call sd_verlet_p_setup
818 call sd_verlet_ciccotti_setup
820 flag_stoch(ifac_time)=.true.
824 pfric0_mat(i,j,itime_scal)=pfric_mat(i,j)
825 afric0_mat(i,j,itime_scal)=afric_mat(i,j)
826 vfric0_mat(i,j,itime_scal)=vfric_mat(i,j)
827 prand0_mat(i,j,itime_scal)=prand_mat(i,j)
828 vrand0_mat1(i,j,itime_scal)=vrand_mat1(i,j)
829 vrand0_mat2(i,j,itime_scal)=vrand_mat2(i,j)
834 fac_time=1.0d0/dsqrt(fac_time)
836 stochforcvec(i)=fac_time*stochforcvec(i)
838 else if (lang.eq.1) then
839 c Rescale the accelerations due to stochastic forces
840 fac_time=1.0d0/dsqrt(fac_time)
842 d_as_work(i)=d_as_work(i)*fac_time
845 if (large) write (iout,'(a,i10,a,f8.6,a,i3,a,i3)')
846 & "itime",itime," Timestep scaled down to ",
847 & d_time," ifac_time",ifac_time," itime_scal",itime_scal
849 c Second step of the velocity Verlet algorithm
852 else if (lang.eq.3) then
853 call sd_verlet2_ciccotti
854 else if (lang.eq.1) then
859 if (rattle) call rattle2
861 if (d_time.ne.d_time0) then
863 if (lang.eq.2 .or. lang.eq.3) then
864 if (large) write (iout,'(a)')
865 & "Restore original matrices for stochastic step"
866 c write (iout,*) "Calling sd_verlet_setup: 2"
867 c Restore the matrices of tinker integrator if the time step has been restored
871 pfric_mat(i,j)=pfric0_mat(i,j,0)
872 afric_mat(i,j)=afric0_mat(i,j,0)
873 vfric_mat(i,j)=vfric0_mat(i,j,0)
874 prand_mat(i,j)=prand0_mat(i,j,0)
875 vrand_mat1(i,j)=vrand0_mat1(i,j,0)
876 vrand_mat2(i,j)=vrand0_mat2(i,j,0)
885 c Calculate the kinetic and the total energy and the kinetic temperature
890 c write (iout,*) "step",itime," EK",EK," EK1",EK1
892 c Couple the system to Berendsen bath if needed
893 if (tbf .and. lang.eq.0) then
896 kinetic_T=2.0d0/(dimen*Rb)*EK
897 c Backup the coordinates, velocities, and accelerations
901 d_t_old(j,i)=d_t(j,i)
902 d_a_old(j,i)=d_a(j,i)
906 if (mod(itime,ntwe).eq.0 .and. large) then
907 write (iout,*) "Velocities, step 2"
909 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),
910 & (d_t(j,i+nres),j=1,3)
916 c-------------------------------------------------------------------------------
917 subroutine RESPA_step(itime)
918 c-------------------------------------------------------------------------------
919 c Perform a single RESPA step.
920 c-------------------------------------------------------------------------------
921 implicit real*8 (a-h,o-z)
926 include 'COMMON.CONTROL'
930 include 'COMMON.LANGEVIN'
932 include 'COMMON.LANGEVIN.lang0'
934 include 'COMMON.CHAIN'
935 include 'COMMON.DERIV'
937 include 'COMMON.LOCAL'
938 include 'COMMON.INTERACT'
939 include 'COMMON.IOUNITS'
940 include 'COMMON.NAMES'
941 include 'COMMON.TIME1'
942 double precision energia_short(0:n_ene),
943 & energia_long(0:n_ene)
944 double precision cm(3),L(3),vcm(3),incr(3)
945 integer ilen,count,rstcount
948 integer maxcount_scale /10/
950 double precision stochforcvec(MAXRES6)
951 common /stochcalc/ stochforcvec
954 common /cipiszcze/ itt
956 large=(itime.gt.14600 .and. itime.lt.14700)
958 if (large.and. mod(itime,ntwe).eq.0) then
959 write (iout,*) "***************** RESPA itime",itime
960 write (iout,*) "Cartesian and internal coordinates: step 0"
962 call pdbout(0.0d0,"cipiszcze",iout)
964 write (iout,*) "Accelerations"
966 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),
967 & (d_a(j,i+nres),j=1,3)
969 write (iout,*) "Velocities, step 0"
971 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),
972 & (d_t(j,i+nres),j=1,3)
977 c Perform the initial RESPA step (increment velocities)
978 c write (iout,*) "*********************** RESPA ini"
981 if (mod(itime,ntwe).eq.0 .and. large) then
982 write (iout,*) "Velocities, end"
984 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),
985 & (d_t(j,i+nres),j=1,3)
989 c Compute the short-range forces
996 call etotal_short(energia_short)
997 if (large) write (iout,*) "energia_short",energia_short(0)
1001 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1003 t_enegrad=t_enegrad+tcpu()-tt0
1008 d_t_old(j,i)=d_t(j,i)
1009 d_a_old(j,i)=d_a(j,i)
1013 c Split the time step
1014 d_time=d_time/ntime_split
1015 c Perform the short-range RESPSA steps (velocity Verlet increments of
1016 c positions and velocities using short-range forces)
1017 c write (iout,*) "*********************** RESPA split"
1018 do itsplit=1,ntime_split
1021 else if (lang.eq.2 .or. lang.eq.3) then
1022 call stochastic_force(stochforcvec)
1024 c First step of the velocity Verlet algorithm
1027 else if (lang.eq.3) then
1028 call sd_verlet1_ciccotti
1029 else if (lang.eq.1) then
1034 c Build the chain from the newly calculated coordinates
1035 call chainbuild_cart
1036 if (rattle) call rattle1
1038 if (large.and. mod(itime,ntwe).eq.0) then
1039 write (iout,*) "Cartesian and internal coordinates: step 1"
1040 call pdbout(0.0d0,"cipiszcze",iout)
1043 write (iout,*) "Accelerations"
1045 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),
1046 & (d_a(j,i+nres),j=1,3)
1048 write (iout,*) "Velocities, step 1"
1050 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),
1051 & (d_t(j,i+nres),j=1,3)
1060 c Calculate energy and forces
1062 call etotal_short(energia_short)
1063 if (large) write (iout,*) "energia_short",energia_short(0)
1065 c Get the new accelerations
1068 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1070 t_enegrad=t_enegrad+tcpu()-tt0
1072 c Second step of the velocity Verlet algorithm
1075 else if (lang.eq.3) then
1076 call sd_verlet2_ciccotti
1077 else if (lang.eq.1) then
1082 if (rattle) call rattle2
1083 c Backup the coordinates, velocities, and accelerations
1087 d_t_old(j,i)=d_t(j,i)
1088 d_a_old(j,i)=d_a(j,i)
1092 c Restore the time step
1094 c Compute long-range forces
1101 call etotal_long(energia_long)
1102 if (large) write (iout,*) "energia_long",energia_long(0)
1106 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1108 t_enegrad=t_enegrad+tcpu()-tt0
1110 c Compute accelerations from long-range forces
1112 if (large.and. mod(itime,ntwe).eq.0) then
1113 write (iout,*) "Cartesian and internal coordinates: step 2"
1115 call pdbout(0.0d0,"cipiszcze",iout)
1117 write (iout,*) "Accelerations"
1119 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),
1120 & (d_a(j,i+nres),j=1,3)
1122 write (iout,*) "Velocities, step 2"
1124 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),
1125 & (d_t(j,i+nres),j=1,3)
1129 c Compute the final RESPA step (increment velocities)
1130 c write (iout,*) "*********************** RESPA fin"
1132 c Compute the complete potential energy
1134 potEcomp(i)=energia_short(i)+energia_long(i)
1136 potE=potEcomp(0)-potEcomp(20)
1137 c potE=energia_short(0)+energia_long(0)
1139 c Calculate the kinetic and the total energy and the kinetic temperature
1142 c Couple the system to Berendsen bath if needed
1143 if (tbf .and. lang.eq.0) then
1146 kinetic_T=2.0d0/(dimen*Rb)*EK
1147 c Backup the coordinates, velocities, and accelerations
1149 if (mod(itime,ntwe).eq.0 .and. large) then
1150 write (iout,*) "Velocities, end"
1152 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),
1153 & (d_t(j,i+nres),j=1,3)
1159 c---------------------------------------------------------------------
1160 subroutine RESPA_vel
1161 c First and last RESPA step (incrementing velocities using long-range
1163 implicit real*8 (a-h,o-z)
1164 include 'DIMENSIONS'
1165 include 'COMMON.CONTROL'
1166 include 'COMMON.VAR'
1168 include 'COMMON.CHAIN'
1169 include 'COMMON.DERIV'
1170 include 'COMMON.GEO'
1171 include 'COMMON.LOCAL'
1172 include 'COMMON.INTERACT'
1173 include 'COMMON.IOUNITS'
1174 include 'COMMON.NAMES'
1176 d_t(j,0)=d_t(j,0)+0.5d0*d_a(j,0)*d_time
1180 d_t(j,i)=d_t(j,i)+0.5d0*d_a(j,i)*d_time
1184 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
1187 d_t(j,inres)=d_t(j,inres)+0.5d0*d_a(j,inres)*d_time
1193 c-----------------------------------------------------------------
1195 c Applying velocity Verlet algorithm - step 1 to coordinates
1196 implicit real*8 (a-h,o-z)
1197 include 'DIMENSIONS'
1198 include 'COMMON.CONTROL'
1199 include 'COMMON.VAR'
1201 include 'COMMON.CHAIN'
1202 include 'COMMON.DERIV'
1203 include 'COMMON.GEO'
1204 include 'COMMON.LOCAL'
1205 include 'COMMON.INTERACT'
1206 include 'COMMON.IOUNITS'
1207 include 'COMMON.NAMES'
1208 double precision adt,adt2
1211 adt=d_a_old(j,0)*d_time
1213 dc(j,0)=dc_old(j,0)+(d_t_old(j,0)+adt2)*d_time
1214 d_t_new(j,0)=d_t_old(j,0)+adt2
1215 d_t(j,0)=d_t_old(j,0)+adt
1219 adt=d_a_old(j,i)*d_time
1221 dc(j,i)=dc_old(j,i)+(d_t_old(j,i)+adt2)*d_time
1222 d_t_new(j,i)=d_t_old(j,i)+adt2
1223 d_t(j,i)=d_t_old(j,i)+adt
1227 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
1230 adt=d_a_old(j,inres)*d_time
1232 dc(j,inres)=dc_old(j,inres)+(d_t_old(j,inres)+adt2)*d_time
1233 d_t_new(j,inres)=d_t_old(j,inres)+adt2
1234 d_t(j,inres)=d_t_old(j,inres)+adt
1240 c---------------------------------------------------------------------
1242 c Step 2 of the velocity Verlet algorithm: update velocities
1243 implicit real*8 (a-h,o-z)
1244 include 'DIMENSIONS'
1245 include 'COMMON.CONTROL'
1246 include 'COMMON.VAR'
1248 include 'COMMON.CHAIN'
1249 include 'COMMON.DERIV'
1250 include 'COMMON.GEO'
1251 include 'COMMON.LOCAL'
1252 include 'COMMON.INTERACT'
1253 include 'COMMON.IOUNITS'
1254 include 'COMMON.NAMES'
1256 d_t(j,0)=d_t_new(j,0)+0.5d0*d_a(j,0)*d_time
1260 d_t(j,i)=d_t_new(j,i)+0.5d0*d_a(j,i)*d_time
1264 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
1267 d_t(j,inres)=d_t_new(j,inres)+0.5d0*d_a(j,inres)*d_time
1273 c-----------------------------------------------------------------
1274 subroutine sddir_precalc
1275 c Applying velocity Verlet algorithm - step 1 to coordinates
1276 implicit real*8 (a-h,o-z)
1277 include 'DIMENSIONS'
1278 include 'COMMON.CONTROL'
1279 include 'COMMON.VAR'
1282 include 'COMMON.LANGEVIN'
1284 include 'COMMON.LANGEVIN.lang0'
1286 include 'COMMON.CHAIN'
1287 include 'COMMON.DERIV'
1288 include 'COMMON.GEO'
1289 include 'COMMON.LOCAL'
1290 include 'COMMON.INTERACT'
1291 include 'COMMON.IOUNITS'
1292 include 'COMMON.NAMES'
1293 double precision stochforcvec(MAXRES6)
1294 common /stochcalc/ stochforcvec
1296 c Compute friction and stochastic forces
1299 call stochastic_force(stochforcvec)
1301 c Compute the acceleration due to friction forces (d_af_work) and stochastic
1302 c forces (d_as_work)
1309 d_af_work(i)=d_af_work(i)+Ginv(i,j)*fric_work(j)
1310 d_as_work(i)=d_as_work(i)+Ginv(i,j)*stochforcvec(j)
1314 call ginv_mult(fric_work, d_af_work)
1315 call ginv_mult(stochforcvec, d_as_work)
1319 c---------------------------------------------------------------------
1320 subroutine sddir_verlet1
1321 c Applying velocity Verlet algorithm - step 1 to velocities
1322 implicit real*8 (a-h,o-z)
1323 include 'DIMENSIONS'
1324 include 'COMMON.CONTROL'
1325 include 'COMMON.VAR'
1328 include 'COMMON.LANGEVIN'
1330 include 'COMMON.LANGEVIN.lang0'
1332 include 'COMMON.CHAIN'
1333 include 'COMMON.DERIV'
1334 include 'COMMON.GEO'
1335 include 'COMMON.LOCAL'
1336 include 'COMMON.INTERACT'
1337 include 'COMMON.IOUNITS'
1338 include 'COMMON.NAMES'
1339 c Revised 3/31/05 AL: correlation between random contributions to
1340 c position and velocity increments included.
1341 double precision sqrt13 /0.57735026918962576451d0/ ! 1/sqrt(3)
1342 double precision adt,adt2
1344 c Add the contribution from BOTH friction and stochastic force to the
1345 c coordinates, but ONLY the contribution from the friction forces to velocities
1348 adt=(d_a_old(j,0)+d_af_work(j))*d_time
1349 adt2=0.5d0*adt+sqrt13*d_as_work(j)*d_time
1350 dc(j,0)=dc_old(j,0)+(d_t_old(j,0)+adt2)*d_time
1351 d_t_new(j,0)=d_t_old(j,0)+0.5d0*adt
1352 d_t(j,0)=d_t_old(j,0)+adt
1357 adt=(d_a_old(j,i)+d_af_work(ind+j))*d_time
1358 adt2=0.5d0*adt+sqrt13*d_as_work(ind+j)*d_time
1359 dc(j,i)=dc_old(j,i)+(d_t_old(j,i)+adt2)*d_time
1360 d_t_new(j,i)=d_t_old(j,i)+0.5d0*adt
1361 d_t(j,i)=d_t_old(j,i)+adt
1366 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
1369 adt=(d_a_old(j,inres)+d_af_work(ind+j))*d_time
1370 adt2=0.5d0*adt+sqrt13*d_as_work(ind+j)*d_time
1371 dc(j,inres)=dc_old(j,inres)+(d_t_old(j,inres)+adt2)*d_time
1372 d_t_new(j,inres)=d_t_old(j,inres)+0.5d0*adt
1373 d_t(j,inres)=d_t_old(j,inres)+adt
1380 c---------------------------------------------------------------------
1381 subroutine sddir_verlet2
1382 c Calculating the adjusted velocities for accelerations
1383 implicit real*8 (a-h,o-z)
1384 include 'DIMENSIONS'
1385 include 'COMMON.CONTROL'
1386 include 'COMMON.VAR'
1389 include 'COMMON.LANGEVIN'
1391 include 'COMMON.LANGEVIN.lang0'
1393 include 'COMMON.CHAIN'
1394 include 'COMMON.DERIV'
1395 include 'COMMON.GEO'
1396 include 'COMMON.LOCAL'
1397 include 'COMMON.INTERACT'
1398 include 'COMMON.IOUNITS'
1399 include 'COMMON.NAMES'
1400 double precision stochforcvec(MAXRES6),d_as_work1(MAXRES6)
1401 double precision cos60 /0.5d0/, sin60 /0.86602540378443864676d0/
1402 c Revised 3/31/05 AL: correlation between random contributions to
1403 c position and velocity increments included.
1404 c The correlation coefficients are calculated at low-friction limit.
1405 c Also, friction forces are now not calculated with new velocities.
1407 c call friction_force
1408 call stochastic_force(stochforcvec)
1410 c Compute the acceleration due to friction forces (d_af_work) and stochastic
1411 c forces (d_as_work)
1415 c d_af_work(i)=0.0d0
1418 c d_af_work(i)=d_af_work(i)+Ginv(i,j)*fric_work(j)
1419 d_as_work1(i)=d_as_work1(i)+Ginv(i,j)*stochforcvec(j)
1423 call ginv_mult(stochforcvec, d_as_work1)
1430 d_t(j,0)=d_t_new(j,0)+(0.5d0*(d_a(j,0)+d_af_work(j))
1431 & +sin60*d_as_work(j)+cos60*d_as_work1(j))*d_time
1436 d_t(j,i)=d_t_new(j,i)+(0.5d0*(d_a(j,i)+d_af_work(ind+j))
1437 & +sin60*d_as_work(ind+j)+cos60*d_as_work1(ind+j))*d_time
1442 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
1445 d_t(j,inres)=d_t_new(j,inres)+(0.5d0*(d_a(j,inres)
1446 & +d_af_work(ind+j))+sin60*d_as_work(ind+j)
1447 & +cos60*d_as_work1(ind+j))*d_time
1454 c---------------------------------------------------------------------
1455 subroutine max_accel
1457 c Find the maximum difference in the accelerations of the the sites
1458 c at the beginning and the end of the time step.
1460 implicit real*8 (a-h,o-z)
1461 include 'DIMENSIONS'
1462 include 'COMMON.CONTROL'
1463 include 'COMMON.VAR'
1465 include 'COMMON.CHAIN'
1466 include 'COMMON.DERIV'
1467 include 'COMMON.GEO'
1468 include 'COMMON.LOCAL'
1469 include 'COMMON.INTERACT'
1470 include 'COMMON.IOUNITS'
1471 double precision aux(3),accel(3)
1473 aux(j)=d_a(j,0)-d_a_old(j,0)
1480 accel(j)=aux(j)+0.5d0*(d_a(j,i)-d_a_old(j,i))
1481 if (dabs(accel(j)).gt.amax) amax=dabs(accel(j))
1488 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
1490 accel(j)=accel(j)+d_a(j,i+nres)-d_a_old(j,i+nres)
1494 if (dabs(accel(j)).gt.amax) amax=dabs(accel(j))
1497 aux(j)=aux(j)+d_a(j,i)-d_a_old(j,i)
1502 c---------------------------------------------------------------------
1503 subroutine predict_edrift(epdrift)
1505 c Predict the drift of the potential energy
1507 implicit real*8 (a-h,o-z)
1508 include 'DIMENSIONS'
1509 include 'COMMON.CONTROL'
1510 include 'COMMON.VAR'
1512 include 'COMMON.CHAIN'
1513 include 'COMMON.DERIV'
1514 include 'COMMON.GEO'
1515 include 'COMMON.LOCAL'
1516 include 'COMMON.INTERACT'
1517 include 'COMMON.IOUNITS'
1518 include 'COMMON.MUCA'
1519 double precision epdrift,epdriftij
1520 c Drift of the potential energy
1526 epdriftij=dabs((d_a(j,i)-d_a_old(j,i))*gcart(j,i))
1527 if (lmuca) epdriftij=epdriftij*factor
1528 c write (iout,*) "back",i,j,epdriftij
1529 if (epdriftij.gt.epdrift) epdrift=epdriftij
1533 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
1536 & dabs((d_a(j,i+nres)-d_a_old(j,i+nres))*gxcart(j,i))
1537 if (lmuca) epdriftij=epdriftij*factor
1538 c write (iout,*) "side",i,j,epdriftij
1539 if (epdriftij.gt.epdrift) epdrift=epdriftij
1543 epdrift=0.5d0*epdrift*d_time*d_time
1544 c write (iout,*) "epdrift",epdrift
1547 c-----------------------------------------------------------------------
1548 subroutine verlet_bath
1550 c Coupling to the thermostat by using the Berendsen algorithm
1552 implicit real*8 (a-h,o-z)
1553 include 'DIMENSIONS'
1554 include 'COMMON.CONTROL'
1555 include 'COMMON.VAR'
1557 include 'COMMON.CHAIN'
1558 include 'COMMON.DERIV'
1559 include 'COMMON.GEO'
1560 include 'COMMON.LOCAL'
1561 include 'COMMON.INTERACT'
1562 include 'COMMON.IOUNITS'
1563 include 'COMMON.NAMES'
1564 double precision T_half,fact
1566 T_half=2.0d0/(dimen*Rb)*EK
1567 fact=dsqrt(1.0d0+(d_time/tau_bath)*(t_bath/T_half-1.0d0))
1568 c write(iout,*) "T_half", T_half
1569 c write(iout,*) "EK", EK
1570 c write(iout,*) "fact", fact
1572 d_t(j,0)=fact*d_t(j,0)
1576 d_t(j,i)=fact*d_t(j,i)
1580 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
1583 d_t(j,inres)=fact*d_t(j,inres)
1589 c---------------------------------------------------------
1591 c Set up the initial conditions of a MD simulation
1592 implicit real*8 (a-h,o-z)
1593 include 'DIMENSIONS'
1596 include 'COMMON.SETUP'
1599 include 'COMMON.CONTROL'
1600 include 'COMMON.VAR'
1603 include 'COMMON.LANGEVIN'
1605 include 'COMMON.LANGEVIN.lang0'
1607 include 'COMMON.CHAIN'
1608 include 'COMMON.DERIV'
1609 include 'COMMON.GEO'
1610 include 'COMMON.LOCAL'
1611 include 'COMMON.INTERACT'
1612 include 'COMMON.IOUNITS'
1613 include 'COMMON.NAMES'
1614 include 'COMMON.REMD'
1615 real*8 energia_long(0:n_ene),
1616 & energia_short(0:n_ene),vcm(3),incr(3)
1617 double precision cm(3),L(3),xv,sigv,lowb,highb
1618 double precision varia(maxvar)
1626 c write(iout,*) "d_time", d_time
1627 c Compute the standard deviations of stochastic forces for Langevin dynamics
1628 c if the friction coefficients do not depend on surface area
1629 if (lang.gt.0 .and. .not.surfarea) then
1631 stdforcp(i)=stdfp*dsqrt(gamp)
1634 stdforcsc(i)=stdfsc(itype(i))*dsqrt(gamsc(iabs(itype(i))))
1637 c Open the pdb file for snapshotshots
1640 if (ilen(tmpdir).gt.0)
1641 & call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD"//
1642 & liczba(:ilen(liczba))//".pdb")
1644 & file=prefix(:ilen(prefix))//"_MD"//liczba(:ilen(liczba))
1648 if (ilen(tmpdir).gt.0 .and. (me.eq.king .or. .not.traj1file))
1649 & call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD"//
1650 & liczba(:ilen(liczba))//".x")
1651 cartname=prefix(:ilen(prefix))//"_MD"//liczba(:ilen(liczba))
1654 if (ilen(tmpdir).gt.0 .and. (me.eq.king .or. .not.traj1file))
1655 & call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD"//
1656 & liczba(:ilen(liczba))//".cx")
1657 cartname=prefix(:ilen(prefix))//"_MD"//liczba(:ilen(liczba))
1663 if (ilen(tmpdir).gt.0)
1664 & call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD.pdb")
1665 open(ipdb,file=prefix(:ilen(prefix))//"_MD.pdb")
1667 if (ilen(tmpdir).gt.0)
1668 & call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_MD.cx")
1669 cartname=prefix(:ilen(prefix))//"_MD.cx"
1673 write (qstr,'(256(1h ))')
1676 iq = qinfrag(i,iset)*10
1677 iw = wfrag(i,iset)/100
1679 if(me.eq.king.or..not.out1file)
1680 & write (iout,*) "Frag",qinfrag(i,iset),wfrag(i,iset),iq,iw
1681 write (qstr(ipos:ipos+6),'(2h_f,i1,1h_,i1,1h_,i1)') i,iq,iw
1686 iq = qinpair(i,iset)*10
1687 iw = wpair(i,iset)/100
1689 if(me.eq.king.or..not.out1file)
1690 & write (iout,*) "Pair",i,qinpair(i,iset),wpair(i,iset),iq,iw
1691 write (qstr(ipos:ipos+6),'(2h_p,i1,1h_,i1,1h_,i1)') i,iq,iw
1695 c pdbname=pdbname(:ilen(pdbname)-4)//qstr(:ipos-1)//'.pdb'
1697 c cartname=cartname(:ilen(cartname)-2)//qstr(:ipos-1)//'.x'
1699 c cartname=cartname(:ilen(cartname)-3)//qstr(:ipos-1)//'.cx'
1701 c statname=statname(:ilen(statname)-5)//qstr(:ipos-1)//'.stat'
1705 if (restart1file) then
1707 & inquire(file=mremd_rst_name,exist=file_exist)
1708 write (*,*) me," Before broadcast: file_exist",file_exist
1709 call MPI_Bcast(file_exist,1,MPI_LOGICAL,king,CG_COMM,
1711 write (*,*) me," After broadcast: file_exist",file_exist
1712 c inquire(file=mremd_rst_name,exist=file_exist)
1713 if(me.eq.king.or..not.out1file)
1714 & write(iout,*) "Initial state read by master and distributed"
1716 if (ilen(tmpdir).gt.0)
1717 & call copy_to_tmp(pref_orig(:ilen(pref_orig))//'_'
1718 & //liczba(:ilen(liczba))//'.rst')
1719 inquire(file=rest2name,exist=file_exist)
1722 if(.not.restart1file) then
1723 if(me.eq.king.or..not.out1file)
1724 & write(iout,*) "Initial state will be read from file ",
1725 & rest2name(:ilen(rest2name))
1728 call rescale_weights(t_bath)
1730 if(me.eq.king.or..not.out1file)then
1731 if (restart1file) then
1732 write(iout,*) "File ",mremd_rst_name(:ilen(mremd_rst_name)),
1735 write(iout,*) "File ",rest2name(:ilen(rest2name)),
1738 write(iout,*) "Initial velocities randomly generated"
1744 c Generate initial velocities
1745 if(me.eq.king.or..not.out1file)
1746 & write(iout,*) "Initial velocities randomly generated"
1750 c rest2name = prefix(:ilen(prefix))//'.rst'
1751 if(me.eq.king.or..not.out1file)then
1752 write(iout,*) "Initial backbone velocities"
1754 write(iout,*) (d_t(j,i),j=1,3)
1756 write(iout,*) "Initial side-chain velocities"
1758 write(iout,*) (d_t(j,i+nres),j=1,3)
1760 c Zeroing the total angular momentum of the system
1761 write(iout,*) "Calling the zero-angular
1762 & momentum subroutine"
1765 c Getting the potential energy and forces and velocities and accelerations
1767 c write (iout,*) "velocity of the center of the mass:"
1768 c write (iout,*) (vcm(j),j=1,3)
1770 d_t(j,0)=d_t(j,0)-vcm(j)
1772 c Removing the velocity of the center of mass
1774 if(me.eq.king.or..not.out1file)then
1775 write (iout,*) "vcm right after adjustment:"
1776 write (iout,*) (vcm(j),j=1,3)
1780 if(iranconf.ne.0) then
1782 print *, 'Calling OVERLAP_SC'
1783 call overlap_sc(fail)
1787 call sc_move(2,nres-1,10,1d10,nft_sc,etot)
1788 print *,'SC_move',nft_sc,etot
1789 if(me.eq.king.or..not.out1file)
1790 & write(iout,*) 'SC_move',nft_sc,etot
1794 print *, 'Calling MINIM_DC'
1795 call minim_dc(etot,iretcode,nfun)
1797 call geom_to_var(nvar,varia)
1798 print *,'Calling MINIMIZE.'
1799 call minimize(etot,varia,iretcode,nfun)
1800 call var_to_geom(nvar,varia)
1802 if(me.eq.king.or..not.out1file)
1803 & write(iout,*) 'SUMSL return code is',iretcode,' eval ',nfun
1806 call chainbuild_cart
1809 call verlet_bath(EK)
1811 kinetic_T=2.0d0/(dimen*Rb)*EK
1812 if(me.eq.king.or..not.out1file)then
1817 call etotal(potEcomp)
1822 if (amax*d_time .gt. dvmax) d_time=d_time*dvmax/amax
1823 if(me.eq.king.or..not.out1file)then
1824 write(iout,*) "Potential energy and its components"
1825 write(iout,*) (potEcomp(i),i=0,n_ene)
1827 potE=potEcomp(0)-potEcomp(20)
1830 if (ntwe.ne.0) call statout(itime)
1831 if(me.eq.king.or..not.out1file)
1832 & write (iout,*) "Initial:",
1833 & " Kinetic energy",EK," potential energy",potE,
1834 & " total energy",totE," maximum acceleration ",
1837 write (iout,*) "Initial coordinates"
1839 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(c(j,i),j=1,3),
1840 & (c(j,i+nres),j=1,3)
1842 write (iout,*) "Initial dC"
1844 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(dc(j,i),j=1,3),
1845 & (dc(j,i+nres),j=1,3)
1847 write (iout,*) "Initial velocities"
1849 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),
1850 & (d_t(j,i+nres),j=1,3)
1852 write (iout,*) "Initial accelerations"
1854 write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_a(j,i),j=1,3),
1855 & (d_a(j,i+nres),j=1,3)
1861 d_t_old(j,i)=d_t(j,i)
1862 d_a_old(j,i)=d_a(j,i)
1864 c write (iout,*) "dc_old",i,(dc_old(j,i),j=1,3)
1873 call etotal_long(energia_long)
1874 if (large) write (iout,*) "energia_long",energia_long(0)
1878 t_enegrad=t_enegrad+MPI_Wtime()-tt0
1880 t_enegrad=t_enegrad+tcpu()-tt0
1882 c call etotal_short(energia_short)
1883 c write (iout,*) "energia_long",energia_long(0),
1884 c & " energia_short",energia_short(0),
1885 c & " total",energia_long(0)+energia_short(0)
1889 c-----------------------------------------------------------
1890 subroutine random_vel
1891 implicit real*8 (a-h,o-z)
1892 include 'DIMENSIONS'
1893 include 'COMMON.CONTROL'
1894 include 'COMMON.VAR'
1897 include 'COMMON.LANGEVIN'
1899 include 'COMMON.LANGEVIN.lang0'
1901 include 'COMMON.CHAIN'
1902 include 'COMMON.DERIV'
1903 include 'COMMON.GEO'
1904 include 'COMMON.LOCAL'
1905 include 'COMMON.INTERACT'
1906 include 'COMMON.IOUNITS'
1907 include 'COMMON.NAMES'
1908 include 'COMMON.TIME1'
1909 double precision xv,sigv,lowb,highb
1910 c Generate random velocities from Gaussian distribution of mean 0 and std of KT/m
1911 c First generate velocities in the eigenspace of the G matrix
1912 c write (iout,*) "Calling random_vel"
1915 sigv=dsqrt((Rb*t_bath)/geigen(i))
1918 d_t_work_new(i)=anorm_distr(xv,sigv,lowb,highb)
1922 c Ek1=Ek1+0.5d0*geigen(i)*d_t_work_new(i)**2
1924 c Transform velocities to UNRES coordinate space
1928 d_t_work(i)=d_t_work(i)+Gvec(i,j)*d_t_work_new(j)
1931 c Transfer to the d_t vector
1933 d_t(j,0)=d_t_work(j)
1939 if (itype(i).ne.ntyp1 .and. itype(i+1).ne.ntyp1) then
1940 d_t(j,i)=d_t_work(ind)
1947 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
1950 d_t(j,i+nres)=d_t_work(ind)
1955 c write (iout,*) "Kinetic energy",Ek,EK1," kinetic temperature",
1956 c & 2.0d0/(dimen*Rb)*EK,2.0d0/(dimen*Rb)*EK1
1959 c-----------------------------------------------------------
1960 subroutine sd_verlet_p_setup
1961 c Sets up the parameters of stochastic Verlet algorithm
1962 implicit real*8 (a-h,o-z)
1963 include 'DIMENSIONS'
1967 include 'COMMON.CONTROL'
1968 include 'COMMON.VAR'
1971 include 'COMMON.LANGEVIN'
1973 include 'COMMON.LANGEVIN.lang0'
1975 include 'COMMON.CHAIN'
1976 include 'COMMON.DERIV'
1977 include 'COMMON.GEO'
1978 include 'COMMON.LOCAL'
1979 include 'COMMON.INTERACT'
1980 include 'COMMON.IOUNITS'
1981 include 'COMMON.NAMES'
1982 include 'COMMON.TIME1'
1983 double precision emgdt(MAXRES6),
1984 & pterm,vterm,rho,rhoc,vsig,
1985 & pfric_vec(MAXRES6),vfric_vec(MAXRES6),
1986 & afric_vec(MAXRES6),prand_vec(MAXRES6),
1987 & vrand_vec1(MAXRES6),vrand_vec2(MAXRES6)
1988 logical lprn /.false./
1989 double precision zero /1.0d-8/, gdt_radius /0.05d0/
1990 double precision ktm
1997 c AL 8/17/04 Code adapted from tinker
1999 c Get the frictional and random terms for stochastic dynamics in the
2000 c eigenspace of mass-scaled UNRES friction matrix
2003 gdt = fricgam(i) * d_time
2005 c Stochastic dynamics reduces to simple MD for zero friction
2007 if (gdt .le. zero) then
2008 pfric_vec(i) = 1.0d0
2009 vfric_vec(i) = d_time
2010 afric_vec(i) = 0.5d0 * d_time * d_time
2011 prand_vec(i) = 0.0d0
2012 vrand_vec1(i) = 0.0d0
2013 vrand_vec2(i) = 0.0d0
2015 c Analytical expressions when friction coefficient is large
2018 if (gdt .ge. gdt_radius) then
2021 vfric_vec(i) = (1.0d0-egdt) / fricgam(i)
2022 afric_vec(i) = (d_time-vfric_vec(i)) / fricgam(i)
2023 pterm = 2.0d0*gdt - 3.0d0 + (4.0d0-egdt)*egdt
2024 vterm = 1.0d0 - egdt**2
2025 rho = (1.0d0-egdt)**2 / sqrt(pterm*vterm)
2027 c Use series expansions when friction coefficient is small
2038 afric_vec(i) = (gdt2/2.0d0 - gdt3/6.0d0 + gdt4/24.0d0
2039 & - gdt5/120.0d0 + gdt6/720.0d0
2040 & - gdt7/5040.0d0 + gdt8/40320.0d0
2041 & - gdt9/362880.0d0) / fricgam(i)**2
2042 vfric_vec(i) = d_time - fricgam(i)*afric_vec(i)
2043 pfric_vec(i) = 1.0d0 - fricgam(i)*vfric_vec(i)
2044 pterm = 2.0d0*gdt3/3.0d0 - gdt4/2.0d0
2045 & + 7.0d0*gdt5/30.0d0 - gdt6/12.0d0
2046 & + 31.0d0*gdt7/1260.0d0 - gdt8/160.0d0
2047 & + 127.0d0*gdt9/90720.0d0
2048 vterm = 2.0d0*gdt - 2.0d0*gdt2 + 4.0d0*gdt3/3.0d0
2049 & - 2.0d0*gdt4/3.0d0 + 4.0d0*gdt5/15.0d0
2050 & - 4.0d0*gdt6/45.0d0 + 8.0d0*gdt7/315.0d0
2051 & - 2.0d0*gdt8/315.0d0 + 4.0d0*gdt9/2835.0d0
2052 rho = sqrt(3.0d0) * (0.5d0 - 3.0d0*gdt/16.0d0
2053 & - 17.0d0*gdt2/1280.0d0
2054 & + 17.0d0*gdt3/6144.0d0
2055 & + 40967.0d0*gdt4/34406400.0d0
2056 & - 57203.0d0*gdt5/275251200.0d0
2057 & - 1429487.0d0*gdt6/13212057600.0d0)
2060 c Compute the scaling factors of random terms for the nonzero friction case
2062 ktm = 0.5d0*d_time/fricgam(i)
2063 psig = dsqrt(ktm*pterm) / fricgam(i)
2064 vsig = dsqrt(ktm*vterm)
2065 rhoc = dsqrt(1.0d0 - rho*rho)
2067 vrand_vec1(i) = vsig * rho
2068 vrand_vec2(i) = vsig * rhoc
2073 & "pfric_vec, vfric_vec, afric_vec, prand_vec, vrand_vec1,",
2076 write (iout,'(i5,6e15.5)') i,pfric_vec(i),vfric_vec(i),
2077 & afric_vec(i),prand_vec(i),vrand_vec1(i),vrand_vec2(i)
2081 c Transform from the eigenspace of mass-scaled friction matrix to UNRES variables
2084 call eigtransf(dimen,maxres6,mt3,mt2,pfric_vec,pfric_mat)
2085 call eigtransf(dimen,maxres6,mt3,mt2,vfric_vec,vfric_mat)
2086 call eigtransf(dimen,maxres6,mt3,mt2,afric_vec,afric_mat)
2087 call eigtransf(dimen,maxres6,mt3,mt1,prand_vec,prand_mat)
2088 call eigtransf(dimen,maxres6,mt3,mt1,vrand_vec1,vrand_mat1)
2089 call eigtransf(dimen,maxres6,mt3,mt1,vrand_vec2,vrand_mat2)
2091 c call eigtransf1(dimen,maxres6,mt3mt2,pfric_vec,pfric_mat)
2092 c call eigtransf1(dimen,maxres6,mt3mt2,vfric_vec,vfric_mat)
2093 c call eigtransf1(dimen,maxres6,mt3mt2,afric_vec,afric_mat)
2094 c call eigtransf1(dimen,maxres6,mt3mt1,prand_vec,prand_mat)
2095 c call eigtransf1(dimen,maxres6,mt3mt1,vrand_vec1,vrand_mat1)
2096 c call eigtransf1(dimen,maxres6,mt3mt1,vrand_vec2,vrand_mat2)
2098 t_sdsetup=t_sdsetup+MPI_Wtime()
2100 t_sdsetup=t_sdsetup+tcpu()-tt0
2104 c-------------------------------------------------------------
2105 subroutine eigtransf1(n,ndim,ab,d,c)
2108 double precision ab(ndim,ndim,n),c(ndim,n),d(ndim)
2114 c(i,j)=c(i,j)+ab(k,j,i)*d(k)
2120 c-------------------------------------------------------------
2121 subroutine eigtransf(n,ndim,a,b,d,c)
2124 double precision a(ndim,n),b(ndim,n),c(ndim,n),d(ndim)
2130 c(i,j)=c(i,j)+a(i,k)*b(k,j)*d(k)
2136 c-------------------------------------------------------------
2137 subroutine sd_verlet1
2138 c Applying stochastic velocity Verlet algorithm - step 1 to velocities
2139 implicit real*8 (a-h,o-z)
2140 include 'DIMENSIONS'
2141 include 'COMMON.CONTROL'
2142 include 'COMMON.VAR'
2145 include 'COMMON.LANGEVIN'
2147 include 'COMMON.LANGEVIN.lang0'
2149 include 'COMMON.CHAIN'
2150 include 'COMMON.DERIV'
2151 include 'COMMON.GEO'
2152 include 'COMMON.LOCAL'
2153 include 'COMMON.INTERACT'
2154 include 'COMMON.IOUNITS'
2155 include 'COMMON.NAMES'
2156 double precision stochforcvec(MAXRES6)
2157 common /stochcalc/ stochforcvec
2158 logical lprn /.false./
2160 c write (iout,*) "dc_old"
2162 c write (iout,'(i5,3f10.5,5x,3f10.5)')
2163 c & i,(dc_old(j,i),j=1,3),(dc_old(j,i+nres),j=1,3)
2166 dc_work(j)=dc_old(j,0)
2167 d_t_work(j)=d_t_old(j,0)
2168 d_a_work(j)=d_a_old(j,0)
2173 dc_work(ind+j)=dc_old(j,i)
2174 d_t_work(ind+j)=d_t_old(j,i)
2175 d_a_work(ind+j)=d_a_old(j,i)
2180 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
2182 dc_work(ind+j)=dc_old(j,i+nres)
2183 d_t_work(ind+j)=d_t_old(j,i+nres)
2184 d_a_work(ind+j)=d_a_old(j,i+nres)
2192 & "pfric_mat, vfric_mat, afric_mat, prand_mat, vrand_mat1,",
2196 write (iout,'(2i5,6e15.5)') i,j,pfric_mat(i,j),
2197 & vfric_mat(i,j),afric_mat(i,j),
2198 & prand_mat(i,j),vrand_mat1(i,j),vrand_mat2(i,j)
2206 dc_work(i)=dc_work(i)+vfric_mat(i,j)*d_t_work(j)
2207 & +afric_mat(i,j)*d_a_work(j)+prand_mat(i,j)*stochforcvec(j)
2208 ddt1=ddt1+pfric_mat(i,j)*d_t_work(j)
2209 ddt2=ddt2+vfric_mat(i,j)*d_a_work(j)
2211 d_t_work_new(i)=ddt1+0.5d0*ddt2
2212 d_t_work(i)=ddt1+ddt2
2217 d_t(j,0)=d_t_work(j)
2222 dc(j,i)=dc_work(ind+j)
2223 d_t(j,i)=d_t_work(ind+j)
2228 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
2231 dc(j,inres)=dc_work(ind+j)
2232 d_t(j,inres)=d_t_work(ind+j)
2239 c--------------------------------------------------------------------------
2240 subroutine sd_verlet2
2241 c Calculating the adjusted velocities for accelerations
2242 implicit real*8 (a-h,o-z)
2243 include 'DIMENSIONS'
2244 include 'COMMON.CONTROL'
2245 include 'COMMON.VAR'
2248 include 'COMMON.LANGEVIN'
2250 include 'COMMON.LANGEVIN.lang0'
2252 include 'COMMON.CHAIN'
2253 include 'COMMON.DERIV'
2254 include 'COMMON.GEO'
2255 include 'COMMON.LOCAL'
2256 include 'COMMON.INTERACT'
2257 include 'COMMON.IOUNITS'
2258 include 'COMMON.NAMES'
2259 double precision stochforcvec(MAXRES6),stochforcvecV(MAXRES6)
2260 common /stochcalc/ stochforcvec
2262 c Compute the stochastic forces which contribute to velocity change
2264 call stochastic_force(stochforcvecV)
2271 ddt1=ddt1+vfric_mat(i,j)*d_a_work(j)
2272 ddt2=ddt2+vrand_mat1(i,j)*stochforcvec(j)+
2273 & vrand_mat2(i,j)*stochforcvecV(j)
2275 d_t_work(i)=d_t_work_new(i)+0.5d0*ddt1+ddt2
2279 d_t(j,0)=d_t_work(j)
2284 d_t(j,i)=d_t_work(ind+j)
2289 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
2292 d_t(j,inres)=d_t_work(ind+j)
2299 c-----------------------------------------------------------
2300 subroutine sd_verlet_ciccotti_setup
2301 c Sets up the parameters of stochastic velocity Verlet algorithmi; Ciccotti's
2303 implicit real*8 (a-h,o-z)
2304 include 'DIMENSIONS'
2308 include 'COMMON.CONTROL'
2309 include 'COMMON.VAR'
2312 include 'COMMON.LANGEVIN'
2314 include 'COMMON.LANGEVIN.lang0'
2316 include 'COMMON.CHAIN'
2317 include 'COMMON.DERIV'
2318 include 'COMMON.GEO'
2319 include 'COMMON.LOCAL'
2320 include 'COMMON.INTERACT'
2321 include 'COMMON.IOUNITS'
2322 include 'COMMON.NAMES'
2323 include 'COMMON.TIME1'
2324 double precision emgdt(MAXRES6),
2325 & pterm,vterm,rho,rhoc,vsig,
2326 & pfric_vec(MAXRES6),vfric_vec(MAXRES6),
2327 & afric_vec(MAXRES6),prand_vec(MAXRES6),
2328 & vrand_vec1(MAXRES6),vrand_vec2(MAXRES6)
2329 logical lprn /.false./
2330 double precision zero /1.0d-8/, gdt_radius /0.05d0/
2331 double precision ktm
2338 c AL 8/17/04 Code adapted from tinker
2340 c Get the frictional and random terms for stochastic dynamics in the
2341 c eigenspace of mass-scaled UNRES friction matrix
2344 write (iout,*) "i",i," fricgam",fricgam(i)
2345 gdt = fricgam(i) * d_time
2347 c Stochastic dynamics reduces to simple MD for zero friction
2349 if (gdt .le. zero) then
2350 pfric_vec(i) = 1.0d0
2351 vfric_vec(i) = d_time
2352 afric_vec(i) = 0.5d0*d_time*d_time
2353 prand_vec(i) = afric_vec(i)
2354 vrand_vec2(i) = vfric_vec(i)
2356 c Analytical expressions when friction coefficient is large
2361 vfric_vec(i) = dexp(-0.5d0*gdt)*d_time
2362 afric_vec(i) = 0.5d0*dexp(-0.25d0*gdt)*d_time*d_time
2363 prand_vec(i) = afric_vec(i)
2364 vrand_vec2(i) = vfric_vec(i)
2366 c Compute the scaling factors of random terms for the nonzero friction case
2368 c ktm = 0.5d0*d_time/fricgam(i)
2369 c psig = dsqrt(ktm*pterm) / fricgam(i)
2370 c vsig = dsqrt(ktm*vterm)
2371 c prand_vec(i) = psig*afric_vec(i)
2372 c vrand_vec2(i) = vsig*vfric_vec(i)
2377 & "pfric_vec, vfric_vec, afric_vec, prand_vec, vrand_vec1,",
2380 write (iout,'(i5,6e15.5)') i,pfric_vec(i),vfric_vec(i),
2381 & afric_vec(i),prand_vec(i),vrand_vec1(i),vrand_vec2(i)
2385 c Transform from the eigenspace of mass-scaled friction matrix to UNRES variables
2387 call eigtransf(dimen,maxres6,mt3,mt2,pfric_vec,pfric_mat)
2388 call eigtransf(dimen,maxres6,mt3,mt2,vfric_vec,vfric_mat)
2389 call eigtransf(dimen,maxres6,mt3,mt2,afric_vec,afric_mat)
2390 call eigtransf(dimen,maxres6,mt3,mt1,prand_vec,prand_mat)
2391 call eigtransf(dimen,maxres6,mt3,mt1,vrand_vec2,vrand_mat2)
2393 t_sdsetup=t_sdsetup+MPI_Wtime()
2395 t_sdsetup=t_sdsetup+tcpu()-tt0
2399 c-------------------------------------------------------------
2400 subroutine sd_verlet1_ciccotti
2401 c Applying stochastic velocity Verlet algorithm - step 1 to velocities
2402 implicit real*8 (a-h,o-z)
2403 include 'DIMENSIONS'
2407 include 'COMMON.CONTROL'
2408 include 'COMMON.VAR'
2411 include 'COMMON.LANGEVIN'
2413 include 'COMMON.LANGEVIN.lang0'
2415 include 'COMMON.CHAIN'
2416 include 'COMMON.DERIV'
2417 include 'COMMON.GEO'
2418 include 'COMMON.LOCAL'
2419 include 'COMMON.INTERACT'
2420 include 'COMMON.IOUNITS'
2421 include 'COMMON.NAMES'
2422 double precision stochforcvec(MAXRES6)
2423 common /stochcalc/ stochforcvec
2424 logical lprn /.false./
2426 c write (iout,*) "dc_old"
2428 c write (iout,'(i5,3f10.5,5x,3f10.5)')
2429 c & i,(dc_old(j,i),j=1,3),(dc_old(j,i+nres),j=1,3)
2432 dc_work(j)=dc_old(j,0)
2433 d_t_work(j)=d_t_old(j,0)
2434 d_a_work(j)=d_a_old(j,0)
2439 dc_work(ind+j)=dc_old(j,i)
2440 d_t_work(ind+j)=d_t_old(j,i)
2441 d_a_work(ind+j)=d_a_old(j,i)
2446 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
2448 dc_work(ind+j)=dc_old(j,i+nres)
2449 d_t_work(ind+j)=d_t_old(j,i+nres)
2450 d_a_work(ind+j)=d_a_old(j,i+nres)
2459 & "pfric_mat, vfric_mat, afric_mat, prand_mat, vrand_mat1,",
2463 write (iout,'(2i5,6e15.5)') i,j,pfric_mat(i,j),
2464 & vfric_mat(i,j),afric_mat(i,j),
2465 & prand_mat(i,j),vrand_mat1(i,j),vrand_mat2(i,j)
2473 dc_work(i)=dc_work(i)+vfric_mat(i,j)*d_t_work(j)
2474 & +afric_mat(i,j)*d_a_work(j)+prand_mat(i,j)*stochforcvec(j)
2475 ddt1=ddt1+pfric_mat(i,j)*d_t_work(j)
2476 ddt2=ddt2+vfric_mat(i,j)*d_a_work(j)
2478 d_t_work_new(i)=ddt1+0.5d0*ddt2
2479 d_t_work(i)=ddt1+ddt2
2484 d_t(j,0)=d_t_work(j)
2489 dc(j,i)=dc_work(ind+j)
2490 d_t(j,i)=d_t_work(ind+j)
2495 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
2498 dc(j,inres)=dc_work(ind+j)
2499 d_t(j,inres)=d_t_work(ind+j)
2506 c--------------------------------------------------------------------------
2507 subroutine sd_verlet2_ciccotti
2508 c Calculating the adjusted velocities for accelerations
2509 implicit real*8 (a-h,o-z)
2510 include 'DIMENSIONS'
2511 include 'COMMON.CONTROL'
2512 include 'COMMON.VAR'
2515 include 'COMMON.LANGEVIN'
2517 include 'COMMON.LANGEVIN.lang0'
2519 include 'COMMON.CHAIN'
2520 include 'COMMON.DERIV'
2521 include 'COMMON.GEO'
2522 include 'COMMON.LOCAL'
2523 include 'COMMON.INTERACT'
2524 include 'COMMON.IOUNITS'
2525 include 'COMMON.NAMES'
2526 double precision stochforcvec(MAXRES6),stochforcvecV(MAXRES6)
2527 common /stochcalc/ stochforcvec
2529 c Compute the stochastic forces which contribute to velocity change
2531 call stochastic_force(stochforcvecV)
2538 ddt1=ddt1+vfric_mat(i,j)*d_a_work(j)
2539 c ddt2=ddt2+vrand_mat2(i,j)*stochforcvecV(j)
2540 ddt2=ddt2+vrand_mat2(i,j)*stochforcvec(j)
2542 d_t_work(i)=d_t_work_new(i)+0.5d0*ddt1+ddt2
2546 d_t(j,0)=d_t_work(j)
2551 d_t(j,i)=d_t_work(ind+j)
2556 if (itype(i).ne.10 .and. itype(i).ne.ntyp1) then
2559 d_t(j,inres)=d_t_work(ind+j)