2 implicit real*8 (a-h,o-z)
5 include 'COMMON.CONTROL'
9 include 'COMMON.LANGEVIN'
11 include 'COMMON.LANGEVIN.lang0'
13 include 'COMMON.CHAIN'
14 include 'COMMON.DERIV'
16 include 'COMMON.LOCAL'
17 include 'COMMON.INTERACT'
18 include 'COMMON.IOUNITS'
19 include 'COMMON.NAMES'
20 include 'COMMON.TIME1'
22 include 'COMMON.SETUP'
24 include 'COMMON.HAIRPIN'
25 double precision cm(3),L(3),vcm(3)
26 double precision energia(0:n_ene)
27 double precision remd_t_bath(maxprocs)
28 double precision remd_ene(0:n_ene+1,maxprocs)
29 integer iremd_acc(maxprocs),iremd_tot(maxprocs)
35 integer nup(0:maxprocs),ndown(0:maxprocs)
36 integer rep2i(0:maxprocs)
37 integer itime_all(maxprocs)
38 integer status(MPI_STATUS_SIZE)
39 logical synflag,end_of_run,file_exist
42 if(me.eq.king.or..not.out1file)
43 & write (iout,*) 'MREMD',nodes,'time before',time00-walltime
46 mremd_rst_name=prefix(:ilen(prefix))//"_mremd.rst"
48 cd print *,'MREMD',nodes
50 cd print *,'mmm',me,remd_mlist,(remd_m(i),i=1,nrep)
52 cde write (iout,*) "Start MREMD: me",me," t_bath",t_bath
65 c print *,'i2rep',me,i2rep(me)
66 c print *,'rep2i',(rep2i(i),i=0,nrep)
68 if (i2rep(me).eq.nrep) then
71 nup(0)=remd_m(i2rep(me)+1)
79 cd print '(i4,a4,100i4)',me,' nup',(nup(i),i=0,nup(0))
81 if (i2rep(me).eq.1) then
84 ndown(0)=remd_m(i2rep(me)-1)
85 k=rep2i(i2rep(me)-2)+1
92 cd print '(i4,a6,100i4)',me,' ndown',(ndown(i),i=0,ndown(0))
95 if(rest.and.restart1file) then
96 inquire(file=mremd_rst_name,exist=file_exist)
97 if(file_exist) call read1restart
101 if (rest.and..not.restart1file)
102 & inquire(file=mremd_rst_name,exist=file_exist)
103 IF (rest.and.file_exist.and..not.restart1file) THEN
104 open(irest2,file=mremd_rst_name,status='unknown')
106 read (irest2,*) (i2rep(i),i=0,nodes-1)
108 read (irest2,*) (ifirst(i),i=1,remd_m(1))
111 read (irest2,*) nupa(0,il),(nupa(i,il),i=1,nupa(0,il))
113 read (irest2,*) ndowna(0,il),
114 & (ndowna(i,il),i=1,ndowna(0,il))
118 write (iout,'(a6,1000i5)') "i2rep",(i2rep(i),i=0,nodes-1)
119 write (iout,'(a6,1000i5)') "ifirst",
120 & (ifirst(i),i=1,remd_m(1))
122 write (iout,'(a6,i4,a1,100i4)') "nupa",il,":",
123 & (nupa(i,il),i=1,nupa(0,il))
124 write (iout,'(a6,i4,a1,100i4)') "ndowna",il,":",
125 & (ndowna(i,il),i=1,ndowna(0,il))
134 if (i2rep(il-1).eq.nrep) then
137 nupa(0,il)=remd_m(i2rep(il-1)+1)
138 k=rep2i(i2rep(il-1))+1
145 if (i2rep(il-1).eq.1) then
148 ndowna(0,il)=remd_m(i2rep(il-1)-1)
149 k=rep2i(i2rep(il-1)-2)+1
158 c write (iout,'(a6,100i4)') "ifirst",
159 c & (ifirst(i),i=1,remd_m(1))
161 c write (iout,'(a6,i4,a1,100i4)') "nupa",il,":",
162 c & (nupa(i,il),i=1,nupa(0,il))
163 c write (iout,'(a6,i4,a1,100i4)') "ndowna",il,":",
164 c & (ndowna(i,il),i=1,ndowna(0,il))
170 c t_bath=retmin+(retmax-retmin)*me/(nodes-1)
171 if(.not.(rest.and.file_exist.and.restart1file)) then
172 if (me .eq. king) then
175 t_bath=retmin+(retmax-retmin)*exp(float(i2rep(me)-nrep))
177 cd print *,'ttt',me,remd_tlist,(remd_t(i),i=1,nrep)
178 if (remd_tlist) t_bath=remd_t(i2rep(me))
181 stdfp=dsqrt(2*Rb*t_bath/d_time)
183 stdfsc(i)=dsqrt(2*Rb*t_bath/d_time)
186 c print *,'irep',me,t_bath
188 if (me.eq.king .or. .not. out1file)
189 & write (iout,'(a60,f10.5)') "REMD Temperature:",t_bath
190 call rescale_weights(t_bath)
194 c------copy MD--------------
195 c The driver for molecular dynamics subroutines
196 c------------------------------------------------
202 if(me.eq.king.or..not.out1file)
203 & write (iout,'(20(1h=),a20,20(1h=))') "MD calculation started"
205 c Determine the inverse of the inertia matrix.
206 call setup_MD_matrices
210 if (me.eq.king .or. .not. out1file)
211 & write (iout,'(a60,f10.5)') "REMD restart Temperature:",t_bath
212 stdfp=dsqrt(2*Rb*t_bath/d_time)
214 stdfsc(i)=dsqrt(2*Rb*t_bath/d_time)
216 call rescale_weights(t_bath)
219 t_MDsetup = tcpu()-tt0
221 c Entering the MD loop
223 if (lang.eq.2 .or. lang.eq.3) then
226 call sd_verlet_p_setup
228 call sd_verlet_ciccotti_setup
233 pfric0_mat(i,j,0)=pfric_mat(i,j)
234 afric0_mat(i,j,0)=afric_mat(i,j)
235 vfric0_mat(i,j,0)=vfric_mat(i,j)
236 prand0_mat(i,j,0)=prand_mat(i,j)
237 vrand0_mat1(i,j,0)=vrand_mat1(i,j)
238 vrand0_mat2(i,j,0)=vrand_mat2(i,j)
244 flag_stoch(i)=.false.
246 else if (lang.eq.1 .or. lang.eq.4) then
250 if (me.eq.king .or. .not. out1file)
251 & write(iout,*) 'Setup time',time00-walltime
253 t_langsetup=tcpu()-tt0
257 do while(.not.end_of_run)
259 if(itime.eq.n_timestep.and.me.eq.king) end_of_run=.true.
260 if(mremdsync.and.itime.eq.n_timestep) end_of_run=.true.
262 if (lang.gt.0 .and. surfarea .and.
263 & mod(itime,reset_fricmat).eq.0) then
264 if (lang.eq.2 .or. lang.eq.3) then
267 call sd_verlet_p_setup
269 call sd_verlet_ciccotti_setup
274 pfric0_mat(i,j,0)=pfric_mat(i,j)
275 afric0_mat(i,j,0)=afric_mat(i,j)
276 vfric0_mat(i,j,0)=vfric_mat(i,j)
277 prand0_mat(i,j,0)=prand_mat(i,j)
278 vrand0_mat1(i,j,0)=vrand_mat1(i,j)
279 vrand0_mat2(i,j,0)=vrand_mat2(i,j)
285 flag_stoch(i)=.false.
287 else if (lang.eq.1 .or. lang.eq.4) then
290 write (iout,'(a,i10)')
291 & "Friction matrix reset based on surface area, itime",itime
293 if (reset_vel .and. tbf .and. lang.eq.0
294 & .and. mod(itime,count_reset_vel).eq.0) then
296 if (me.eq.king .or. .not. out1file)
297 & write(iout,'(a,f20.2)')
298 & "Velocities reset to random values, time",totT
301 d_t_old(j,i)=d_t(j,i)
305 if (reset_moment .and. mod(itime,count_reset_moment).eq.0) then
309 d_t(j,0)=d_t(j,0)-vcm(j)
312 kinetic_T=2.0d0/(dimen*Rb)*EK
313 scalfac=dsqrt(T_bath/kinetic_T)
314 cd write(iout,'(a,f20.2)') "Momenta zeroed out, time",totT
317 d_t_old(j,i)=scalfac*d_t(j,i)
323 c Time-reversible RESPA algorithm
324 c (Tuckerman et al., J. Chem. Phys., 97, 1990, 1992)
325 call RESPA_step(itime)
327 c Variable time step algorithm.
328 call velverlet_step(itime)
331 call brown_step(itime)
334 if (mod(itime,ntwe).eq.0) call statout(itime)
336 if (mod(itime,ntwx).eq.0.and..not.traj1file) then
337 write (tytul,'("time",f8.2," temp",f8.1)') totT,t_bath
339 call hairpin(.true.,nharp,iharp)
340 call secondary2(.true.)
341 call pdbout(potE,tytul,ipdb)
346 if ((rstcount.eq.1000.or.itime.eq.n_timestep)
347 & .and..not.restart1file) then
350 open(irest1,file=mremd_rst_name,status='unknown')
351 write (irest1,*) "i2rep"
352 write (irest1,*) (i2rep(i),i=0,nodes-1)
353 write (irest1,*) "ifirst"
354 write (irest1,*) (ifirst(i),i=1,remd_m(1))
356 write (irest1,*) "nupa",il
357 write (irest1,*) nupa(0,il),(nupa(i,il),i=1,nupa(0,il))
358 write (irest1,*) "ndowna",il
359 write (irest1,*) ndowna(0,il),
360 & (ndowna(i,il),i=1,ndowna(0,il))
364 open(irest2,file=rest2name,status='unknown')
365 write(irest2,*) totT,EK,potE,totE,t_bath
367 write (irest2,'(3e15.5)') (d_t(j,i),j=1,3)
370 write (irest2,'(3e15.5)') (dc(j,i),j=1,3)
377 c forced synchronization
378 if (mod(itime,100).eq.0 .and. me.ne.king
379 & .and. .not. mremdsync) then
381 call mpi_iprobe(0,101,CG_COMM,synflag,status,ierr)
383 call mpi_recv(itime_master, 1, MPI_INTEGER,
384 & 0,101,CG_COMM, status, ierr)
385 if (.not. out1file) then
386 write(iout,*) 'REMD synchro at',itime_master,itime
388 call mpi_gather(itime,1,mpi_integer,
389 & itime_all,1,mpi_integer,king,
392 if(itime_master.ge.n_timestep) end_of_run=.true.
398 if ((mod(itime,nstex).eq.0.and.me.eq.king
399 & .or.end_of_run.and.me.eq.king )
400 & .and. .not. mremdsync ) then
404 call mpi_isend(itime,1,MPI_INTEGER,i,101,
405 & CG_COMM, ireq, ierr)
406 cd write(iout,*) 'REMD synchro with',i
410 write(iout,*) 'REMD synchro at',itime,'time=',time02-time00
412 call mpi_gather(itime,1,mpi_integer,
413 & itime_all,1,mpi_integer,king,
415 write(iout,'(a18,8000i8)') 'REMD synchro itime',
416 & (itime_all(i),i=1,nodes)
420 if(mremdsync .and. mod(itime,nstex).eq.0) then
422 if (me.eq.king .or. .not. out1file)
423 & write(iout,*) 'REMD synchro at',itime
426 if(synflag.and..not.end_of_run) then
430 cd write(iout,*) 'REMD before',me,t_bath
432 c call mpi_gather(t_bath,1,mpi_double_precision,
433 c & remd_t_bath,1,mpi_double_precision,king,
435 potEcomp(n_ene+1)=t_bath
436 call mpi_gather(potEcomp(0),n_ene+2,mpi_double_precision,
437 & remd_ene(0,1),n_ene+2,mpi_double_precision,king,
440 call mpi_gather(elow,1,mpi_double_precision,
441 & elowi,1,mpi_double_precision,king,
443 call mpi_gather(ehigh,1,mpi_double_precision,
444 & ehighi,1,mpi_double_precision,king,
448 if (restart1file) call write1rst
449 if (traj1file) call write1traj
453 remd_t_bath(i)=remd_ene(n_ene+1,i)
456 co write(iout,*) 'REMD exchange temp,ene,elow,ehigh'
458 write(iout,'(i4,4f12.5)') i,remd_t_bath(i),remd_ene(0,i),
462 cd write(iout,*) 'REMD exchange temp,ene'
464 co write(iout,'(i4,2f12.5)') i,remd_t_bath(i),remd_ene(0,i)
465 c write(iout,'(6f12.5)') (remd_ene(j,i),j=1,n_ene)
468 c-------------------------------------
470 i=ifirst(iran_num(1,remd_m(1)))
473 if(i.gt.0.and.nupa(0,i).gt.0) then
474 iex=nupa(iran_num(1,int(nupa(0,i))),i)
476 call muca_delta(remd_t_bath,remd_ene,i,iex,delta)
478 c Swap temperatures between conformations i and iex with recalculating the free energies
479 c following temperature changes.
480 ene_iex_iex=remd_ene(0,iex)
481 ene_i_i=remd_ene(0,i)
482 co write (iout,*) "rescaling weights with temperature",
484 call rescale_weights(remd_t_bath(i))
485 call sum_energy(remd_ene(0,iex),.false.)
486 ene_iex_i=remd_ene(0,iex)
487 cd write (iout,*) "ene_iex_i",remd_ene(0,iex)
488 call sum_energy(remd_ene(0,i),.false.)
489 cd write (iout,*) "ene_i_i",remd_ene(0,i)
490 c write (iout,*) "rescaling weights with temperature",
492 if (real(ene_i_i).ne.real(remd_ene(0,i))) then
493 write (iout,*) "ERROR: inconsistent energies:",i,
494 & ene_i_i,remd_ene(0,i)
496 call rescale_weights(remd_t_bath(iex))
497 call sum_energy(remd_ene(0,i),.false.)
498 c write (iout,*) "ene_i_iex",remd_ene(0,i)
499 ene_i_iex=remd_ene(0,i)
500 call sum_energy(remd_ene(0,iex),.false.)
501 if (real(ene_iex_iex).ne.real(remd_ene(0,iex))) then
502 write (iout,*) "ERROR: inconsistent energies:",iex,
503 & ene_iex_iex,remd_ene(0,iex)
505 c write (iout,*) "ene_iex_iex",remd_ene(0,iex)
506 c write (iout,*) "i",i," iex",iex
507 co write (iout,'(4(a,e15.5))') "ene_i_i",ene_i_i,
508 co & " ene_i_iex",ene_i_iex,
509 co & " ene_iex_i",ene_iex_i," ene_iex_iex",ene_iex_iex
510 delta=(ene_iex_iex-ene_i_iex)/(Rb*remd_t_bath(iex))-
511 & (ene_iex_i-ene_i_i)/(Rb*remd_t_bath(i))
513 c write(iout,*) 'delta',delta
514 c delta=(remd_t_bath(i)-remd_t_bath(iex))*
515 c & (remd_ene(i)-remd_ene(iex))/Rb/
516 c & (remd_t_bath(i)*remd_t_bath(iex))
518 if (delta .gt. 50.0d0) then
524 else if (delta.lt.-50.0d0) then
533 iremd_tot(i2rep(i-1))=iremd_tot(i2rep(i-1))+1
534 xxx=ran_number(0.0d0,1.0d0)
535 co write(iout,'(2i4,a6,2f12.5)') i,iex,' delta',delta,xxx
536 if (delta .gt. xxx) then
538 remd_t_bath(i)=remd_t_bath(iex)
540 remd_ene(0,i)=ene_i_iex
541 remd_ene(0,iex)=ene_iex_i
547 ehighi(i)=ehighi(iex)
554 nupa(k,i)=nupa(k,iex)
557 ndowna(k,i)=ndowna(k,iex)
561 if (ifirst(il).eq.i) ifirst(il)=iex
563 if (nupa(k,il).eq.i) then
565 elseif (nupa(k,il).eq.iex) then
570 if (ndowna(k,il).eq.i) then
572 elseif (ndowna(k,il).eq.iex) then
578 iremd_acc(i2rep(i-1))=iremd_acc(i2rep(i-1))+1
580 i2rep(i-1)=i2rep(iex-1)
583 cd write(iout,*) 'exchange',i,iex
584 cd write (iout,'(a8,100i4)') "@ ifirst",
585 cd & (ifirst(k),k=1,remd_m(1))
587 cd write (iout,'(a8,i4,a1,100i4)') "@ nupa",il,":",
588 cd & (nupa(k,il),k=1,nupa(0,il))
589 cd write (iout,'(a8,i4,a1,100i4)') "@ ndowna",il,":",
590 cd & (ndowna(k,il),k=1,ndowna(0,il))
594 remd_ene(0,iex)=ene_iex_iex
595 remd_ene(0,i)=ene_i_i
601 c-------------------------------------
603 if(iremd_tot(i).ne.0)
604 & write(iout,'(a3,i4,2f12.5)') 'ACC',i,remd_t(i)
605 & ,iremd_acc(i)/(1.0*iremd_tot(i))
608 cd write (iout,'(a6,100i4)') "ifirst",
609 cd & (ifirst(i),i=1,remd_m(1))
611 cd write (iout,'(a5,i4,a1,100i4)') "nup",il,":",
612 cd & (nupa(i,il),i=1,nupa(0,il))
613 cd write (iout,'(a5,i4,a1,100i4)') "ndown",il,":",
614 cd & (ndowna(i,il),i=1,ndowna(0,il))
618 call mpi_scatter(remd_t_bath,1,mpi_double_precision,
619 & t_bath,1,mpi_double_precision,king,
622 call mpi_scatter(elowi,1,mpi_double_precision,
623 & elow,1,mpi_double_precision,king,
625 call mpi_scatter(ehighi,1,mpi_double_precision,
626 & ehigh,1,mpi_double_precision,king,
629 call rescale_weights(t_bath)
630 co write (iout,*) "Processor",me,
631 co & " rescaling weights with temperature",t_bath
633 stdfp=dsqrt(2*Rb*t_bath/d_time)
635 stdfsc(i)=dsqrt(2*Rb*t_bath/d_time)
638 cde write(iout,*) 'REMD after',me,t_bath
640 if (me.eq.king .or. .not. out1file) then
641 write(iout,*) 'REMD exchange time=',time02-time00
647 if (restart1file) then
648 if (me.eq.king .or. .not. out1file)
649 & write(iout,*) 'writing restart at the end of run'
653 if (traj1file) call write1traj
657 if (me.eq.king .or. .not. out1file) then
658 write (iout,'(//35(1h=),a10,35(1h=)/10(/a40,1pe15.5))')
660 & 'MD calculations setup:',t_MDsetup,
661 & 'Energy & gradient evaluation:',t_enegrad,
662 & 'Stochastic MD setup:',t_langsetup,
663 & 'Stochastic MD step setup:',t_sdsetup,
665 write (iout,'(/28(1h=),a25,27(1h=))')
666 & ' End of MD calculation '
672 implicit real*8 (a-h,o-z)
676 include 'COMMON.IOUNITS'
677 include 'COMMON.REMD'
678 include 'COMMON.SETUP'
679 include 'COMMON.CHAIN'
680 include 'COMMON.SBRIDGE'
681 include 'COMMON.INTERACT'
683 real d_restart1(3,2*maxres*maxprocs),r_d(3,2*maxres),
684 & d_restart2(3,2*maxres*maxprocs)
692 t5_restart1(4)=t_bath
693 t5_restart1(5)=Uconst
695 call mpi_gather(t5_restart1,5,mpi_real,
696 & t_restart1,5,mpi_real,king,CG_COMM,ierr)
704 call mpi_gather(r_d,3*2*nres,mpi_real,
705 & d_restart1,3*2*nres,mpi_real,king,
714 call mpi_gather(r_d,3*2*nres,mpi_real,
715 & d_restart2,3*2*nres,mpi_real,king,
719 open(irest1,file=mremd_rst_name,status='unknown')
720 write (irest1,*) (i2rep(i),i=0,nodes-1)
721 write (irest1,*) (ifirst(i),i=1,remd_m(1))
723 write (irest1,*) nupa(0,il),(nupa(i,il),i=1,nupa(0,il))
724 write (irest1,*) ndowna(0,il),
725 & (ndowna(i,il),i=1,ndowna(0,il))
729 write(irest1,*) (t_restart1(j,il),j=1,4)
734 write(irest1,'(3e15.5)') (d_restart1(j,i+2*nres*il),j=1,3)
739 write(irest1,'(3e15.5)') (d_restart2(j,i+2*nres*il),j=1,3)
749 subroutine write1traj
750 implicit real*8 (a-h,o-z)
754 include 'COMMON.IOUNITS'
755 include 'COMMON.REMD'
756 include 'COMMON.SETUP'
757 include 'COMMON.CHAIN'
758 include 'COMMON.SBRIDGE'
759 include 'COMMON.INTERACT'
763 real xcoord(3,maxres2+2),prec
764 real r_qfrag(50),r_qpair(100)
765 real p_qfrag(50*maxprocs),p_qpair(100*maxprocs)
766 real p_c(3,(maxres2+2)*maxprocs),r_c(3,maxres2+2)
768 if(.not.restart1file) then
772 t5_restart1(4)=t_bath
773 t5_restart1(5)=Uconst
774 call mpi_gather(t5_restart1,5,mpi_real,
775 & t_restart1,5,mpi_real,king,CG_COMM,ierr)
785 call mpi_gather(r_qfrag,nfrag,mpi_real,
786 & p_qfrag,nfrag,mpi_real,king,
788 call mpi_gather(qpair,nfrag,mpi_real,
789 & p_qpair,nfrag,mpi_real,king,
798 call mpi_gather(r_c,3*2*nres,mpi_real,
799 & p_c,3*2*nres,mpi_real,king,
803 call xdrfopen(ixdrf,cartname, "a", iret)
805 call xdrffloat(ixdrf, real(t_restart1(1,il)), iret)
806 call xdrffloat(ixdrf, real(t_restart1(3,il)), iret)
807 call xdrffloat(ixdrf, real(t_restart1(5,il)), iret)
808 call xdrffloat(ixdrf, real(t_restart1(4,il)), iret)
809 call xdrfint(ixdrf, nss, iret)
811 call xdrfint(ixdrf, ihpb(j), iret)
812 call xdrfint(ixdrf, jhpb(j), iret)
814 call xdrfint(ixdrf, nfrag+npair, iret)
816 call xdrffloat(ixdrf, p_qfrag(i+(il-1)*nfrag), iret)
819 call xdrffloat(ixdrf, p_qpair(i+(il-1)*npair), iret)
824 xcoord(j,i)=p_c(j,i+(il-1)*nres*2)
829 xcoord(j,nres+i-nnt+1)=p_c(j,i+nres+(il-1)*nres*2)
833 call xdrf3dfcoord(ixdrf, xcoord, itmp, prec, iret)
835 call xdrfclose(ixdrf, iret)
842 subroutine read1restart
843 implicit real*8 (a-h,o-z)
847 include 'COMMON.IOUNITS'
848 include 'COMMON.REMD'
849 include 'COMMON.SETUP'
850 include 'COMMON.CHAIN'
851 include 'COMMON.SBRIDGE'
852 include 'COMMON.INTERACT'
853 real d_restart1(3,2*maxres*maxprocs),r_d(3,2*maxres),
857 open(irest2,file=mremd_rst_name,status='unknown')
858 read (irest2,*) (i2rep(i),i=0,nodes-1)
859 read (irest2,*) (ifirst(i),i=1,remd_m(1))
861 read (irest2,*) nupa(0,il),(nupa(i,il),i=1,nupa(0,il))
862 read (irest2,*) ndowna(0,il),
863 & (ndowna(i,il),i=1,ndowna(0,il))
866 read(irest2,*) (t_restart1(j,il),j=1,4)
869 call mpi_scatter(t_restart1,5,mpi_real,
870 & t5_restart1,5,mpi_real,king,CG_COMM,ierr)
874 t_bath=t5_restart1(4)
879 read(irest2,'(3e15.5)')
880 & (d_restart1(j,i+2*nres*il),j=1,3)
884 call mpi_scatter(d_restart1,3*2*nres,mpi_real,
885 & r_d,3*2*nres,mpi_real,king,CG_COMM,ierr)
895 read(irest2,'(3e15.5)')
896 & (d_restart1(j,i+2*nres*il),j=1,3)
900 call mpi_scatter(d_restart1,3*2*nres,mpi_real,
901 & r_d,3*2*nres,mpi_real,king,CG_COMM,ierr)
907 if(me.eq.king) close(irest2)