1 subroutine WHAM_CALC(islice,*)
2 ! Weighed Histogram Analysis Method (WHAM) code
3 ! Written by A. Liwo based on the work of Kumar et al.,
4 ! J.Comput.Chem., 13, 1011 (1992)
6 ! 2/1/05 Multiple temperatures allowed.
7 ! 2/2/05 Free energies calculated directly from data points
8 ! acc. to Eq. (21) of Kumar et al.; final histograms also
9 ! constructed based on this equation.
10 ! 2/12/05 Multiple parameter sets included
12 ! 2/2/05 Parallel version
15 include "DIMENSIONS.ZSCOPT"
16 include "DIMENSIONS.FREE"
18 parameter (NGridT=400)
19 integer MaxBinRms,MaxBinRgy
20 parameter (MaxBinRms=100,MaxBinRgy=100)
22 c parameter (MaxHdim=200000)
23 parameter (MaxHdim=200)
25 parameter (maxinde=200)
29 integer ierror,errcode,status(MPI_STATUS_SIZE)
31 include "COMMON.CONTROL"
32 include "COMMON.IOUNITS"
34 include "COMMON.ENERGIES"
35 include "COMMON.FFIELD"
36 include "COMMON.SBRIDGE"
38 include "COMMON.ENEPS"
39 integer MaxPoint,MaxPointProc
40 parameter (MaxPoint=MaxStr,
41 & MaxPointProc=MaxStr_Proc)
42 double precision finorm_max,potfac,entmin,entmax,expfac,vf
43 parameter (finorm_max=1.0d0)
45 integer i,ii,j,jj,k,kk,l,m,ind,iter,t,tmax,ient,ientmax,iln
46 integer start,end,iharm,ib,iib,nbin1,nbin,nbin_rms,nbin_rgy,
47 & nbin_rmsrgy,liczba,iparm,nFi,indrgy,indrms
48 integer htot(0:MaxHdim),histent(0:2000)
49 double precision v(MaxPointProc,MaxR,MaxT_h,Max_Parm)
50 double precision energia(0:max_ene)
52 integer tmax_t,upindE_p
53 double precision fi_p(MaxR,MaxT_h,Max_Parm)
54 double precision sumW_p(0:nGridT,Max_Parm),
55 & sumE_p(0:nGridT,Max_Parm),sumEsq_p(0:nGridT,Max_Parm),
56 & sumQ_p(MaxQ1,0:nGridT,Max_Parm),
57 & sumQsq_p(MaxQ1,0:nGridT,Max_Parm),
58 & sumEQ_p(MaxQ1,0:nGridT,Max_Parm),
59 & sumEprim_p(MaxQ1,0:nGridT,Max_Parm),
60 & sumEbis_p(0:nGridT,Max_Parm)
61 double precision hfin_p(0:MaxHdim,maxT_h),
62 & hfin_ent_p(0:MaxHdim),histE_p(0:maxindE),sumH,
63 & hrmsrgy_p(0:MaxBinRgy,0:MaxBinRms,maxT_h)
64 double precision rgymin_t,rmsmin_t,rgymax_t,rmsmax_t
65 double precision potEmin_t,entmin_p,entmax_p
66 integer histent_p(0:2000)
67 logical lprint /.true./
69 double precision delta_T /1.0d0/
70 double precision rgymin,rmsmin,rgymax,rmsmax
71 double precision sumW(0:NGridT,Max_Parm),sumE(0:NGridT,Max_Parm),
72 & sumEsq(0:NGridT,Max_Parm),sumQ(MaxQ1,0:NGridT,Max_Parm),
73 & sumQsq(MaxQ1,0:NGridT,Max_Parm),sumEQ(MaxQ1,0:NGridT,Max_Parm),
74 & sumEprim(0:NGridT,Max_Parm),sumEbis(0:NGridT,Max_Parm),betaT,
76 double precision fi(MaxR,maxT_h,Max_Parm),
77 & dd,dd1,dd2,hh,dmin,denom,finorm,avefi,pom,
78 & hfin(0:MaxHdim,maxT_h),histE(0:maxindE),
79 & hrmsrgy(0:MaxBinRgy,0:MaxBinRms,maxT_h),
81 & hfin_ent(0:MaxHdim),vmax,aux
82 double precision fT(6),fTprim(6),fTbis(6),quot,quotl1,quotl,kfacl,
83 & eprim,ebis,temper,kfac/2.4d0/,T0/300.0d0/,startGridT/200.0d0/,
84 & eplus,eminus,logfac,tanhT,tt
85 double precision etot,evdw,evdw_t,evdw2,ees,evdw1,ebe,etors,
86 & escloc,ehpb,ecorr,ecorr5,ecorr6,eello_turn4,eello_turn3,
87 & eturn6,eel_loc,edihcnstr,etors_d,estr,evdw2_14,esccor,
90 integer ind_point(maxpoint),upindE,indE
99 write(licz2,'(bz,i2.2)') islice
101 write (iout,'(//80(1h-)/"Solving WHAM equations for slice",
102 & i2/80(1h-)//)') islice
103 write (iout,*) "delta",delta," nbin1",nbin1
104 write (iout,*) "MaxN",MaxN," MaxQ",MaxQ," MaHdim",MaxHdim
122 if (potE(i,j).le.potEmin) potEmin=potE(i,j)
124 if (q(nQ+1,i).lt.rmsmin) rmsmin=q(nQ+1,i)
125 if (q(nQ+1,i).gt.rmsmax) rmsmax=q(nQ+1,i)
126 if (q(nQ+2,i).lt.rgymin) rgymin=q(nQ+2,i)
127 if (q(nQ+2,i).gt.rgymax) rgymax=q(nQ+2,i)
130 ind=(q(j,i)-dmin+1.0d-8)/delta
132 ind_point(i)=ind_point(i)+ind
134 ind_point(i)=ind_point(i)+nbin1**(j-1)*ind
136 c write (iout,*) "i",i," j",j," q",q(j,i)," ind_point",
139 if (ind_point(i).lt.0 .or. ind_point(i).gt.MaxHdim) then
140 write (iout,*) "Error - index exceeds range for point",i,
141 & " q=",q(j,i)," ind",ind_point(i)
143 write (iout,*) "Processor",me1
145 call MPI_Abort(MPI_COMM_WORLD, Ierror, Errcode )
150 if (ind_point(i).gt.tmax) tmax=ind_point(i)
151 htot(ind_point(i))=htot(ind_point(i))+1
153 write (iout,*) "i",i,"q",(q(j,i),j=1,nQ)," ind",ind_point(i),
154 & " htot",htot(ind_point(i))
161 write (iout,'(a)') "Numbers of counts in Q bins"
163 if (htot(t).gt.0) then
164 write (iout,'(i15,$)') t
167 jj = mod(liczba,nbin1)
169 write (iout,'(i5,$)') jj
171 write (iout,'(i8)') htot(t)
175 write (iout,'(a,i3)') "Number of data points for parameter set",
177 write (iout,'(i7,$)') ((snk(m,ib,iparm,islice),m=1,nr(ib,iparm)),
179 write (iout,'(i8)') stot(islice)
185 call MPI_AllReduce(tmax,tmax_t,1,MPI_INTEGER,MPI_MAX,
188 call MPI_AllReduce(potEmin,potEmin_t,1,MPI_DOUBLE_PRECISION,
189 & MPI_MIN,WHAM_COMM,IERROR)
190 call MPI_AllReduce(rmsmin,rmsmin_t,1,MPI_DOUBLE_PRECISION,
191 & MPI_MIN,WHAM_COMM,IERROR)
192 call MPI_AllReduce(rmsmax,rmsmax_t,1,MPI_DOUBLE_PRECISION,
193 & MPI_MAX,WHAM_COMM,IERROR)
194 call MPI_AllReduce(rgymin,rgymin_t,1,MPI_DOUBLE_PRECISION,
195 & MPI_MIN,WHAM_COMM,IERROR)
196 call MPI_AllReduce(rgymax,rgymax_t,1,MPI_DOUBLE_PRECISION,
197 & MPI_MAX,WHAM_COMM,IERROR)
203 write (iout,*) "potEmin",potEmin
205 rmsmin=deltrms*dint(rmsmin/deltrms)
206 rmsmax=deltrms*dint(rmsmax/deltrms)
207 rgymin=deltrms*dint(rgymin/deltrgy)
208 rgymax=deltrms*dint(rgymax/deltrgy)
209 nbin_rms=(rmsmax-rmsmin)/deltrms
210 nbin_rgy=(rgymax-rgymin)/deltrgy
211 write (iout,*) "rmsmin",rmsmin," rmsmax",rmsmax," rgymin",rgymin,
212 & " rgymax",rgymax," nbin_rms",nbin_rms," nbin_rgy",nbin_rgy
219 write (iout,*) "nFi",nFi
220 ! Compute the Boltzmann factor corresponing to restrain potentials in different
227 c write (9,'(3i5,f10.5)') i,(iparm,potE(i,iparm),iparm=1,nParmSet)
230 write (iout,'(2i5,21f8.2)') i,iparm,
231 & (enetb(k,i,iparm),k=1,21)
233 call restore_parm(iparm)
235 write (iout,*) wsc,wscp,welec,wvdwpp,wang,wtor,wscloc,
236 & wcorr,wcorr5,wcorr6,wturn4,wturn3,wturn6,wel_loc,
237 & wtor_d,wsccor,wbond
240 if (rescale_mode.eq.1) then
241 quot=1.0d0/(beta_h(ib,iparm)*1.987D-3*T0)
248 fT(l)=kfacl/(kfacl-1.0d0+quotl)
251 tt = 1.0d0/(beta_h(ib,iparm)*1.987D-3)
252 ft(6)=(320.0d0+80.0d0*dtanh((tt-320.0d0)/80.0d0))/320.0d0
254 ft(6)=1.0d0/(beta_h(ib,iparm)*1.987D-3*T0)
258 else if (rescale_mode.eq.2) then
259 quot=1.0d0/(T0*beta_h(ib,iparm)*1.987D-3)
263 fT(l)=1.12692801104297249644d0/
264 & dlog(dexp(quotl)+dexp(-quotl))
267 tt = 1.0d0/(beta_h(ib,iparm)*1.987D-3)
268 ft(6)=(320.0d0+80.0d0*dtanh((tt-320.0d0)/80.0d0))/320.0d0
270 ft(6)=1.0d0/(beta_h(ib,iparm)*1.987D-3*T0)
274 c write (iout,*) 1.0d0/(beta_h(ib,iparm)*1.987D-3),ft
275 else if (rescale_mode.eq.0) then
280 write (iout,*) "Error in WHAM_CALC: wrong RESCALE_MODE",
285 evdw=enetb(1,i,iparm)
286 evdw_t=enetb(21,i,iparm)
288 evdw2_14=enetb(17,i,iparm)
289 evdw2=enetb(2,i,iparm)+evdw2_14
291 evdw2=enetb(2,i,iparm)
296 evdw1=enetb(16,i,iparm)
301 ecorr=enetb(4,i,iparm)
302 ecorr5=enetb(5,i,iparm)
303 ecorr6=enetb(6,i,iparm)
304 eel_loc=enetb(7,i,iparm)
305 eello_turn3=enetb(8,i,iparm)
306 eello_turn4=enetb(9,i,iparm)
307 eturn6=enetb(10,i,iparm)
308 ebe=enetb(11,i,iparm)
309 escloc=enetb(12,i,iparm)
310 etors=enetb(13,i,iparm)
311 etors_d=enetb(14,i,iparm)
312 ehpb=enetb(15,i,iparm)
313 estr=enetb(18,i,iparm)
314 esccor=enetb(19,i,iparm)
315 edihcnstr=enetb(20,i,iparm)
316 eliptran=enetb(22,i,iparm)
319 write (iout,'(3i5,6f5.2,14f12.3)') i,ib,iparm,(ft(l),l=1,6),
320 & evdw+evdw_t,evdw2,ees,evdw1,ecorr,eel_loc,estr,ebe,escloc,
321 & etors,etors_d,eello_turn3,eello_turn4,esccor
325 etot=wsc*(evdw+ft(6)*evdw_t)+wscp*evdw2+ft(1)*welec*ees
327 & +wang*ebe+ft(1)*wtor*etors+wscloc*escloc
328 & +wstrain*ehpb+nss*ebr+ft(3)*wcorr*ecorr+ft(4)*wcorr5*ecorr5
329 & +ft(5)*wcorr6*ecorr6+ft(3)*wturn4*eello_turn4
330 & +ft(2)*wturn3*eello_turn3
331 & +ft(5)*wturn6*eturn6+ft(2)*wel_loc*eel_loc
332 & +edihcnstr+ft(2)*wtor_d*etors_d+ft(1)*wsccor*esccor
333 & +wbond*estr+wliptran*eliptran
335 etot=wsc*(evdw+ft(6)*evdw_t)+wscp*evdw2
336 & +ft(1)*welec*(ees+evdw1)
337 & +wang*ebe+ft(1)*wtor*etors+wscloc*escloc
338 & +wstrain*ehpb+nss*ebr+ft(3)*wcorr*ecorr+ft(4)*wcorr5*ecorr5
339 & +ft(5)*wcorr6*ecorr6+ft(3)*wturn4*eello_turn4
340 & +ft(2)*wturn3*eello_turn3
341 & +ft(5)*wturn6*eturn6+ft(2)*wel_loc*eel_loc+edihcnstr
342 & +ft(2)*wtor_d*etors_d+ft(1)*wsccor*esccor
343 & +wbond*estr+wliptran*eliptran
346 write (iout,*) i,iparm,1.0d0/(beta_h(ib,iparm)*1.987D-3),
350 if (iparm.eq.1 .and. ib.eq.1) then
351 write (iout,*)"Conformation",i
354 energia(k)=enetb(k,i,iparm)
356 call enerprint(energia(0),fT)
363 Econstr=Econstr+Kh(j,kk,ib,iparm)
364 & *(dd-q0(j,kk,ib,iparm))**2
367 & -beta_h(ib,iparm)*(etot-potEmin+Econstr)
369 write (iout,'(4i5,4e15.5)') i,kk,ib,iparm,
370 & etot,potEmin,etot-potEmin,v(i,kk,ib,iparm)
376 ! Simple iteration to calculate free energies corresponding to all simulation
380 ! Compute new free-energy values corresponding to the righ-hand side of the
381 ! equation and their derivatives.
382 write (iout,*) "------------------------fi"
392 vf=v(t,l,k,i)+f(l,k,i)
393 if (vf.gt.vmax) vmax=vf
401 aux=f(l,k,i)+v(t,l,k,i)-vmax
403 & denom=denom+snk(l,k,i,islice)*dexp(aux)
407 entfac(t)=-dlog(denom)-vmax
409 write (iout,*) t,"vmax",vmax," denom",denom,"entfac",entfac(t)
414 do ii=1,nR(iib,iparm)
416 fi_p(ii,iib,iparm)=0.0d0
418 fi_p(ii,iib,iparm)=fi_p(ii,iib,iparm)
419 & +dexp(v(t,ii,iib,iparm)+entfac(t))
421 write (iout,'(4i5,3e15.5)') t,ii,iib,iparm,
422 & v(t,ii,iib,iparm),entfac(t),fi_p(ii,iib,iparm)
426 fi(ii,iib,iparm)=0.0d0
428 fi(ii,iib,iparm)=fi(ii,iib,iparm)
429 & +dexp(v(t,ii,iib,iparm)+entfac(t))
438 write (iout,*) "fi before MPI_Reduce me",me,' master',master
440 do ib=1,nT_h(nparmset)
441 write (iout,*) "iparm",iparm," ib",ib
442 write (iout,*) "beta=",beta_h(ib,iparm)
443 write (iout,'(8e15.5)') (fi_p(i,ib,iparm),i=1,nR(ib,iparm))
447 write (iout,*) "REDUCE size",maxR,MaxT_h,nParmSet,
448 & maxR*MaxT_h*nParmSet
449 write (iout,*) "MPI_COMM_WORLD",MPI_COMM_WORLD,
450 & " WHAM_COMM",WHAM_COMM
451 call MPI_Reduce(fi_p(1,1,1),fi(1,1,1),maxR*MaxT_h*nParmSet,
452 & MPI_DOUBLE_PRECISION,
453 & MPI_SUM,Master,WHAM_COMM,IERROR)
455 write (iout,*) "fi after MPI_Reduce nparmset",nparmset
457 write (iout,*) "iparm",iparm
459 write (iout,*) "beta=",beta_h(ib,iparm)
460 write (iout,'(8e15.5)') (fi(i,ib,iparm),i=1,nR(ib,iparm))
464 if (me1.eq.Master) then
470 fi(i,ib,iparm)=-dlog(fi(i,ib,iparm))
471 avefi=avefi+fi(i,ib,iparm)
477 write (iout,*) "Parameter set",iparm
479 write (iout,*) "beta=",beta_h(ib,iparm)
481 fi(i,ib,iparm)=fi(i,ib,iparm)-avefi
483 write (iout,'(8f10.5)') (fi(i,ib,iparm),i=1,nR(ib,iparm))
484 write (iout,'(8f10.5)') (f(i,ib,iparm),i=1,nR(ib,iparm))
488 ! Compute the norm of free-energy increments.
493 finorm=finorm+dabs(fi(i,ib,iparm)-f(i,ib,iparm))
494 f(i,ib,iparm)=fi(i,ib,iparm)
499 write (iout,*) 'Iteration',iter,' finorm',finorm
503 call MPI_Bcast(f(1,1,1),MaxR*MaxT_h*nParmSet,
504 & MPI_DOUBLE_PRECISION,Master,
506 call MPI_Bcast(finorm,1,MPI_DOUBLE_PRECISION,Master,
509 ! Exit, if the increment norm is smaller than pre-assigned tolerance.
510 if (finorm.lt.fimin) then
511 write (iout,*) 'Iteration converged'
518 ! Now, put together the histograms from all simulations, in order to get the
519 ! unbiased total histogram.
529 write (iout,*) "--------------hist"
533 sumW_p(i,iparm)=0.0d0
534 sumE_p(i,iparm)=0.0d0
535 sumEbis_p(i,iparm)=0.0d0
536 sumEsq_p(i,iparm)=0.0d0
538 sumQ_p(j,i,iparm)=0.0d0
539 sumQsq_p(j,i,iparm)=0.0d0
540 sumEQ_p(j,i,iparm)=0.0d0
550 sumEbis(i,iparm)=0.0d0
551 sumEsq(i,iparm)=0.0d0
553 sumQ(j,i,iparm)=0.0d0
554 sumQsq(j,i,iparm)=0.0d0
555 sumEQ(j,i,iparm)=0.0d0
561 c 8/26/05 entropy distribution
566 c ent=-dlog(entfac(t))
568 if (ent.lt.entmin_p) entmin_p=ent
569 if (ent.gt.entmax_p) entmax_p=ent
571 write (iout,*) "entmin",entmin_p," entmax",entmax_p
573 call MPI_Allreduce(entmin_p,entmin,1,MPI_DOUBLE_PRECISION,MPI_MIN,
575 call MPI_Allreduce(entmax_p,entmax,1,MPI_DOUBLE_PRECISION,MPI_MAX,
577 ientmax=entmax-entmin
578 if (ientmax.gt.2000) ientmax=2000
579 write (iout,*) "entmin",entmin," entmax",entmax," ientmax",ientmax
582 c ient=-dlog(entfac(t))-entmin
583 ient=entfac(t)-entmin
584 if (ient.le.2000) histent_p(ient)=histent_p(ient)+1
586 call MPI_Allreduce(histent_p(0),histent(0),ientmax+1,MPI_INTEGER,
587 & MPI_SUM,WHAM_COMM,IERROR)
588 if (me1.eq.Master) then
589 write (iout,*) "Entropy histogram"
591 write(iout,'(f15.4,i10)') entmin+i,histent(i)
599 if (ent.lt.entmin) entmin=ent
600 if (ent.gt.entmax) entmax=ent
602 ientmax=-dlog(entmax)-entmin
603 if (ientmax.gt.2000) ientmax=2000
605 ient=entfac(t)-entmin
606 if (ient.le.2000) histent(ient)=histent(ient)+1
608 write (iout,*) "Entropy histogram"
610 write(iout,'(2f15.4)') entmin+i,histent(i)
615 c write (iout,*) "me1",me1," scount",scount(me1)
641 hrmsrgy(j,i,ib)=0.0d0
643 hrmsrgy_p(j,i,ib)=0.0d0
655 hfin_ent_p(ind)=hfin_ent_p(ind)+dexp(entfac(t))
657 hfin_ent(ind)=hfin_ent(ind)+dexp(entfac(t))
659 c write (iout,'(2i5,20f8.2)') t,t,(enetb(k,t,iparm),k=1,18)
660 call restore_parm(iparm)
661 evdw=enetb(21,t,iparm)
662 evdw_t=enetb(1,t,iparm)
664 evdw2_14=enetb(17,t,iparm)
665 evdw2=enetb(2,t,iparm)+evdw2_14
667 evdw2=enetb(2,t,iparm)
672 evdw1=enetb(16,t,iparm)
677 ecorr=enetb(4,t,iparm)
678 ecorr5=enetb(5,t,iparm)
679 ecorr6=enetb(6,t,iparm)
680 eel_loc=enetb(7,t,iparm)
681 eello_turn3=enetb(8,t,iparm)
682 eello_turn4=enetb(9,t,iparm)
683 eturn6=enetb(10,t,iparm)
684 ebe=enetb(11,t,iparm)
685 escloc=enetb(12,t,iparm)
686 etors=enetb(13,t,iparm)
687 etors_d=enetb(14,t,iparm)
688 ehpb=enetb(15,t,iparm)
689 estr=enetb(18,t,iparm)
690 esccor=enetb(19,t,iparm)
691 edihcnstr=enetb(20,t,iparm)
694 betaT=startGridT+k*delta_T
698 if (rescale_mode.eq.1) then
706 denom=kfacl-1.0d0+quotl
708 ftprim(l)=-l*ft(l)*quotl1/(T0*denom)
709 ftbis(l)=l*kfacl*quotl1*
710 & (2*l*quotl-(l-1)*denom)/(quot*t0*t0*denom**3)
713 ft(6)=(320.0d0+80.0d0*dtanh((betaT-320.0d0)/80.0d0))/
715 ftprim(6)=1.0d0/(320.0d0*dcosh((betaT-320.0d0)/80.0d0)**2)
716 ftbis(6)=-2.0d0*dtanh((betaT-320.0d0)/80.0d0)
717 & /(320.0d0*80.0d0*dcosh((betaT-320.0d0)/80.0d0)**3)
727 else if (rescale_mode.eq.2) then
735 logfac=1.0d0/dlog(eplus+eminus)
736 tanhT=(eplus-eminus)/(eplus+eminus)
737 fT(l)=1.12692801104297249644d0*logfac
738 ftprim(l)=-l*quotl1*ft(l)*tanhT*logfac/T0
739 ftbis(l)=(l-1)*ftprim(l)/(quot*T0)-
740 & 2*l*quotl1/T0*logfac*
741 & (2*l*quotl1*ft(l)/(T0*(eplus+eminus)**2)
745 ft(6)=(320.0d0+80.0d0*dtanh((betaT-320.0d0)/80.0d0))/
747 ftprim(6)=1.0d0/(320.0d0*dcosh((betaT-320.0d0)/80.0d0)**2)
748 ftbis(6)=-2.0d0*dtanh((betaT-320.0d0)/80.0d0)
749 & /(320.0d0*80.0d0*dcosh((betaT-320.0d0)/80.0d0)**3)
759 else if (rescale_mode.eq.0) then
765 write (iout,*) "Error in WHAM_CALC: wrong RESCALE_MODE",
770 c write (iout,*) "ftprim",ftprim
771 c write (iout,*) "ftbis",ftbis
772 betaT=1.0d0/(1.987D-3*betaT)
774 etot=wsc*(evdw+ft(6)*evdw_t)+wscp*evdw2+ft(1)*welec*ees
776 & +wang*ebe+ft(1)*wtor*etors+wscloc*escloc
777 & +wstrain*ehpb+nss*ebr+ft(3)*wcorr*ecorr+ft(4)*wcorr5*ecorr5
778 & +ft(5)*wcorr6*ecorr6+ft(3)*wturn4*eello_turn4
779 & +ft(2)*wturn3*eello_turn3
780 & +ft(5)*wturn6*eturn6+ft(2)*wel_loc*eel_loc
781 & +edihcnstr+ft(2)*wtor_d*etors_d+ft(1)*wsccor*esccor
782 & +wbond*estr+wliptran*eliptran
783 eprim=ftprim(6)*evdw_t+ftprim(1)*welec*ees
784 & +ftprim(1)*wtor*etors+
785 & ftprim(3)*wcorr*ecorr+ftprim(4)*wcorr5*ecorr5+
786 & ftprim(5)*wcorr6*ecorr6+ftprim(3)*wturn4*eello_turn4+
787 & ftprim(2)*wturn3*eello_turn3+ftprim(5)*wturn6*eturn6+
788 & ftprim(2)*wel_loc*eel_loc+ftprim(2)*wtor_d*etors_d+
789 & ftprim(1)*wsccor*esccor
790 ebis=ftbis(1)*welec*ees+ftbis(1)*wtor*etors+
791 & ftbis(3)*wcorr*ecorr+ftbis(4)*wcorr5*ecorr5+
792 & ftbis(5)*wcorr6*ecorr6+ftbis(3)*wturn4*eello_turn4+
793 & ftbis(2)*wturn3*eello_turn3+ftbis(5)*wturn6*eturn6+
794 & ftbis(2)*wel_loc*eel_loc+ftbis(2)*wtor_d*etors_d+
795 & ftbis(1)*wsccor*esccor
797 etot=wsc*(evdw+ft(6)*evdw_t)+wscp*evdw2
798 & +ft(1)*welec*(ees+evdw1)
799 & +wang*ebe+ft(1)*wtor*etors+wscloc*escloc
800 & +wstrain*ehpb+nss*ebr+ft(3)*wcorr*ecorr+ft(4)*wcorr5*ecorr5
801 & +ft(5)*wcorr6*ecorr6+ft(3)*wturn4*eello_turn4
802 & +ft(2)*wturn3*eello_turn3
803 & +ft(5)*wturn6*eturn6+ft(2)*wel_loc*eel_loc+edihcnstr
804 & +ft(2)*wtor_d*etors_d+ft(1)*wsccor*esccor
805 & +wbond*estr+wliptran*eliptran
806 eprim=ftprim(6)*evdw_t+ftprim(1)*welec*(ees+evdw1)
807 & +ftprim(1)*wtor*etors+
808 & ftprim(3)*wcorr*ecorr+ftprim(4)*wcorr5*ecorr5+
809 & ftprim(5)*wcorr6*ecorr6+ftprim(3)*wturn4*eello_turn4+
810 & ftprim(2)*wturn3*eello_turn3+ftprim(5)*wturn6*eturn6+
811 & ftprim(2)*wel_loc*eel_loc+ftprim(2)*wtor_d*etors_d+
812 & ftprim(1)*wsccor*esccor
813 ebis=ftbis(1)*welec*(ees+evdw1)+ftbis(1)*wtor*etors+
814 & ftbis(3)*wcorr*ecorr+ftbis(4)*wcorr5*ecorr5+
815 & ftbis(5)*wcorr6*ecorr6+ftbis(3)*wturn4*eello_turn4+
816 & ftbis(2)*wturn3*eello_turn3+ftbis(5)*wturn6*eturn6+
817 & ftbis(2)*wel_loc*eel_loc+ftbis(2)*wtor_d*etors_d+
818 & ftprim(1)*wsccor*esccor
820 weight=dexp(-betaT*(etot-potEmin)+entfac(t))
822 write (iout,*) "iparm",iparm," t",t," betaT",betaT,
823 & " etot",etot," entfac",entfac(t),
824 & " weight",weight," ebis",ebis
826 etot=etot-temper*eprim
828 sumW_p(k,iparm)=sumW_p(k,iparm)+weight
829 sumE_p(k,iparm)=sumE_p(k,iparm)+etot*weight
830 sumEbis_p(k,iparm)=sumEbis_p(k,iparm)+ebis*weight
831 sumEsq_p(k,iparm)=sumEsq_p(k,iparm)+etot**2*weight
833 sumQ_p(j,k,iparm)=sumQ_p(j,k,iparm)+q(j,t)*weight
834 sumQsq_p(j,k,iparm)=sumQsq_p(j,k,iparm)+q(j,t)**2*weight
835 sumEQ_p(j,k,iparm)=sumEQ_p(j,k,iparm)
836 & +etot*q(j,t)*weight
839 sumW(k,iparm)=sumW(k,iparm)+weight
840 sumE(k,iparm)=sumE(k,iparm)+etot*weight
841 sumEbis(k,iparm)=sumEbis(k,iparm)+ebis*weight
842 sumEsq(k,iparm)=sumEsq(k,iparm)+etot**2*weight
844 sumQ(j,k,iparm)=sumQ(j,k,iparm)+q(j,t)*weight
845 sumQsq(j,k,iparm)=sumQsq(j,k,iparm)+q(j,t)**2*weight
846 sumEQ(j,k,iparm)=sumEQ(j,k,iparm)
847 & +etot*q(j,t)*weight
851 indE = aint(potE(t,iparm)-aint(potEmin))
852 if (indE.ge.0 .and. indE.le.maxinde) then
853 if (indE.gt.upindE_p) upindE_p=indE
854 histE_p(indE)=histE_p(indE)+dexp(-entfac(t))
858 expfac=dexp(-beta_h(ib,iparm)*(etot-potEmin)+entfac(t))
859 hfin_p(ind,ib)=hfin_p(ind,ib)+
860 & dexp(-beta_h(ib,iparm)*(etot-potEmin)+entfac(t))
862 indrgy=dint((q(nQ+2,t)-rgymin)/deltrgy)
863 indrms=dint((q(nQ+1,t)-rmsmin)/deltrms)
864 hrmsrgy_p(indrgy,indrms,ib)=
865 & hrmsrgy_p(indrgy,indrms,ib)+expfac
870 expfac=dexp(-beta_h(ib,iparm)*(etot-potEmin)+entfac(t))
871 hfin(ind,ib)=hfin(ind,ib)+
872 & dexp(-beta_h(ib,iparm)*(etot-potEmin)+entfac(t))
874 indrgy=dint((q(nQ+2,t)-rgymin)/deltrgy)
875 indrms=dint((q(nQ+1,t)-rmsmin)/deltrms)
876 hrmsrgy(indrgy,indrms,ib)=
877 & hrmsrgy(indrgy,indrms,ib)+expfac
883 if (histout) call MPI_Reduce(hfin_p(0,ib),hfin(0,ib),nbin,
884 & MPI_DOUBLE_PRECISION,MPI_SUM,Master,WHAM_COMM,IERROR)
886 call MPI_Reduce(hrmsrgy_p(0,0,ib),hrmsrgy(0,0,ib),
887 & (MaxBinRgy+1)*(nbin_rms+1),MPI_DOUBLE_PRECISION,MPI_SUM,Master,
891 call MPI_Reduce(upindE_p,upindE,1,
892 & MPI_INTEGER,MPI_MAX,Master,WHAM_COMM,IERROR)
893 call MPI_Reduce(histE_p(0),histE(0),maxindE,
894 & MPI_DOUBLE_PRECISION,MPI_SUM,Master,WHAM_COMM,IERROR)
896 if (me1.eq.master) then
900 write (iout,'(6x,$)')
901 write (iout,'(f20.2,$)') (1.0d0/(1.987D-3*beta_h(ib,iparm)),
905 write (iout,'(/a)') 'Final histograms'
907 if (nslice.eq.1) then
908 if (separate_parset) then
909 write(licz3,"(bz,i3.3)") myparm
910 histname=prefix(:ilen(prefix))//'_par'//licz3//'.hist'
912 histname=prefix(:ilen(prefix))//'.hist'
915 if (separate_parset) then
916 write(licz3,"(bz,i3.3)") myparm
917 histname=prefix(:ilen(prefix))//'_par'//licz3//
918 & '_slice_'//licz2//'.hist'
920 histname=prefix(:ilen(prefix))//'_slice_'//licz2//'.hist'
923 #if defined(AIX) || defined(PGI)
924 open (ihist,file=histname,position='append')
926 open (ihist,file=histname,access='append')
936 if (sumH.gt.0.0d0) then
938 jj = mod(liczba,nbin1)
940 write (iout,'(f6.3,$)') dmin+(jj+0.5d0)*delta
942 & write (ihist,'(f6.3,$)') dmin+(jj+0.5d0)*delta
945 write (iout,'(e20.10,$)') hfin(t,ib)
946 if (histfile) write (ihist,'(e20.10,$)') hfin(t,ib)
948 write (iout,'(i5)') iparm
949 if (histfile) write (ihist,'(i5)') iparm
956 if (nslice.eq.1) then
957 if (separate_parset) then
958 write(licz3,"(bz,i3.3)") myparm
959 histname=prefix(:ilen(prefix))//"_par"//licz3//'.ent'
961 histname=prefix(:ilen(prefix))//'.ent'
964 if (separate_parset) then
965 write(licz3,"(bz,i3.3)") myparm
966 histname=prefix(:ilen(prefix))//'par_'//licz3//
967 & '_slice_'//licz2//'.ent'
969 histname=prefix(:ilen(prefix))//'_slice_'//licz2//'.ent'
972 #if defined(AIX) || defined(PGI)
973 open (ihist,file=histname,position='append')
975 open (ihist,file=histname,access='append')
977 write (ihist,'(a)') "# Microcanonical entropy"
979 write (ihist,'(f8.0,$)') dint(potEmin)+i
980 if (histE(i).gt.0.0e0) then
981 write (ihist,'(f15.5,$)') dlog(histE(i))
983 write (ihist,'(f15.5,$)') 0.0d0
989 write (iout,*) "Microcanonical entropy"
991 write (iout,'(f8.0,$)') dint(potEmin)+i
992 if (histE(i).gt.0.0e0) then
993 write (iout,'(f15.5,$)') dlog(histE(i))
995 write (iout,'(f15.5,$)') 0.0d0
1000 if (nslice.eq.1) then
1001 if (separate_parset) then
1002 write(licz3,"(bz,i3.3)") myparm
1003 histname=prefix(:ilen(prefix))//'_par'//licz3//'.rmsrgy'
1005 histname=prefix(:ilen(prefix))//'.rmsrgy'
1008 if (separate_parset) then
1009 write(licz3,"(bz,i3.3)") myparm
1010 histname=prefix(:ilen(prefix))//'_par'//licz3//
1011 & '_slice_'//licz2//'.rmsrgy'
1013 histname=prefix(:ilen(prefix))//'_slice_'//licz2//'.rmsrgy'
1016 #if defined(AIX) || defined(PGI)
1017 open (ihist,file=histname,position='append')
1019 open (ihist,file=histname,access='append')
1023 write(ihist,'(2f8.2,$)')
1024 & rgymin+deltrgy*j,rmsmin+deltrms*i
1026 if (hrmsrgy(j,i,ib).gt.0.0d0) then
1027 write(ihist,'(e14.5,$)')
1028 & -dlog(hrmsrgy(j,i,ib))/beta_h(ib,iparm)
1031 write(ihist,'(e14.5,$)') 1.0d6
1034 write (ihist,'(i2)') iparm
1042 call MPI_Reduce(hfin_ent_p(0),hfin_ent(0),nbin,
1043 & MPI_DOUBLE_PRECISION,MPI_SUM,Master,WHAM_COMM,IERROR)
1044 call MPI_Reduce(sumW_p(0,1),sumW(0,1),(nGridT+1)*nParmSet,
1045 & MPI_DOUBLE_PRECISION,MPI_SUM,Master,WHAM_COMM,IERROR)
1046 call MPI_Reduce(sumE_p(0,1),sumE(0,1),(nGridT+1)*nParmSet,
1047 & MPI_DOUBLE_PRECISION,MPI_SUM,Master,WHAM_COMM,IERROR)
1048 call MPI_Reduce(sumEbis_p(0,1),sumEbis(0,1),(nGridT+1)*nParmSet,
1049 & MPI_DOUBLE_PRECISION,MPI_SUM,Master,WHAM_COMM,IERROR)
1050 call MPI_Reduce(sumEsq_p(0,1),sumEsq(0,1),(nGridT+1)*nParmSet,
1051 & MPI_DOUBLE_PRECISION,MPI_SUM,Master,WHAM_COMM,IERROR)
1052 call MPI_Reduce(sumQ_p(1,0,1),sumQ(1,0,1),
1053 & MaxQ1*(nGridT+1)*nParmSet,MPI_DOUBLE_PRECISION,MPI_SUM,Master,
1055 call MPI_Reduce(sumQsq_p(1,0,1),sumQsq(1,0,1),
1056 & MaxQ1*(nGridT+1)*nParmSet,MPI_DOUBLE_PRECISION,MPI_SUM,Master,
1058 call MPI_Reduce(sumEQ_p(1,0,1),sumEQ(1,0,1),
1059 & MaxQ1*(nGridT+1)*nParmSet,MPI_DOUBLE_PRECISION,MPI_SUM,Master,
1061 if (me.eq.master) then
1063 write (iout,'(/a)') 'Thermal characteristics of folding'
1064 if (nslice.eq.1) then
1067 nazwa=prefix(:ilen(prefix))//"_slice_"//licz2
1070 if (nparmset.eq.1 .and. .not.separate_parset) then
1071 nazwa=nazwa(:iln)//".thermal"
1072 else if (nparmset.eq.1 .and. separate_parset) then
1073 write(licz3,"(bz,i3.3)") myparm
1074 nazwa=nazwa(:iln)//"_par_"//licz3//".thermal"
1077 if (nparmset.gt.1) then
1078 write(licz3,"(bz,i3.3)") iparm
1079 nazwa=nazwa(:iln)//"_par_"//licz3//".thermal"
1082 if (separate_parset) then
1083 write (iout,'(a,i3)') "Parameter set",myparm
1085 write (iout,'(a,i3)') "Parameter set",iparm
1088 sumE(i,iparm)=sumE(i,iparm)/sumW(i,iparm)
1089 sumEbis(i,iparm)=(startGridT+i*delta_T)*sumEbis(i,iparm)/
1091 sumEsq(i,iparm)=(sumEsq(i,iparm)/sumW(i,iparm)
1092 & -sumE(i,iparm)**2)/(1.987D-3*(startGridT+i*delta_T)**2)
1094 sumQ(j,i,iparm)=sumQ(j,i,iparm)/sumW(i,iparm)
1095 sumQsq(j,i,iparm)=sumQsq(j,i,iparm)/sumW(i,iparm)
1096 & -sumQ(j,i,iparm)**2
1097 sumEQ(j,i,iparm)=sumEQ(j,i,iparm)/sumW(i,iparm)
1098 & -sumQ(j,i,iparm)*sumE(i,iparm)
1100 sumW(i,iparm)=-dlog(sumW(i,iparm))*(1.987D-3*
1101 & (startGridT+i*delta_T))+potEmin
1102 write (iout,'(f7.1,2f15.5,$)') startGridT+i*delta_T,
1103 & sumW(i,iparm),sumE(i,iparm)
1104 write (iout,'(f10.5,$)') (sumQ(j,i,iparm),j=1,nQ+2)
1105 write (iout,'(e15.5,$)') sumEsq(i,iparm)-sumEbis(i,iparm),
1106 & (sumQsq(j,i,iparm),j=1,nQ+2),(sumEQ(j,i,iparm),j=1,nQ+2)
1108 write (34,'(f7.1,2f15.5,$)') startGridT+i*delta_T,
1109 & sumW(i,iparm),sumE(i,iparm)
1110 write (34,'(f10.5,$)') (sumQ(j,i,iparm),j=1,nQ+2)
1111 write (34,'(e15.5,$)') sumEsq(i,iparm)-sumEbis(i,iparm),
1112 & (sumQsq(j,i,iparm),j=1,nQ+2),(sumEQ(j,i,iparm),j=1,nQ+2)
1120 if (hfin_ent(t).gt.0.0d0) then
1122 jj = mod(liczba,nbin1)
1123 write (iout,'(f6.3,e20.10," ent")') dmin+(jj+0.5d0)*delta,
1125 if (histfile) write (ihist,'(f6.3,e20.10," ent")')
1126 & dmin+(jj+0.5d0)*delta,
1130 if (histfile) close(ihist)
1134 ! Write data for zscore
1135 if (nslice.eq.1) then
1136 zscname=prefix(:ilen(prefix))//".zsc"
1138 zscname=prefix(:ilen(prefix))//"_slice_"//licz2//".zsc"
1140 #if defined(AIX) || defined(PGI)
1141 open (izsc,file=prefix(:ilen(prefix))//'.zsc',position='append')
1143 open (izsc,file=prefix(:ilen(prefix))//'.zsc',access='append')
1145 write (izsc,'("NQ=",i1," NPARM=",i1)') nQ,nParmSet
1147 write (izsc,'("NT=",i1)') nT_h(iparm)
1149 write (izsc,'("TEMP=",f6.1," NR=",i2," SNK=",$)')
1150 & 1.0d0/(beta_h(ib,iparm)*1.987D-3),nR(ib,iparm)
1151 jj = min0(nR(ib,iparm),7)
1152 write (izsc,'(i8,$)') (snk(i,ib,iparm,islice),i=1,jj)
1153 write (izsc,'(a1,$)') (" ",i=22+8*jj+1,79)
1154 write (izsc,'("&")')
1155 if (nR(ib,iparm).gt.7) then
1156 do ii=8,nR(ib,iparm),9
1157 jj = min0(nR(ib,iparm),ii+8)
1158 write (izsc,'(i8,$)') (snk(i,ib,iparm,islice),i=ii,jj)
1159 write (izsc,'(a1,$') (" ",i=(jj-ii+1)*8+1,79)
1160 write (izsc,'("&")')
1163 write (izsc,'("FI=",$)')
1164 jj=min0(nR(ib,iparm),7)
1165 write (izsc,'(f10.5,$)') (fi(i,ib,iparm),i=1,jj)
1166 write (izsc,'(a1,$)') (" ",i=3+10*jj+1,79)
1167 write (izsc,'("&")')
1168 if (nR(ib,iparm).gt.7) then
1169 do ii=8,nR(ib,iparm),9
1170 jj = min0(nR(ib,iparm),ii+8)
1171 write (izsc,'(f10.5,$)') (fi(i,ib,iparm),i=ii,jj)
1172 if (jj.eq.nR(ib,iparm)) then
1175 write (izsc,'(a1,$)') (" ",i=10*(jj-ii+1)+1,79)
1176 write (izsc,'(t80,"&")')
1181 write (izsc,'("KH=",$)')
1182 write (izsc,'(f7.2,$)') (Kh(j,i,ib,iparm),j=1,nQ)
1183 write (izsc,'(" Q0=",$)')
1184 write (izsc,'(f7.5,$)') (q0(j,i,ib,iparm),j=1,nQ)