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
89 integer ind_point(maxpoint),upindE,indE
98 write(licz2,'(bz,i2.2)') islice
100 write (iout,'(//80(1h-)/"Solving WHAM equations for slice",
101 & i2/80(1h-)//)') islice
102 write (iout,*) "delta",delta," nbin1",nbin1
103 write (iout,*) "MaxN",MaxN," MaxQ",MaxQ," MaHdim",MaxHdim
121 if (potE(i,j).le.potEmin) potEmin=potE(i,j)
123 if (q(nQ+1,i).lt.rmsmin) rmsmin=q(nQ+1,i)
124 if (q(nQ+1,i).gt.rmsmax) rmsmax=q(nQ+1,i)
125 if (q(nQ+2,i).lt.rgymin) rgymin=q(nQ+2,i)
126 if (q(nQ+2,i).gt.rgymax) rgymax=q(nQ+2,i)
129 ind=(q(j,i)-dmin+1.0d-8)/delta
131 ind_point(i)=ind_point(i)+ind
133 ind_point(i)=ind_point(i)+nbin1**(j-1)*ind
135 c write (iout,*) "i",i," j",j," q",q(j,i)," ind_point",
138 if (ind_point(i).lt.0 .or. ind_point(i).gt.MaxHdim) then
139 write (iout,*) "Error - index exceeds range for point",i,
140 & " q=",q(j,i)," ind",ind_point(i)
142 write (iout,*) "Processor",me1
144 call MPI_Abort(MPI_COMM_WORLD, Ierror, Errcode )
149 if (ind_point(i).gt.tmax) tmax=ind_point(i)
150 htot(ind_point(i))=htot(ind_point(i))+1
152 write (iout,*) "i",i,"q",(q(j,i),j=1,nQ)," ind",ind_point(i),
153 & " htot",htot(ind_point(i))
160 write (iout,'(a)') "Numbers of counts in Q bins"
162 if (htot(t).gt.0) then
163 write (iout,'(i15,$)') t
166 jj = mod(liczba,nbin1)
168 write (iout,'(i5,$)') jj
170 write (iout,'(i8)') htot(t)
174 write (iout,'(a,i3)') "Number of data points for parameter set",
176 write (iout,'(i7,$)') ((snk(m,ib,iparm,islice),m=1,nr(ib,iparm)),
178 write (iout,'(i8)') stot(islice)
184 call MPI_AllReduce(tmax,tmax_t,1,MPI_INTEGER,MPI_MAX,
187 call MPI_AllReduce(potEmin,potEmin_t,1,MPI_DOUBLE_PRECISION,
188 & MPI_MIN,WHAM_COMM,IERROR)
189 call MPI_AllReduce(rmsmin,rmsmin_t,1,MPI_DOUBLE_PRECISION,
190 & MPI_MIN,WHAM_COMM,IERROR)
191 call MPI_AllReduce(rmsmax,rmsmax_t,1,MPI_DOUBLE_PRECISION,
192 & MPI_MAX,WHAM_COMM,IERROR)
193 call MPI_AllReduce(rgymin,rgymin_t,1,MPI_DOUBLE_PRECISION,
194 & MPI_MIN,WHAM_COMM,IERROR)
195 call MPI_AllReduce(rgymax,rgymax_t,1,MPI_DOUBLE_PRECISION,
196 & MPI_MAX,WHAM_COMM,IERROR)
202 write (iout,*) "potEmin",potEmin
204 rmsmin=deltrms*dint(rmsmin/deltrms)
205 rmsmax=deltrms*dint(rmsmax/deltrms)
206 rgymin=deltrms*dint(rgymin/deltrgy)
207 rgymax=deltrms*dint(rgymax/deltrgy)
208 nbin_rms=(rmsmax-rmsmin)/deltrms
209 nbin_rgy=(rgymax-rgymin)/deltrgy
210 write (iout,*) "rmsmin",rmsmin," rmsmax",rmsmax," rgymin",rgymin,
211 & " rgymax",rgymax," nbin_rms",nbin_rms," nbin_rgy",nbin_rgy
218 write (iout,*) "nFi",nFi
219 ! Compute the Boltzmann factor corresponing to restrain potentials in different
226 c write (9,'(3i5,f10.5)') i,(iparm,potE(i,iparm),iparm=1,nParmSet)
229 write (iout,'(2i5,21f8.2)') i,iparm,
230 & (enetb(k,i,iparm),k=1,21)
232 call restore_parm(iparm)
234 write (iout,*) wsc,wscp,welec,wvdwpp,wang,wtor,wscloc,
235 & wcorr,wcorr5,wcorr6,wturn4,wturn3,wturn6,wel_loc,
236 & wtor_d,wsccor,wbond
239 if (rescale_mode.eq.1) then
240 quot=1.0d0/(beta_h(ib,iparm)*1.987D-3*T0)
247 fT(l)=kfacl/(kfacl-1.0d0+quotl)
250 tt = 1.0d0/(beta_h(ib,iparm)*1.987D-3)
251 ft(6)=(320.0d0+80.0d0*dtanh((tt-320.0d0)/80.0d0))/320.0d0
253 ft(6)=1.0d0/(beta_h(ib,iparm)*1.987D-3*T0)
257 else if (rescale_mode.eq.2) then
258 quot=1.0d0/(T0*beta_h(ib,iparm)*1.987D-3)
262 fT(l)=1.12692801104297249644d0/
263 & dlog(dexp(quotl)+dexp(-quotl))
266 tt = 1.0d0/(beta_h(ib,iparm)*1.987D-3)
267 ft(6)=(320.0d0+80.0d0*dtanh((tt-320.0d0)/80.0d0))/320.0d0
269 ft(6)=1.0d0/(beta_h(ib,iparm)*1.987D-3*T0)
273 c write (iout,*) 1.0d0/(beta_h(ib,iparm)*1.987D-3),ft
274 else if (rescale_mode.eq.0) then
279 write (iout,*) "Error in WHAM_CALC: wrong RESCALE_MODE",
284 evdw=enetb(1,i,iparm)
285 evdw_t=enetb(21,i,iparm)
287 evdw2_14=enetb(17,i,iparm)
288 evdw2=enetb(2,i,iparm)+evdw2_14
290 evdw2=enetb(2,i,iparm)
295 evdw1=enetb(16,i,iparm)
300 ecorr=enetb(4,i,iparm)
301 ecorr5=enetb(5,i,iparm)
302 ecorr6=enetb(6,i,iparm)
303 eel_loc=enetb(7,i,iparm)
304 eello_turn3=enetb(8,i,iparm)
305 eello_turn4=enetb(9,i,iparm)
306 eturn6=enetb(10,i,iparm)
307 ebe=enetb(11,i,iparm)
308 escloc=enetb(12,i,iparm)
309 etors=enetb(13,i,iparm)
310 etors_d=enetb(14,i,iparm)
311 ehpb=enetb(15,i,iparm)
312 estr=enetb(18,i,iparm)
313 esccor=enetb(19,i,iparm)
314 edihcnstr=enetb(20,i,iparm)
316 write (iout,'(3i5,6f5.2,14f12.3)') i,ib,iparm,(ft(l),l=1,6),
317 & evdw+evdw_t,evdw2,ees,evdw1,ecorr,eel_loc,estr,ebe,escloc,
318 & etors,etors_d,eello_turn3,eello_turn4,esccor
322 etot=wsc*(evdw+ft(6)*evdw_t)+wscp*evdw2+ft(1)*welec*ees
324 & +wang*ebe+ft(1)*wtor*etors+wscloc*escloc
325 & +wstrain*ehpb+nss*ebr+ft(3)*wcorr*ecorr+ft(4)*wcorr5*ecorr5
326 & +ft(5)*wcorr6*ecorr6+ft(3)*wturn4*eello_turn4
327 & +ft(2)*wturn3*eello_turn3
328 & +ft(5)*wturn6*eturn6+ft(2)*wel_loc*eel_loc
329 & +edihcnstr+ft(2)*wtor_d*etors_d+ft(1)*wsccor*esccor
332 etot=wsc*(evdw+ft(6)*evdw_t)+wscp*evdw2
333 & +ft(1)*welec*(ees+evdw1)
334 & +wang*ebe+ft(1)*wtor*etors+wscloc*escloc
335 & +wstrain*ehpb+nss*ebr+ft(3)*wcorr*ecorr+ft(4)*wcorr5*ecorr5
336 & +ft(5)*wcorr6*ecorr6+ft(3)*wturn4*eello_turn4
337 & +ft(2)*wturn3*eello_turn3
338 & +ft(5)*wturn6*eturn6+ft(2)*wel_loc*eel_loc+edihcnstr
339 & +ft(2)*wtor_d*etors_d+ft(1)*wsccor*esccor
343 write (iout,*) i,iparm,1.0d0/(beta_h(ib,iparm)*1.987D-3),
347 if (iparm.eq.1 .and. ib.eq.1) then
348 write (iout,*)"Conformation",i
351 energia(k)=enetb(k,i,iparm)
353 call enerprint(energia(0),fT)
360 Econstr=Econstr+Kh(j,kk,ib,iparm)
361 & *(dd-q0(j,kk,ib,iparm))**2
364 & -beta_h(ib,iparm)*(etot-potEmin+Econstr)
366 write (iout,'(4i5,4e15.5)') i,kk,ib,iparm,
367 & etot,potEmin,etot-potEmin,v(i,kk,ib,iparm)
373 ! Simple iteration to calculate free energies corresponding to all simulation
377 ! Compute new free-energy values corresponding to the righ-hand side of the
378 ! equation and their derivatives.
379 write (iout,*) "------------------------fi"
389 vf=v(t,l,k,i)+f(l,k,i)
390 if (vf.gt.vmax) vmax=vf
398 aux=f(l,k,i)+v(t,l,k,i)-vmax
400 & denom=denom+snk(l,k,i,islice)*dexp(aux)
404 entfac(t)=-dlog(denom)-vmax
406 write (iout,*) t,"vmax",vmax," denom",denom,"entfac",entfac(t)
411 do ii=1,nR(iib,iparm)
413 fi_p(ii,iib,iparm)=0.0d0
415 fi_p(ii,iib,iparm)=fi_p(ii,iib,iparm)
416 & +dexp(v(t,ii,iib,iparm)+entfac(t))
418 write (iout,'(4i5,3e15.5)') t,ii,iib,iparm,
419 & v(t,ii,iib,iparm),entfac(t),fi_p(ii,iib,iparm)
423 fi(ii,iib,iparm)=0.0d0
425 fi(ii,iib,iparm)=fi(ii,iib,iparm)
426 & +dexp(v(t,ii,iib,iparm)+entfac(t))
435 write (iout,*) "fi before MPI_Reduce me",me,' master',master
437 do ib=1,nT_h(nparmset)
438 write (iout,*) "iparm",iparm," ib",ib
439 write (iout,*) "beta=",beta_h(ib,iparm)
440 write (iout,'(8e15.5)') (fi_p(i,ib,iparm),i=1,nR(ib,iparm))
444 write (iout,*) "REDUCE size",maxR,MaxT_h,nParmSet,
445 & maxR*MaxT_h*nParmSet
446 write (iout,*) "MPI_COMM_WORLD",MPI_COMM_WORLD,
447 & " WHAM_COMM",WHAM_COMM
448 call MPI_Reduce(fi_p(1,1,1),fi(1,1,1),maxR*MaxT_h*nParmSet,
449 & MPI_DOUBLE_PRECISION,
450 & MPI_SUM,Master,WHAM_COMM,IERROR)
452 write (iout,*) "fi after MPI_Reduce nparmset",nparmset
454 write (iout,*) "iparm",iparm
456 write (iout,*) "beta=",beta_h(ib,iparm)
457 write (iout,'(8e15.5)') (fi(i,ib,iparm),i=1,nR(ib,iparm))
461 if (me1.eq.Master) then
467 fi(i,ib,iparm)=-dlog(fi(i,ib,iparm))
468 avefi=avefi+fi(i,ib,iparm)
474 write (iout,*) "Parameter set",iparm
476 write (iout,*) "beta=",beta_h(ib,iparm)
478 fi(i,ib,iparm)=fi(i,ib,iparm)-avefi
480 write (iout,'(8f10.5)') (fi(i,ib,iparm),i=1,nR(ib,iparm))
481 write (iout,'(8f10.5)') (f(i,ib,iparm),i=1,nR(ib,iparm))
485 ! Compute the norm of free-energy increments.
490 finorm=finorm+dabs(fi(i,ib,iparm)-f(i,ib,iparm))
491 f(i,ib,iparm)=fi(i,ib,iparm)
496 write (iout,*) 'Iteration',iter,' finorm',finorm
500 call MPI_Bcast(f(1,1,1),MaxR*MaxT_h*nParmSet,
501 & MPI_DOUBLE_PRECISION,Master,
503 call MPI_Bcast(finorm,1,MPI_DOUBLE_PRECISION,Master,
506 ! Exit, if the increment norm is smaller than pre-assigned tolerance.
507 if (finorm.lt.fimin) then
508 write (iout,*) 'Iteration converged'
515 ! Now, put together the histograms from all simulations, in order to get the
516 ! unbiased total histogram.
526 write (iout,*) "--------------hist"
530 sumW_p(i,iparm)=0.0d0
531 sumE_p(i,iparm)=0.0d0
532 sumEbis_p(i,iparm)=0.0d0
533 sumEsq_p(i,iparm)=0.0d0
535 sumQ_p(j,i,iparm)=0.0d0
536 sumQsq_p(j,i,iparm)=0.0d0
537 sumEQ_p(j,i,iparm)=0.0d0
547 sumEbis(i,iparm)=0.0d0
548 sumEsq(i,iparm)=0.0d0
550 sumQ(j,i,iparm)=0.0d0
551 sumQsq(j,i,iparm)=0.0d0
552 sumEQ(j,i,iparm)=0.0d0
558 c 8/26/05 entropy distribution
563 c ent=-dlog(entfac(t))
565 if (ent.lt.entmin_p) entmin_p=ent
566 if (ent.gt.entmax_p) entmax_p=ent
568 write (iout,*) "entmin",entmin_p," entmax",entmax_p
570 call MPI_Allreduce(entmin_p,entmin,1,MPI_DOUBLE_PRECISION,MPI_MIN,
572 call MPI_Allreduce(entmax_p,entmax,1,MPI_DOUBLE_PRECISION,MPI_MAX,
574 ientmax=entmax-entmin
575 if (ientmax.gt.2000) ientmax=2000
576 write (iout,*) "entmin",entmin," entmax",entmax," ientmax",ientmax
579 c ient=-dlog(entfac(t))-entmin
580 ient=entfac(t)-entmin
581 if (ient.le.2000) histent_p(ient)=histent_p(ient)+1
583 call MPI_Allreduce(histent_p(0),histent(0),ientmax+1,MPI_INTEGER,
584 & MPI_SUM,WHAM_COMM,IERROR)
585 if (me1.eq.Master) then
586 write (iout,*) "Entropy histogram"
588 write(iout,'(f15.4,i10)') entmin+i,histent(i)
596 if (ent.lt.entmin) entmin=ent
597 if (ent.gt.entmax) entmax=ent
599 ientmax=-dlog(entmax)-entmin
600 if (ientmax.gt.2000) ientmax=2000
602 ient=entfac(t)-entmin
603 if (ient.le.2000) histent(ient)=histent(ient)+1
605 write (iout,*) "Entropy histogram"
607 write(iout,'(2f15.4)') entmin+i,histent(i)
612 c write (iout,*) "me1",me1," scount",scount(me1)
638 hrmsrgy(j,i,ib)=0.0d0
640 hrmsrgy_p(j,i,ib)=0.0d0
652 hfin_ent_p(ind)=hfin_ent_p(ind)+dexp(entfac(t))
654 hfin_ent(ind)=hfin_ent(ind)+dexp(entfac(t))
656 c write (iout,'(2i5,20f8.2)') t,t,(enetb(k,t,iparm),k=1,18)
657 call restore_parm(iparm)
658 evdw=enetb(21,t,iparm)
659 evdw_t=enetb(1,t,iparm)
661 evdw2_14=enetb(17,t,iparm)
662 evdw2=enetb(2,t,iparm)+evdw2_14
664 evdw2=enetb(2,t,iparm)
669 evdw1=enetb(16,t,iparm)
674 ecorr=enetb(4,t,iparm)
675 ecorr5=enetb(5,t,iparm)
676 ecorr6=enetb(6,t,iparm)
677 eel_loc=enetb(7,t,iparm)
678 eello_turn3=enetb(8,t,iparm)
679 eello_turn4=enetb(9,t,iparm)
680 eturn6=enetb(10,t,iparm)
681 ebe=enetb(11,t,iparm)
682 escloc=enetb(12,t,iparm)
683 etors=enetb(13,t,iparm)
684 etors_d=enetb(14,t,iparm)
685 ehpb=enetb(15,t,iparm)
686 estr=enetb(18,t,iparm)
687 esccor=enetb(19,t,iparm)
688 edihcnstr=enetb(20,t,iparm)
691 betaT=startGridT+k*delta_T
695 if (rescale_mode.eq.1) then
703 denom=kfacl-1.0d0+quotl
705 ftprim(l)=-l*ft(l)*quotl1/(T0*denom)
706 ftbis(l)=l*kfacl*quotl1*
707 & (2*l*quotl-(l-1)*denom)/(quot*t0*t0*denom**3)
710 ft(6)=(320.0d0+80.0d0*dtanh((betaT-320.0d0)/80.0d0))/
712 ftprim(6)=1.0d0/(320.0d0*dcosh((betaT-320.0d0)/80.0d0)**2)
713 ftbis(6)=-2.0d0*dtanh((betaT-320.0d0)/80.0d0)
714 & /(320.0d0*80.0d0*dcosh((betaT-320.0d0)/80.0d0)**3)
724 else if (rescale_mode.eq.2) then
732 logfac=1.0d0/dlog(eplus+eminus)
733 tanhT=(eplus-eminus)/(eplus+eminus)
734 fT(l)=1.12692801104297249644d0*logfac
735 ftprim(l)=-l*quotl1*ft(l)*tanhT*logfac/T0
736 ftbis(l)=(l-1)*ftprim(l)/(quot*T0)-
737 & 2*l*quotl1/T0*logfac*
738 & (2*l*quotl1*ft(l)/(T0*(eplus+eminus)**2)
742 ft(6)=(320.0d0+80.0d0*dtanh((betaT-320.0d0)/80.0d0))/
744 ftprim(6)=1.0d0/(320.0d0*dcosh((betaT-320.0d0)/80.0d0)**2)
745 ftbis(6)=-2.0d0*dtanh((betaT-320.0d0)/80.0d0)
746 & /(320.0d0*80.0d0*dcosh((betaT-320.0d0)/80.0d0)**3)
756 else if (rescale_mode.eq.0) then
762 write (iout,*) "Error in WHAM_CALC: wrong RESCALE_MODE",
767 c write (iout,*) "ftprim",ftprim
768 c write (iout,*) "ftbis",ftbis
769 betaT=1.0d0/(1.987D-3*betaT)
771 etot=wsc*(evdw+ft(6)*evdw_t)+wscp*evdw2+ft(1)*welec*ees
773 & +wang*ebe+ft(1)*wtor*etors+wscloc*escloc
774 & +wstrain*ehpb+nss*ebr+ft(3)*wcorr*ecorr+ft(4)*wcorr5*ecorr5
775 & +ft(5)*wcorr6*ecorr6+ft(3)*wturn4*eello_turn4
776 & +ft(2)*wturn3*eello_turn3
777 & +ft(5)*wturn6*eturn6+ft(2)*wel_loc*eel_loc
778 & +edihcnstr+ft(2)*wtor_d*etors_d+ft(1)*wsccor*esccor
780 eprim=ftprim(6)*evdw_t+ftprim(1)*welec*ees
781 & +ftprim(1)*wtor*etors+
782 & ftprim(3)*wcorr*ecorr+ftprim(4)*wcorr5*ecorr5+
783 & ftprim(5)*wcorr6*ecorr6+ftprim(3)*wturn4*eello_turn4+
784 & ftprim(2)*wturn3*eello_turn3+ftprim(5)*wturn6*eturn6+
785 & ftprim(2)*wel_loc*eel_loc+ftprim(2)*wtor_d*etors_d+
786 & ftprim(1)*wsccor*esccor
787 ebis=ftbis(1)*welec*ees+ftbis(1)*wtor*etors+
788 & ftbis(3)*wcorr*ecorr+ftbis(4)*wcorr5*ecorr5+
789 & ftbis(5)*wcorr6*ecorr6+ftbis(3)*wturn4*eello_turn4+
790 & ftbis(2)*wturn3*eello_turn3+ftbis(5)*wturn6*eturn6+
791 & ftbis(2)*wel_loc*eel_loc+ftbis(2)*wtor_d*etors_d+
792 & ftbis(1)*wsccor*esccor
794 etot=wsc*(evdw+ft(6)*evdw_t)+wscp*evdw2
795 & +ft(1)*welec*(ees+evdw1)
796 & +wang*ebe+ft(1)*wtor*etors+wscloc*escloc
797 & +wstrain*ehpb+nss*ebr+ft(3)*wcorr*ecorr+ft(4)*wcorr5*ecorr5
798 & +ft(5)*wcorr6*ecorr6+ft(3)*wturn4*eello_turn4
799 & +ft(2)*wturn3*eello_turn3
800 & +ft(5)*wturn6*eturn6+ft(2)*wel_loc*eel_loc+edihcnstr
801 & +ft(2)*wtor_d*etors_d+ft(1)*wsccor*esccor
803 eprim=ftprim(6)*evdw_t+ftprim(1)*welec*(ees+evdw1)
804 & +ftprim(1)*wtor*etors+
805 & ftprim(3)*wcorr*ecorr+ftprim(4)*wcorr5*ecorr5+
806 & ftprim(5)*wcorr6*ecorr6+ftprim(3)*wturn4*eello_turn4+
807 & ftprim(2)*wturn3*eello_turn3+ftprim(5)*wturn6*eturn6+
808 & ftprim(2)*wel_loc*eel_loc+ftprim(2)*wtor_d*etors_d+
809 & ftprim(1)*wsccor*esccor
810 ebis=ftbis(1)*welec*(ees+evdw1)+ftbis(1)*wtor*etors+
811 & ftbis(3)*wcorr*ecorr+ftbis(4)*wcorr5*ecorr5+
812 & ftbis(5)*wcorr6*ecorr6+ftbis(3)*wturn4*eello_turn4+
813 & ftbis(2)*wturn3*eello_turn3+ftbis(5)*wturn6*eturn6+
814 & ftbis(2)*wel_loc*eel_loc+ftbis(2)*wtor_d*etors_d+
815 & ftprim(1)*wsccor*esccor
817 weight=dexp(-betaT*(etot-potEmin)+entfac(t))
819 write (iout,*) "iparm",iparm," t",t," betaT",betaT,
820 & " etot",etot," entfac",entfac(t),
821 & " weight",weight," ebis",ebis
823 etot=etot-temper*eprim
825 sumW_p(k,iparm)=sumW_p(k,iparm)+weight
826 sumE_p(k,iparm)=sumE_p(k,iparm)+etot*weight
827 sumEbis_p(k,iparm)=sumEbis_p(k,iparm)+ebis*weight
828 sumEsq_p(k,iparm)=sumEsq_p(k,iparm)+etot**2*weight
830 sumQ_p(j,k,iparm)=sumQ_p(j,k,iparm)+q(j,t)*weight
831 sumQsq_p(j,k,iparm)=sumQsq_p(j,k,iparm)+q(j,t)**2*weight
832 sumEQ_p(j,k,iparm)=sumEQ_p(j,k,iparm)
833 & +etot*q(j,t)*weight
836 sumW(k,iparm)=sumW(k,iparm)+weight
837 sumE(k,iparm)=sumE(k,iparm)+etot*weight
838 sumEbis(k,iparm)=sumEbis(k,iparm)+ebis*weight
839 sumEsq(k,iparm)=sumEsq(k,iparm)+etot**2*weight
841 sumQ(j,k,iparm)=sumQ(j,k,iparm)+q(j,t)*weight
842 sumQsq(j,k,iparm)=sumQsq(j,k,iparm)+q(j,t)**2*weight
843 sumEQ(j,k,iparm)=sumEQ(j,k,iparm)
844 & +etot*q(j,t)*weight
848 indE = aint(potE(t,iparm)-aint(potEmin))
849 if (indE.ge.0 .and. indE.le.maxinde) then
850 if (indE.gt.upindE_p) upindE_p=indE
851 histE_p(indE)=histE_p(indE)+dexp(-entfac(t))
855 expfac=dexp(-beta_h(ib,iparm)*(etot-potEmin)+entfac(t))
856 hfin_p(ind,ib)=hfin_p(ind,ib)+
857 & dexp(-beta_h(ib,iparm)*(etot-potEmin)+entfac(t))
859 indrgy=dint((q(nQ+2,t)-rgymin)/deltrgy)
860 indrms=dint((q(nQ+1,t)-rmsmin)/deltrms)
861 hrmsrgy_p(indrgy,indrms,ib)=
862 & hrmsrgy_p(indrgy,indrms,ib)+expfac
867 expfac=dexp(-beta_h(ib,iparm)*(etot-potEmin)+entfac(t))
868 hfin(ind,ib)=hfin(ind,ib)+
869 & dexp(-beta_h(ib,iparm)*(etot-potEmin)+entfac(t))
871 indrgy=dint((q(nQ+2,t)-rgymin)/deltrgy)
872 indrms=dint((q(nQ+1,t)-rmsmin)/deltrms)
873 hrmsrgy(indrgy,indrms,ib)=
874 & hrmsrgy(indrgy,indrms,ib)+expfac
880 if (histout) call MPI_Reduce(hfin_p(0,ib),hfin(0,ib),nbin,
881 & MPI_DOUBLE_PRECISION,MPI_SUM,Master,WHAM_COMM,IERROR)
883 call MPI_Reduce(hrmsrgy_p(0,0,ib),hrmsrgy(0,0,ib),
884 & (MaxBinRgy+1)*(nbin_rms+1),MPI_DOUBLE_PRECISION,MPI_SUM,Master,
888 call MPI_Reduce(upindE_p,upindE,1,
889 & MPI_INTEGER,MPI_MAX,Master,WHAM_COMM,IERROR)
890 call MPI_Reduce(histE_p(0),histE(0),maxindE,
891 & MPI_DOUBLE_PRECISION,MPI_SUM,Master,WHAM_COMM,IERROR)
893 if (me1.eq.master) then
897 write (iout,'(6x,$)')
898 write (iout,'(f20.2,$)') (1.0d0/(1.987D-3*beta_h(ib,iparm)),
902 write (iout,'(/a)') 'Final histograms'
904 if (nslice.eq.1) then
905 if (separate_parset) then
906 write(licz3,"(bz,i3.3)") myparm
907 histname=prefix(:ilen(prefix))//'_par'//licz3//'.hist'
909 histname=prefix(:ilen(prefix))//'.hist'
912 if (separate_parset) then
913 write(licz3,"(bz,i3.3)") myparm
914 histname=prefix(:ilen(prefix))//'_par'//licz3//
915 & '_slice_'//licz2//'.hist'
917 histname=prefix(:ilen(prefix))//'_slice_'//licz2//'.hist'
920 #if defined(AIX) || defined(PGI)
921 open (ihist,file=histname,position='append')
923 open (ihist,file=histname,access='append')
933 if (sumH.gt.0.0d0) then
935 jj = mod(liczba,nbin1)
937 write (iout,'(f6.3,$)') dmin+(jj+0.5d0)*delta
939 & write (ihist,'(f6.3,$)') dmin+(jj+0.5d0)*delta
942 write (iout,'(e20.10,$)') hfin(t,ib)
943 if (histfile) write (ihist,'(e20.10,$)') hfin(t,ib)
945 write (iout,'(i5)') iparm
946 if (histfile) write (ihist,'(i5)') iparm
953 if (nslice.eq.1) then
954 if (separate_parset) then
955 write(licz3,"(bz,i3.3)") myparm
956 histname=prefix(:ilen(prefix))//"_par"//licz3//'.ent'
958 histname=prefix(:ilen(prefix))//'.ent'
961 if (separate_parset) then
962 write(licz3,"(bz,i3.3)") myparm
963 histname=prefix(:ilen(prefix))//'par_'//licz3//
964 & '_slice_'//licz2//'.ent'
966 histname=prefix(:ilen(prefix))//'_slice_'//licz2//'.ent'
969 #if defined(AIX) || defined(PGI)
970 open (ihist,file=histname,position='append')
972 open (ihist,file=histname,access='append')
974 write (ihist,'(a)') "# Microcanonical entropy"
976 write (ihist,'(f8.0,$)') dint(potEmin)+i
977 if (histE(i).gt.0.0e0) then
978 write (ihist,'(f15.5,$)') dlog(histE(i))
980 write (ihist,'(f15.5,$)') 0.0d0
986 write (iout,*) "Microcanonical entropy"
988 write (iout,'(f8.0,$)') dint(potEmin)+i
989 if (histE(i).gt.0.0e0) then
990 write (iout,'(f15.5,$)') dlog(histE(i))
992 write (iout,'(f15.5,$)') 0.0d0
997 if (nslice.eq.1) then
998 if (separate_parset) then
999 write(licz3,"(bz,i3.3)") myparm
1000 histname=prefix(:ilen(prefix))//'_par'//licz3//'.rmsrgy'
1002 histname=prefix(:ilen(prefix))//'.rmsrgy'
1005 if (separate_parset) then
1006 write(licz3,"(bz,i3.3)") myparm
1007 histname=prefix(:ilen(prefix))//'_par'//licz3//
1008 & '_slice_'//licz2//'.rmsrgy'
1010 histname=prefix(:ilen(prefix))//'_slice_'//licz2//'.rmsrgy'
1013 #if defined(AIX) || defined(PGI)
1014 open (ihist,file=histname,position='append')
1016 open (ihist,file=histname,access='append')
1020 write(ihist,'(2f8.2,$)')
1021 & rgymin+deltrgy*j,rmsmin+deltrms*i
1023 if (hrmsrgy(j,i,ib).gt.0.0d0) then
1024 write(ihist,'(e14.5,$)')
1025 & -dlog(hrmsrgy(j,i,ib))/beta_h(ib,iparm)
1028 write(ihist,'(e14.5,$)') 1.0d6
1031 write (ihist,'(i2)') iparm
1039 call MPI_Reduce(hfin_ent_p(0),hfin_ent(0),nbin,
1040 & MPI_DOUBLE_PRECISION,MPI_SUM,Master,WHAM_COMM,IERROR)
1041 call MPI_Reduce(sumW_p(0,1),sumW(0,1),(nGridT+1)*nParmSet,
1042 & MPI_DOUBLE_PRECISION,MPI_SUM,Master,WHAM_COMM,IERROR)
1043 call MPI_Reduce(sumE_p(0,1),sumE(0,1),(nGridT+1)*nParmSet,
1044 & MPI_DOUBLE_PRECISION,MPI_SUM,Master,WHAM_COMM,IERROR)
1045 call MPI_Reduce(sumEbis_p(0,1),sumEbis(0,1),(nGridT+1)*nParmSet,
1046 & MPI_DOUBLE_PRECISION,MPI_SUM,Master,WHAM_COMM,IERROR)
1047 call MPI_Reduce(sumEsq_p(0,1),sumEsq(0,1),(nGridT+1)*nParmSet,
1048 & MPI_DOUBLE_PRECISION,MPI_SUM,Master,WHAM_COMM,IERROR)
1049 call MPI_Reduce(sumQ_p(1,0,1),sumQ(1,0,1),
1050 & MaxQ1*(nGridT+1)*nParmSet,MPI_DOUBLE_PRECISION,MPI_SUM,Master,
1052 call MPI_Reduce(sumQsq_p(1,0,1),sumQsq(1,0,1),
1053 & MaxQ1*(nGridT+1)*nParmSet,MPI_DOUBLE_PRECISION,MPI_SUM,Master,
1055 call MPI_Reduce(sumEQ_p(1,0,1),sumEQ(1,0,1),
1056 & MaxQ1*(nGridT+1)*nParmSet,MPI_DOUBLE_PRECISION,MPI_SUM,Master,
1058 if (me.eq.master) then
1060 write (iout,'(/a)') 'Thermal characteristics of folding'
1061 if (nslice.eq.1) then
1064 nazwa=prefix(:ilen(prefix))//"_slice_"//licz2
1067 if (nparmset.eq.1 .and. .not.separate_parset) then
1068 nazwa=nazwa(:iln)//".thermal"
1069 else if (nparmset.eq.1 .and. separate_parset) then
1070 write(licz3,"(bz,i3.3)") myparm
1071 nazwa=nazwa(:iln)//"_par_"//licz3//".thermal"
1074 if (nparmset.gt.1) then
1075 write(licz3,"(bz,i3.3)") iparm
1076 nazwa=nazwa(:iln)//"_par_"//licz3//".thermal"
1079 if (separate_parset) then
1080 write (iout,'(a,i3)') "Parameter set",myparm
1082 write (iout,'(a,i3)') "Parameter set",iparm
1085 sumE(i,iparm)=sumE(i,iparm)/sumW(i,iparm)
1086 sumEbis(i,iparm)=(startGridT+i*delta_T)*sumEbis(i,iparm)/
1088 sumEsq(i,iparm)=(sumEsq(i,iparm)/sumW(i,iparm)
1089 & -sumE(i,iparm)**2)/(1.987D-3*(startGridT+i*delta_T)**2)
1091 sumQ(j,i,iparm)=sumQ(j,i,iparm)/sumW(i,iparm)
1092 sumQsq(j,i,iparm)=sumQsq(j,i,iparm)/sumW(i,iparm)
1093 & -sumQ(j,i,iparm)**2
1094 sumEQ(j,i,iparm)=sumEQ(j,i,iparm)/sumW(i,iparm)
1095 & -sumQ(j,i,iparm)*sumE(i,iparm)
1097 sumW(i,iparm)=-dlog(sumW(i,iparm))*(1.987D-3*
1098 & (startGridT+i*delta_T))+potEmin
1099 write (iout,'(f7.1,2f15.5,$)') startGridT+i*delta_T,
1100 & sumW(i,iparm),sumE(i,iparm)
1101 write (iout,'(f10.5,$)') (sumQ(j,i,iparm),j=1,nQ+2)
1102 write (iout,'(e15.5,$)') sumEsq(i,iparm)-sumEbis(i,iparm),
1103 & (sumQsq(j,i,iparm),j=1,nQ+2),(sumEQ(j,i,iparm),j=1,nQ+2)
1105 write (34,'(f7.1,2f15.5,$)') startGridT+i*delta_T,
1106 & sumW(i,iparm),sumE(i,iparm)
1107 write (34,'(f10.5,$)') (sumQ(j,i,iparm),j=1,nQ+2)
1108 write (34,'(e15.5,$)') sumEsq(i,iparm)-sumEbis(i,iparm),
1109 & (sumQsq(j,i,iparm),j=1,nQ+2),(sumEQ(j,i,iparm),j=1,nQ+2)
1117 if (hfin_ent(t).gt.0.0d0) then
1119 jj = mod(liczba,nbin1)
1120 write (iout,'(f6.3,e20.10," ent")') dmin+(jj+0.5d0)*delta,
1122 if (histfile) write (ihist,'(f6.3,e20.10," ent")')
1123 & dmin+(jj+0.5d0)*delta,
1127 if (histfile) close(ihist)
1131 ! Write data for zscore
1132 if (nslice.eq.1) then
1133 zscname=prefix(:ilen(prefix))//".zsc"
1135 zscname=prefix(:ilen(prefix))//"_slice_"//licz2//".zsc"
1137 #if defined(AIX) || defined(PGI)
1138 open (izsc,file=prefix(:ilen(prefix))//'.zsc',position='append')
1140 open (izsc,file=prefix(:ilen(prefix))//'.zsc',access='append')
1142 write (izsc,'("NQ=",i1," NPARM=",i1)') nQ,nParmSet
1144 write (izsc,'("NT=",i1)') nT_h(iparm)
1146 write (izsc,'("TEMP=",f6.1," NR=",i2," SNK=",$)')
1147 & 1.0d0/(beta_h(ib,iparm)*1.987D-3),nR(ib,iparm)
1148 jj = min0(nR(ib,iparm),7)
1149 write (izsc,'(i8,$)') (snk(i,ib,iparm,islice),i=1,jj)
1150 write (izsc,'(a1,$)') (" ",i=22+8*jj+1,79)
1151 write (izsc,'("&")')
1152 if (nR(ib,iparm).gt.7) then
1153 do ii=8,nR(ib,iparm),9
1154 jj = min0(nR(ib,iparm),ii+8)
1155 write (izsc,'(i8,$)') (snk(i,ib,iparm,islice),i=ii,jj)
1156 write (izsc,'(a1,$') (" ",i=(jj-ii+1)*8+1,79)
1157 write (izsc,'("&")')
1160 write (izsc,'("FI=",$)')
1161 jj=min0(nR(ib,iparm),7)
1162 write (izsc,'(f10.5,$)') (fi(i,ib,iparm),i=1,jj)
1163 write (izsc,'(a1,$)') (" ",i=3+10*jj+1,79)
1164 write (izsc,'("&")')
1165 if (nR(ib,iparm).gt.7) then
1166 do ii=8,nR(ib,iparm),9
1167 jj = min0(nR(ib,iparm),ii+8)
1168 write (izsc,'(f10.5,$)') (fi(i,ib,iparm),i=ii,jj)
1169 if (jj.eq.nR(ib,iparm)) then
1172 write (izsc,'(a1,$)') (" ",i=10*(jj-ii+1)+1,79)
1173 write (izsc,'(t80,"&")')
1178 write (izsc,'("KH=",$)')
1179 write (izsc,'(f7.2,$)') (Kh(j,i,ib,iparm),j=1,nQ)
1180 write (izsc,'(" Q0=",$)')
1181 write (izsc,'(f7.5,$)') (q0(j,i,ib,iparm),j=1,nQ)