2 C Does modified entropic sampling in the space of minima.
3 implicit real*8 (a-h,o-z)
5 include 'COMMON.IOUNITS'
10 include 'COMMON.CHAIN'
13 include 'COMMON.CONTACTS'
14 include 'COMMON.CONTROL'
16 include 'COMMON.INTERACT'
17 include 'COMMON.THREAD'
18 include 'COMMON.NAMES'
19 logical accepted,not_done,over,ovrtim,error,lprint
20 integer MoveType,nbond
22 double precision RandOrPert
23 double precision varia(maxvar),elowest,ehighest,eold
24 double precision przes(3),obr(3,3)
25 double precision varold(maxvar)
27 double precision energia(0:n_ene),energia_ave(0:n_ene)
29 cd write (iout,*) 'print_mc=',print_mc
32 c---------------------------------------------------------------------------
33 C Initialize counters.
34 c---------------------------------------------------------------------------
35 C Total number of generated confs.
37 C Total number of moves. In general this won't be equal to the number of
38 C attempted moves, because we may want to reject some "bad" confs just by
41 C Total number of shift (nbond_move(1)), spike, crankshaft, three-bond,...
46 C Initialize total and accepted number of moves of various kind.
51 C Total number of energy evaluations.
57 facee=1.0D0/(maxacc*delte)
59 C Read entropy from previous simulations.
61 read (ientin,*) indminn,indmaxx,emin,emax
62 print *,'indminn=',indminn,' indmaxx=',indmaxx,' emin=',emin,
65 entropy(i)=(emin+i*delte)*betbol
67 read (ientin,*) (ijunk,ejunk,entropy(i),i=indminn,indmaxx)
70 write (iout,*) 'indminn=',indminn,' indmaxx=',indmaxx,
71 & ' emin=',emin,' emax=',emax
72 write (iout,'(/a)') 'Initial entropy'
74 write (iout,'(i5,2f10.5)') i,emin+i*delte,entropy(i)
77 C Read the pool of conformations
79 C----------------------------------------------------------------------------
80 C Entropy-sampling simulations with continually updated entropy
81 C Loop thru simulations
82 C----------------------------------------------------------------------------
84 C----------------------------------------------------------------------------
85 C Take a conformation from the pool
86 C----------------------------------------------------------------------------
92 write (iout,*) 'Took conformation',ii,' from the pool energy=',
94 call var_to_geom(nvar,varia)
95 C Print internal coordinates of the initial conformation
98 call gen_rand_conf(1,*20)
100 C----------------------------------------------------------------------------
101 C Compute and print initial energies.
102 C----------------------------------------------------------------------------
105 if (MyID.eq.MasterID) then
113 write (iout,'(/80(1h*)/a,i2/80(1h*)/)') 'MCE iteration #',isweep
114 write (iout,'(/80(1h*)/a)') 'Initial energies:'
116 call etotal(energia(0))
118 call enerprint(energia(0))
119 C Minimize the energy of the first conformation.
121 call geom_to_var(nvar,varia)
122 call minimize(etot,varia,iretcode,nfun)
123 call etotal(energia(0))
125 write (iout,'(/80(1h*)/a/80(1h*))')
126 & 'Results of the first energy minimization:'
127 call enerprint(energia(0))
131 call fitsq(rms,c(1,nstart_seq),cref(1,nstart_sup,kkk),
135 call contact(.false.,ncont,icont,co)
136 frac=contact_fract(ncont,ncont_ref,icont,icont_ref)
137 write (iout,'(a,f8.3,a,f8.3,a,f8.3)')
138 & 'RMS deviation from the reference structure:',rms,
139 & ' % of native contacts:',frac*100,' contact order:',co
140 write (istat,'(i5,11(1pe14.5))') 0,
141 & (energia(print_order(i)),i=1,nprint_ene),etot,rms,frac,co
143 write (istat,'(i5,9(1pe14.5))') 0,
144 & (energia(print_order(i)),i=1,nprint_ene),etot
147 neneval=neneval+nfun+1
148 if (.not. ent_read) then
149 C Initialize the entropy array
150 do i=-max_ene,max_ene
152 C Uncomment the line below for actual entropic sampling (start with uniform
153 C energy distribution).
155 C Uncomment the line below for multicanonical sampling (start with Boltzmann
157 entropy(i)=(emin+i*delte)*betbol
161 write (iout,'(/a)') 'Initial entropy'
163 write (iout,'(i5,2f10.5)') i,emin+i*delte,entropy(i)
167 call recv_stop_sig(Kwita)
168 if (whatsup.eq.1) then
169 call send_stop_sig(-2)
171 else if (whatsup.le.-2) then
173 else if (whatsup.eq.2) then
179 not_done = (iretcode.ne.11)
181 write (iout,'(/80(1h*)/20x,a/80(1h*))')
182 & 'Enter Monte Carlo procedure.'
184 call briefout(0,etot)
189 indeold=(eold-emin)/delte
190 deix=eold-(emin+indeold*delte)
191 dent=entropy(indeold+1)-entropy(indeold)
192 cd write (iout,*) 'indeold=',indeold,' deix=',deix,' dent=',dent
193 cd write (*,*) 'Processor',MyID,' indeold=',indeold,' deix=',deix,
195 sold=entropy(indeold)+(dent/delte)*deix
197 write (iout,*) 'eold=',eold,' sold=',sold,' elowest=',etot
198 write (*,*) 'Processor',MyID,' eold=',eold,' sold=',sold,
200 if (minim) call zapis(varia,etot)
202 C NACC is the counter for the accepted conformations of a given processor
204 C NACC_TOT counts the total number of accepted conformations
207 if (MyID.eq.MasterID) then
208 call receive_MCM_info
210 call send_MCM_info(2)
213 do iene=indminn,indmaxx
220 c----------------------------------------------------------------------------
226 if (print_mc.gt.0) write (iout,'(80(1h*)/20x,a,i7)')
227 & 'Beginning iteration #',it
228 C Initialize local counter.
229 ntrial=0 ! # of generated non-overlapping confs.
230 noverlap=0 ! # of overlapping confs.
232 do while (.not. accepted .and. WhatsUp.eq.0 .and. Kwita.eq.0)
234 C Retrieve the angles of previously accepted conformation
238 cd write (iout,'(a)') 'Old variables:'
239 cd write (iout,'(10f8.1)') (rad2deg*varia(i),i=1,nvar)
240 call var_to_geom(nvar,varia)
246 C Decide whether to generate a random conformation or perturb the old one
247 RandOrPert=ran_number(0.0D0,1.0D0)
248 if (RandOrPert.gt.RanFract) then
250 & write (iout,'(a)') 'Perturbation-generated conformation.'
251 call perturb(error,lprint,MoveType,nbond,1.0D0)
253 if (MoveType.lt.1 .or. MoveType.gt.MaxMoveType) then
254 write (iout,'(/a,i7,a/)') 'Error - unknown MoveType=',
255 & MoveType,' returned from PERTURB.'
262 nstart_grow=iran_num(3,nres)
264 & write (iout,'(2a,i3)') 'Random-generated conformation',
265 & ' - chain regrown from residue',nstart_grow
266 call gen_rand_conf(nstart_grow,*30)
268 call geom_to_var(nvar,varia)
269 cd write (iout,'(a)') 'New variables:'
270 cd write (iout,'(10f8.1)') (rad2deg*varia(i),i=1,nvar)
272 if (print_mc.gt.0) write (iout,'(a,i5,a,i10,a,i10)')
273 & 'Processor',MyId,' trial move',ntrial,' total generated:',ngen
274 if (print_mc.gt.0) write (*,'(a,i5,a,i10,a,i10)')
275 & 'Processor',MyId,' trial move',ntrial,' total generated:',ngen
276 call etotal(energia(0))
278 c call enerprint(energia(0))
279 c write (iout,'(2(a,1pe14.5))') 'Etot=',Etot,' Elowest=',Elowest
280 if (etot-elowest.gt.overlap_cut) then
281 write (iout,'(a,i5,a,1pe14.5)') 'Iteration',it,
282 & ' Overlap detected in the current conf.; energy is',etot
286 if (noverlap.gt.maxoverlap) then
287 write (iout,'(a)') 'Too many overlapping confs.'
292 call minimize(etot,varia,iretcode,nfun)
293 cd write (iout,'(a)') 'Variables after minimization:'
294 cd write (iout,'(10f8.1)') (rad2deg*varia(i),i=1,nvar)
295 call etotal(energia(0))
297 neneval=neneval+nfun+1
299 if (print_mc.gt.2) then
300 write (iout,'(a)') 'Total energies of trial conf:'
301 call enerprint(energia(0))
302 else if (print_mc.eq.1) then
303 write (iout,'(a,i6,a,1pe16.6)')
304 & 'Trial conformation:',ngen,' energy:',etot
306 C--------------------------------------------------------------------------
308 C--------------------------------------------------------------------------
311 & call accepting(etot,eold,scur,sold,varia,varold,
316 if (elowest.gt.etot) elowest=etot
317 if (ehighest.lt.etot) ehighest=etot
318 moves_acc(MoveType)=moves_acc(MoveType)+1
319 if (MoveType.eq.1) then
320 nbond_acc(nbond)=nbond_acc(nbond)+1
322 C Check against conformation repetitions.
323 irep=conf_comp(varia,etot)
324 #if defined(AIX) || defined(PGI)
325 open (istat,file=statname,position='append')
327 open (istat,file=statname,access='append')
331 call fitsq(rms,c(1,nstart_seq),cref(1,nstart_sup,kkk),
333 & przes,obr,non_conv)
335 call contact(.false.,ncont,icont,co)
336 frac=contact_fract(ncont,ncont_ref,icont,icont_ref)
338 & write (iout,'(a,f8.3,a,f8.3,a,f8.3)')
339 & 'RMS deviation from the reference structure:',rms,
340 & ' % of native contacts:',frac*100,' contact order:',co
342 & write (istat,'(i5,11(1pe14.5))') it,
343 & (energia(print_order(i)),i=1,nprint_ene),etot,
345 elseif (print_stat) then
346 write (istat,'(i5,10(1pe14.5))') it,
347 & (energia(print_order(i)),i=1,nprint_ene),etot
351 & call statprint(nacc,nfun,iretcode,etot,elowest)
352 C Print internal coordinates.
353 if (print_int) call briefout(nacc,etot)
355 if (MyID.ne.MasterID) then
356 call recv_stop_sig(Kwita)
357 cd print *,'Processor:',MyID,' STOP=',Kwita
359 call send_MCM_info(2)
361 call send_MCM_info(1)
365 C Store the accepted conf. and its energy.
373 cd write (iout,*) 'Accepted conformation:'
374 cd write (iout,*) (rad2deg*varia(i),i=1,nphi)
375 if (minim) call zapis(varia,etot)
377 ener(i,nsave)=energia(i)
379 ener(n_ene+1,nsave)=etot
380 ener(n_ene+2,nsave)=frac
382 nminima(irep)=nminima(irep)+1.0D0
383 c print *,'irep=',irep,' nminima=',nminima(irep)
385 if (Kwita.eq.0) call recv_stop_sig(kwita)
390 if (MyID.eq.MasterID) then
391 call receive_MCM_info
392 if (nacc_tot.ge.maxacc) accepted=.true.
395 if (ntrial.gt.maxtrial_iter .and. npool.gt.0) then
396 C Take a conformation from the pool
401 write (iout,*) 'Iteration',it,' max. # of trials exceeded.'
403 & 'Take conformation',ii,' from the pool energy=',epool(ii)
405 & write (iout,'(10f8.3)') (rad2deg*varia(i),i=1,nvar)
407 endif ! (ntrial.gt.maxtrial_iter .and. npool.gt.0)
411 if (MyID.eq.MasterID) then
412 call receive_MCM_info
414 if (Kwita.eq.0) call recv_stop_sig(kwita)
416 if (ovrtim()) WhatsUp=-1
417 cd write (iout,*) 'WhatsUp=',WhatsUp,' Kwita=',Kwita
418 not_done = (nacc_tot.lt.maxacc) .and. (WhatsUp.eq.0)
420 cd write (iout,*) 'not_done=',not_done
423 print *,'Processor',MyID,
424 & ' has received STOP signal =',Kwita,' in EntSamp.'
425 cd print *,'not_done=',not_done
426 if (Kwita.lt.-1) WhatsUp=Kwita
427 else if (nacc_tot.ge.maxacc) then
428 print *,'Processor',MyID,' calls send_stop_sig,',
429 & ' because a sufficient # of confs. have been collected.'
430 cd print *,'not_done=',not_done
431 call send_stop_sig(-1)
432 else if (WhatsUp.eq.-1) then
433 print *,'Processor',MyID,
434 & ' calls send_stop_sig because of timeout.'
435 cd print *,'not_done=',not_done
436 call send_stop_sig(-2)
441 C-----------------------------------------------------------------
442 C... Construct energy histogram & update entropy
443 C-----------------------------------------------------------------
447 write (iout,*) 'Processor',MyID,
448 & ' is broadcasting ERROR-STOP signal.'
449 write (*,*) 'Processor',MyID,
450 & ' is broadcasting ERROR-STOP signal.'
451 call send_stop_sig(-3)
455 if (MyID.eq.MasterID) then
456 c call receive_MCM_results
457 call receive_energies
460 if (esave(i).lt.elowest) elowest=esave(i)
461 if (esave(i).gt.ehighest) ehighest=esave(i)
463 write (iout,'(a,i10)') '# of accepted confs:',nacc_tot
464 write (iout,'(a,f10.5,a,f10.5)') 'Lowest energy:',elowest,
465 & ' Highest energy',ehighest
466 if (isweep.eq.1 .and. .not.ent_read) then
469 write (iout,*) 'EMAX=',emax
471 indmaxx=(ehighest-emin)/delte
474 do i=-max_ene,max_ene
475 entropy(i)=(emin+i*delte)*betbol
479 indmin=(elowest-emin)/delte
480 indmax=(ehighest-emin)/delte
481 if (indmin.lt.indminn) indminn=indmin
482 if (indmax.gt.indmaxx) indmaxx=indmax
484 write(iout,*)'indminn=',indminn,' indmaxx=',indmaxx
485 C Construct energy histogram
487 inde=(esave(i)-emin)/delte
488 nhist(inde)=nhist(inde)+nminima(i)
490 C Update entropy (density of states)
492 if (nhist(i).gt.0) then
493 entropy(i)=entropy(i)+dlog(nhist(i)+0.0D0)
497 Cd entropy(i)=1.0D+10
499 write (iout,'(/80(1h*)/a,i2/80(1h*)/)')
500 & 'End of macroiteration',isweep
501 write (iout,'(a,f10.5,a,f10.5)') 'Elowest=',elowest,
502 & ' Ehighest=',ehighest
503 write (iout,'(a)') 'Frequecies of minima'
505 write (iout,'(i5,f5.0,f10.5)') i,nminima(i),esave(i)
507 write (iout,'(/a)') 'Energy histogram'
509 write (iout,'(i5,2f10.5)') i,emin+i*delte,nhist(i)
511 write (iout,'(/a)') 'Entropy'
513 write (iout,'(i5,2f10.5)') i,emin+i*delte,entropy(i)
515 C-----------------------------------------------------------------
516 C... End of energy histogram construction
517 C-----------------------------------------------------------------
519 entropy(-max_ene-4)=dfloat(indminn)
520 entropy(-max_ene-3)=dfloat(indmaxx)
521 entropy(-max_ene-2)=emin
522 entropy(-max_ene-1)=emax
524 cd print *,entname,ientout
525 open (ientout,file=entname,status='unknown')
526 write (ientout,'(2i5,2e25.17)') indminn,indmaxx,emin,emax
528 write (ientout,'(i5,f10.5,f20.15)') i,emin+i*delte,entropy(i)
532 write (iout,'(a)') 'Frequecies of minima'
534 write (iout,'(i5,f5.0,f10.5)') i,nminima(i),esave(i)
536 c call send_MCM_results
538 call receive_MCM_update
539 indminn=entropy(-max_ene-4)
540 indmaxx=entropy(-max_ene-3)
541 emin=entropy(-max_ene-2)
542 emax=entropy(-max_ene-1)
543 write (iout,*) 'Received from master:'
544 write (iout,*) 'indminn=',indminn,' indmaxx=',indmaxx,
545 & ' emin=',emin,' emax=',emax
546 write (iout,'(/a)') 'Entropy'
548 write (iout,'(i5,2f10.5)') i,emin+i*delte,entropy(i)
551 if (WhatsUp.lt.-1) return
553 if (ovrtim() .or. WhatsUp.lt.0) return
556 write (iout,'(/80(1h*)/20x,a)') 'Summary run statistics:'
557 call statprint(nacc,nfun,iretcode,etot,elowest)
559 & 'Statistics of multiple-bond motions. Total motions:'
560 write (iout,'(16i5)') (nbond_move(i),i=1,Nbm)
561 write (iout,'(a)') 'Accepted motions:'
562 write (iout,'(16i5)') (nbond_acc(i),i=1,Nbm)
563 write (iout,'(a,i10)') 'Number of chain regrowths:',nregrow
564 write (iout,'(a,i10)') 'Accepted chain regrowths:',nregrow_acc
566 C---------------------------------------------------------------------------
568 C---------------------------------------------------------------------------
572 if (isweep.eq.nsweep .and. it.ge.maxacc)
573 &write (iout,'(/80(1h*)/20x,a/80(1h*)/)') 'All iterations done.'
576 c------------------------------------------------------------------------------
577 subroutine accepting(ecur,eold,scur,sold,x,xold,accepted)
578 implicit real*8 (a-h,o-z)
582 include 'COMMON.IOUNITS'
585 include 'COMMON.INFO'
588 double precision ecur,eold,xx,ran_number,bol
589 double precision x(maxvar),xold(maxvar)
590 double precision tole /1.0D-1/, tola /5.0D0/
592 C Check if the conformation is similar.
593 cd write (iout,*) 'Enter ACCEPTING'
594 cd write (iout,*) 'Old PHI angles:'
595 cd write (iout,*) (rad2deg*xold(i),i=1,nphi)
596 cd write (iout,*) 'Current angles'
597 cd write (iout,*) (rad2deg*x(i),i=1,nphi)
598 cd ddif=dif_ang(nphi,x,xold)
599 cd write (iout,*) 'Angle norm:',ddif
600 cd write (iout,*) 'ecur=',ecur,' emax=',emax
601 if (ecur.gt.emax) then
604 & write (iout,'(a)') 'Conformation rejected as too high in energy'
606 else if (dabs(ecur-eold).lt.tole .and.
607 & dif_ang(nphi,x,xold).lt.tola) then
610 & write (iout,'(a)') 'Conformation rejected as too similar'
613 C Else evaluate the entropy of the conf and compare it with that of the previous
615 indecur=(ecur-emin)/delte
616 if (iabs(indecur).gt.max_ene) then
617 write (iout,'(a,2i5)')
618 & 'Accepting: Index out of range:',indecur
620 else if (indecur.eq.indmaxx) then
621 scur=entropy(indecur)
622 if (print_mc.gt.0) write (iout,*)'Energy boundary reached',
623 & indmaxx,indecur,entropy(indecur)
625 deix=ecur-(emin+indecur*delte)
626 dent=entropy(indecur+1)-entropy(indecur)
627 scur=entropy(indecur)+(dent/delte)*deix
629 cd print *,'Processor',MyID,' ecur=',ecur,' indecur=',indecur,
630 cd & ' scur=',scur,' eold=',eold,' sold=',sold
631 cd print *,'deix=',deix,' dent=',dent,' delte=',delte
632 if (print_mc.gt.1) then
633 write(iout,*)'ecur=',ecur,' indecur=',indecur,' scur=',scur
634 write(iout,*)'eold=',eold,' sold=',sold
636 if (scur.le.sold) then
639 C Else carry out acceptance test
640 xx=ran_number(0.0D0,1.0D0)
642 if (xxh.gt.50.0D0) then
649 if (print_mc.gt.0) write (iout,'(a)')
650 & 'Conformation accepted.'
653 if (print_mc.gt.0) write (iout,'(a)')
654 & 'Conformation rejected.'
659 c-----------------------------------------------------------------------------
661 implicit real*8 (a-h,o-z)
663 include 'COMMON.IOUNITS'
668 double precision varia(maxvar)
669 print '(a)','Call READ_POOL'
672 read (intin,'(i5,f10.5)',end=10,err=10) iconf,epool(npool)
673 if (epool(npool).eq.0.0D0) goto 10
674 call read_angles(intin,*10)
675 call geom_to_var(nvar,xpool(1,npool))
679 11 write (iout,'(a,i5)') 'Number of pool conformations:',npool
680 if (print_mc.gt.2) then
682 write (iout,'(a,i5,a,1pe14.5)') 'Pool conformation',i,' energy',
684 write (iout,'(10f8.3)') (rad2deg*xpool(j,i),j=1,nvar)
686 endif ! (print_mc.gt.2)