2 !-----------------------------------------------------------------------------
6 use geometry_data, only: nres,nvar,rad2deg
7 use random, only: iran_num,ran_number
14 !-----------------------------------------------------------------------------
15 ! Max. number of move types in MCM
16 ! integer,parameter :: maxmovetype=4
17 !-----------------------------------------------------------------------------
18 ! Max. number of conformations in Master's cache array
19 integer,parameter :: max_cache=10
20 !-----------------------------------------------------------------------------
21 ! Max. number of stored confs. in MC/MCM simulation
22 ! integer,parameter :: maxsave=20
23 !-----------------------------------------------------------------------------
24 ! Number of threads in deformation
25 integer,parameter :: max_thread=4, max_thread2=2*max_thread
26 !-----------------------------------------------------------------------------
27 ! Number of structures to compare at t=0
28 integer,parameter :: max_threadss=8,max_threadss2=2*max_threadss
29 !-----------------------------------------------------------------------------
30 ! Max. number of conformations in the pool
31 integer,parameter :: max_pool=10
32 !-----------------------------------------------------------------------------
33 !-----------------------------------------------------------------------------
37 ! integer,dimension(max_cache) :: CachSrc nie używane
38 ! integer,dimension(max_cache) :: isent,iused
39 ! logical :: cache_update
40 ! real(kind=8),dimension(max_cache) :: ecache
41 ! real(kind=8),dimension(:,:),allocatable :: xcache !(maxvar,max_cache)
42 !-----------------------------------------------------------------------------
45 ! real(kind=8) :: emin,emax
46 real(kind=8),dimension(:),allocatable :: entropy !(-max_ene-4:max_ene)
47 real(kind=8),dimension(:),allocatable :: nhist !(-max_ene:max_ene)
48 real(kind=8),dimension(:),allocatable :: nminima !(maxsave)
51 integer :: indminn,indmaxx
54 ! real(kind=8) :: pool_fraction
55 real(kind=8),dimension(:,:),allocatable :: xpool !(maxvar,max_pool)
56 real(kind=8),dimension(:),allocatable :: epool !(max_pool)
57 ! common /mce_counters/
58 !------------------------------------------------------------------------------
59 !... Following COMMON block contains variables controlling motion.
60 !------------------------------------------------------------------------------
62 ! real(kind=8),dimension(0:MaxMoveType) :: sumpro_type !(0:MaxMoveType)
63 real(kind=8),dimension(:),allocatable :: sumpro_bond !(0:maxres)
64 integer :: koniecl,Nbm,MaxSideMove!,nmove
65 integer,dimension(:),allocatable :: nbond_move,nbond_acc !(maxres)
66 ! integer,dimension(-1:MaxMoveType+1) :: moves,moves_acc !(-1:MaxMoveType+1)
67 ! common /accept_stats/
69 integer,dimension(:),allocatable :: nacc_part !(0:MaxProcs) !el nie uzywane???
72 ! integer,dimension(:),allocatable :: winstart,winend,winlen !(maxres)
74 ! character(len=16),dimension(-1:MaxMoveType+1) :: MovTypID !(-1:MaxMoveType+1)
75 !------------------------------------------------------------------------------
76 !... koniecl - the number of bonds to be considered "end bonds" subjected to
78 !... Nbm - The maximum length of N-bond segment to be moved;
79 !... MaxSideMove - maximum number of side chains subjected to local moves
81 !... nmove - the current number of attempted moves;
82 !... nbond_move(*) array that stores the total numbers of 2-bond,3-bond,...
84 !... nendmove - number of endmoves;
85 !... nbackmove - number of backbone moves;
86 !... nsidemove - number of local side chain moves;
87 !... sumpro_type(*) - array that stores the lower and upper boundary of the
88 !... random-number range that determines the type of move
89 !... (N-bond, backbone or side chain);
90 !... sumpro_bond(*) - array that stores the probabilities to perform bond
91 !... moves of consecutive segment length.
92 !... winstart(*) - the starting position of the perturbation window;
93 !... winend(*) - the end position of the perturbation window;
94 !... winlen(*) - length of the perturbation window;
95 !... nwindow - the number of perturbation windows (0 - entire chain).
96 !-----------------------------------------------------------------------------
99 !-----------------------------------------------------------------------------
101 !-----------------------------------------------------------------------------
103 !-----------------------------------------------------------------------------
104 subroutine compare_s1(n_thr,num_thread_save,energyx,x,icomp,enetbss,&
105 coordss,rms_d,modif,iprint)
107 ! This subroutine compares the new conformation, whose variables are in X
108 ! with the previously accumulated conformations whose energies and variables
109 ! are stored in ENETBSS and COORDSS, respectively. The meaning of other
110 ! variables is as follows:
112 ! N_THR - on input the previous # of accumulated confs, on output the current
113 ! # of accumulated confs.
114 ! N_REPEAT - an array that indicates how many times the structure has already
115 ! been used to start the reversed-reversing procedure. Addition of
116 ! a new structure replacement of a structure with a similar, but
117 ! lower-energy structure resets the respective entry in N_REPEAT to zero
119 ! ENERGYX,X - the energy and variables of the new conformations.
120 ! ICOMP - comparison result:
121 ! 0 - the new structure is similar to one of the previous ones and does
122 ! not have a remarkably lower energy and is therefore rejected;
123 ! 1 - the new structure is different and is added to the set, because
124 ! there is still room in the COORDSS and ENETBSS arrays;
125 ! 2 - the new structure is different, but higher in energy than any
126 ! previous one and is therefore rejected
127 ! 3 - there is no more room in the COORDSS and ENETBSS arrays, but
128 ! the new structure is lower in energy than at least the highest-
129 ! energy previous structure and therefore replaces it.
130 ! 9 - the new structure is similar to a number of previous structures,
131 ! but has a remarkably lower energy than any of them; therefore
132 ! replaces all these structures;
133 ! MODIF - a logical variable that shows whether to include the new structure
134 ! in the set of accumulated structures
136 ! implicit real*8 (a-h,o-z)
138 use regularize_, only:fitsq
139 ! include 'DIMENSIONS'
140 ! include 'COMMON.GEO'
141 ! include 'COMMON.VAR'
142 !rc include 'COMMON.DEFORM'
143 ! include 'COMMON.IOUNITS'
145 !el use geometry_data !include 'COMMON.CHAIN'
148 real(kind=8),dimension(6*nres) :: x,x1 !(maxvar) (maxvar=6*maxres)
149 real(kind=8) :: przes(3),obrot(3,3)
150 integer :: list(max_thread)
151 logical :: non_conv,modif
152 real(kind=8) :: enetbss(max_threadss)
153 real(kind=8) :: coordss(6*nres,max_threadss)
155 !!! local variables - el
156 integer :: n_thr,num_thread_save,icomp,minimize_s_flag,iprint
157 real(kind=8) :: energyx,energyy,rms_d
158 integer :: nlist,k,kk,j,i,iresult
159 real(kind=8) :: enex_jp,roznica
163 call var_to_geom(nvar,x)
164 write(iout,*) 'Warning calling chainbuild'
172 ! write(iout,*)'*ene=',energyx
179 if (iprint.gt.3) then
180 write (iout,*) 'Compare_ss, i=',i
181 write (iout,*) 'New structure Energy:',energyx
182 write (iout,'(10f8.3)') (rad2deg*x(k),k=1,nvar)
183 write (iout,*) 'Template structure Energy:',enetbss(i)
184 write (iout,'(10f8.3)') (rad2deg*x1(k),k=1,nvar)
188 call var_to_geom(nvar,x1)
189 write(iout,*) 'Warning calling chainbuild'
191 !d write(iout,*)'C and CREF'
192 !d write(iout,'(i5,3f10.5,5x,3f10.5)')(k,(c(j,k),j=1,3),
193 !d & (cref(j,k),j=1,3),k=1,nres)
194 call fitsq(roznica,c(1,1),cref(1,1,1),nres,przes,obrot,non_conv)
196 print *,'Problems in FITSQ!!!'
198 print '(10f8.3)',(x(k),k=1,nvar)
200 print '(10f8.3)',(x1(k),k=1,nvar)
202 print '(i5,3f10.5,5x,3f10.5)',(k,(c(j,k),j=1,3),&
203 (cref(j,k,1),j=1,3),k=1,nres)
205 roznica=dsqrt(dabs(roznica))
207 if (roznica.lt.rms_d) iresult = 0
210 !el call cmprs(x,x1,roznica,energyx,energyy,iresult)
212 if (iprint.gt.1) write(iout,'(i5,f10.6,$)') i,roznica
213 ! print '(i5,f8.3)',i,roznica
214 if(iresult.eq.0) then
217 if (iprint.gt.1) write(iout,*)
218 if(energyx.ge.enetbss(i)) then
220 write(iout,*)'s*>> structure rejected - same as nr ',i, &
227 if(energyx.lt.enetbss(i).and.enex_jp.lt.enetbss(i))then
232 if (iprint.gt.1) write(iout,*)
236 write(iout,'(a,i3,$)')'s*>> structure accepted1 - repl nr ',&
240 write(iout,'(a,i3)') &
241 's*>> structure accepted1 - would repl nr ',list(1)
244 if (.not. modif) goto 1106
251 if (iprint.gt.1) write(iout,'(i3,$)')list(j)
252 do kk=list(j)+1,nlist
253 enetbss(kk-1)=enetbss(kk)
255 coordss(i,kk-1)=coordss(i,kk)
259 if (iprint.gt.1) write(iout,*)
262 if(n_thr.lt.num_thread_save) then
266 write(iout,*)'s*>> structure accepted - add with nr ',n_thr+1
269 write(iout,*)'s*>> structure accepted - would add with nr ',&
274 enetbss(n_thr)=energyx
276 coordss(i,n_thr)=x(i)
281 write(iout,*)'s*>> structure rejected - too high energy'
288 write(iout,*)'s*>> structure accepted - repl nr ',j
291 write(iout,*)'s*>> structure accepted - would repl nr ',j
302 end subroutine compare_s1
303 !-----------------------------------------------------------------------------
305 !-----------------------------------------------------------------------------
310 use MPI_data, only:WhatsUp,MyID
311 use compare_data, only: ener
312 use control_data, only: minim,refstr
314 use regularize_, only:fitsq
315 use control, only: tcpu,ovrtim
317 use minimm, only:minimize
318 ! Does modified entropic sampling in the space of minima.
319 ! implicit real*8 (a-h,o-z)
320 ! include 'DIMENSIONS'
321 ! include 'COMMON.IOUNITS'
323 use MPI_data !include 'COMMON.INFO'
325 ! include 'COMMON.GEO'
326 ! include 'COMMON.CHAIN'
327 ! include 'COMMON.MCM'
328 ! include 'COMMON.MCE'
329 ! include 'COMMON.CONTACTS'
330 ! include 'COMMON.CONTROL'
331 ! include 'COMMON.VAR'
332 ! include 'COMMON.INTERACT'
333 ! include 'COMMON.THREAD'
334 ! include 'COMMON.NAMES'
335 logical :: accepted,not_done,over,error,lprint !,ovrtim
336 integer :: MoveType,nbond
337 ! integer :: conf_comp
338 real(kind=8) :: RandOrPert
339 real(kind=8),dimension(6*nres) :: varia !(maxvar) (maxvar=6*maxres)
340 real(kind=8) :: elowest,ehighest,eold
341 real(kind=8) :: przes(3),obr(3,3)
342 real(kind=8),dimension(6*nres) :: varold !(maxvar) (maxvar=6*maxres)
344 real(kind=8),dimension(0:n_ene) :: energia,energia_ave
346 !!! local variables -el
347 integer :: i,ii,kkk,it,j,nacc,ijunk,indmin,indmax,&
348 ISWEEP,Kwita,iretcode,indeold,iene,noverlap,&
349 irep,nstart_grow,inde
353 real(kind=8) :: facee,conste,ejunk,etot,rms,co,frac,&
354 deix,dent,sold,scur,runtime
357 ! if(.not.allocated(varsave)) allocate(varsave(maxvar,maxsave)) !(maxvar,maxsave)
358 !d write (iout,*) 'print_mc=',print_mc
361 !---------------------------------------------------------------------------
362 ! Initialize counters.
363 !---------------------------------------------------------------------------
364 ! Total number of generated confs.
366 ! Total number of moves. In general this won't be equal to the number of
367 ! attempted moves, because we may want to reject some "bad" confs just by
370 ! Total number of shift (nbond_move(1)), spike, crankshaft, three-bond,...
372 !el allocate(nbond_move(nres)) !(maxres)
377 ! Initialize total and accepted number of moves of various kind.
382 ! Total number of energy evaluations.
388 facee=1.0D0/(maxacc*delte)
390 ! Read entropy from previous simulations.
392 read (ientin,*) indminn,indmaxx,emin,emax
393 print *,'indminn=',indminn,' indmaxx=',indmaxx,' emin=',emin,&
395 do i=-max_ene,max_ene
396 entropy(i)=(emin+i*delte)*betbol
398 read (ientin,*) (ijunk,ejunk,entropy(i),i=indminn,indmaxx)
401 write (iout,*) 'indminn=',indminn,' indmaxx=',indmaxx,&
402 ' emin=',emin,' emax=',emax
403 write (iout,'(/a)') 'Initial entropy'
405 write (iout,'(i5,2f10.5)') i,emin+i*delte,entropy(i)
408 ! Read the pool of conformations
410 !----------------------------------------------------------------------------
411 ! Entropy-sampling simulations with continually updated entropy
412 ! Loop thru simulations
413 !----------------------------------------------------------------------------
415 !----------------------------------------------------------------------------
416 ! Take a conformation from the pool
417 !----------------------------------------------------------------------------
423 write (iout,*) 'Took conformation',ii,' from the pool energy=',&
425 call var_to_geom(nvar,varia)
426 ! Print internal coordinates of the initial conformation
429 call gen_rand_conf(1,*20)
431 !----------------------------------------------------------------------------
432 ! Compute and print initial energies.
433 !----------------------------------------------------------------------------
436 allocate(nsave_part(nctasks))
437 if (MyID.eq.MasterID) then
445 write (iout,'(/80(1h*)/a,i2/80(1h*)/)') 'MCE iteration #',isweep
446 write (iout,'(/80(1h*)/a)') 'Initial energies:'
447 write(iout,*) 'Warning calling chainbuild'
451 call enerprint(energia)
452 ! Minimize the energy of the first conformation.
454 call geom_to_var(nvar,varia)
455 call minimize(etot,varia,iretcode,nfun)
458 write (iout,'(/80(1h*)/a/80(1h*))') &
459 'Results of the first energy minimization:'
460 call enerprint(energia)
464 call fitsq(rms,c(1,nstart_seq),cref(1,nstart_sup,kkk),&
468 call contact(.false.,ncont,icont,co)
469 frac=contact_fract(ncont,ncont_ref,icont,icont_ref)
470 write (iout,'(a,f8.3,a,f8.3,a,f8.3)') &
471 'RMS deviation from the reference structure:',rms,&
472 ' % of native contacts:',frac*100,' contact order:',co
473 write (istat,'(i5,11(1pe14.5))') 0,&
474 (energia(print_order(i)),i=1,nprint_ene),etot,rms,frac,co
476 write (istat,'(i5,9(1pe14.5))') 0,&
477 (energia(print_order(i)),i=1,nprint_ene),etot
480 neneval=neneval+nfun+1
481 if (.not. ent_read) then
482 ! Initialize the entropy array
483 do i=-max_ene,max_ene
485 ! Uncomment the line below for actual entropic sampling (start with uniform
486 ! energy distribution).
488 ! Uncomment the line below for multicanonical sampling (start with Boltzmann
490 entropy(i)=(emin+i*delte)*betbol
494 write (iout,'(/a)') 'Initial entropy'
496 write (iout,'(i5,2f10.5)') i,emin+i*delte,entropy(i)
500 call recv_stop_sig(Kwita)
501 if (whatsup.eq.1) then
502 call send_stop_sig(-2)
504 else if (whatsup.le.-2) then
506 else if (whatsup.eq.2) then
512 not_done = (iretcode.ne.11)
514 write (iout,'(/80(1h*)/20x,a/80(1h*))') &
515 'Enter Monte Carlo procedure.'
517 call briefout(0,etot)
522 indeold=(eold-emin)/delte
523 deix=eold-(emin+indeold*delte)
524 dent=entropy(indeold+1)-entropy(indeold)
525 !d write (iout,*) 'indeold=',indeold,' deix=',deix,' dent=',dent
526 !d write (*,*) 'Processor',MyID,' indeold=',indeold,' deix=',deix,
528 sold=entropy(indeold)+(dent/delte)*deix
530 write (iout,*) 'eold=',eold,' sold=',sold,' elowest=',etot
531 write (*,*) 'Processor',MyID,' eold=',eold,' sold=',sold,&
533 if (minim) call zapis(varia,etot)
535 ! NACC is the counter for the accepted conformations of a given processor
537 ! NACC_TOT counts the total number of accepted conformations
540 if (MyID.eq.MasterID) then
541 call receive_MCM_info
543 call send_MCM_info(2)
546 do iene=indminn,indmaxx
553 !----------------------------------------------------------------------------
559 if (print_mc.gt.0) write (iout,'(80(1h*)/20x,a,i7)') &
560 'Beginning iteration #',it
561 ! Initialize local counter.
562 ntrial=0 ! # of generated non-overlapping confs.
563 noverlap=0 ! # of overlapping confs.
565 do while (.not. accepted .and. WhatsUp.eq.0 .and. Kwita.eq.0)
567 ! Retrieve the angles of previously accepted conformation
571 !d write (iout,'(a)') 'Old variables:'
572 !d write (iout,'(10f8.1)') (rad2deg*varia(i),i=1,nvar)
573 call var_to_geom(nvar,varia)
575 write(iout,*) 'Warning calling chainbuild'
580 ! Decide whether to generate a random conformation or perturb the old one
581 RandOrPert=ran_number(0.0D0,1.0D0)
582 if (RandOrPert.gt.RanFract) then
584 write (iout,'(a)') 'Perturbation-generated conformation.'
585 call perturb(error,lprint,MoveType,nbond,1.0D0)
587 if (MoveType.lt.1 .or. MoveType.gt.MaxMoveType) then
588 write (iout,'(/a,i7,a/)') 'Error - unknown MoveType=',&
589 MoveType,' returned from PERTURB.'
592 write(iout,*) 'Warning calling chainbuild'
597 nstart_grow=iran_num(3,nres)
599 write (iout,'(2a,i3)') 'Random-generated conformation',&
600 ' - chain regrown from residue',nstart_grow
601 call gen_rand_conf(nstart_grow,*30)
603 call geom_to_var(nvar,varia)
604 !d write (iout,'(a)') 'New variables:'
605 !d write (iout,'(10f8.1)') (rad2deg*varia(i),i=1,nvar)
607 if (print_mc.gt.0) write (iout,'(a,i5,a,i10,a,i10)') &
608 'Processor',MyId,' trial move',ntrial,' total generated:',ngen
609 if (print_mc.gt.0) write (*,'(a,i5,a,i10,a,i10)') &
610 'Processor',MyId,' trial move',ntrial,' total generated:',ngen
613 ! call enerprint(energia(0))
614 ! write (iout,'(2(a,1pe14.5))') 'Etot=',Etot,' Elowest=',Elowest
615 if (etot-elowest.gt.overlap_cut) then
616 write (iout,'(a,i5,a,1pe14.5)') 'Iteration',it,&
617 ' Overlap detected in the current conf.; energy is',etot
621 if (noverlap.gt.maxoverlap) then
622 write (iout,'(a)') 'Too many overlapping confs.'
627 call minimize(etot,varia,iretcode,nfun)
628 !d write (iout,'(a)') 'Variables after minimization:'
629 !d write (iout,'(10f8.1)') (rad2deg*varia(i),i=1,nvar)
632 neneval=neneval+nfun+1
634 if (print_mc.gt.2) then
635 write (iout,'(a)') 'Total energies of trial conf:'
636 call enerprint(energia)
637 else if (print_mc.eq.1) then
638 write (iout,'(a,i6,a,1pe16.6)') &
639 'Trial conformation:',ngen,' energy:',etot
641 !--------------------------------------------------------------------------
643 !--------------------------------------------------------------------------
646 call accepting(etot,eold,scur,sold,varia,varold,&
651 if (elowest.gt.etot) elowest=etot
652 if (ehighest.lt.etot) ehighest=etot
653 moves_acc(MoveType)=moves_acc(MoveType)+1
654 if (MoveType.eq.1) then
655 nbond_acc(nbond)=nbond_acc(nbond)+1
657 ! Check against conformation repetitions.
658 irep=conf_comp(varia,etot)
659 #if defined(AIX) || defined(PGI)
660 open (istat,file=statname,position='append')
662 open (istat,file=statname,access='append')
666 call fitsq(rms,c(1,nstart_seq),cref(1,nstart_sup,kkk),&
670 call contact(.false.,ncont,icont,co)
671 frac=contact_fract(ncont,ncont_ref,icont,icont_ref)
673 write (iout,'(a,f8.3,a,f8.3,a,f8.3)') &
674 'RMS deviation from the reference structure:',rms,&
675 ' % of native contacts:',frac*100,' contact order:',co
677 write (istat,'(i5,11(1pe14.5))') it,&
678 (energia(print_order(i)),i=1,nprint_ene),etot,&
680 elseif (print_stat) then
681 write (istat,'(i5,10(1pe14.5))') it,&
682 (energia(print_order(i)),i=1,nprint_ene),etot
686 call statprint(nacc,nfun,iretcode,etot,elowest)
687 ! Print internal coordinates.
688 if (print_int) call briefout(nacc,etot)
690 if (MyID.ne.MasterID) then
691 call recv_stop_sig(Kwita)
692 !d print *,'Processor:',MyID,' STOP=',Kwita
694 call send_MCM_info(2)
696 call send_MCM_info(1)
700 ! Store the accepted conf. and its energy.
708 !d write (iout,*) 'Accepted conformation:'
709 !d write (iout,*) (rad2deg*varia(i),i=1,nphi)
710 if (minim) call zapis(varia,etot)
712 ener(i,nsave)=energia(i)
714 ener(n_ene+1,nsave)=etot
715 ener(n_ene+2,nsave)=frac
717 nminima(irep)=nminima(irep)+1.0D0
718 ! print *,'irep=',irep,' nminima=',nminima(irep)
720 if (Kwita.eq.0) call recv_stop_sig(kwita)
725 if (MyID.eq.MasterID) then
726 call receive_MCM_info
727 if (nacc_tot.ge.maxacc) accepted=.true.
730 if (ntrial.gt.maxtrial_iter .and. npool.gt.0) then
731 ! Take a conformation from the pool
736 write (iout,*) 'Iteration',it,' max. # of trials exceeded.'
738 'Take conformation',ii,' from the pool energy=',epool(ii)
740 write (iout,'(10f8.3)') (rad2deg*varia(i),i=1,nvar)
742 endif ! (ntrial.gt.maxtrial_iter .and. npool.gt.0)
746 if (MyID.eq.MasterID) then
747 call receive_MCM_info
749 if (Kwita.eq.0) call recv_stop_sig(kwita)
751 if (ovrtim()) WhatsUp=-1
752 !d write (iout,*) 'WhatsUp=',WhatsUp,' Kwita=',Kwita
753 not_done = (nacc_tot.lt.maxacc) .and. (WhatsUp.eq.0) &
755 !d write (iout,*) 'not_done=',not_done
758 print *,'Processor',MyID,&
759 ' has received STOP signal =',Kwita,' in EntSamp.'
760 !d print *,'not_done=',not_done
761 if (Kwita.lt.-1) WhatsUp=Kwita
762 else if (nacc_tot.ge.maxacc) then
763 print *,'Processor',MyID,' calls send_stop_sig,',&
764 ' because a sufficient # of confs. have been collected.'
765 !d print *,'not_done=',not_done
766 call send_stop_sig(-1)
767 else if (WhatsUp.eq.-1) then
768 print *,'Processor',MyID,&
769 ' calls send_stop_sig because of timeout.'
770 !d print *,'not_done=',not_done
771 call send_stop_sig(-2)
776 !-----------------------------------------------------------------
777 !... Construct energy histogram & update entropy
778 !-----------------------------------------------------------------
782 write (iout,*) 'Processor',MyID,&
783 ' is broadcasting ERROR-STOP signal.'
784 write (*,*) 'Processor',MyID,&
785 ' is broadcasting ERROR-STOP signal.'
786 call send_stop_sig(-3)
790 if (MyID.eq.MasterID) then
791 ! call receive_MCM_results
792 call receive_energies
795 if (esave(i).lt.elowest) elowest=esave(i)
796 if (esave(i).gt.ehighest) ehighest=esave(i)
798 write (iout,'(a,i10)') '# of accepted confs:',nacc_tot
799 write (iout,'(a,f10.5,a,f10.5)') 'Lowest energy:',elowest,&
800 ' Highest energy',ehighest
801 if (isweep.eq.1 .and. .not.ent_read) then
804 write (iout,*) 'EMAX=',emax
806 indmaxx=(ehighest-emin)/delte
809 do i=-max_ene,max_ene
810 entropy(i)=(emin+i*delte)*betbol
814 indmin=(elowest-emin)/delte
815 indmax=(ehighest-emin)/delte
816 if (indmin.lt.indminn) indminn=indmin
817 if (indmax.gt.indmaxx) indmaxx=indmax
819 write(iout,*)'indminn=',indminn,' indmaxx=',indmaxx
820 ! Construct energy histogram
822 inde=(esave(i)-emin)/delte
823 nhist(inde)=nhist(inde)+nminima(i)
825 ! Update entropy (density of states)
827 if (nhist(i).gt.0) then
828 entropy(i)=entropy(i)+dlog(nhist(i)+0.0D0)
832 !d entropy(i)=1.0D+10
834 write (iout,'(/80(1h*)/a,i2/80(1h*)/)') &
835 'End of macroiteration',isweep
836 write (iout,'(a,f10.5,a,f10.5)') 'Elowest=',elowest,&
837 ' Ehighest=',ehighest
838 write (iout,'(a)') 'Frequecies of minima'
840 write (iout,'(i5,f5.0,f10.5)') i,nminima(i),esave(i)
842 write (iout,'(/a)') 'Energy histogram'
844 write (iout,'(i5,2f10.5)') i,emin+i*delte,nhist(i)
846 write (iout,'(/a)') 'Entropy'
848 write (iout,'(i5,2f10.5)') i,emin+i*delte,entropy(i)
850 !-----------------------------------------------------------------
851 !... End of energy histogram construction
852 !-----------------------------------------------------------------
854 entropy(-max_ene-4)=dfloat(indminn)
855 entropy(-max_ene-3)=dfloat(indmaxx)
856 entropy(-max_ene-2)=emin
857 entropy(-max_ene-1)=emax
859 !d print *,entname,ientout
860 open (ientout,file=entname,status='unknown')
861 write (ientout,'(2i5,2e25.17)') indminn,indmaxx,emin,emax
863 write (ientout,'(i5,f10.5,f20.15)') i,emin+i*delte,entropy(i)
867 write (iout,'(a)') 'Frequecies of minima'
869 write (iout,'(i5,f5.0,f10.5)') i,nminima(i),esave(i)
871 ! call send_MCM_results
873 call receive_MCM_update
874 indminn=entropy(-max_ene-4)
875 indmaxx=entropy(-max_ene-3)
876 emin=entropy(-max_ene-2)
877 emax=entropy(-max_ene-1)
878 write (iout,*) 'Received from master:'
879 write (iout,*) 'indminn=',indminn,' indmaxx=',indmaxx,&
880 ' emin=',emin,' emax=',emax
881 write (iout,'(/a)') 'Entropy'
883 write (iout,'(i5,2f10.5)') i,emin+i*delte,entropy(i)
886 if (WhatsUp.lt.-1) return
888 if (ovrtim() .or. WhatsUp.lt.0) return
891 write (iout,'(/80(1h*)/20x,a)') 'Summary run statistics:'
892 call statprint(nacc,nfun,iretcode,etot,elowest)
894 'Statistics of multiple-bond motions. Total motions:'
895 write (iout,'(16i5)') (nbond_move(i),i=1,Nbm)
896 write (iout,'(a)') 'Accepted motions:'
897 write (iout,'(16i5)') (nbond_acc(i),i=1,Nbm)
898 !el write (iout,'(a,i10)') 'Number of chain regrowths:',nregrow
899 !el write (iout,'(a,i10)') 'Accepted chain regrowths:',nregrow_acc
901 !---------------------------------------------------------------------------
903 !---------------------------------------------------------------------------
907 if (isweep.eq.nsweep .and. it.ge.maxacc) &
908 write (iout,'(/80(1h*)/20x,a/80(1h*)/)') 'All iterations done.'
910 end subroutine entmcm
911 !-----------------------------------------------------------------------------
912 subroutine accepting(ecur,eold,scur,sold,x,xold,accepted)
914 use geometry_data, only: nphi
915 use energy_data, only: max_ene
916 ! implicit real*8 (a-h,o-z)
917 ! include 'DIMENSIONS'
918 ! include 'COMMON.MCM'
919 ! include 'COMMON.MCE'
920 ! include 'COMMON.IOUNITS'
921 ! include 'COMMON.VAR'
923 use MPI_data !include 'COMMON.INFO'
925 ! include 'COMMON.GEO'
926 real(kind=8) :: ecur,eold,xx,bol !,ran_number
927 real(kind=8),dimension(6*nres) :: x,xold !(maxvar) (maxvar=6*maxres)
928 real(kind=8) :: tole=1.0D-1, tola=5.0D0
931 !!! local variables - el
933 real(kind=8) :: scur,sold,xxh,deix,dent
935 ! Check if the conformation is similar.
936 !d write (iout,*) 'Enter ACCEPTING'
937 !d write (iout,*) 'Old PHI angles:'
938 !d write (iout,*) (rad2deg*xold(i),i=1,nphi)
939 !d write (iout,*) 'Current angles'
940 !d write (iout,*) (rad2deg*x(i),i=1,nphi)
941 !d ddif=dif_ang(nphi,x,xold)
942 !d write (iout,*) 'Angle norm:',ddif
943 !d write (iout,*) 'ecur=',ecur,' emax=',emax
944 if (ecur.gt.emax) then
947 write (iout,'(a)') 'Conformation rejected as too high in energy'
949 else if (dabs(ecur-eold).lt.tole .and. &
950 dif_ang(nphi,x,xold).lt.tola) then
953 write (iout,'(a)') 'Conformation rejected as too similar'
956 ! Else evaluate the entropy of the conf and compare it with that of the previous
958 indecur=(ecur-emin)/delte
959 if (iabs(indecur).gt.max_ene) then
960 write (iout,'(a,2i5)') &
961 'Accepting: Index out of range:',indecur
963 else if (indecur.eq.indmaxx) then
964 scur=entropy(indecur)
965 if (print_mc.gt.0) write (iout,*)'Energy boundary reached',&
966 indmaxx,indecur,entropy(indecur)
968 deix=ecur-(emin+indecur*delte)
969 dent=entropy(indecur+1)-entropy(indecur)
970 scur=entropy(indecur)+(dent/delte)*deix
972 !d print *,'Processor',MyID,' ecur=',ecur,' indecur=',indecur,
973 !d & ' scur=',scur,' eold=',eold,' sold=',sold
974 !d print *,'deix=',deix,' dent=',dent,' delte=',delte
975 if (print_mc.gt.1) then
976 write(iout,*)'ecur=',ecur,' indecur=',indecur,' scur=',scur
977 write(iout,*)'eold=',eold,' sold=',sold
979 if (scur.le.sold) then
982 ! Else carry out acceptance test
983 xx=ran_number(0.0D0,1.0D0)
985 if (xxh.gt.50.0D0) then
992 if (print_mc.gt.0) write (iout,'(a)') &
993 'Conformation accepted.'
996 if (print_mc.gt.0) write (iout,'(a)') &
997 'Conformation rejected.'
1001 end subroutine accepting
1002 !-----------------------------------------------------------------------------
1003 subroutine read_pool
1005 use io_base, only:read_angles
1006 ! implicit real*8 (a-h,o-z)
1007 ! include 'DIMENSIONS'
1008 ! include 'COMMON.IOUNITS'
1009 ! include 'COMMON.GEO'
1010 ! include 'COMMON.MCM'
1011 ! include 'COMMON.MCE'
1012 ! include 'COMMON.VAR'
1013 real(kind=8),dimension(6*nres) :: varia !(maxvar) (maxvar=6*maxres)
1015 !!! local variables - el
1016 integer :: j,i,iconf
1018 print '(a)','Call READ_POOL'
1021 read (intin,'(i5,f10.5)',end=10,err=10) iconf,epool(npool)
1022 if (epool(npool).eq.0.0D0) goto 10
1023 call read_angles(intin,*10)
1024 call geom_to_var(nvar,xpool(1,npool))
1028 11 write (iout,'(a,i5)') 'Number of pool conformations:',npool
1029 if (print_mc.gt.2) then
1031 write (iout,'(a,i5,a,1pe14.5)') 'Pool conformation',i,' energy',&
1033 write (iout,'(10f8.3)') (rad2deg*xpool(j,i),j=1,nvar)
1035 endif ! (print_mc.gt.2)
1037 end subroutine read_pool
1038 !-----------------------------------------------------------------------------
1040 !-----------------------------------------------------------------------------
1041 subroutine monte_carlo
1045 use MPI_data, only:ifinish,nctasks,WhatsUp,MyID,NProcs
1046 use control_data, only:refstr !,MaxProcs
1048 use control, only:tcpu,ovrtim
1049 use regularize_, only:fitsq
1052 ! Does Boltzmann and entropic sampling without energy minimization
1053 ! implicit real*8 (a-h,o-z)
1054 ! include 'DIMENSIONS'
1055 ! include 'COMMON.IOUNITS'
1057 use MPI_data !include 'COMMON.INFO'
1059 ! include 'COMMON.GEO'
1060 ! include 'COMMON.CHAIN'
1061 ! include 'COMMON.MCM'
1062 ! include 'COMMON.MCE'
1063 ! include 'COMMON.CONTACTS'
1064 ! include 'COMMON.CONTROL'
1065 ! include 'COMMON.VAR'
1066 ! include 'COMMON.INTERACT'
1067 ! include 'COMMON.THREAD'
1068 ! include 'COMMON.NAMES'
1069 logical :: accepted,not_done,over,error,lprint !,ovrtim
1070 integer :: MoveType,nbond,nbins
1071 ! integer :: conf_comp
1072 real(kind=8) :: RandOrPert
1073 real(kind=8),dimension(6*nres) :: varia !(maxvar) (maxvar=6*maxres)
1074 real(kind=8) :: elowest,elowest1,ehighest,ehighest1,eold
1075 real(kind=8) :: przes(3),obr(3,3)
1076 real(kind=8),dimension(6*nres) :: varold !(maxvar) (maxvar=6*maxres)
1078 integer,dimension(-1:MaxMoveType+1,0:NProcs-1) :: moves1,moves_acc1 !(-1:MaxMoveType+1,0:MaxProcs-1)
1080 real(kind=8) :: etot_temp,etot_all(0:NProcs) !(0:MaxProcs)
1081 external d_vadd,d_vmin,d_vmax
1082 real(kind=8),dimension(-max_ene:max_ene) :: entropy1,nhist1
1083 integer,dimension(nres*(NProcs+1)) :: nbond_move1,nbond_acc1 !(nres*(MaxProcs+1))
1084 integer,dimension(2) :: itemp
1086 real(kind=8),dimension(6*nres) :: var_lowest !(maxvar) (maxvar=6*maxres)
1087 real(kind=8),dimension(0:n_ene) :: energia,energia_ave
1089 !!! local variables - el
1090 integer :: i,j,it,ii,iproc,nacc,ISWEEP,indmax,indmin,ijunk,&
1091 Kwita,indeold,imdmax,inde,iretcode,nstart_grow,noverlap
1095 real(kind=8) :: facee,conste,ejunk,etot,sold,frac,runtime,&
1096 frac_ave,rms_ave,etot_ave,scur,from_pool,co,rms
1098 write(iout,'(a,i8,2x,a,f10.5)') &
1099 'pool_read_freq=',pool_read_freq,' pool_fraction=',pool_fraction
1100 open (istat,file=statname)
1104 facee=1.0D0/(maxacc*delte)
1105 ! Number of bins in energy histogram
1107 write (iout,*) 'NBINS=',nbins
1109 ! Read entropy from previous simulations.
1111 read (ientin,*) indminn,indmaxx,emin,emax
1112 print *,'indminn=',indminn,' indmaxx=',indmaxx,' emin=',emin,&
1114 do i=-max_ene,max_ene
1117 read (ientin,*) (ijunk,ejunk,entropy(i),i=indminn,indmaxx)
1120 write (iout,*) 'indminn=',indminn,' indmaxx=',indmaxx,&
1121 ' emin=',emin,' emax=',emax
1122 write (iout,'(/a)') 'Initial entropy'
1123 do i=indminn,indmaxx
1124 write (iout,'(i5,2f10.5)') i,emin+i*delte,entropy(i)
1127 ! Read the pool of conformations
1131 !----------------------------------------------------------------------------
1132 ! Entropy-sampling simulations with continually updated entropy;
1133 ! set NSWEEP=1 for Boltzmann sampling.
1134 ! Loop thru simulations
1135 !----------------------------------------------------------------------------
1136 allocate(ifinish(nctasks))
1139 ! Initialize the IFINISH array.
1146 !---------------------------------------------------------------------------
1147 ! Initialize counters.
1148 !---------------------------------------------------------------------------
1149 ! Total number of generated confs.
1151 ! Total number of moves. In general this won't be equal to the number of
1152 ! attempted moves, because we may want to reject some "bad" confs just by
1155 ! Total number of shift (nbond_move(1)), spike, crankshaft, three-bond,...
1157 !el allocate(nbond_move(nres)) !(maxres)
1158 !el allocate(nbond_acc(nres)) !(maxres)
1164 ! Initialize total and accepted number of moves of various kind.
1169 ! Total number of energy evaluations.
1172 !----------------------------------------------------------------------------
1173 ! Take a conformation from the pool
1174 !----------------------------------------------------------------------------
1176 write (iout,*) 'emin=',emin,' emax=',emax
1177 if (npool.gt.0) then
1178 ii=iran_num(1,npool)
1180 varia(i)=xpool(i,ii)
1182 write (iout,*) 'Took conformation',ii,' from the pool energy=',&
1184 call var_to_geom(nvar,varia)
1185 ! Print internal coordinates of the initial conformation
1187 else if (isweep.gt.1) then
1188 if (eold.lt.emax) then
1194 varia(i)=var_lowest(i)
1197 call var_to_geom(nvar,varia)
1199 !----------------------------------------------------------------------------
1200 ! Compute and print initial energies.
1201 !----------------------------------------------------------------------------
1205 write (iout,'(/80(1h*)/a,i2/80(1h*)/)') 'MCE iteration #',isweep
1206 write (iout,'(/80(1h*)/a)') 'Initial energies:'
1207 write(iout,*) 'Warning calling chainbuild'
1209 call geom_to_var(nvar,varia)
1210 call etotal(energia)
1212 call enerprint(energia)
1214 call fitsq(rms,c(1,nstart_seq),cref(1,nstart_sup,1),nsup,przes,&
1217 call contact(.false.,ncont,icont,co)
1218 frac=contact_fract(ncont,ncont_ref,icont,icont_ref)
1219 write (iout,'(a,f8.3,a,f8.3,a,f8.3)') &
1220 'RMS deviation from the reference structure:',rms,&
1221 ' % of native contacts:',frac*100,' contact order',co
1222 write (istat,'(i10,16(1pe14.5))') 0,&
1223 (energia(print_order(i)),i=1,nprint_ene),&
1226 write (istat,'(i10,14(1pe14.5))') 0,&
1227 (energia(print_order(i)),i=1,nprint_ene),etot
1231 if (.not. ent_read) then
1232 ! Initialize the entropy array
1234 ! Collect total energies from other processors.
1237 call mp_gather(etot_temp,etot_all,8,MasterID,cgGroupID)
1238 if (MyID.eq.MasterID) then
1239 ! Get the lowest and the highest energy.
1240 print *,'MASTER: etot_temp: ',(etot_all(i),i=0,nprocs-1),&
1241 ' emin=',emin,' emax=',emax
1245 if (emin.gt.etot_all(i)) emin=etot_all(i)
1246 if (emax.lt.etot_all(i)) emax=etot_all(i)
1249 endif ! MyID.eq.MasterID
1252 print *,'Processor',MyID,' calls MP_BCAST to send/recv etot_all'
1253 call mp_bcast(etot_all(1),16,MasterID,cgGroupID)
1254 print *,'Processor',MyID,' MP_BCAST to send/recv etot_all ended'
1255 if (MyID.ne.MasterID) then
1256 print *,'Processor:',MyID,etot_all(1),etot_all(2),&
1257 etot_all(1),etot_all(2)
1260 endif ! MyID.ne.MasterID
1261 write (iout,*) 'After MP_GATHER etot_temp=',&
1262 etot_temp,' emin=',emin
1270 ! Multicanonical sampling - start from Boltzmann distribution
1271 do i=-max_ene,max_ene
1272 entropy(i)=(emin+i*delte)*betbol
1275 ! Entropic sampling - start from uniform distribution of the density of states
1276 do i=-max_ene,max_ene
1280 write (iout,'(/a)') 'Initial entropy'
1281 do i=indminn,indmaxx
1282 write (iout,'(i5,2f10.5)') i,emin+i*delte,entropy(i)
1284 if (isweep.eq.1) then
1288 indmaxx=indminn+nbins
1291 endif ! .not. ent_read
1293 call recv_stop_sig(Kwita)
1294 if (whatsup.eq.1) then
1295 call send_stop_sig(-2)
1297 else if (whatsup.le.-2) then
1299 else if (whatsup.eq.2) then
1307 write (iout,'(/80(1h*)/20x,a/80(1h*))') &
1308 'Enter Monte Carlo procedure.'
1310 call briefout(0,etot)
1315 call entropia(eold,sold,indeold)
1316 ! NACC is the counter for the accepted conformations of a given processor
1318 ! NACC_TOT counts the total number of accepted conformations
1321 !----------------------------------------------------------------------------
1322 ! Zero out average energies
1324 energia_ave(i)=0.0d0
1326 ! Initialize energy histogram
1327 do i=-max_ene,max_ene
1330 ! Zero out iteration counter.
1335 ! Begin MC iteration loop.
1338 ! Initialize local counter.
1339 ntrial=0 ! # of generated non-overlapping confs.
1340 noverlap=0 ! # of overlapping confs.
1342 do while (.not. accepted .and. WhatsUp.eq.0 .and. Kwita.eq.0)
1344 ! Retrieve the angles of previously accepted conformation
1348 call var_to_geom(nvar,varia)
1349 ! Rebuild the chain.
1350 write(iout,*) 'Warning calling chainbuild'
1355 ! Decide whether to take a conformation from the pool or generate/perturb one
1357 from_pool=ran_number(0.0D0,1.0D0)
1358 if (npool.gt.0 .and. from_pool.lt.pool_fraction) then
1359 ! Throw a dice to choose the conformation from the pool
1360 ii=iran_num(1,npool)
1362 varia(i)=xpool(i,ii)
1364 call var_to_geom(nvar,varia)
1365 write(iout,*) 'Warning calling chainbuild'
1368 !d write (iout,'(10f8.1)') (rad2deg*varia(i),i=1,nvar)
1369 if (print_mc.gt.0 .and. (it/print_freq)*print_freq.eq.it) &
1370 write (iout,'(a,i3,a,f10.5)') &
1371 'Try conformation',ii,' from the pool energy=',epool(ii)
1373 moves(-1)=moves(-1)+1
1375 ! Decide whether to generate a random conformation or perturb the old one
1376 RandOrPert=ran_number(0.0D0,1.0D0)
1377 if (RandOrPert.gt.RanFract) then
1378 if (print_mc.gt.0 .and. (it/print_freq)*print_freq.eq.it) &
1379 write (iout,'(a)') 'Perturbation-generated conformation.'
1380 call perturb(error,lprint,MoveType,nbond,0.1D0)
1382 if (MoveType.lt.1 .or. MoveType.gt.MaxMoveType) then
1383 write (iout,'(/a,i7,a/)') 'Error - unknown MoveType=',&
1384 MoveType,' returned from PERTURB.'
1391 nstart_grow=iran_num(3,nres)
1392 if (print_mc.gt.0 .and. (it/print_freq)*print_freq.eq.it) &
1393 write (iout,'(2a,i3)') 'Random-generated conformation',&
1394 ' - chain regrown from residue',nstart_grow
1395 call gen_rand_conf(nstart_grow,*30)
1397 call geom_to_var(nvar,varia)
1399 !d write (iout,'(10f8.1)') (rad2deg*varia(i),i=1,nvar)
1401 if (print_mc.gt.0 .and. (it/print_freq)*print_freq.eq.it) &
1402 write (iout,'(a,i5,a,i10,a,i10)') &
1403 'Processor',MyId,' trial move',ntrial,' total generated:',ngen
1404 if (print_mc.gt.0 .and. (it/print_freq)*print_freq.eq.it) &
1405 write (*,'(a,i5,a,i10,a,i10)') &
1406 'Processor',MyId,' trial move',ntrial,' total generated:',ngen
1407 call etotal(energia)
1410 !d call enerprint(energia(0))
1411 !d write(iout,*)'it=',it,' etot=',etot
1412 if (etot-elowest.gt.overlap_cut) then
1413 if (print_mc.gt.0 .and. (it/print_freq)*print_freq.eq.it) &
1414 write (iout,'(a,i5,a,1pe14.5)') 'Iteration',it,&
1415 ' Overlap detected in the current conf.; energy is',etot
1418 if (noverlap.gt.maxoverlap) then
1419 write (iout,'(a)') 'Too many overlapping confs.'
1423 !--------------------------------------------------------------------------
1424 !... Acceptance test
1425 !--------------------------------------------------------------------------
1428 call accept_mc(it,etot,eold,scur,sold,varia,varold,accepted)
1432 if (elowest.gt.etot) then
1435 var_lowest(i)=varia(i)
1438 if (ehighest.lt.etot) ehighest=etot
1439 moves_acc(MoveType)=moves_acc(MoveType)+1
1440 if (MoveType.eq.1) then
1441 nbond_acc(nbond)=nbond_acc(nbond)+1
1443 ! Compare with reference structure.
1445 call fitsq(rms,c(1,nstart_seq),cref(1,nstart_sup,1),&
1446 nsup,przes,obr,non_conv)
1448 call contact(.false.,ncont,icont,co)
1449 frac=contact_fract(ncont,ncont_ref,icont,icont_ref)
1452 ! Periodically save average energies and confs.
1455 energia_ave(i)=energia_ave(i)+energia(i)
1457 moves(MaxMoveType+1)=nmove
1458 moves_acc(MaxMoveType+1)=nacc
1459 IF ((it/save_frequency)*save_frequency.eq.it) THEN
1461 energia_ave(i)=energia_ave(i)/save_frequency
1463 etot_ave=energia_ave(0)
1465 ! open (istat,file=statname,position='append')
1467 ! open (istat,file=statname,access='append')
1469 if (print_mc.gt.0) &
1470 write (iout,'(80(1h*)/20x,a,i20)') &
1472 if (refstr .and. print_mc.gt.0) then
1473 write (iout,'(a,f8.3,a,f8.3,a,f8.3)') &
1474 'RMS deviation from the reference structure:',rms,&
1475 ' % of native contacts:',frac*100,' contact order:',co
1477 if (print_stat) then
1479 write (istat,'(i10,10(1pe14.5))') it,&
1480 (energia_ave(print_order(i)),i=1,nprint_ene),&
1481 etot_ave,rms_ave,frac_ave
1483 write (istat,'(i10,10(1pe14.5))') it,&
1484 (energia_ave(print_order(i)),i=1,nprint_ene),&
1489 if (print_mc.gt.0) &
1490 call statprint(nacc,nfun,iretcode,etot,elowest)
1491 ! Print internal coordinates.
1492 if (print_int) call briefout(nacc,etot)
1494 energia_ave(i)=0.0d0
1496 ENDIF ! ( (it/save_frequency)*save_frequency.eq.it)
1498 inde=icialosc((etot-emin)/delte)
1499 nhist(inde)=nhist(inde)+1.0D0
1501 if ( (it/message_frequency)*message_frequency.eq.it &
1502 .and. (MyID.ne.MasterID) ) then
1503 call recv_stop_sig(Kwita)
1504 call send_MCM_info(message_frequency)
1507 ! Store the accepted conf. and its energy.
1514 if (Kwita.eq.0) call recv_stop_sig(kwita)
1519 if (MyID.eq.MasterID .and. &
1520 (it/message_frequency)*message_frequency.eq.it) then
1521 call receive_MC_info
1522 if (nacc_tot.ge.maxacc) accepted=.true.
1525 ! if ((ntrial.gt.maxtrial_iter
1526 ! & .or. (it/pool_read_freq)*pool_read_freq.eq.it)
1527 ! & .and. npool.gt.0) then
1528 ! Take a conformation from the pool
1529 ! ii=iran_num(1,npool)
1531 ! varold(i)=xpool(i,ii)
1533 ! if (ntrial.gt.maxtrial_iter)
1534 ! & write (iout,*) 'Iteration',it,' max. # of trials exceeded.'
1536 ! & 'Take conformation',ii,' from the pool energy=',epool(ii)
1537 ! if (print_mc.gt.2)
1538 ! & write (iout,'(10f8.3)') (rad2deg*varold(i),i=1,nvar)
1541 ! call entropia(eold,sold,indeold)
1543 ! endif ! (ntrial.gt.maxtrial_iter .and. npool.gt.0)
1547 if (MyID.eq.MasterID .and. &
1548 (it/message_frequency)*message_frequency.eq.it) then
1549 call receive_MC_info
1551 if (Kwita.eq.0) call recv_stop_sig(kwita)
1553 if (ovrtim()) WhatsUp=-1
1554 !d write (iout,*) 'WhatsUp=',WhatsUp,' Kwita=',Kwita
1555 not_done = (nacc_tot.lt.maxacc) .and. (WhatsUp.eq.0) &
1557 !d write (iout,*) 'not_done=',not_done
1559 if (Kwita.lt.0) then
1560 print *,'Processor',MyID,&
1561 ' has received STOP signal =',Kwita,' in EntSamp.'
1562 !d print *,'not_done=',not_done
1563 if (Kwita.lt.-1) WhatsUp=Kwita
1564 if (MyID.ne.MasterID) call send_MCM_info(-1)
1565 else if (nacc_tot.ge.maxacc) then
1566 print *,'Processor',MyID,' calls send_stop_sig,',&
1567 ' because a sufficient # of confs. have been collected.'
1568 !d print *,'not_done=',not_done
1569 call send_stop_sig(-1)
1570 if (MyID.ne.MasterID) call send_MCM_info(-1)
1571 else if (WhatsUp.eq.-1) then
1572 print *,'Processor',MyID,&
1573 ' calls send_stop_sig because of timeout.'
1574 !d print *,'not_done=',not_done
1575 call send_stop_sig(-2)
1576 if (MyID.ne.MasterID) call send_MCM_info(-1)
1581 !-----------------------------------------------------------------
1582 !... Construct energy histogram & update entropy
1583 !-----------------------------------------------------------------
1587 write (iout,*) 'Processor',MyID,&
1588 ' is broadcasting ERROR-STOP signal.'
1589 write (*,*) 'Processor',MyID,&
1590 ' is broadcasting ERROR-STOP signal.'
1591 call send_stop_sig(-3)
1592 if (MyID.ne.MasterID) call send_MCM_info(-1)
1595 write (iout,'(/a)') 'Energy histogram'
1597 write (iout,'(i5,2f20.5)') i,emin+i*delte,nhist(i)
1600 ! Wait until every processor has sent complete MC info.
1601 if (MyID.eq.MasterID) then
1604 ! write (*,*) 'The IFINISH array:'
1605 ! write (*,*) (ifinish(i),i=1,nctasks)
1608 not_done=not_done.or.(ifinish(i).ge.0)
1610 if (not_done) call receive_MC_info
1613 ! Make collective histogram from the work of all processors.
1614 msglen=(2*max_ene+1)*8
1616 'Processor',MyID,' calls MP_REDUCE to send/receive histograms',&
1618 call mp_reduce(nhist,nhist1,msglen,MasterID,d_vadd,&
1620 print *,'Processor',MyID,' MP_REDUCE accomplished for histogr.'
1621 do i=-max_ene,max_ene
1624 ! Collect min. and max. energy
1626 'Processor',MyID,' calls MP_REDUCE to send/receive energy borders'
1627 call mp_reduce(elowest,elowest1,8,MasterID,d_vmin,cgGroupID)
1628 call mp_reduce(ehighest,ehighest1,8,MasterID,d_vmax,cgGroupID)
1629 print *,'Processor',MyID,' MP_REDUCE accomplished for energies.'
1630 IF (MyID.eq.MasterID) THEN
1634 write (iout,'(a,i10)') '# of accepted confs:',nacc_tot
1635 write (iout,'(a,f10.5,a,f10.5)') 'Lowest energy:',elowest,&
1636 ' Highest energy',ehighest
1637 indmin=icialosc((elowest-emin)/delte)
1638 imdmax=icialosc((ehighest-emin)/delte)
1639 if (indmin.lt.indminn) then
1640 emax=emin+indmin*delte+e_up
1641 indmaxx=indmin+nbins
1644 if (.not.ent_read) ent_read=.true.
1645 write(iout,*)'indminn=',indminn,' indmaxx=',indmaxx
1646 ! Update entropy (density of states)
1648 if (nhist(i).gt.0) then
1649 entropy(i)=entropy(i)+dlog(nhist(i)+0.0D0)
1652 write (iout,'(/80(1h*)/a,i2/80(1h*)/)') &
1653 'End of macroiteration',isweep
1654 write (iout,'(a,f10.5,a,f10.5)') 'Elowest=',elowest,&
1655 ' Ehighest=',ehighest
1656 write (iout,'(/a)') 'Energy histogram'
1657 do i=indminn,indmaxx
1658 write (iout,'(i5,2f20.5)') i,emin+i*delte,nhist(i)
1660 write (iout,'(/a)') 'Entropy'
1661 do i=indminn,indmaxx
1662 write (iout,'(i5,2f20.5)') i,emin+i*delte,entropy(i)
1664 !-----------------------------------------------------------------
1665 !... End of energy histogram construction
1666 !-----------------------------------------------------------------
1669 if (.not. ent_read) ent_read=.true.
1670 ENDIF ! MyID .eq. MaterID
1671 if (MyID.eq.MasterID) then
1675 print *,'before mp_bcast processor',MyID,' indminn=',indminn,&
1676 ' indmaxx=',indmaxx,' itemp=',itemp(1),itemp(2)
1677 call mp_bcast(itemp(1),8,MasterID,cgGroupID)
1678 call mp_bcast(emax,8,MasterID,cgGroupID)
1679 print *,'after mp_bcast processor',MyID,' indminn=',indminn,&
1680 ' indmaxx=',indmaxx,' itemp=',itemp(1),itemp(2)
1681 if (MyID .ne. MasterID) then
1685 msglen=(indmaxx-indminn+1)*8
1686 print *,'processor',MyID,' calling mp_bcast msglen=',msglen,&
1687 ' indminn=',indminn,' indmaxx=',indmaxx,' isweep=',isweep
1688 call mp_bcast(entropy(indminn),msglen,MasterID,cgGroupID)
1689 IF(MyID.eq.MasterID .and. .not. ovrtim() .and. WhatsUp.ge.0)THEN
1690 open (ientout,file=entname,status='unknown')
1691 write (ientout,'(2i5,2e25.17)') indminn,indmaxx,emin,emax
1692 do i=indminn,indmaxx
1693 write (ientout,'(i5,f10.5,f20.15)') i,emin+i*delte,entropy(i)
1697 write (iout,*) 'Received from master:'
1698 write (iout,*) 'indminn=',indminn,' indmaxx=',indmaxx,&
1699 ' emin=',emin,' emax=',emax
1700 write (iout,'(/a)') 'Entropy'
1701 do i=indminn,indmaxx
1702 write (iout,'(i5,2f10.5)') i,emin+i*delte,entropy(i)
1704 ENDIF ! MyID.eq.MasterID
1705 print *,'Processor',MyID,' calls MP_GATHER'
1706 call mp_gather(nbond_move,nbond_move1,4*Nbm,MasterID,&
1708 call mp_gather(nbond_acc,nbond_acc1,4*Nbm,MasterID,&
1710 print *,'Processor',MyID,' MP_GATHER call accomplished'
1711 if (MyID.eq.MasterID) then
1713 write (iout,'(/80(1h*)/20x,a)') 'Summary run statistics:'
1714 call statprint(nacc_tot,nfun,iretcode,etot,elowest)
1715 write (iout,'(a)') &
1716 'Statistics of multiple-bond motions. Total motions:'
1717 write (iout,'(8i10)') (nbond_move(i),i=1,Nbm)
1718 write (iout,'(a)') 'Accepted motions:'
1719 write (iout,'(8i10)') (nbond_acc(i),i=1,Nbm)
1721 write (iout,'(a)') &
1722 'Statistics of multi-bond moves of respective processors:'
1726 nbond_move(i)=nbond_move(i)+nbond_move1(ind)
1727 nbond_acc(i)=nbond_acc(i)+nbond_acc1(ind)
1731 write (iout,*) 'Processor',iproc,' nbond_move:', &
1732 (nbond_move1(iproc*nbm+i),i=1,Nbm),&
1733 ' nbond_acc:',(nbond_acc1(iproc*nbm+i),i=1,Nbm)
1736 call mp_gather(moves,moves1,4*(MaxMoveType+3),MasterID,&
1738 call mp_gather(moves_acc,moves_acc1,4*(MaxMoveType+3),&
1740 if (MyID.eq.MasterID) then
1742 do i=-1,MaxMoveType+1
1743 moves(i)=moves(i)+moves1(i,iproc)
1744 moves_acc(i)=moves_acc(i)+moves_acc1(i,iproc)
1748 do i=0,MaxMoveType+1
1749 nmove=nmove+moves(i)
1752 write (iout,*) 'Processor',iproc,' moves',&
1753 (moves1(i,iproc),i=0,MaxMoveType+1),&
1754 ' moves_acc:',(moves_acc1(i,iproc),i=0,MaxMoveType+1)
1758 open (ientout,file=entname,status='unknown')
1759 write (ientout,'(2i5,2e25.17)') indminn,indmaxx,emin,emax
1760 do i=indminn,indmaxx
1761 write (ientout,'(i5,f10.5,f20.15)') i,emin+i*delte,entropy(i)
1765 write (iout,'(/80(1h*)/20x,a)') 'Summary run statistics:'
1766 call statprint(nacc_tot,nfun,iretcode,etot,elowest)
1767 write (iout,'(a)') &
1768 'Statistics of multiple-bond motions. Total motions:'
1769 write (iout,'(8i10)') (nbond_move(i),i=1,Nbm)
1770 write (iout,'(a)') 'Accepted motions:'
1771 write (iout,'(8i10)') (nbond_acc(i),i=1,Nbm)
1772 if (ovrtim() .or. WhatsUp.lt.0) return
1774 !---------------------------------------------------------------------------
1776 !---------------------------------------------------------------------------
1780 if (isweep.eq.nsweep .and. it.ge.maxacc) &
1781 write (iout,'(/80(1h*)/20x,a/80(1h*)/)') 'All iterations done.'
1783 end subroutine monte_carlo
1784 !-----------------------------------------------------------------------------
1785 subroutine accept_mc(it,ecur,eold,scur,sold,x,xold,accepted)
1787 ! implicit real*8 (a-h,o-z)
1788 ! include 'DIMENSIONS'
1789 ! include 'COMMON.MCM'
1790 ! include 'COMMON.MCE'
1791 ! include 'COMMON.IOUNITS'
1792 ! include 'COMMON.VAR'
1794 use MPI_data !include 'COMMON.INFO'
1796 ! include 'COMMON.GEO'
1797 real(kind=8) :: ecur,eold,xx,bol
1798 real(kind=8),dimension(6*nres) :: x,xold !(maxvar) (maxvar=6*maxres)
1802 integer :: it,indecur
1803 real(kind=8) :: scur,sold,xxh
1804 ! Check if the conformation is similar.
1805 !d write (iout,*) 'Enter ACCEPTING'
1806 !d write (iout,*) 'Old PHI angles:'
1807 !d write (iout,*) (rad2deg*xold(i),i=1,nphi)
1808 !d write (iout,*) 'Current angles'
1809 !d write (iout,*) (rad2deg*x(i),i=1,nphi)
1810 !d ddif=dif_ang(nphi,x,xold)
1811 !d write (iout,*) 'Angle norm:',ddif
1812 !d write (iout,*) 'ecur=',ecur,' emax=',emax
1813 if (ecur.gt.emax) then
1815 if (print_mc.gt.0 .and. (it/print_freq)*print_freq.eq.it) &
1816 write (iout,'(a)') 'Conformation rejected as too high in energy'
1819 ! Else evaluate the entropy of the conf and compare it with that of the previous
1821 call entropia(ecur,scur,indecur)
1822 !d print *,'Processor',MyID,' ecur=',ecur,' indecur=',indecur,
1823 !d & ' scur=',scur,' eold=',eold,' sold=',sold
1824 !d print *,'deix=',deix,' dent=',dent,' delte=',delte
1825 if (print_mc.gt.0 .and. (it/print_freq)*print_freq.eq.it) then
1826 write(iout,*)'it=',it,'ecur=',ecur,' indecur=',indecur,&
1828 write(iout,*)'eold=',eold,' sold=',sold
1830 if (scur.le.sold) then
1833 ! Else carry out acceptance test
1834 xx=ran_number(0.0D0,1.0D0)
1836 if (xxh.gt.50.0D0) then
1843 if (print_mc.gt.0 .and. (it/print_freq)*print_freq.eq.it) &
1844 write (iout,'(a)') 'Conformation accepted.'
1847 if (print_mc.gt.0 .and. (it/print_freq)*print_freq.eq.it) &
1848 write (iout,'(a)') 'Conformation rejected.'
1852 end subroutine accept_mc
1853 !-----------------------------------------------------------------------------
1854 integer function icialosc(x)
1857 if (x.lt.0.0D0) then
1863 end function icialosc
1864 !-----------------------------------------------------------------------------
1865 subroutine entropia(ecur,scur,indecur)
1867 use energy_data, only: max_ene
1868 ! implicit real*8 (a-h,o-z)
1869 ! include 'DIMENSIONS'
1870 ! include 'COMMON.MCM'
1871 ! include 'COMMON.MCE'
1872 ! include 'COMMON.IOUNITS'
1873 real(kind=8) :: ecur,scur,deix,dent
1874 integer :: indecur,it !???el
1876 indecur=icialosc((ecur-emin)/delte)
1877 if (iabs(indecur).gt.max_ene) then
1878 if ((it/print_freq)*it.eq.it) write (iout,'(a,2i5)') &
1879 'Accepting: Index out of range:',indecur
1881 else if (indecur.ge.indmaxx) then
1882 scur=entropy(indecur)
1883 if (print_mc.gt.0 .and. (it/print_freq)*it.eq.it) &
1884 write (iout,*)'Energy boundary reached',&
1885 indmaxx,indecur,entropy(indecur)
1887 deix=ecur-(emin+indecur*delte)
1888 dent=entropy(indecur+1)-entropy(indecur)
1889 scur=entropy(indecur)+(dent/delte)*deix
1892 end subroutine entropia
1893 !-----------------------------------------------------------------------------
1895 !-----------------------------------------------------------------------------
1896 subroutine mcm_setup
1899 ! implicit real*8 (a-h,o-z)
1900 ! include 'DIMENSIONS'
1901 ! include 'COMMON.IOUNITS'
1902 ! include 'COMMON.MCM'
1903 ! include 'COMMON.CONTROL'
1904 ! include 'COMMON.INTERACT'
1905 ! include 'COMMON.NAMES'
1906 ! include 'COMMON.CHAIN'
1907 ! include 'COMMON.VAR'
1909 !!! local variables - el
1910 integer :: i,i1,i2,it1,it2,ngly,mmm,maxwinlen
1912 ! Set up variables used in MC/MCM.
1914 ! allocate(sumpro_bond(0:nres)) !(0:maxres)
1916 write (iout,'(80(1h*)/20x,a/80(1h*))') 'MCM control parameters:'
1917 write (iout,'(5(a,i7))') 'Maxacc:',maxacc,' MaxTrial:',MaxTrial,&
1918 ' MaxRepm:',MaxRepm,' MaxGen:',MaxGen,' MaxOverlap:',MaxOverlap
1919 write (iout,'(4(a,f8.1)/2(a,i3))') &
1920 'Tmin:',Tmin,' Tmax:',Tmax,' TstepH:',TstepH,&
1921 ' TstepC:',TstepC,'NstepH:',NstepH,' NstepC:',NstepC
1922 if (nwindow.gt.0) then
1923 write (iout,'(a)') 'Perturbation windows:'
1929 write (iout,'(a,i3,a,i3,a,i3)') restyp(it1,1),i1,restyp(it2,1),i2,&
1933 ! Rbolt=8.3143D-3*2.388459D-01 kcal/(mol*K)
1935 ! Number of "end bonds".
1938 print *,'koniecl=',koniecl
1939 write (iout,'(a)') 'Probabilities of move types:'
1940 write (*,'(a)') 'Probabilities of move types:'
1942 write (iout,'(a,f10.5)') MovTypID(i),&
1943 sumpro_type(i)-sumpro_type(i-1)
1944 write (*,'(a,f10.5)') MovTypID(i),&
1945 sumpro_type(i)-sumpro_type(i-1)
1948 ! Maximum length of N-bond segment to be moved
1949 ! nbm=nres-1-(2*koniecl-1)
1950 if (nwindow.gt.0) then
1953 if (winlen(i).gt.maxwinlen) maxwinlen=winlen(i)
1955 nbm=min0(maxwinlen,6)
1956 write (iout,'(a,i3,a,i3)') 'Nbm=',Nbm,' Maxwinlen=',Maxwinlen
1960 sumpro_bond(0)=0.0D0
1961 sumpro_bond(1)=0.0D0
1963 sumpro_bond(i)=sumpro_bond(i-1)+1.0D0/dfloat(i)
1965 write (iout,'(a)') 'The SumPro_Bond array:'
1966 write (iout,'(8f10.5)') (sumpro_bond(i),i=1,nbm)
1967 write (*,'(a)') 'The SumPro_Bond array:'
1968 write (*,'(8f10.5)') (sumpro_bond(i),i=1,nbm)
1969 ! Maximum number of side chains moved simultaneously
1970 ! print *,'nnt=',nnt,' nct=',nct
1973 if (itype(i,1).eq.10) ngly=ngly+1
1977 MaxSideMove=min0((nct-nnt+1)/2,mmm)
1979 ! print *,'MaxSideMove=',MaxSideMove
1980 ! Max. number of generated confs (not used at present).
1982 ! Set initial temperature
1984 betbol=1.0D0/(Rbol*Tcur)
1985 write (iout,'(a,f8.1,a,f10.5)') 'Initial temperature:',Tcur,&
1987 write (iout,*) 'RanFract=',ranfract
1989 end subroutine mcm_setup
1990 !-----------------------------------------------------------------------------
1992 subroutine do_mcm(i_orig)
1996 use MPI_data, only:Whatsup
1997 use control_data, only:refstr,minim,iprint
1999 use control, only:tcpu,ovrtim
2000 use regularize_, only:fitsq
2002 use minimm, only:minimize
2003 ! Monte-Carlo-with-Minimization calculations - serial code.
2004 ! implicit real*8 (a-h,o-z)
2005 ! include 'DIMENSIONS'
2006 ! include 'COMMON.IOUNITS'
2007 ! include 'COMMON.GEO'
2008 ! include 'COMMON.CHAIN'
2009 ! include 'COMMON.MCM'
2010 ! include 'COMMON.CONTACTS'
2011 ! include 'COMMON.CONTROL'
2012 ! include 'COMMON.VAR'
2013 ! include 'COMMON.INTERACT'
2014 ! include 'COMMON.CACHE'
2015 !rc include 'COMMON.DEFORM'
2016 !rc include 'COMMON.DEFORM1'
2017 ! include 'COMMON.NAMES'
2018 logical :: accepted,over,error,lprint,not_done,my_conf,&
2019 enelower,non_conv !,ovrtim
2020 integer :: MoveType,nbond !,conf_comp
2021 integer,dimension(max_cache) :: ifeed
2022 real(kind=8),dimension(6*nres) :: varia,varold !(maxvar) (maxvar=6*maxres)
2023 real(kind=8) :: elowest,eold
2024 real(kind=8) :: przes(3),obr(3,3)
2025 real(kind=8) :: energia(0:n_ene)
2026 real(kind=8) :: coord1(6*nres,max_thread2),enetb1(max_threadss) !el
2027 !!! local variables - el
2028 integer :: i,nf,nacc,it,nout,j,i_orig,nfun,Kwita,iretcode,&
2029 noverlap,nstart_grow,irepet,n_thr,ii
2030 real(kind=8) :: etot,frac,rms,co,RandOrPert,&
2032 !---------------------------------------------------------------------------
2033 ! Initialize counters.
2034 !---------------------------------------------------------------------------
2035 ! Total number of generated confs.
2037 ! Total number of moves. In general this won't be equal to the number of
2038 ! attempted moves, because we may want to reject some "bad" confs just by
2041 ! Total number of temperature jumps.
2043 ! Total number of shift (nbond_move(1)), spike, crankshaft, three-bond,...
2045 ! if(.not.allocated(varsave)) allocate(varsave(maxvar,maxsave)) !(maxvar,maxsave)
2046 ! allocate(nbond_move(nres)) !(maxres)
2052 ! Initialize total and accepted number of moves of various kind.
2057 ! Total number of energy evaluations.
2062 write (iout,*) 'RanFract=',RanFract
2067 !----------------------------------------------------------------------------
2068 ! Compute and print initial energies.
2069 !----------------------------------------------------------------------------
2071 write (iout,'(/80(1h*)/a)') 'Initial energies:'
2075 call etotal(energia)
2077 ! Minimize the energy of the first conformation.
2079 call geom_to_var(nvar,varia)
2080 ! write (iout,*) 'The VARIA array'
2081 ! write (iout,'(8f10.4)') (rad2deg*varia(i),i=1,nvar)
2082 call minimize(etot,varia,iretcode,nfun)
2083 call var_to_geom(nvar,varia)
2085 write (iout,*) 'etot from MINIMIZE:',etot
2086 ! write (iout,*) 'Tha VARIA array'
2087 ! write (iout,'(8f10.4)') (rad2deg*varia(i),i=1,nvar)
2089 call etotal(energia)
2091 call enerprint(energia)
2094 call fitsq(rms,c(1,nstart_seq),cref(1,nstart_sup,1),nsup,przes,& !el cref(1,nstart_sup)
2097 call contact(.false.,ncont,icont,co)
2098 frac=contact_fract(ncont,ncont_ref,icont,icont_ref)
2099 write (iout,'(a,f8.3,a,f8.3,a,f8.3)') &
2100 'RMS deviation from the reference structure:',rms,&
2101 ' % of native contacts:',frac*100,' contact order:',co
2103 write (istat,'(i5,17(1pe14.5))') 0,&
2104 (energia(print_order(i)),i=1,nprint_ene),&
2107 if (print_stat) write (istat,'(i5,16(1pe14.5))') 0,&
2108 (energia(print_order(i)),i=1,nprint_ene),etot
2110 if (print_stat) close(istat)
2111 neneval=neneval+nfun+1
2112 write (iout,'(/80(1h*)/20x,a/80(1h*))') &
2113 'Enter Monte Carlo procedure.'
2116 call briefout(0,etot)
2123 call zapis(varia,etot)
2124 nacc=0 ! total # of accepted confs of the current processor.
2125 nacc_tot=0 ! total # of accepted confs of all processors.
2127 not_done = (iretcode.ne.11)
2129 !----------------------------------------------------------------------------
2131 !----------------------------------------------------------------------------
2136 write (iout,'(80(1h*)/20x,a,i7)') &
2137 'Beginning iteration #',it
2138 ! Initialize local counter.
2139 ntrial=0 ! # of generated non-overlapping confs.
2141 do while (.not. accepted)
2143 ! Retrieve the angles of previously accepted conformation
2144 noverlap=0 ! # of overlapping confs.
2148 call var_to_geom(nvar,varia)
2149 ! Rebuild the chain.
2151 ! Heat up the system, if necessary.
2153 ! If temperature cannot be further increased, stop.
2158 !d write (iout,'(a)') 'Old variables:'
2159 !d write (iout,'(10f8.1)') (rad2deg*varia(i),i=1,nvar)
2160 ! Decide whether to generate a random conformation or perturb the old one
2161 RandOrPert=ran_number(0.0D0,1.0D0)
2162 if (RandOrPert.gt.RanFract) then
2163 if (print_mc.gt.0) &
2164 write (iout,'(a)') 'Perturbation-generated conformation.'
2165 call perturb(error,lprint,MoveType,nbond,1.0D0)
2167 if (MoveType.lt.1 .or. MoveType.gt.MaxMoveType) then
2168 write (iout,'(/a,i7,a/)') 'Error - unknown MoveType=',&
2169 MoveType,' returned from PERTURB.'
2176 nstart_grow=iran_num(3,nres)
2177 if (print_mc.gt.0) &
2178 write (iout,'(2a,i3)') 'Random-generated conformation',&
2179 ' - chain regrown from residue',nstart_grow
2180 call gen_rand_conf(nstart_grow,*30)
2182 call geom_to_var(nvar,varia)
2183 !d write (iout,'(a)') 'New variables:'
2184 !d write (iout,'(10f8.1)') (rad2deg*varia(i),i=1,nvar)
2187 call etotal(energia)
2189 ! call enerprint(energia(0))
2190 ! write (iout,'(2(a,1pe14.5))') 'Etot=',Etot,' Elowest=',Elowest
2191 if (etot-elowest.gt.overlap_cut) then
2192 if(iprint.gt.1.or.etot.lt.1d20) &
2193 write (iout,'(a,1pe14.5)') &
2194 'Overlap detected in the current conf.; energy is',etot
2198 if (noverlap.gt.maxoverlap) then
2199 write (iout,'(a)') 'Too many overlapping confs.'
2204 call minimize(etot,varia,iretcode,nfun)
2205 !d write (iout,*) 'etot from MINIMIZE:',etot
2206 !d write (iout,'(a)') 'Variables after minimization:'
2207 !d write (iout,'(10f8.1)') (rad2deg*varia(i),i=1,nvar)
2209 call etotal(energia)
2211 neneval=neneval+nfun+2
2213 ! call enerprint(energia(0))
2214 write (iout,'(a,i6,a,1pe16.6)') 'Conformation:',ngen,&
2216 !--------------------------------------------------------------------------
2217 !... Do Metropolis test
2218 !--------------------------------------------------------------------------
2222 if (WhatsUp.eq.0 .and. Kwita.eq.0) then
2223 call metropolis(nvar,varia,varold,etot,eold,accepted,&
2226 write (iout,*) 'My_Conf=',My_Conf,' EneLower=',EneLower
2231 if (elowest.gt.etot) elowest=etot
2232 moves_acc(MoveType)=moves_acc(MoveType)+1
2233 if (MoveType.eq.1) then
2234 nbond_acc(nbond)=nbond_acc(nbond)+1
2236 ! Check against conformation repetitions.
2237 irepet=conf_comp(varia,etot)
2238 if (print_stat) then
2239 #if defined(AIX) || defined(PGI)
2240 open (istat,file=statname,position='append')
2242 open (istat,file=statname,access='append')
2245 call statprint(nacc,nfun,iretcode,etot,elowest)
2247 call var_to_geom(nvar,varia)
2249 call fitsq(rms,c(1,nstart_seq),cref(1,nstart_sup,1),& !el cref(1,nstart_sup)
2250 nsup,przes,obr,non_conv)
2252 call contact(.false.,ncont,icont,co)
2253 frac=contact_fract(ncont,ncont_ref,icont,icont_ref)
2254 write (iout,'(a,f8.3,a,f8.3)') &
2255 'RMS deviation from the reference structure:',rms,&
2256 ' % of native contacts:',frac*100,' contact order',co
2260 write (iout,*) 'Writing new conformation',nout
2262 write (istat,'(i5,16(1pe14.5))') nout,&
2263 (energia(print_order(i)),i=1,nprint_ene),&
2267 write (istat,'(i5,17(1pe14.5))') nout,&
2268 (energia(print_order(i)),i=1,nprint_ene),etot
2270 if (print_stat) close(istat)
2271 ! Print internal coordinates.
2272 if (print_int) call briefout(nout,etot)
2273 ! Accumulate the newly accepted conf in the coord1 array, if it is different
2274 ! from all confs that are already there.
2275 call compare_s1(n_thr,max_thread2,etot,varia,ii,&
2276 enetb1,coord1,rms_deform,.true.,iprint)
2277 write (iout,*) 'After compare_ss: n_thr=',n_thr
2278 if (ii.eq.1 .or. ii.eq.3) then
2279 write (iout,'(8f10.4)') &
2280 (rad2deg*coord1(i,n_thr),i=1,nvar)
2283 write (iout,*) 'Conformation from cache, not written.'
2286 if (nrepm.gt.maxrepm) then
2287 write (iout,'(a)') 'Too many conformation repetitions.'
2290 ! Store the accepted conf. and its energy.
2295 if (irepet.eq.0) call zapis(varia,etot)
2296 ! Lower the temperature, if necessary.
2307 ! Check for time limit.
2308 if (ovrtim()) WhatsUp=-1
2309 not_done = (nacc_tot.lt.maxacc) .and. (WhatsUp.eq.0) &
2318 write (iout,'(/80(1h*)/20x,a)') 'Summary run statistics:'
2319 call statprint(nacc,nfun,iretcode,etot,elowest)
2320 write (iout,'(a)') &
2321 'Statistics of multiple-bond motions. Total motions:'
2322 write (iout,'(16i5)') (nbond_move(i),i=1,Nbm)
2323 write (iout,'(a)') 'Accepted motions:'
2324 write (iout,'(16i5)') (nbond_acc(i),i=1,Nbm)
2326 write (iout,'(/80(1h*)/20x,a/80(1h*)/)') 'All iterations done.'
2327 !(maxvar) (maxvar=6*maxres)
2329 end subroutine do_mcm
2331 !-----------------------------------------------------------------------------
2333 subroutine do_mcm(i_orig)
2335 ! Monte-Carlo-with-Minimization calculations - parallel code.
2337 use control_data, only:refstr!,tag
2338 use io_base, only:intout,briefout
2339 use control, only:ovrtim,tcpu
2340 use compare, only:contact,contact_fract
2341 use minimm, only:minimize
2342 use regularize_, only:fitsq
2343 ! use contact_, only:contact
2345 ! implicit real*8 (a-h,o-z)
2346 ! include 'DIMENSIONS'
2348 ! include 'COMMON.IOUNITS'
2349 ! include 'COMMON.GEO'
2350 ! include 'COMMON.CHAIN'
2351 ! include 'COMMON.MCM'
2352 ! include 'COMMON.CONTACTS'
2353 ! include 'COMMON.CONTROL'
2354 ! include 'COMMON.VAR'
2355 ! include 'COMMON.INTERACT'
2356 ! include 'COMMON.INFO'
2357 ! include 'COMMON.CACHE'
2358 !rc include 'COMMON.DEFORM'
2359 !rc include 'COMMON.DEFORM1'
2360 !rc include 'COMMON.DEFORM2'
2361 ! include 'COMMON.MINIM'
2362 ! include 'COMMON.NAMES'
2363 logical :: accepted,over,error,lprint,not_done,similar,&
2364 enelower,non_conv,flag,finish !,ovrtim
2365 integer :: MoveType,nbond !,conf_comp
2366 real(kind=8),dimension(6*nres) :: x1,varold1,varold,varia !(maxvar) (maxvar=6*maxres)
2367 real(kind=8) :: elowest,eold
2368 real(kind=8) :: przes(3),obr(3,3)
2369 integer :: iparentx(max_threadss2)
2370 integer :: iparentx1(max_threadss2)
2371 integer :: imtasks(150),imtasks_n
2372 real(kind=8) :: energia(0:n_ene)
2375 integer :: nfun,nodenum,i_orig,i,nf,nacc,it,nout,j,kkk,is,&
2376 Kwita,iretcode,noverlap,nstart_grow,ierr,iitt,&
2377 ii_grnum_d,ii_ennum_d,ii_hesnum_d,i_grnum_d,i_ennum_d,&
2378 i_hesnum_d,i_minimiz,irepet
2379 real(kind=8) :: etot,frac,eneglobal,RandOrPert,eold1,co,&
2382 ! if(.not.allocated(varsave)) allocate(varsave(maxvar,maxsave)) !(maxvar,maxsave)
2383 print *,'Master entered DO_MCM'
2391 !---------------------------------------------------------------------------
2392 ! Initialize counters.
2393 !---------------------------------------------------------------------------
2394 ! Total number of generated confs.
2396 ! Total number of moves. In general this won`t be equal to the number of
2397 ! attempted moves, because we may want to reject some "bad" confs just by
2400 ! Total number of temperature jumps.
2402 ! Total number of shift (nbond_move(1)), spike, crankshaft, three-bond,...
2404 allocate(nbond_move(nres)) !(maxres)
2410 ! Initialize total and accepted number of moves of various kind.
2415 ! Total number of energy evaluations.
2419 ! write (iout,*) 'RanFract=',RanFract
2422 !----------------------------------------------------------------------------
2423 ! Compute and print initial energies.
2424 !----------------------------------------------------------------------------
2426 write (iout,'(/80(1h*)/a)') 'Initial energies:'
2429 call etotal(energia)
2431 call enerprint(energia)
2432 ! Request energy computation from slave processors.
2433 call geom_to_var(nvar,varia)
2434 ! write (iout,*) 'The VARIA array'
2435 ! write (iout,'(8f10.4)') (rad2deg*varia(i),i=1,nvar)
2436 call minimize(etot,varia,iretcode,nfun)
2437 call var_to_geom(nvar,varia)
2439 write (iout,*) 'etot from MINIMIZE:',etot
2440 ! write (iout,*) 'Tha VARIA array'
2441 ! write (iout,'(8f10.4)') (rad2deg*varia(i),i=1,nvar)
2444 if (print_mc .gt. 0) write (iout,'(/80(1h*)/20x,a/80(1h*))') &
2445 'Enter Monte Carlo procedure.'
2446 if (print_mc .gt. 0) write (iout,'(i5,1pe14.5)' ) i_orig,etot
2452 call zapis(varia,etot)
2454 call var_to_geom(nvar,varia)
2456 call etotal(energia)
2457 if (print_mc.gt.0) write (iout,*) 'Initial energy:',etot
2459 nacc=0 ! total # of accepted confs of the current processor.
2460 nacc_tot=0 ! total # of accepted confs of all processors.
2462 !----------------------------------------------------------------------------
2464 !----------------------------------------------------------------------------
2467 LOOP1:do while (not_done)
2469 if (print_mc.gt.0) write (iout,'(80(1h*)/20x,a,i7)') &
2470 'Beginning iteration #',it
2471 ! Initialize local counter.
2472 ntrial=0 ! # of generated non-overlapping confs.
2473 noverlap=0 ! # of overlapping confs.
2475 LOOP2:do while (.not. accepted)
2477 LOOP3:do while (imtasks_n.lt.nodenum-1.and..not.finish)
2479 if(imtasks(i).eq.0) then
2484 ! Retrieve the angles of previously accepted conformation
2488 call var_to_geom(nvar,varia)
2489 ! Rebuild the chain.
2491 ! Heat up the system, if necessary.
2493 ! If temperature cannot be further increased, stop.
2499 ! write (iout,'(a)') 'Old variables:'
2500 ! write (iout,'(10f8.1)') (rad2deg*varia(i),i=1,nvar)
2501 ! Decide whether to generate a random conformation or perturb the old one
2502 RandOrPert=ran_number(0.0D0,1.0D0)
2503 if (RandOrPert.gt.RanFract) then
2504 if (print_mc.gt.0) &
2505 write (iout,'(a)') 'Perturbation-generated conformation.'
2506 call perturb(error,lprint,MoveType,nbond,1.0D0)
2507 ! print *,'after perturb',error,finish
2508 if (error) finish = .true.
2509 if (MoveType.lt.1 .or. MoveType.gt.MaxMoveType) then
2510 write (iout,'(/a,i7,a/)') 'Error - unknown MoveType=',&
2511 MoveType,' returned from PERTURB.'
2513 write (*,'(/a,i7,a/)') 'Error - unknown MoveType=',&
2514 MoveType,' returned from PERTURB.'
2520 nstart_grow=iran_num(3,nres)
2521 if (print_mc.gt.0) &
2522 write (iout,'(2a,i3)') 'Random-generated conformation',&
2523 ' - chain regrown from residue',nstart_grow
2524 call gen_rand_conf(nstart_grow,*30)
2526 call geom_to_var(nvar,varia)
2528 ! print *,'finish=',finish
2529 if (etot-elowest.gt.overlap_cut) then
2530 if (print_mc.gt.1) write (iout,'(a,1pe14.5)') &
2531 'Overlap detected in the current conf.; energy is',etot
2532 if(iprint.gt.1.or.etot.lt.1d19) print *,&
2533 'Overlap detected in the current conf.; energy is',etot
2537 if (noverlap.gt.maxoverlap) then
2538 write (iout,*) 'Too many overlapping confs.',&
2539 ' etot, elowest, overlap_cut', etot, elowest, overlap_cut
2542 else if (.not. finish) then
2543 ! Distribute tasks to processors
2544 ! print *,'Master sending order'
2545 call MPI_SEND(12, 1, MPI_INTEGER, is, tag,&
2547 ! write (iout,*) '12: tag=',tag
2548 ! print *,'Master sent order to processor',is
2549 call MPI_SEND(it, 1, MPI_INTEGER, is, tag,&
2551 ! write (iout,*) 'it: tag=',tag
2552 call MPI_SEND(eold, 1, MPI_DOUBLE_PRECISION, is, tag,&
2554 ! write (iout,*) 'eold: tag=',tag
2555 call MPI_SEND(varia(1), nvar, MPI_DOUBLE_PRECISION, &
2558 ! write (iout,*) 'varia: tag=',tag
2559 call MPI_SEND(varold(1), nvar, MPI_DOUBLE_PRECISION, &
2562 ! write (iout,*) 'varold: tag=',tag
2569 imtasks_n=imtasks_n+1
2575 LOOP_RECV:do while(.not.flag)
2577 call MPI_IPROBE(is,tag,CG_COMM,flag,status,ierr)
2579 call MPI_RECV(iitt, 1, MPI_INTEGER, is, tag,&
2580 CG_COMM, status, ierr)
2581 call MPI_RECV(eold1, 1, MPI_DOUBLE_PRECISION, is, tag,&
2582 CG_COMM, status, ierr)
2583 call MPI_RECV(etot, 1, MPI_DOUBLE_PRECISION, is, tag,&
2584 CG_COMM, status, ierr)
2585 call MPI_RECV(varia(1), nvar, MPI_DOUBLE_PRECISION,is,tag,&
2586 CG_COMM, status, ierr)
2587 call MPI_RECV(varold1(1), nvar, MPI_DOUBLE_PRECISION, is, &
2588 tag, CG_COMM, status, ierr)
2589 call MPI_RECV(ii_grnum_d, 1, MPI_INTEGER, is, tag,&
2590 CG_COMM, status, ierr)
2591 call MPI_RECV(ii_ennum_d, 1, MPI_INTEGER, is, tag,&
2592 CG_COMM, status, ierr)
2593 call MPI_RECV(ii_hesnum_d, 1, MPI_INTEGER, is, tag,&
2594 CG_COMM, status, ierr)
2595 i_grnum_d=i_grnum_d+ii_grnum_d
2596 i_ennum_d=i_ennum_d+ii_ennum_d
2597 neneval = neneval+ii_ennum_d
2598 i_hesnum_d=i_hesnum_d+ii_hesnum_d
2599 i_minimiz=i_minimiz+1
2601 imtasks_n=imtasks_n-1
2607 if(print_mc.gt.0) write (iout,'(a,i6,a,i6,a,i6,a,1pe16.6)') &
2608 'From Worker #',is,' iitt',iitt,&
2609 ' Conformation:',ngen,' energy:',etot
2610 !--------------------------------------------------------------------------
2611 !... Do Metropolis test
2612 !--------------------------------------------------------------------------
2613 call metropolis(nvar,varia,varold1,etot,eold1,accepted,&
2615 if(iitt.ne.it.and..not.similar) then
2616 call metropolis(nvar,varia,varold,etot,eold,accepted,&
2620 if(etot.lt.eneglobal)eneglobal=etot
2621 ! if(mod(it,100).eq.0)
2622 write(iout,*)'CHUJOJEB ',neneval,eneglobal
2624 ! Write the accepted conformation.
2627 call var_to_geom(nvar,varia)
2630 call fitsq(rms,c(1,nstart_seq),cref(1,nstart_sup,kkk),&
2631 nsup,przes,obr,non_conv)
2633 call contact(.false.,ncont,icont,co)
2634 frac=contact_fract(ncont,ncont_ref,icont,icont_ref)
2635 write (iout,'(a,f8.3,a,f8.3,a,f8.3)') &
2636 'RMS deviation from the reference structure:',rms,&
2637 ' % of native contacts:',frac*100,' contact order:',co
2639 if (print_mc.gt.0) &
2640 write (iout,*) 'Writing new conformation',nout
2641 if (print_stat) then
2642 call var_to_geom(nvar,varia)
2643 #if defined(AIX) || defined(PGI)
2644 open (istat,file=statname,position='append')
2646 open (istat,file=statname,access='append')
2649 write (istat,'(i5,16(1pe14.5))') nout,&
2650 (energia(print_order(i)),i=1,nprint_ene),&
2653 write (istat,'(i5,16(1pe14.5))') nout,&
2654 (energia(print_order(i)),i=1,nprint_ene),etot
2658 ! Print internal coordinates.
2659 if (print_int) call briefout(nout,etot)
2662 if (elowest.gt.etot) elowest=etot
2663 moves_acc(MoveType)=moves_acc(MoveType)+1
2664 if (MoveType.eq.1) then
2665 nbond_acc(nbond)=nbond_acc(nbond)+1
2667 ! Check against conformation repetitions.
2668 irepet=conf_comp(varia,etot)
2669 if (nrepm.gt.maxrepm) then
2670 if (print_mc.gt.0) &
2671 write (iout,'(a)') 'Too many conformation repetitions.'
2674 ! Store the accepted conf. and its energy.
2679 if (irepet.eq.0) call zapis(varia,etot)
2680 ! Lower the temperature, if necessary.
2686 if(finish.and.imtasks_n.eq.0)exit LOOP2
2687 enddo LOOP2 ! accepted
2688 ! Check for time limit.
2689 not_done = (it.lt.max_mcm_it) .and. (nacc_tot.lt.maxacc)
2690 if(.not.not_done .or. finish) then
2691 if(imtasks_n.gt.0) then
2698 enddo LOOP1 ! not_done
2700 if (print_mc.gt.0) then
2701 write (iout,'(/80(1h*)/20x,a)') 'Summary run statistics:'
2702 call statprint(nacc,nfun,iretcode,etot,elowest)
2703 write (iout,'(a)') &
2704 'Statistics of multiple-bond motions. Total motions:'
2705 write (iout,'(16i5)') (nbond_move(i),i=1,Nbm)
2706 write (iout,'(a)') 'Accepted motions:'
2707 write (iout,'(16i5)') (nbond_acc(i),i=1,Nbm)
2709 write (iout,'(/80(1h*)/20x,a/80(1h*)/)') 'All iterations done.'
2717 call MPI_SEND(999, 1, MPI_INTEGER, is, tag,&
2721 end subroutine do_mcm
2722 !-----------------------------------------------------------------------------
2723 subroutine execute_slave(nodeinfo,iprint)
2726 use minimm, only:minimize
2728 ! implicit real*8 (a-h,o-z)
2729 ! include 'DIMENSIONS'
2731 ! include 'COMMON.TIME1'
2732 ! include 'COMMON.IOUNITS'
2733 !rc include 'COMMON.DEFORM'
2734 !rc include 'COMMON.DEFORM1'
2735 !rc include 'COMMON.DEFORM2'
2736 ! include 'COMMON.LOCAL'
2737 ! include 'COMMON.VAR'
2738 ! include 'COMMON.INFO'
2739 ! include 'COMMON.MINIM'
2740 character(len=10) :: nodeinfo
2741 real(kind=8),dimension(6*nres) :: x,x1 !(maxvar) (maxvar=6*maxres)
2742 integer :: nfun,iprint,i_switch,ierr,i_grnum_d,i_ennum_d,&
2743 i_hesnum_d,iitt,iretcode,iminrep
2744 real(kind=8) :: ener,energyx
2746 nodeinfo='chujwdupe'
2747 ! print *,'Processor:',MyID,' Entering execute_slave'
2749 ! call MPI_SEND(nodeinfo, 10, MPI_CHARACTER, 0, tag,
2752 1001 call MPI_RECV(i_switch, 1, MPI_INTEGER, 0, tag,&
2753 CG_COMM, status, ierr)
2754 ! write(iout,*)'12: tag=',tag
2755 if(iprint.ge.2)print *, MyID,' recv order ',i_switch
2756 if (i_switch.eq.12) then
2760 call MPI_RECV(iitt, 1, MPI_INTEGER, 0, tag,&
2761 CG_COMM, status, ierr)
2762 ! write(iout,*)'12: tag=',tag
2763 call MPI_RECV(ener, 1, MPI_DOUBLE_PRECISION, 0, tag,&
2764 CG_COMM, status, ierr)
2765 ! write(iout,*)'ener: tag=',tag
2766 call MPI_RECV(x(1), nvar, MPI_DOUBLE_PRECISION, 0, tag,&
2767 CG_COMM, status, ierr)
2768 ! write(iout,*)'x: tag=',tag
2769 call MPI_RECV(x1(1), nvar, MPI_DOUBLE_PRECISION, 0, tag,&
2770 CG_COMM, status, ierr)
2771 ! write(iout,*)'x1: tag=',tag
2777 ! print *,'calling minimize'
2778 call minimize(energyx,x,iretcode,nfun)
2780 write(iout,100)'minimized energy = ',energyx,&
2781 ' # funeval:',nfun,' iret ',iretcode
2782 write(*,100)'minimized energy = ',energyx,&
2783 ' # funeval:',nfun,' iret ',iretcode
2784 100 format(a20,f10.5,a12,i5,a6,i2)
2785 if(iretcode.eq.10) then
2788 write(iout,*)' ... not converged - trying again ',iminrep
2789 call minimize(energyx,x,iretcode,nfun)
2791 write(iout,*)'minimized energy = ',energyx,&
2792 ' # funeval:',nfun,' iret ',iretcode
2793 if(iretcode.ne.10)go to 812
2795 if(iretcode.eq.10) then
2797 write(iout,*)' ... not converged again - giving up'
2802 ! print *,'Sending results'
2803 call MPI_SEND(iitt, 1, MPI_INTEGER, 0, tag,&
2805 call MPI_SEND(ener, 1, MPI_DOUBLE_PRECISION, 0, tag,&
2807 call MPI_SEND(energyx, 1, MPI_DOUBLE_PRECISION, 0, tag,&
2809 call MPI_SEND(x(1), nvar, MPI_DOUBLE_PRECISION, 0, tag,&
2811 call MPI_SEND(x1(1), nvar, MPI_DOUBLE_PRECISION, 0, tag,&
2813 call MPI_SEND(i_grnum_d, 1, MPI_INTEGER, 0, tag,&
2815 call MPI_SEND(nfun, 1, MPI_INTEGER, 0, tag,&
2817 call MPI_SEND(i_hesnum_d, 1, MPI_INTEGER, 0, tag,&
2819 ! print *,'End sending'
2824 end subroutine execute_slave
2826 !-----------------------------------------------------------------------------
2827 subroutine heat(over)
2829 ! implicit real*8 (a-h,o-z)
2830 ! include 'DIMENSIONS'
2831 ! include 'COMMON.MCM'
2832 ! include 'COMMON.IOUNITS'
2834 ! Check if there`s a need to increase temperature.
2835 if (ntrial.gt.maxtrial) then
2836 if (NstepH.gt.0) then
2837 if (dabs(Tcur-TMax).lt.1.0D-7) then
2838 if (print_mc.gt.0) &
2839 write (iout,'(/80(1h*)/a,f8.3,a/80(1h*))') &
2840 'Upper limit of temperature reached. Terminating.'
2845 if (Tcur.gt.Tmax) Tcur=Tmax
2846 betbol=1.0D0/(Rbol*Tcur)
2847 if (print_mc.gt.0) &
2848 write (iout,'(/80(1h*)/a,f8.3,a,f10.5/80(1h*))') &
2849 'System heated up to ',Tcur,' K; BetBol:',betbol
2855 if (print_mc.gt.0) &
2856 write (iout,'(a)') &
2857 'Maximum number of trials in a single MCM iteration exceeded.'
2866 !-----------------------------------------------------------------------------
2869 ! implicit real*8 (a-h,o-z)
2870 ! include 'DIMENSIONS'
2871 ! include 'COMMON.MCM'
2872 ! include 'COMMON.IOUNITS'
2873 if (nstepC.gt.0 .and. dabs(Tcur-Tmin).gt.1.0D-7) then
2875 if (Tcur.lt.Tmin) Tcur=Tmin
2876 betbol=1.0D0/(Rbol*Tcur)
2877 if (print_mc.gt.0) &
2878 write (iout,'(/80(1h*)/a,f8.3,a,f10.5/80(1h*))') &
2879 'System cooled down up to ',Tcur,' K; BetBol:',betbol
2883 !-----------------------------------------------------------------------------
2884 subroutine perturb(error,lprint,MoveType,nbond,max_phi)
2887 use energy, only:nnt,nct,itype
2888 use md_calc, only:bond_move
2889 ! implicit real*8 (a-h,o-z)
2890 ! include 'DIMENSIONS'
2891 integer,parameter :: MMaxSideMove=100
2892 ! include 'COMMON.MCM'
2893 ! include 'COMMON.CHAIN'
2894 ! include 'COMMON.INTERACT'
2895 ! include 'COMMON.VAR'
2896 ! include 'COMMON.GEO'
2897 ! include 'COMMON.NAMES'
2898 ! include 'COMMON.IOUNITS'
2899 !rc include 'COMMON.DEFORM1'
2900 logical :: error,lprint,fail
2901 integer :: MoveType,nbond,end_select,ind_side(MMaxSideMove)
2902 real(kind=8) :: max_phi
2903 real(kind=8) :: psi!,gen_psi
2904 !el external iran_num
2905 !el integer iran_num
2908 !!! local variables - el
2909 integer :: itrial,iiwin,iwindow,isctry,i,icount,j,nstart,&
2910 nside_move,inds,indx,ii,iti
2911 real(kind=8) :: bond_prob,theta_new
2916 ! Perturb the conformation according to a randomly selected move.
2917 call SelectMove(MoveType)
2918 ! write (iout,*) 'MoveType=',MoveType
2920 goto (100,200,300,400,500) MoveType
2921 !------------------------------------------------------------------------------
2922 ! Backbone N-bond move.
2923 ! Select the number of bonds (length of the segment to perturb).
2925 if (itrial.gt.1000) then
2926 write (iout,'(a)') 'Too many attempts at multiple-bond move.'
2930 bond_prob=ran_number(0.0D0,sumpro_bond(nbm))
2931 ! print *,'sumpro_bond(nbm)=',sumpro_bond(nbm),
2932 ! & ' Bond_prob=',Bond_Prob
2934 ! print *,i,Bond_Prob,sumpro_bond(i),sumpro_bond(i+1)
2935 if (bond_prob.ge.sumpro_bond(i) .and. &
2936 bond_prob.le.sumpro_bond(i+1)) then
2941 write (iout,'(2a)') 'In PERTURB: Error - number of bonds',&
2942 ' to move out of range.'
2946 if (nwindow.gt.0) then
2947 ! Select the first residue to perturb
2948 iwindow=iran_num(1,nwindow)
2949 print *,'iwindow=',iwindow
2951 do while (winlen(iwindow).lt.nbond)
2952 iwindow=iran_num(1,nwindow)
2954 if (iiwin.gt.1000) then
2955 write (iout,'(a)') 'Cannot select moveable residues.'
2960 nstart=iran_num(winstart(iwindow),winend(iwindow))
2962 nstart = iran_num(koniecl+2,nres-nbond-koniecl)
2963 !d print *,'nres=',nres,' nbond=',nbond,' koniecl=',koniecl,
2964 !d & ' nstart=',nstart
2967 if (psi.eq.0.0) then
2971 if (print_mc.gt.1) write (iout,'(a,i4,a,i4,a,f8.3)') &
2972 'PERTURB: nbond=',nbond,' nstart=',nstart,' psi=',psi*rad2deg
2973 !d print *,'nstart=',nstart
2974 call bond_move(nbond,nstart,psi,.false.,error)
2976 write (iout,'(2a)') &
2977 'Could not define reference system in bond_move, ',&
2978 'choosing ahother segment.'
2982 nbond_move(nbond)=nbond_move(nbond)+1
2986 !------------------------------------------------------------------------------
2987 ! Backbone endmove. Perturb a SINGLE angle of a residue close to the end of
2991 ! end_select=iran_num(1,2*koniecl)
2992 ! if (end_select.gt.koniecl) then
2993 ! end_select=nphi-(end_select-koniecl)
2995 ! end_select=koniecl+3
2997 ! if (nwindow.gt.0) then
2998 ! iwin=iran_num(1,nwindow)
2999 ! i1=max0(4,winstart(iwin))
3000 ! i2=min0(winend(imin)+2,nres)
3001 ! end_select=iran_num(i1,i2)
3003 ! iselect = iran_num(1,nmov_var)
3006 ! if (isearch_tab(i).eq.1) jj = jj+1
3007 ! if (jj.eq.iselect) then
3013 end_select = iran_num(4,nres)
3014 psi=max_phi*gen_psi()
3015 if (psi.eq.0.0D0) then
3019 phi(end_select)=pinorm(phi(end_select)+psi)
3020 if (print_mc.gt.1) write (iout,'(a,i4,a,f8.3,a,f8.3)') &
3021 'End angle',end_select,' moved by ',psi*rad2deg,' new angle:',&
3022 phi(end_select)*rad2deg
3023 ! if (end_select.gt.3)
3024 ! & theta(end_select-1)=gen_theta(itype(end_select-2),
3025 ! & phi(end_select-1),phi(end_select))
3026 ! if (end_select.lt.nres)
3027 ! & theta(end_select)=gen_theta(itype(end_select-1),
3028 ! & phi(end_select),phi(end_select+1))
3029 !d print *,'nres=',nres,' end_select=',end_select
3030 !d print *,'theta',end_select-1,theta(end_select-1)
3031 !d print *,'theta',end_select,theta(end_select)
3036 !------------------------------------------------------------------------------
3038 ! Select the number of SCs to perturb.
3040 301 nside_move=iran_num(1,MaxSideMove)
3041 ! print *,'nside_move=',nside_move,' MaxSideMove',MaxSideMove
3042 ! Select the indices.
3045 111 inds=iran_num(nnt,nct)
3047 if (icount.gt.1000) then
3048 write (iout,'(a)')'Error - cannot select side chains to move.'
3052 if (itype(inds,1).eq.10) goto 111
3054 if (inds.eq.ind_side(j)) goto 111
3057 if (inds.lt.ind_side(j)) then
3063 112 do j=i,indx+1,-1
3064 ind_side(j)=ind_side(j-1)
3066 113 ind_side(indx)=inds
3068 ! Carry out perturbation.
3072 call gen_side(iti,theta(ii+1),alph(ii),omeg(ii),fail,1)
3075 if (isctry.gt.1000) then
3076 write (iout,'(a)') 'Too many errors in SC generation.'
3082 if (print_mc.gt.1) write (iout,'(2a,i4,a,2f8.3)') &
3083 'Side chain ',restyp(iti,1),ii,' moved to ',&
3084 alph(ii)*rad2deg,omeg(ii)*rad2deg
3089 !------------------------------------------------------------------------------
3091 400 end_select=iran_num(3,nres)
3092 theta_new=gen_theta(itype(end_select,1),phi(end_select),&
3093 phi(end_select+1),1)
3094 if (print_mc.gt.1) write (iout,'(a,i3,a,f8.3,a,f8.3)') &
3095 'Theta ',end_select,' moved from',theta(end_select)*rad2deg,&
3096 ' to ',theta_new*rad2deg
3097 theta(end_select)=theta_new
3101 !------------------------------------------------------------------------------
3102 ! Error returned from SelectMove.
3105 end subroutine perturb
3106 !-----------------------------------------------------------------------------
3107 subroutine SelectMove(MoveType)
3109 ! implicit real*8 (a-h,o-z)
3110 ! include 'DIMENSIONS'
3111 ! include 'COMMON.MCM'
3112 ! include 'COMMON.IOUNITS'
3114 !!! local variables - el
3115 integer :: i,MoveType
3116 real(kind=8) :: what_move
3118 what_move=ran_number(0.0D0,sumpro_type(MaxMoveType))
3120 if (what_move.ge.sumpro_type(i-1).and. &
3121 what_move.lt.sumpro_type(i)) then
3126 write (iout,'(a)') &
3127 'Fatal error in SelectMoveType: cannot select move.'
3128 MoveType=MaxMoveType+1
3130 end subroutine SelectMove
3131 !-----------------------------------------------------------------------------
3132 real(kind=8) function gen_psi()
3134 use geometry_data, only: angmin,pi
3137 real(kind=8) :: x !,ran_number
3138 ! include 'COMMON.IOUNITS'
3139 ! include 'COMMON.GEO'
3142 x=ran_number(-pi,pi)
3143 if (dabs(x).gt.angmin) then
3148 write (iout,'(a)')'From Gen_Psi: Cannot generate angle increment.'
3151 end function gen_psi
3152 !-----------------------------------------------------------------------------
3153 subroutine metropolis(n,xcur,xold,ecur,eold,accepted,similar,enelower)
3155 ! implicit real*8 (a-h,o-z)
3156 ! include 'DIMENSIONS'
3157 ! include 'COMMON.MCM'
3158 ! include 'COMMON.IOUNITS'
3159 ! include 'COMMON.VAR'
3160 ! include 'COMMON.GEO'
3161 !rc include 'COMMON.DEFORM'
3163 real(kind=8) :: ecur,eold,xx,bol !,ran_number
3164 real(kind=8),dimension(n) :: xcur,xold
3165 real(kind=8) :: ecut1 ,ecut2 ,tola
3166 logical :: accepted,similar,not_done,enelower
3169 !!! local variables - el
3170 real(kind=8) :: xxh,difene,reldife
3172 data ecut1 /-1.0D-5/,ecut2 /5.0D-3/,tola/5.0D0/
3176 ! Set lprn=.true. for debugging.
3179 !el write(iout,*)'enedif',enedif,' ecut1',ecut1,' ecut2',ecut2
3180 write(iout,*)' ecut1',ecut1,' ecut2',ecut2
3184 ! Check if the conformation is similar.
3186 reldife=difene/dmax1(dabs(eold),dabs(ecur),1.0D0)
3188 write (iout,*) 'Metropolis'
3189 write(iout,*)'ecur,eold,difene,reldife',ecur,eold,difene,reldife
3191 ! If energy went down remarkably, we accept the new conformation
3193 !jp if (reldife.lt.ecut1) then
3194 if (difene.lt.ecut1) then
3197 if (lprn) write (iout,'(a)') &
3198 'Conformation accepted, because energy has lowered remarkably.'
3199 ! elseif (reldife.lt.ecut2 .and. dif_ang(nphi,xcur,xold).lt.tola)
3200 !jp elseif (reldife.lt.ecut2)
3201 elseif (difene.lt.ecut2) &
3203 ! Reject the conf. if energy has changed insignificantly and there is not
3204 ! much change in conformation.
3206 write (iout,'(2a)') 'Conformation rejected, because it is',&
3207 ' similar to the preceding one.'
3211 ! Else carry out Metropolis test.
3213 xx=ran_number(0.0D0,1.0D0)
3216 write (iout,*) 'betbol=',betbol,' difene=',difene,' xxh=',xxh
3217 if (xxh.gt.50.0D0) then
3222 if (lprn) write (iout,*) 'bol=',bol,' xx=',xx
3225 if (lprn) write (iout,'(a)') &
3226 'Conformation accepted, because it passed Metropolis test.'
3229 if (lprn) write (iout,'(a)') &
3230 'Conformation rejected, because it did not pass Metropolis test.'
3239 end subroutine metropolis
3240 !-----------------------------------------------------------------------------
3241 integer function conf_comp(x,ene)
3243 use geometry_data, only: nphi
3244 ! implicit real*8 (a-h,o-z)
3245 ! include 'DIMENSIONS'
3246 ! include 'COMMON.MCM'
3247 ! include 'COMMON.VAR'
3248 ! include 'COMMON.IOUNITS'
3249 ! include 'COMMON.GEO'
3250 real(kind=8) :: etol, angtol
3251 real(kind=8),dimension(6*nres) :: x !(maxvar) (maxvar=6*maxres)
3252 real(kind=8) :: difa !dif_ang,
3254 !!! local variables - el
3258 data etol /0.1D0/, angtol /20.0D0/
3260 ! write (iout,*) 'ii=',ii,'ene=',ene,esave(ii),dabs(ene-esave(ii))
3261 if (dabs(ene-esave(ii)).lt.etol) then
3262 difa=dif_ang(nphi,x,varsave(1,ii))
3264 ! write(iout,'(i3,3f8.3)')i,rad2deg*x(i),
3265 ! & rad2deg*varsave(i,ii)
3267 ! write(iout,*) 'ii=',ii,' difa=',difa,' angtol=',angtol
3268 if (difa.le.angtol) then
3269 if (print_mc.gt.0) then
3270 write (iout,'(a,i5,2(a,1pe15.4))') &
3271 'Current conformation matches #',ii,&
3272 ' in the store array ene=',ene,' esave=',esave(ii)
3273 ! write (*,'(a,i5,a)') 'Current conformation matches #',ii,
3274 ! & ' in the store array.'
3275 endif ! print_mc.gt.0
3276 if (print_mc.gt.1) then
3278 write(iout,'(i3,3f8.3)')i,rad2deg*x(i),&
3279 rad2deg*varsave(i,ii)
3281 endif ! print_mc.gt.1
3290 end function conf_comp
3291 !-----------------------------------------------------------------------------
3292 real(kind=8) function dif_ang(n,x,y)
3294 use geometry_data, only: dwapi
3297 real(kind=8),dimension(n) :: x,y
3298 real(kind=8) :: w,wa,dif,difa
3299 !el real(kind=8) :: pinorm
3300 ! include 'COMMON.GEO'
3304 dif=dabs(pinorm(y(i)-x(i)))
3305 if (dabs(dif-dwapi).lt.dif) dif=dabs(dif-dwapi)
3306 w=1.0D0-(2.0D0*(i-1)/(n-1)-1.0D0)**2+1.0D0/n
3310 dif_ang=rad2deg*dsqrt(difa/wa)
3312 end function dif_ang
3313 !-----------------------------------------------------------------------------
3314 subroutine add2cache(n1,n2,ncache,nvar,SourceID,CachSrc,ecur,xcur,ecache,xcache)
3317 ! include 'COMMON.GEO'
3318 ! include 'COMMON.IOUNITS'
3319 integer :: n1,n2,ncache,nvar,SourceID,CachSrc(n2)
3321 real(kind=8) :: ecur,xcur(nvar),ecache(n2),xcache(n1,n2)
3322 !d write (iout,*) 'Enter ADD2CACHE ncache=',ncache ,' ecur',ecur
3323 !d write (iout,'(10f8.3)') (rad2deg*xcur(i),i=1,nvar)
3324 !d write (iout,*) 'Old CACHE array:'
3326 !d write (iout,*) 'i=',i,' ecache=',ecache(i),' CachSrc',CachSrc(i)
3327 !d write (iout,'(10f8.3)') (rad2deg*xcache(j,i),j=1,nvar)
3331 do while (i.gt.0 .and. ecur.lt.ecache(i))
3335 !d write (iout,*) 'i=',i,' ncache=',ncache
3336 if (ncache.eq.n2) then
3337 write (iout,*) 'Cache dimension exceeded',ncache,n2
3338 write (iout,*) 'Highest-energy conformation will be removed.'
3342 ecache(ii+1)=ecache(ii)
3343 CachSrc(ii+1)=CachSrc(ii)
3345 xcache(j,ii+1)=xcache(j,ii)
3354 !d write (iout,*) 'New CACHE array:'
3356 !d write (iout,*) 'i=',i,' ecache=',ecache(i),' CachSrc',CachSrc(i)
3357 !d write (iout,'(10f8.3)') (rad2deg*xcache(j,i),j=1,nvar)
3360 end subroutine add2cache
3361 !-----------------------------------------------------------------------------
3362 subroutine rm_from_cache(i,n1,n2,ncache,nvar,CachSrc,ecache,xcache)
3365 ! include 'COMMON.GEO'
3366 ! include 'COMMON.IOUNITS'
3367 integer :: n1,n2,ncache,nvar,CachSrc(n2)
3369 real(kind=8) :: ecache(n2),xcache(n1,n2)
3371 !d write (iout,*) 'Enter RM_FROM_CACHE'
3372 !d write (iout,*) 'Old CACHE array:'
3374 !d write (iout,*)'i=',ii,' ecache=',ecache(ii),' CachSrc',CachSrc(ii)
3375 !d write (iout,'(10f8.3)') (rad2deg*xcache(j,ii),j=1,nvar)
3379 ecache(ii-1)=ecache(ii)
3380 CachSrc(ii-1)=CachSrc(ii)
3382 xcache(j,ii-1)=xcache(j,ii)
3386 !d write (iout,*) 'New CACHE array:'
3388 !d write (iout,*) 'i=',i,' ecache=',ecache(i),' CachSrc',CachSrc(i)
3389 !d write (iout,'(10f8.3)') (rad2deg*xcache(j,i),j=1,nvar)
3392 end subroutine rm_from_cache
3393 !-----------------------------------------------------------------------------
3395 !-----------------------------------------------------------------------------
3396 subroutine statprint(it,nfun,iretcode,etot,elowest)
3398 use control_data, only: MaxMoveType,minim
3399 use control, only: tcpu
3401 ! implicit real*8 (a-h,o-z)
3402 ! include 'DIMENSIONS'
3403 ! include 'COMMON.IOUNITS'
3404 ! include 'COMMON.CONTROL'
3405 ! include 'COMMON.MCM'
3407 integer :: it,nfun,iretcode,i
3408 real(kind=8) :: etot,elowest,fr_mov_i
3412 '(80(1h*)/a,i5,a,1pe14.5,a,1pe14.5/a,i3,a,i10,a,i5,a,i5)') &
3413 'Finished iteration #',it,' energy is',etot,&
3414 ' lowest energy:',elowest,&
3415 'SUMSL return code:',iretcode,&
3416 ' # of energy evaluations:',neneval,&
3417 '# of temperature jumps:',ntherm,&
3418 ' # of minima repetitions:',nrepm
3420 write (iout,'(80(1h*)/a,i8,a,1pe14.5,a,1pe14.5)') &
3421 'Finished iteration #',it,' energy is',etot,&
3422 ' lowest energy:',elowest
3424 write (iout,'(/4a)') &
3425 'Kind of move ',' total',' accepted',&
3427 write (iout,'(58(1h-))')
3429 if (moves(i).eq.0) then
3432 fr_mov_i=dfloat(moves_acc(i))/dfloat(moves(i))
3434 write(iout,'(a,2i15,f10.5)')MovTypID(i),moves(i),moves_acc(i),&
3437 write (iout,'(a,2i15,f10.5)') 'total ',nmove,nacc_tot,&
3438 dfloat(nacc_tot)/dfloat(nmove)
3439 write (iout,'(58(1h-))')
3440 write (iout,'(a,1pe12.4)') 'Elapsed time:',tcpu()
3442 end subroutine statprint
3443 !-----------------------------------------------------------------------------
3444 subroutine zapis(varia,etot)
3446 use geometry_data, only: nres,rad2deg,nvar
3449 ! implicit real*8 (a-h,o-z)
3450 ! include 'DIMENSIONS'
3452 use MPI_data !include 'COMMON.INFO'
3455 ! include 'COMMON.GEO'
3456 ! include 'COMMON.VAR'
3457 ! include 'COMMON.MCM'
3458 ! include 'COMMON.IOUNITS'
3459 integer,dimension(nsave) :: itemp
3460 real(kind=8),dimension(6*nres) :: varia !(maxvar) (maxvar=6*maxres)
3463 integer :: j,i,maxvar
3464 real(kind=8) :: etot
3466 !el allocate(esave(nsave)) !(maxsave)
3471 write (iout,'(a,i5,a,i5)') 'Enter ZAPIS NSave=',Nsave,&
3473 write (iout,'(a)') 'Current energy and conformation:'
3474 write (iout,'(1pe14.5)') etot
3475 write (iout,'(10f8.3)') (rad2deg*varia(i),i=1,nvar)
3477 ! Shift the contents of the esave and varsave arrays if filled up.
3478 call add2cache(6*nres,nsave,nsave,nvar,MyID,itemp,&
3479 etot,varia,esave,varsave)
3481 write (iout,'(a)') 'Energies and the VarSave array.'
3483 write (iout,'(i5,1pe14.5)') i,esave(i)
3484 write (iout,'(10f8.3)') (rad2deg*varsave(j,i),j=1,nvar)
3488 end subroutine zapis
3489 !-----------------------------------------------------------------------------
3490 !-----------------------------------------------------------------------------
3491 subroutine alloc_MCM_arrays
3493 use energy_data, only: max_ene
3497 allocate(entropy(-max_ene-4:max_ene)) !(-max_ene-4:max_ene)
3498 allocate(nhist(-max_ene:max_ene)) !(-max_ene:max_ene)
3499 allocate(nminima(maxsave)) !(maxsave)
3501 allocate(xpool(6*nres,max_pool)) !(maxvar,max_pool)(maxvar=6*maxres)
3502 allocate(epool(max_pool)) !(max_pool)
3505 if(.not.allocated(nsave_part)) allocate(nsave_part(nctasks)) !(max_cg_procs)
3508 ! real(kind=8),dimension(:),allocatable :: sumpro_type !(0:MaxMoveType)
3509 allocate(sumpro_bond(0:nres)) !(0:maxres)
3510 allocate(nbond_move(nres),nbond_acc(nres)) !(maxres)
3511 allocate(moves(-1:MaxMoveType+1),moves_acc(-1:MaxMoveType+1)) !(-1:MaxMoveType+1)
3512 ! common /accept_stats/
3513 ! allocate(nacc_part !(0:MaxProcs) !el nie uzywane???
3514 ! common /windows/ in io: mcmread
3515 ! allocate(winstart,winend,winlen !(maxres)
3517 !el allocate(MovTypID(-1:MaxMoveType+1)) !(-1:MaxMoveType+1)
3520 allocate(varsave(nres*6,maxsave)) !(maxvar,maxsave)(maxvar=6*maxres)
3521 allocate(esave(maxsave)) !(maxsave)
3522 allocate(Origin(maxsave)) !(maxsave)
3525 end subroutine alloc_MCM_arrays
3526 !-----------------------------------------------------------------------------
3527 !-----------------------------------------------------------------------------