3 implicit real*8 (a-h,o-z)
6 include 'COMMON.CONTROL'
10 include 'COMMON.LANGEVIN'
12 include 'COMMON.LANGEVIN.lang0'
14 include 'COMMON.CHAIN'
15 include 'COMMON.DERIV'
17 include 'COMMON.LOCAL'
18 include 'COMMON.INTERACT'
19 include 'COMMON.IOUNITS'
20 include 'COMMON.NAMES'
21 include 'COMMON.TIME1'
23 include 'COMMON.SETUP'
25 include 'COMMON.HAIRPIN'
27 double precision cm(3),L(3),vcm(3)
28 double precision energia(0:n_ene)
29 double precision remd_t_bath(maxprocs)
30 integer iremd_iset(maxprocs)
32 & (maxprocs/4,maxprocs/20,maxprocs/200,maxprocs/200)
33 double precision remd_ene(0:n_ene+4,maxprocs),t_bath_old,e_tmp
34 integer iremd_acc(maxprocs),iremd_tot(maxprocs)
35 integer iremd_acc_usa(maxprocs),iremd_tot_usa(maxprocs)
41 cold integer nup(0:maxprocs),ndown(0:maxprocs)
42 integer rep2i(0:maxprocs),ireqi(maxprocs)
43 integer icache_all(maxprocs)
44 integer status(MPI_STATUS_SIZE),statusi(MPI_STATUS_SIZE,maxprocs)
45 logical synflag,end_of_run,file_exist /.false./,ovrtim
52 if(me.eq.king.or..not.out1file) then
53 write (iout,*) 'MREMD',nodes,'time before',time00-walltime
54 write (iout,*) "NREP=",nrep
58 if (ilen(tmpdir).gt.0 .and. (me.eq.king)) then
59 call copy_to_tmp(pref_orig(:ilen(pref_orig))//"_mremd.rst")
61 mremd_rst_name=prefix(:ilen(prefix))//"_mremd.rst"
63 cd print *,'MREMD',nodes,homol_nset
64 cd print *,'mmm',me,remd_mlist,(remd_m(i),i=1,nrep)
65 cde write (iout,*) "Start MREMD: me",me," t_bath",t_bath
66 if(homol_nset.gt.1) then
74 if(usampl) i_econstr=20
79 do il1=1,max0(mset(il),1)
95 if(me.eq.king.or..not.out1file) then
96 write(iout,*) "i2rep",(i2rep(i),i=0,nodes-1)
97 write(iout,*) "i2set",(i2set(i),i=0,nodes-1)
98 write(iout,*) "i,j,il,il1,i_index(i,j,il,il1)"
103 write(iout,*) i,j,il,il1,i_index(i,j,il,il1)
110 c print *,'i2rep',me,i2rep(me)
111 c print *,'rep2i',(rep2i(i),i=0,nrep)
113 cold if (i2rep(me).eq.nrep) then
116 cold nup(0)=remd_m(i2rep(me)+1)
117 cold k=rep2i(int(i2rep(me)))+1
124 cd print '(i4,a4,100i4)',me,' nup',(nup(i),i=0,nup(0))
126 cold if (i2rep(me).eq.1) then
129 cold ndown(0)=remd_m(i2rep(me)-1)
130 cold k=rep2i(i2rep(me)-2)+1
137 cd print '(i4,a6,100i4)',me,' ndown',(ndown(i),i=0,ndown(0))
140 write (*,*) "Processor",me," rest",rest,"
141 & restart1fie",restart1file
142 if(rest.and.restart1file) then
144 & inquire(file=mremd_rst_name,exist=file_exist)
145 cd write (*,*) me," Before broadcast: file_exist",file_exist
146 call MPI_Bcast(file_exist,1,MPI_LOGICAL,king,CG_COMM,
148 cd write (*,*) me," After broadcast: file_exist",file_exist
150 if(me.eq.king.or..not.out1file)
151 & write (iout,*) 'Master is reading restart1file'
152 call read1restart(i_index)
154 if(me.eq.king.or..not.out1file)
155 & write (iout,*) 'WARNING : no restart1file'
158 if(me.eq.king.or..not.out1file) then
159 write(iout,*) "i2set",(i2set(i),i=0,nodes-1)
160 write(iout,*) "i_index"
165 write(iout,*) i,j,il,il1,i_index(i,j,il,il1)
174 if (rest.and..not.restart1file)
175 & inquire(file=mremd_rst_name,exist=file_exist)
176 if(.not.file_exist.and.rest.and..not.restart1file)
177 & write(iout,*) 'WARNING : no restart file',mremd_rst_name
178 IF (rest.and.file_exist.and..not.restart1file) THEN
179 write (iout,*) 'Master is reading restart file',
181 open(irest2,file=mremd_rst_name,status='unknown')
183 read (irest2,*) (i2rep(i),i=0,nodes-1)
185 read (irest2,*) (ifirst(i),i=1,remd_m(1))
188 read (irest2,*) nupa(0,il),(nupa(i,il),i=1,nupa(0,il))
190 read (irest2,*) ndowna(0,il),
191 & (ndowna(i,il),i=1,ndowna(0,il))
193 if(usampl.or.hremd.gt.0.or.homol_nset.gt.1) then
197 read (irest2,*) (mset(i),i=1,nset)
199 read (irest2,*) (i2set(i),i=0,nodes-1)
204 read(irest2,*) (i_index(i,j,il,il1),j=1,remd_m(i))
209 write(iout,*) "i2set",(i2set(i),i=0,nodes-1)
210 write(iout,*) "i_index"
215 write(iout,*) i,j,il,il1,i_index(i,j,il,il1)
224 write (iout,'(a6,1000i5)') "i2rep",(i2rep(i),i=0,nodes-1)
225 write (iout,'(a6,1000i5)') "ifirst",
226 & (ifirst(i),i=1,remd_m(1))
228 write (iout,'(a6,i4,a1,100i4)') "nupa",il,":",
229 & (nupa(i,il),i=1,nupa(0,il))
230 write (iout,'(a6,i4,a1,100i4)') "ndowna",il,":",
231 & (ndowna(i,il),i=1,ndowna(0,il))
233 ELSE IF (.not.(rest.and.file_exist)) THEN
239 if (i2rep(il-1).eq.nrep) then
242 nupa(0,il)=remd_m(i2rep(il-1)+1)
243 k=rep2i(int(i2rep(il-1)))+1
249 if (i2rep(il-1).eq.1) then
252 ndowna(0,il)=remd_m(i2rep(il-1)-1)
253 k=rep2i(i2rep(il-1)-2)+1
261 write (iout,'(a6,100i4)') "ifirst",
262 & (ifirst(i),i=1,remd_m(1))
264 write (iout,'(a6,i4,a1,100i4)') "nupa",il,":",
265 & (nupa(i,il),i=1,nupa(0,il))
266 write (iout,'(a6,i4,a1,100i4)') "ndowna",il,":",
267 & (ndowna(i,il),i=1,ndowna(0,il))
273 c t_bath=retmin+(retmax-retmin)*me/(nodes-1)
274 if(.not.(rest.and.file_exist.and.restart1file)) then
275 if (me .eq. king) then
278 t_bath=retmin+(retmax-retmin)*exp(float(i2rep(me)-nrep))
280 cd print *,'ttt',me,remd_tlist,(remd_t(i),i=1,nrep)
281 if (remd_tlist) t_bath=remd_t(int(i2rep(me)))
284 if(usampl.or.hremd.gt.0.or.homol_nset.gt.1) then
286 c broadcast iset to slaves
287 if (nfgtasks.gt.1) then
288 call MPI_Bcast(11,1,MPI_INTEGER,king,FG_COMM,IERROR)
289 call MPI_Bcast(iset,1,MPI_INTEGER,king,FG_COMM,IERROR)
291 if(me.eq.king.or..not.out1file)
292 & write(iout,*) me,"iset=",iset,"t_bath=",t_bath
295 stdfp=dsqrt(2*Rb*t_bath/d_time)
297 stdfsc(i)=dsqrt(2*Rb*t_bath/d_time)
300 c print *,'irep',me,t_bath
302 if (me.eq.king .or. .not. out1file)
303 & write (iout,'(a60,f10.5)') "REMD Temperature:",t_bath
304 call rescale_weights(t_bath)
308 c------copy MD--------------
309 c The driver for molecular dynamics subroutines
310 c------------------------------------------------
316 if(me.eq.king.or..not.out1file)
317 & write (iout,'(20(1h=),a20,20(1h=))') "MD calculation started"
323 c Determine the inverse of the inertia matrix.
324 call setup_MD_matrices
328 if (me.eq.king .or. .not. out1file)
329 & write (iout,'(a60,f10.5)') "REMD restart Temperature:",t_bath
330 stdfp=dsqrt(2*Rb*t_bath/d_time)
332 stdfsc(i)=dsqrt(2*Rb*t_bath/d_time)
334 call rescale_weights(t_bath)
338 t_MDsetup = MPI_Wtime()-tt0
340 t_MDsetup = tcpu()-tt0
343 c Entering the MD loop
349 if (lang.eq.2 .or. lang.eq.3) then
353 call sd_verlet_p_setup
355 call sd_verlet_ciccotti_setup
359 pfric0_mat(i,j,0)=pfric_mat(i,j)
360 afric0_mat(i,j,0)=afric_mat(i,j)
361 vfric0_mat(i,j,0)=vfric_mat(i,j)
362 prand0_mat(i,j,0)=prand_mat(i,j)
363 vrand0_mat1(i,j,0)=vrand_mat1(i,j)
364 vrand0_mat2(i,j,0)=vrand_mat2(i,j)
369 flag_stoch(i)=.false.
373 & "LANG=2 or 3 NOT SUPPORTED. Recompile without -DLANG0"
375 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
379 else if (lang.eq.1 .or. lang.eq.4) then
383 if (me.eq.king .or. .not. out1file)
384 & write(iout,*) 'Setup time',time00-walltime
387 t_langsetup=MPI_Wtime()-tt0
390 t_langsetup=tcpu()-tt0
395 do while(.not.end_of_run)
397 if(itime.eq.n_timestep.and.me.eq.king) end_of_run=.true.
398 if(mremdsync.and.itime.eq.n_timestep) end_of_run=.true.
400 if (lang.gt.0 .and. surfarea .and.
401 & mod(itime,reset_fricmat).eq.0) then
402 if (lang.eq.2 .or. lang.eq.3) then
406 call sd_verlet_p_setup
408 call sd_verlet_ciccotti_setup
412 pfric0_mat(i,j,0)=pfric_mat(i,j)
413 afric0_mat(i,j,0)=afric_mat(i,j)
414 vfric0_mat(i,j,0)=vfric_mat(i,j)
415 prand0_mat(i,j,0)=prand_mat(i,j)
416 vrand0_mat1(i,j,0)=vrand_mat1(i,j)
417 vrand0_mat2(i,j,0)=vrand_mat2(i,j)
422 flag_stoch(i)=.false.
425 else if (lang.eq.1 .or. lang.eq.4) then
428 write (iout,'(a,i10)')
429 & "Friction matrix reset based on surface area, itime",itime
431 if (reset_vel .and. tbf .and. lang.eq.0
432 & .and. mod(itime,count_reset_vel).eq.0) then
434 if (me.eq.king .or. .not. out1file)
435 & write(iout,'(a,f20.2)')
436 & "Velocities reset to random values, time",totT
439 d_t_old(j,i)=d_t(j,i)
443 if (reset_moment .and. mod(itime,count_reset_moment).eq.0) then
447 d_t(j,0)=d_t(j,0)-vcm(j)
450 kinetic_T=2.0d0/(dimen3*Rb)*EK
451 scalfac=dsqrt(T_bath/kinetic_T)
452 cd write(iout,'(a,f20.2)') "Momenta zeroed out, time",totT
455 d_t_old(j,i)=scalfac*d_t(j,i)
461 c Time-reversible RESPA algorithm
462 c (Tuckerman et al., J. Chem. Phys., 97, 1990, 1992)
463 call RESPA_step(itime)
465 c Variable time step algorithm.
466 call velverlet_step(itime)
470 call brown_step(itime)
472 print *,"Brown dynamics not here!"
474 call MPI_Abort(MPI_COMM_WORLD,IERROR,ERRCODE)
480 if (mod(itime,ntwe).eq.0) call statout(itime)
482 if (mod(itime,ntwx).eq.0.and..not.traj1file) then
483 write (tytul,'("time",f8.2," temp",f8.1)') totT,t_bath
485 call hairpin(.true.,nharp,iharp)
486 call secondary2(.true.)
487 call pdbout(potE,tytul,ipdb)
492 if (mod(itime,ntwx).eq.0.and.traj1file) then
493 if(ntwx_cache.lt.max_cache_traj_use) then
494 ntwx_cache=ntwx_cache+1
496 if (max_cache_traj_use.ne.1)
497 & print *,itime,"processor ",me," over cache ",ntwx_cache
500 totT_cache(i)=totT_cache(i+1)
501 EK_cache(i)=EK_cache(i+1)
502 potE_cache(i)=potE_cache(i+1)
503 t_bath_cache(i)=t_bath_cache(i+1)
504 Uconst_cache(i)=Uconst_cache(i+1)
505 iset_cache(i)=iset_cache(i+1)
508 qfrag_cache(ii,i)=qfrag_cache(ii,i+1)
511 qpair_cache(ii,i)=qpair_cache(ii,i+1)
514 utheta_cache(ii,i)=utheta_cache(ii,i+1)
515 ugamma_cache(ii,i)=ugamma_cache(ii,i+1)
516 uscdiff_cache(ii,i)=uscdiff_cache(ii,i+1)
522 c_cache(j,ii,i)=c_cache(j,ii,i+1)
528 totT_cache(ntwx_cache)=totT
529 EK_cache(ntwx_cache)=EK
530 potE_cache(ntwx_cache)=potE
531 t_bath_cache(ntwx_cache)=t_bath
532 Uconst_cache(ntwx_cache)=Uconst
533 iset_cache(ntwx_cache)=iset
536 qfrag_cache(i,ntwx_cache)=qfrag(i)
539 qpair_cache(i,ntwx_cache)=qpair(i)
542 utheta_cache(i,ntwx_cache)=utheta(i)
543 ugamma_cache(i,ntwx_cache)=ugamma(i)
544 uscdiff_cache(i,ntwx_cache)=uscdiff(i)
546 C print *,'przed returnbox'
548 C call enerprint(remd_ene(0,i))
551 c_cache(j,i,ntwx_cache)=c(j,i)
556 if ((rstcount.eq.1000.or.itime.eq.n_timestep)
557 & .and..not.restart1file) then
560 open(irest1,file=mremd_rst_name,status='unknown')
561 write (irest1,*) "i2rep"
562 write (irest1,*) (i2rep(i),i=0,nodes-1)
563 write (irest1,*) "ifirst"
564 write (irest1,*) (ifirst(i),i=1,remd_m(1))
566 write (irest1,*) "nupa",il
567 write (irest1,*) nupa(0,il),(nupa(i,il),i=1,nupa(0,il))
568 write (irest1,*) "ndowna",il
569 write (irest1,*) ndowna(0,il),
570 & (ndowna(i,il),i=1,ndowna(0,il))
572 if(usampl.or.hremd.gt.0.or.homol_nset.gt.1) then
573 write (irest1,*) "nset"
574 write (irest1,*) nset
575 write (irest1,*) "mset"
576 write (irest1,*) (mset(i),i=1,nset)
577 write (irest1,*) "i2set"
578 write (irest1,*) (i2set(i),i=0,nodes-1)
579 write (irest1,*) "i_index"
583 write(irest1,*) (i_index(i,j,il,il1),j=1,remd_m(i))
591 open(irest2,file=rest2name,status='unknown')
592 write(irest2,*) totT,EK,potE,totE,t_bath
594 write (irest2,'(3e15.5)') (d_t(j,i),j=1,3)
597 write (irest2,'(3e15.5)') (dc(j,i),j=1,3)
599 if(usampl.or.hremd.gt.0.or.homol_nset.gt.1) then
600 write (irest2,*) iset
607 c forced synchronization
608 if (mod(itime,i_sync_step).eq.0 .and. me.ne.king
609 & .and. .not. mremdsync) then
611 call mpi_iprobe(0,101,CG_COMM,synflag,status,ierr)
613 call mpi_recv(itime_master, 1, MPI_INTEGER,
614 & 0,101,CG_COMM, status, ierr)
615 call mpi_barrier(CG_COMM, ierr)
616 cdeb if (out1file.or.traj1file) then
617 cdeb call mpi_gather(itime,1,mpi_integer,
618 cdeb & icache_all,1,mpi_integer,king,
621 & call mpi_gather(ntwx_cache,1,mpi_integer,
622 & icache_all,1,mpi_integer,king,
625 & write(iout,*) 'REMD synchro at',itime_master,itime
626 if (itime_master.ge.n_timestep .or. ovrtim())
628 ctime call flush(iout)
633 if ((mod(itime,nstex).eq.0.and.me.eq.king
634 & .or.end_of_run.and.me.eq.king )
635 & .and. .not. mremdsync ) then
639 call mpi_isend(itime,1,MPI_INTEGER,i,101,
640 & CG_COMM, ireqi(i), ierr)
641 cd write(iout,*) 'REMD synchro with',i
644 call mpi_waitall(nodes-1,ireqi,statusi,ierr)
645 call mpi_barrier(CG_COMM, ierr)
647 write(iout,*) 'REMD synchro at',itime,'time=',time01-time01_
648 if (out1file.or.traj1file) then
649 cdeb call mpi_gather(itime,1,mpi_integer,
650 cdeb & itime_all,1,mpi_integer,king,
652 cdeb write(iout,'(a19,8000i8)') ' REMD synchro itime',
653 cdeb & (itime_all(i),i=1,nodes)
655 cdeb imin_itime=itime_all(1)
657 cdeb if(itime_all(i).lt.imin_itime) imin_itime=itime_all(i)
659 cdeb ii_write=(imin_itime-imin_itime_old)/ntwx
660 cdeb imin_itime_old=int(imin_itime/ntwx)*ntwx
661 cdeb write(iout,*) imin_itime,imin_itime_old,ii_write
662 call mpi_gather(ntwx_cache,1,mpi_integer,
663 & icache_all,1,mpi_integer,king,
665 c write(iout,'(a19,8000i8)') ' ntwx_cache',
666 c & (icache_all(i),i=1,nodes)
667 ii_write=icache_all(1)
669 if(icache_all(i).lt.ii_write) ii_write=icache_all(i)
671 c write(iout,*) "MIN ii_write=",ii_write
674 ctime call flush(iout)
676 if(mremdsync .and. mod(itime,nstex).eq.0) then
678 if (me.eq.king .or. .not. out1file)
679 & write(iout,*) 'REMD synchro at',itime
682 call mpi_gather(ntwx_cache,1,mpi_integer,
683 & icache_all,1,mpi_integer,king,
686 write(iout,'(a19,8000i8)') ' ntwx_cache',
687 & (icache_all(i),i=1,nodes)
688 ii_write=icache_all(1)
690 if(icache_all(i).lt.ii_write) ii_write=icache_all(i)
692 write(iout,*) "MIN ii_write=",ii_write
698 c Update the time safety limiy
699 if (time001-time00.gt.safety) then
700 safety=time001-time00+600
701 write (iout,*) "****** SAFETY increased to",safety," s"
703 if (ovrtim() .and. me.eq.king) end_of_run=.true.
704 call MPI_Bcast(end_of_run,1,MPI_LOGICAL,king,CG_COMM,IERR)
706 if(synflag.and..not.end_of_run) then
710 c write(iout,*) 'REMD before',me,t_bath
712 c call mpi_gather(t_bath,1,mpi_double_precision,
713 c & remd_t_bath,1,mpi_double_precision,king,
715 potEcomp(n_ene+1)=t_bath
717 if (usampl.or.homol_nset.gt.1) then
718 potEcomp(n_ene+2)=iset
719 if (iset.lt.nset) then
722 if (homol_nset.gt.1) then
723 c broadcast iset to slaves and reduce energy
724 if (nfgtasks.gt.1) then
725 call MPI_Bcast(12,1,MPI_INTEGER,king,FG_COMM,IERROR)
726 call MPI_Bcast(iset,1,MPI_INTEGER,king,FG_COMM,IERROR)
727 call e_modeller(e_tmp)
728 c write(iout,*) "iset+1 before reduce",e_tmp
729 call MPI_Barrier(FG_COMM,IERR)
730 call MPI_Reduce(e_tmp,potEcomp(n_ene+3),1,
731 & MPI_DOUBLE_PRECISION,MPI_SUM,king,FG_COMM,IERR)
733 call e_modeller(potEcomp(n_ene+3))
735 c write(iout,*) "iset+1",potEcomp(n_ene+3)
738 potEcomp(n_ene+3)=Uconst
741 c broadcast iset to slaves
742 if (nfgtasks.gt.1) then
743 call MPI_Bcast(11,1,MPI_INTEGER,king,FG_COMM,IERROR)
744 call MPI_Bcast(iset,1,MPI_INTEGER,king,FG_COMM,IERROR)
747 potEcomp(n_ene+3)=0.0
752 if (homol_nset.gt.1) then
753 c broadcast iset to slaves and reduce energy
754 if (nfgtasks.gt.1) then
755 call MPI_Bcast(12,1,MPI_INTEGER,king,FG_COMM,IERROR)
756 call MPI_Bcast(iset,1,MPI_INTEGER,king,FG_COMM,IERROR)
757 call e_modeller(e_tmp)
758 c write(iout,*) "iset-1 before reduce",e_tmp
759 call MPI_Barrier(FG_COMM,IERR)
760 call MPI_Reduce(e_tmp,potEcomp(n_ene+4),1,
761 & MPI_DOUBLE_PRECISION,MPI_SUM,king,FG_COMM,IERR)
763 call e_modeller(potEcomp(n_ene+4))
765 c write(iout,*) "iset-1",potEcomp(n_ene+4)
768 potEcomp(n_ene+4)=Uconst
771 c broadcast iset to slaves
772 if (nfgtasks.gt.1) then
773 call MPI_Bcast(11,1,MPI_INTEGER,king,FG_COMM,IERROR)
774 call MPI_Bcast(iset,1,MPI_INTEGER,king,FG_COMM,IERROR)
777 potEcomp(n_ene+4)=0.0
780 call mpi_gather(potEcomp(0),n_ene+5,mpi_double_precision,
781 & remd_ene(0,1),n_ene+5,mpi_double_precision,king,
784 call mpi_gather(elow,1,mpi_double_precision,
785 & elowi,1,mpi_double_precision,king,
787 call mpi_gather(ehigh,1,mpi_double_precision,
788 & ehighi,1,mpi_double_precision,king,
793 if (me.eq.king .or. .not. out1file) then
794 write(iout,*) 'REMD gather times=',time03-time01
798 if (restart1file) call write1rst(i_index)
801 if (me.eq.king .or. .not. out1file) then
802 write(iout,*) 'REMD writing rst time=',time04-time03
805 if (traj1file) call write1traj
807 cdeb call mpi_gather(ntwx_cache,1,mpi_integer,
808 cdeb & icache_all,1,mpi_integer,king,
810 cdeb write(iout,'(a19,8000i8)') ' ntwx_cache after traj1file',
811 cdeb & (icache_all(i),i=1,nodes)
816 if (me.eq.king .or. .not. out1file) then
817 write(iout,*) 'REMD writing traj time=',time05-time04
823 if(homol_nset.gt.1) write(iout,*)
824 & 'energy_c temperature iset energy_c(iset+1) energy_c(iset-1)'
826 remd_t_bath(i)=remd_ene(n_ene+1,i)
827 iremd_iset(i)=remd_ene(n_ene+2,i)
829 & write(iout,'(i4,f10.3,f6.0,i3,2f10.3)')
830 & i,remd_ene(i_econstr,i),
831 & remd_ene(n_ene+1,i),iremd_iset(i),
832 & remd_ene(n_ene+3,i),remd_ene(n_ene+4,i)
836 co write(iout,*) 'REMD exchange temp,ene,elow,ehigh'
838 write(iout,'(i4,4f12.5)') i,remd_t_bath(i),remd_ene(0,i),
842 write(iout,*) 'REMD exchange temp,ene'
844 write(iout,'(i4,2f12.5)') i,remd_t_bath(i),remd_ene(0,i)
845 write(iout,'(6f12.5)') (remd_ene(j,i),j=1,n_ene)
849 c-------------------------------------
850 IF(.not.usampl.and.hremd.eq.0.and.homol_nset.le.1) THEN
852 write (iout,*) "Enter exchnge, remd_m",remd_m(1),
854 ctime call flush(iout)
855 write (iout,*) "remd_m(1)",remd_m(1)
858 i=ifirst(iran_num(1,remd_m(1)))
862 ctime call flush(iout)
867 write (iout,*) "i",i," nupa(0,i)",int(nupa(0,i))
869 if(i.gt.0.and.nupa(0,i).gt.0) then
871 c if (i.eq.1 .and. int(nupa(0,i)).eq.1) then
873 c & "CHUJ ABSOLUTNY!!! No way to sample a distinct replica in MREMD"
875 c call MPI_Abort(MPI_COMM_WORLD,ERRCODE,ierr)
877 c do while (iex.eq.i)
878 c write (iout,*) "upper",nupa(int(nupa(0,i)),i)
879 iex=nupa(iran_num(1,int(nupa(0,i))),i)
881 c write (iout,*) "nupa(0,i)",nupa(0,i)," iex",iex
883 call muca_delta(remd_t_bath,remd_ene,i,iex,delta)
885 c Swap temperatures between conformations i and iex with recalculating the free energies
886 c following temperature changes.
887 ene_iex_iex=remd_ene(0,iex)
888 ene_i_i=remd_ene(0,i)
889 c write (iout,*) "i",i," ene_i_i",ene_i_i,
890 c & " iex",iex," ene_iex_iex",ene_iex_iex
891 c write (iout,*) "rescaling weights with temperature",
894 call rescale_weights(remd_t_bath(i))
896 c write (iout,*) "0,iex",remd_t_bath(i)
897 c call enerprint(remd_ene(0,iex))
899 call sum_energy(remd_ene(0,iex),.false.)
900 ene_iex_i=remd_ene(0,iex)
901 c write (iout,*) "ene_iex_i",remd_ene(0,iex)
903 c write (iout,*) "0,i",remd_t_bath(i)
904 c call enerprint(remd_ene(0,i))
906 call sum_energy(remd_ene(0,i),.false.)
907 c write (iout,*) "ene_i_i",remd_ene(0,i)
909 c write (iout,*) "rescaling weights with temperature",
911 if (abs(ene_i_i-remd_ene(0,i)).gt.ene_tol) then
912 write (iout,*) "ERROR: inconsistent energies:",i,
913 & ene_i_i,remd_ene(0,i)
915 call rescale_weights(remd_t_bath(iex))
917 c write (iout,*) "0,i",remd_t_bath(iex)
918 c call enerprint(remd_ene(0,i))
920 call sum_energy(remd_ene(0,i),.false.)
921 c write (iout,*) "ene_i_iex",remd_ene(0,i)
923 ene_i_iex=remd_ene(0,i)
925 c write (iout,*) "0,iex",remd_t_bath(iex)
926 c call enerprint(remd_ene(0,iex))
928 call sum_energy(remd_ene(0,iex),.false.)
929 if (abs(ene_iex_iex-remd_ene(0,iex)).gt.ene_tol) then
930 write (iout,*) "ERROR: inconsistent energies:",iex,
931 & ene_iex_iex,remd_ene(0,iex)
933 c write (iout,*) "ene_iex_iex",remd_ene(0,iex)
934 c write (iout,*) "i",i," iex",iex
935 c write (iout,'(4(a,e15.5))') "ene_i_i",ene_i_i,
936 c & " ene_i_iex",ene_i_iex,
937 c & " ene_iex_i",ene_iex_i," ene_iex_iex",ene_iex_iex
939 delta=(ene_iex_iex-ene_i_iex)/(Rb*remd_t_bath(iex))-
940 & (ene_iex_i-ene_i_i)/(Rb*remd_t_bath(i))
942 c write(iout,*) 'delta',delta
943 c delta=(remd_t_bath(i)-remd_t_bath(iex))*
944 c & (remd_ene(i)-remd_ene(iex))/Rb/
945 c & (remd_t_bath(i)*remd_t_bath(iex))
947 if (delta .gt. 50.0d0) then
953 else if (delta.lt.-50.0d0) then
962 iremd_tot(int(i2rep(i-1)))=iremd_tot(int(i2rep(i-1)))+1
963 xxx=ran_number(0.0d0,1.0d0)
964 c write(iout,'(2i4,a6,2f12.5)') i,iex,' delta',delta,xxx
966 if (delta .gt. xxx) then
968 remd_t_bath(i)=remd_t_bath(iex)
970 remd_ene(0,i)=ene_i_iex
971 remd_ene(0,iex)=ene_iex_i
977 ehighi(i)=ehighi(iex)
984 nupa(k,i)=nupa(k,iex)
987 ndowna(k,i)=ndowna(k,iex)
991 if (ifirst(il).eq.i) ifirst(il)=iex
993 if (nupa(k,il).eq.i) then
995 elseif (nupa(k,il).eq.iex) then
1000 if (ndowna(k,il).eq.i) then
1002 elseif (ndowna(k,il).eq.iex) then
1008 iremd_acc(int(i2rep(i-1)))=iremd_acc(int(i2rep(i-1)))+1
1010 i2rep(i-1)=i2rep(iex-1)
1013 c write(iout,*) 'exchange',i,iex
1014 c write (iout,'(a8,100i4)') "@ ifirst",
1015 c & (ifirst(k),k=1,remd_m(1))
1017 c write (iout,'(a8,i4,a1,100i4)') "@ nupa",il,":",
1018 c & (nupa(k,il),k=1,nupa(0,il))
1019 c write (iout,'(a8,i4,a1,100i4)') "@ ndowna",il,":",
1020 c & (ndowna(k,il),k=1,ndowna(0,il))
1025 remd_ene(0,iex)=ene_iex_iex
1026 remd_ene(0,i)=ene_i_i
1032 cd write (iout,*) "exchange completed"
1034 ELSEIF (usampl.or.homol_nset.gt.1) THEN
1036 c write(iout,*) "########",ii
1038 i_temp=iran_num(1,nrep)
1039 i_mult=iran_num(1,remd_m(i_temp))
1040 i_iset=iran_num(1,nset)
1041 i_mset=iran_num(1,mset(i_iset))
1042 i=i_index(i_temp,i_mult,i_iset,i_mset)
1044 c write(iout,*) "i=",i,i_temp,i_mult,i_iset,i_mset
1046 if(t_exchange_only)then
1051 c write(iout,*) "i_dir=",i_dir
1053 if(i_dir.eq.1 .and. remd_m(i_temp+1).gt.0 )then
1056 i_mult1=iran_num(1,remd_m(i_temp1))
1058 i_mset1=iran_num(1,mset(i_iset1))
1059 iex=i_index(i_temp1,i_mult1,i_iset1,i_mset1)
1061 elseif(i_dir.eq.2 .and. mset(i_iset+1).gt.0)then
1064 i_mult1=iran_num(1,remd_m(i_temp1))
1066 i_mset1=iran_num(1,mset(i_iset1))
1067 iex=i_index(i_temp1,i_mult1,i_iset1,i_mset1)
1069 econstr_temp_i=remd_ene(i_econstr,i)
1070 econstr_temp_iex=remd_ene(i_econstr,iex)
1071 remd_ene(i_econstr,i)=remd_ene(n_ene+3,i)
1072 remd_ene(i_econstr,iex)=remd_ene(n_ene+4,iex)
1074 elseif(remd_m(i_temp+1).gt.0.and.mset(i_iset+1).gt.0)then
1077 i_mult1=iran_num(1,remd_m(i_temp1))
1079 i_mset1=iran_num(1,mset(i_iset1))
1080 iex=i_index(i_temp1,i_mult1,i_iset1,i_mset1)
1081 econstr_temp_i=remd_ene(i_econstr,i)
1082 econstr_temp_iex=remd_ene(i_econstr,iex)
1083 remd_ene(i_econstr,i)=remd_ene(n_ene+3,i)
1084 remd_ene(i_econstr,iex)=remd_ene(n_ene+4,iex)
1090 c write(iout,*) "iex=",iex,i_temp1,i_mult1,i_iset1,i_mset1
1091 ctime call flush(iout)
1093 c Swap temperatures between conformations i and iex with recalculating the free energies
1094 c following temperature changes.
1095 ene_iex_iex=remd_ene(0,iex)
1096 ene_i_i=remd_ene(0,i)
1097 co write (iout,*) "rescaling weights with temperature",
1099 call rescale_weights(remd_t_bath(i))
1101 call sum_energy(remd_ene(0,iex),.false.)
1102 ene_iex_i=remd_ene(0,iex)
1104 c ERROR only makes sense for dir =1
1105 c write (iout,*) "ene_iex_i",remd_ene(0,iex)
1106 c call sum_energy(remd_ene(0,i),.false.)
1107 c write (iout,*) "ene_i_i",remd_ene(0,i)
1108 c write (iout,*) "rescaling weights with temperature",
1109 c & remd_t_bath(iex)
1110 c if (real(ene_i_i).ne.real(remd_ene(0,i))) then
1111 c write (iout,*) "ERROR: inconsistent energies i:",i,
1112 c & ene_i_i,remd_ene(0,i)
1115 call rescale_weights(remd_t_bath(iex))
1116 call sum_energy(remd_ene(0,i),.false.)
1117 cd write (iout,*) "ene_i_iex",remd_ene(0,i)
1118 ene_i_iex=remd_ene(0,i)
1120 c ERROR only makes sense for dir =1
1121 c call sum_energy(remd_ene(0,iex),.false.)
1122 c if (real(ene_iex_iex).ne.real(remd_ene(0,iex))) then
1123 c write (iout,*) "ERROR: inconsistent energies iex:",iex,
1124 c & ene_iex_iex,remd_ene(0,iex)
1126 c write (iout,*) "ene_iex_iex",remd_ene(0,iex)
1127 c write (iout,*) "i",i," iex",iex
1128 c write (iout,'(4(a,e15.5))') "ene_i_i",ene_i_i,
1129 c & " ene_i_iex",ene_i_iex,
1130 c & " ene_iex_i",ene_iex_i," ene_iex_iex",ene_iex_iex
1132 delta=(ene_iex_iex-ene_i_iex)/(Rb*remd_t_bath(iex))-
1133 & (ene_iex_i-ene_i_i)/(Rb*remd_t_bath(i))
1135 c write(iout,*) 'delta',delta
1136 c delta=(remd_t_bath(i)-remd_t_bath(iex))*
1137 c & (remd_ene(i)-remd_ene(iex))/Rb/
1138 c & (remd_t_bath(i)*remd_t_bath(iex))
1139 if (delta .gt. 50.0d0) then
1144 if (i_dir.eq.1.or.i_dir.eq.3)
1145 & iremd_tot(int(i2rep(i-1)))=iremd_tot(int(i2rep(i-1)))+1
1146 if (i_dir.eq.2.or.i_dir.eq.3)
1147 & iremd_tot_usa(int(i2set(i-1)))=
1148 & iremd_tot_usa(int(i2set(i-1)))+1
1149 xxx=ran_number(0.0d0,1.0d0)
1150 c write(iout,'(2i4,a6,2f12.5)') i,iex,' delta',delta,xxx
1151 if (delta .gt. xxx) then
1153 remd_t_bath(i)=remd_t_bath(iex)
1154 remd_t_bath(iex)=tmp
1157 iremd_iset(i)=iremd_iset(iex)
1158 iremd_iset(iex)=itmp
1160 remd_ene(0,i)=ene_i_iex
1161 remd_ene(0,iex)=ene_iex_i
1163 if (i_dir.eq.1.or.i_dir.eq.3)
1164 & iremd_acc(int(i2rep(i-1)))=iremd_acc(int(i2rep(i-1)))+1
1167 i2rep(i-1)=i2rep(iex-1)
1170 if (i_dir.eq.2.or.i_dir.eq.3)
1171 & iremd_acc_usa(int(i2set(i-1)))=
1172 & iremd_acc_usa(int(i2set(i-1)))+1
1175 i2set(i-1)=i2set(iex-1)
1178 itmp=i_index(i_temp,i_mult,i_iset,i_mset)
1179 i_index(i_temp,i_mult,i_iset,i_mset)=
1180 & i_index(i_temp1,i_mult1,i_iset1,i_mset1)
1181 i_index(i_temp1,i_mult1,i_iset1,i_mset1)=itmp
1184 remd_ene(0,iex)=ene_iex_iex
1185 remd_ene(0,i)=ene_i_i
1186 remd_ene(i_econstr,iex)=econstr_temp_iex
1187 remd_ene(i_econstr,i)=econstr_temp_i
1191 cd do il1=1,mset(il)
1194 cd write(iout,*) i,j,il,il1,i_index(i,j,il,il1)
1207 c-------------------------------------
1208 write (iout,*) "NREP",nrep
1210 if(iremd_tot(i).ne.0)
1211 & write(iout,'(a3,i4,2f12.5,i5)') 'ACC',i,remd_t(i)
1212 & ,iremd_acc(i)/(1.0*iremd_tot(i)),iremd_tot(i)
1215 if(usampl.or.homol_nset.gt.1) then
1217 if(iremd_tot_usa(i).ne.0)
1218 & write(iout,'(a10,i4,f12.5,i8)') 'ACC_usampl',i,
1219 & iremd_acc_usa(i)/(1.0*iremd_tot_usa(i)),iremd_tot_usa(i)
1225 cd write (iout,'(a6,100i4)') "ifirst",
1226 cd & (ifirst(i),i=1,remd_m(1))
1228 cd write (iout,'(a5,i4,a1,100i4)') "nup",il,":",
1229 cd & (nupa(i,il),i=1,nupa(0,il))
1230 cd write (iout,'(a5,i4,a1,100i4)') "ndown",il,":",
1231 cd & (ndowna(i,il),i=1,ndowna(0,il))
1236 cd write (iout,*) "Before scatter"
1238 call mpi_scatter(remd_t_bath,1,mpi_double_precision,
1239 & t_bath,1,mpi_double_precision,king,
1241 cd write (iout,*) "After scatter"
1243 if(usampl.or.hremd.gt.0.or.homol_nset.gt.1) then
1244 call mpi_scatter(iremd_iset,1,mpi_integer,
1245 & iset,1,mpi_integer,king,
1247 c 8/31/2015 Correction by AL: send new iset to slaves
1248 if (nfgtasks.gt.1) then
1249 call MPI_Bcast(11,1,MPI_INTEGER,king,FG_COMM,IERROR)
1250 call MPI_Bcast(iset,1,MPI_INTEGER,king,FG_COMM,IERROR)
1256 if (me.eq.king .or. .not. out1file) then
1257 write(iout,*) 'REMD scatter time=',time07-time06
1261 call mpi_scatter(elowi,1,mpi_double_precision,
1262 & elow,1,mpi_double_precision,king,
1264 call mpi_scatter(ehighi,1,mpi_double_precision,
1265 & ehigh,1,mpi_double_precision,king,
1268 call rescale_weights(t_bath)
1269 co write (iout,*) "Processor",me,
1270 co & " rescaling weights with temperature",t_bath
1272 stdfp=dsqrt(2*Rb*t_bath/d_time)
1274 stdfsc(i)=dsqrt(2*Rb*t_bath/d_time)
1277 cde write(iout,*) 'REMD after',me,t_bath
1279 if (me.eq.king .or. .not. out1file) then
1280 write(iout,*) 'REMD exchange time=',time08-time02
1281 ctime call flush(iout)
1286 if (restart1file) then
1287 if (me.eq.king .or. .not. out1file)
1288 & write(iout,*) 'writing restart at the end of run'
1289 call write1rst(i_index)
1292 if (traj1file) call write1traj
1294 cdeb call mpi_gather(ntwx_cache,1,mpi_integer,
1295 cdeb & icache_all,1,mpi_integer,king,
1296 cdeb & CG_COMM,ierr)
1297 cdeb write(iout,'(a40,8000i8)')
1298 cdeb & ' ntwx_cache after traj1file at the end',
1299 cdeb & (icache_all(i),i=1,nodes)
1304 t_MD=MPI_Wtime()-tt0
1308 if (me.eq.king .or. .not. out1file) then
1309 write (iout,'(//35(1h=),a10,35(1h=)/10(/a40,1pe15.5))')
1311 & 'MD calculations setup:',t_MDsetup,
1312 & 'Energy & gradient evaluation:',t_enegrad,
1313 & 'Stochastic MD setup:',t_langsetup,
1314 & 'Stochastic MD step setup:',t_sdsetup,
1316 write (iout,'(/28(1h=),a25,27(1h=))')
1317 & ' End of MD calculation '
1322 c-----------------------------------------------------------------------
1323 subroutine write1rst(i_index)
1324 implicit real*8 (a-h,o-z)
1325 include 'DIMENSIONS'
1328 include 'COMMON.IOUNITS'
1329 include 'COMMON.REMD'
1330 include 'COMMON.SETUP'
1331 include 'COMMON.CHAIN'
1332 include 'COMMON.SBRIDGE'
1333 include 'COMMON.INTERACT'
1334 include 'COMMON.CONTROL'
1336 real d_restart1(3,2*maxres*maxprocs),r_d(3,2*maxres),
1337 & d_restart2(3,2*maxres*maxprocs)
1341 & (maxprocs/4,maxprocs/20,maxprocs/200,maxprocs/200)
1342 common /przechowalnia/ d_restart1,d_restart2
1347 t5_restart1(4)=t_bath
1348 t5_restart1(5)=Uconst
1350 call mpi_gather(t5_restart1,5,mpi_real,
1351 & t_restart1,5,mpi_real,king,CG_COMM,ierr)
1359 call mpi_gather(r_d,3*2*nres,mpi_real,
1360 & d_restart1,3*2*nres,mpi_real,king,
1369 call mpi_gather(r_d,3*2*nres,mpi_real,
1370 & d_restart2,3*2*nres,mpi_real,king,
1375 call xdrfopen_(ixdrf,mremd_rst_name, "w", iret)
1377 call xdrfint_(ixdrf, i2rep(i), iret)
1380 call xdrfint_(ixdrf, ifirst(i), iret)
1384 call xdrfint_(ixdrf, nupa(i,il), iret)
1388 call xdrfint_(ixdrf, ndowna(i,il), iret)
1394 call xdrffloat_(ixdrf, t_restart1(j,il), iret)
1401 call xdrffloat_(ixdrf, d_restart1(j,i+2*nres*il), iret)
1408 call xdrffloat_(ixdrf, d_restart2(j,i+2*nres*il), iret)
1413 if(usampl.or.homol_nset.gt.1) then
1414 call xdrfint_(ixdrf, nset, iret)
1416 call xdrfint_(ixdrf,mset(i), iret)
1419 call xdrfint_(ixdrf,i2set(i), iret)
1425 itmp=i_index(i,j,il,il1)
1426 call xdrfint_(ixdrf,itmp, iret)
1433 call xdrfclose_(ixdrf, iret)
1435 call xdrfopen(ixdrf,mremd_rst_name, "w", iret)
1437 call xdrfint(ixdrf, i2rep(i), iret)
1440 call xdrfint(ixdrf, ifirst(i), iret)
1444 call xdrfint(ixdrf, nupa(i,il), iret)
1448 call xdrfint(ixdrf, ndowna(i,il), iret)
1454 call xdrffloat(ixdrf, t_restart1(j,il), iret)
1461 call xdrffloat(ixdrf, d_restart1(j,i+2*nres*il), iret)
1468 call xdrffloat(ixdrf, d_restart2(j,i+2*nres*il), iret)
1474 if(usampl.or.homol_nset.gt.1) then
1475 call xdrfint(ixdrf, nset, iret)
1477 call xdrfint(ixdrf,mset(i), iret)
1480 call xdrfint(ixdrf,i2set(i), iret)
1486 itmp=i_index(i,j,il,il1)
1487 call xdrfint(ixdrf,itmp, iret)
1494 call xdrfclose(ixdrf, iret)
1501 subroutine write1traj
1502 implicit real*8 (a-h,o-z)
1503 include 'DIMENSIONS'
1506 include 'COMMON.IOUNITS'
1507 include 'COMMON.REMD'
1508 include 'COMMON.SETUP'
1509 include 'COMMON.CHAIN'
1510 include 'COMMON.SBRIDGE'
1511 include 'COMMON.INTERACT'
1515 real xcoord(3,maxres2+2),prec
1516 real r_qfrag(50),r_qpair(100)
1517 real r_utheta(50),r_ugamma(100),r_uscdiff(100)
1518 real p_qfrag(50*maxprocs),p_qpair(100*maxprocs)
1519 real p_utheta(50*maxprocs),p_ugamma(100*maxprocs),
1520 & p_uscdiff(100*maxprocs)
1521 real p_c(3,(maxres2+2)*maxprocs),r_c(3,maxres2+2)
1522 common /przechowalnia/ p_c
1524 call mpi_bcast(ii_write,1,mpi_integer,
1525 & king,CG_COMM,ierr)
1528 print *,'traj1file',me,ii_write,ntwx_cache
1532 if(me.eq.king) call xdrfopen_(ixdrf,cartname, "a", iret)
1534 if(me.eq.king) call xdrfopen(ixdrf,cartname, "a", iret)
1537 t5_restart1(1)=totT_cache(ii)
1538 t5_restart1(2)=EK_cache(ii)
1539 t5_restart1(3)=potE_cache(ii)
1540 t5_restart1(4)=t_bath_cache(ii)
1541 t5_restart1(5)=Uconst_cache(ii)
1542 call mpi_gather(t5_restart1,5,mpi_real,
1543 & t_restart1,5,mpi_real,king,CG_COMM,ierr)
1545 call mpi_gather(iset_cache(ii),1,mpi_integer,
1546 & iset_restart1,1,mpi_integer,king,CG_COMM,ierr)
1549 r_qfrag(i)=qfrag_cache(i,ii)
1552 r_qpair(i)=qpair_cache(i,ii)
1555 r_utheta(i)=utheta_cache(i,ii)
1556 r_ugamma(i)=ugamma_cache(i,ii)
1557 r_uscdiff(i)=uscdiff_cache(i,ii)
1560 call mpi_gather(r_qfrag,nfrag,mpi_real,
1561 & p_qfrag,nfrag,mpi_real,king,
1563 call mpi_gather(r_qpair,npair,mpi_real,
1564 & p_qpair,npair,mpi_real,king,
1566 call mpi_gather(r_utheta,nfrag_back,mpi_real,
1567 & p_utheta,nfrag_back,mpi_real,king,
1569 call mpi_gather(r_ugamma,nfrag_back,mpi_real,
1570 & p_ugamma,nfrag_back,mpi_real,king,
1572 call mpi_gather(r_uscdiff,nfrag_back,mpi_real,
1573 & p_uscdiff,nfrag_back,mpi_real,king,
1577 write (iout,*) "p_qfrag"
1579 write (iout,*) i,(p_qfrag((i-1)*nfrag+j),j=1,nfrag)
1581 write (iout,*) "p_qpair"
1583 write (iout,*) i,(p_qpair((i-1)*npair+j),j=1,npair)
1589 r_c(j,i)=c_cache(j,i,ii)
1593 call mpi_gather(r_c,3*2*nres,mpi_real,
1594 & p_c,3*2*nres,mpi_real,king,
1600 call xdrffloat_(ixdrf, real(t_restart1(1,il)), iret)
1601 call xdrffloat_(ixdrf, real(t_restart1(3,il)), iret)
1602 call xdrffloat_(ixdrf, real(t_restart1(5,il)), iret)
1603 call xdrffloat_(ixdrf, real(t_restart1(4,il)), iret)
1604 call xdrfint_(ixdrf, nss, iret)
1607 call xdrfint_(ixdrf, idssb(j)+nres, iret)
1608 call xdrfint_(ixdrf, jdssb(j)+nres, iret)
1610 call xdrfint_(ixdrf, ihpb(j), iret)
1611 call xdrfint_(ixdrf, jhpb(j), iret)
1614 call xdrfint_(ixdrf, nfrag+npair+3*nfrag_back, iret)
1615 call xdrfint_(ixdrf, iset_restart1(il), iret)
1617 call xdrffloat_(ixdrf, p_qfrag(i+(il-1)*nfrag), iret)
1620 call xdrffloat_(ixdrf, p_qpair(i+(il-1)*npair), iret)
1623 call xdrffloat_(ixdrf, p_utheta(i+(il-1)*nfrag_back), iret)
1624 call xdrffloat_(ixdrf, p_ugamma(i+(il-1)*nfrag_back), iret)
1625 call xdrffloat_(ixdrf, p_uscdiff(i+(il-1)*nfrag_back), iret)
1630 xcoord(j,i)=p_c(j,i+(il-1)*nres*2)
1635 xcoord(j,nres+i-nnt+1)=p_c(j,i+nres+(il-1)*nres*2)
1639 call xdrf3dfcoord_(ixdrf, xcoord, itmp, prec, iret)
1643 call xdrffloat(ixdrf, real(t_restart1(1,il)), iret)
1644 call xdrffloat(ixdrf, real(t_restart1(3,il)), iret)
1645 call xdrffloat(ixdrf, real(t_restart1(5,il)), iret)
1646 call xdrffloat(ixdrf, real(t_restart1(4,il)), iret)
1647 call xdrfint(ixdrf, nss, iret)
1650 call xdrfint(ixdrf, idssb(j)+nres, iret)
1651 call xdrfint(ixdrf, jdssb(j)+nres, iret)
1653 call xdrfint(ixdrf, ihpb(j), iret)
1654 call xdrfint(ixdrf, jhpb(j), iret)
1657 call xdrfint(ixdrf, nfrag+npair+3*nfrag_back, iret)
1658 call xdrfint(ixdrf, iset_restart1(il), iret)
1660 call xdrffloat(ixdrf, p_qfrag(i+(il-1)*nfrag), iret)
1663 call xdrffloat(ixdrf, p_qpair(i+(il-1)*npair), iret)
1666 call xdrffloat(ixdrf, p_utheta(i+(il-1)*nfrag_back), iret)
1667 call xdrffloat(ixdrf, p_ugamma(i+(il-1)*nfrag_back), iret)
1668 call xdrffloat(ixdrf, p_uscdiff(i+(il-1)*nfrag_back), iret)
1673 xcoord(j,i)=p_c(j,i+(il-1)*nres*2)
1678 xcoord(j,nres+i-nnt+1)=p_c(j,i+nres+(il-1)*nres*2)
1682 call xdrf3dfcoord(ixdrf, xcoord, itmp, prec, iret)
1688 if(me.eq.king) call xdrfclose_(ixdrf, iret)
1690 if(me.eq.king) call xdrfclose(ixdrf, iret)
1692 do i=1,ntwx_cache-ii_write
1694 totT_cache(i)=totT_cache(ii_write+i)
1695 EK_cache(i)=EK_cache(ii_write+i)
1696 potE_cache(i)=potE_cache(ii_write+i)
1697 t_bath_cache(i)=t_bath_cache(ii_write+i)
1698 Uconst_cache(i)=Uconst_cache(ii_write+i)
1699 iset_cache(i)=iset_cache(ii_write+i)
1702 qfrag_cache(ii,i)=qfrag_cache(ii,ii_write+i)
1705 qpair_cache(ii,i)=qpair_cache(ii,ii_write+i)
1708 utheta_cache(ii,i)=utheta_cache(ii,ii_write+i)
1709 ugamma_cache(ii,i)=ugamma_cache(ii,ii_write+i)
1710 uscdiff_cache(ii,i)=uscdiff_cache(ii,ii_write+i)
1715 c_cache(j,ii,i)=c_cache(j,ii,ii_write+i)
1719 ntwx_cache=ntwx_cache-ii_write
1724 subroutine read1restart(i_index)
1725 implicit real*8 (a-h,o-z)
1726 include 'DIMENSIONS'
1729 include 'COMMON.IOUNITS'
1730 include 'COMMON.REMD'
1731 include 'COMMON.SETUP'
1732 include 'COMMON.CHAIN'
1733 include 'COMMON.SBRIDGE'
1734 include 'COMMON.INTERACT'
1735 include 'COMMON.CONTROL'
1736 real d_restart1(3,2*maxres*maxprocs),r_d(3,2*maxres),
1739 & (maxprocs/4,maxprocs/20,maxprocs/200,maxprocs/200)
1740 common /przechowalnia/ d_restart1
1741 write (*,*) "Processor",me," called read1restart"
1744 open(irest2,file=mremd_rst_name,status='unknown')
1745 read(irest2,*,err=334) i
1746 write(iout,*) "Reading old rst in ASCI format"
1748 call read1restart_old
1752 call xdrfopen_(ixdrf,mremd_rst_name, "r", iret)
1755 call xdrfint_(ixdrf, i2rep(i), iret)
1758 call xdrfint_(ixdrf, ifirst(i), iret)
1761 call xdrfint_(ixdrf, nupa(0,il), iret)
1763 call xdrfint_(ixdrf, nupa(i,il), iret)
1766 call xdrfint_(ixdrf, ndowna(0,il), iret)
1768 call xdrfint_(ixdrf, ndowna(i,il), iret)
1773 call xdrffloat_(ixdrf, t_restart1(j,il), iret)
1777 call xdrfopen(ixdrf,mremd_rst_name, "r", iret)
1780 call xdrfint(ixdrf, i2rep(i), iret)
1783 call xdrfint(ixdrf, ifirst(i), iret)
1786 call xdrfint(ixdrf, nupa(0,il), iret)
1788 call xdrfint(ixdrf, nupa(i,il), iret)
1791 call xdrfint(ixdrf, ndowna(0,il), iret)
1793 call xdrfint(ixdrf, ndowna(i,il), iret)
1798 call xdrffloat(ixdrf, t_restart1(j,il), iret)
1803 call mpi_scatter(t_restart1,5,mpi_real,
1804 & t5_restart1,5,mpi_real,king,CG_COMM,ierr)
1808 t_bath=t5_restart1(4)
1813 c read(irest2,'(3e15.5)')
1814 c & (d_restart1(j,i+2*nres*il),j=1,3)
1817 call xdrffloat_(ixdrf, d_restart1(j,i+2*nres*il), iret)
1819 call xdrffloat(ixdrf, d_restart1(j,i+2*nres*il), iret)
1824 write (iout,*) "Conformation read",il
1826 write (iout,'(i5,3f10.5,5x,3f10.5)')
1827 & i,(d_restart1(j,i+2*nres*il),j=1,3),
1828 & (d_restart1(j,nres+i+2*nres*il),j=1,3)
1833 call mpi_scatter(d_restart1,3*2*nres,mpi_real,
1834 & r_d,3*2*nres,mpi_real,king,CG_COMM,ierr)
1844 c read(irest2,'(3e15.5)')
1845 c & (d_restart1(j,i+2*nres*il),j=1,3)
1848 call xdrffloat_(ixdrf, d_restart1(j,i+2*nres*il), iret)
1850 call xdrffloat(ixdrf, d_restart1(j,i+2*nres*il), iret)
1856 call mpi_scatter(d_restart1,3*2*nres,mpi_real,
1857 & r_d,3*2*nres,mpi_real,king,CG_COMM,ierr)
1865 if(usampl.or.homol_nset.gt.1) then
1868 call xdrfint_(ixdrf, nset, iret)
1870 call xdrfint_(ixdrf,mset(i), iret)
1873 call xdrfint_(ixdrf,i2set(i), iret)
1879 call xdrfint_(ixdrf,itmp, iret)
1880 i_index(i,j,il,il1)=itmp
1888 call xdrfint(ixdrf, nset, iret)
1890 call xdrfint(ixdrf,mset(i), iret)
1893 call xdrfint(ixdrf,i2set(i), iret)
1899 call xdrfint(ixdrf,itmp, iret)
1900 i_index(i,j,il,il1)=itmp
1907 c Corrected AL 8/19/2014: each processor needs whole iset array not only its
1909 c call mpi_scatter(i2set,1,mpi_integer,
1910 c & iset,1,mpi_integer,king,
1912 call mpi_bcast(i2set(0),nodes,mpi_integer,king,
1915 c broadcast iset to slaves
1916 if (nfgtasks.gt.1) then
1917 call MPI_Bcast(11,1,MPI_INTEGER,king,FG_COMM,IERROR)
1918 call MPI_Bcast(iset,1,MPI_INTEGER,king,FG_COMM,IERROR)
1923 if(me.eq.king) close(irest2)
1927 subroutine read1restart_old
1928 implicit real*8 (a-h,o-z)
1929 include 'DIMENSIONS'
1932 include 'COMMON.IOUNITS'
1933 include 'COMMON.REMD'
1934 include 'COMMON.SETUP'
1935 include 'COMMON.CHAIN'
1936 include 'COMMON.SBRIDGE'
1937 include 'COMMON.INTERACT'
1938 real d_restart1(3,2*maxres*maxprocs),r_d(3,2*maxres),
1940 common /przechowalnia/ d_restart1
1942 open(irest2,file=mremd_rst_name,status='unknown')
1943 read (irest2,*) (i2rep(i),i=0,nodes-1)
1944 read (irest2,*) (ifirst(i),i=1,remd_m(1))
1946 read (irest2,*) nupa(0,il),(nupa(i,il),i=1,nupa(0,il))
1947 read (irest2,*) ndowna(0,il),
1948 & (ndowna(i,il),i=1,ndowna(0,il))
1951 read(irest2,*) (t_restart1(j,il),j=1,4)
1954 call mpi_scatter(t_restart1,5,mpi_real,
1955 & t5_restart1,5,mpi_real,king,CG_COMM,ierr)
1959 t_bath=t5_restart1(4)
1964 read(irest2,'(3e15.5)')
1965 & (d_restart1(j,i+2*nres*il),j=1,3)
1969 call mpi_scatter(d_restart1,3*2*nres,mpi_real,
1970 & r_d,3*2*nres,mpi_real,king,CG_COMM,ierr)
1980 read(irest2,'(3e15.5)')
1981 & (d_restart1(j,i+2*nres*il),j=1,3)
1985 call mpi_scatter(d_restart1,3*2*nres,mpi_real,
1986 & r_d,3*2*nres,mpi_real,king,CG_COMM,ierr)
1992 if(me.eq.king) close(irest2)
1995 c------------------------------------------