2 !-----------------------------------------------------------------------------
12 !-----------------------------------------------------------------------------
15 !-----------------------------------------------------------------------------
17 !-----------------------------------------------------------------------------
19 subroutine WHAMCALC(islice,*)
20 ! Weighed Histogram Analysis Method (WHAM) code
21 ! Written by A. Liwo based on the work of Kumar et al.,
22 ! J.Comput.Chem., 13, 1011 (1992)
24 ! 2/1/05 Multiple temperatures allowed.
25 ! 2/2/05 Free energies calculated directly from data points
26 ! acc. to Eq. (21) of Kumar et al.; final histograms also
27 ! constructed based on this equation.
28 ! 2/12/05 Multiple parameter sets included
30 ! 2/2/05 Parallel version
34 use io_base, only:ilen
39 ! include "DIMENSIONS"
40 ! include "DIMENSIONS.ZSCOPT"
41 ! include "DIMENSIONS.FREE"
42 integer,parameter :: NGridT=400
43 integer,parameter :: MaxBinRms=100,MaxBinRgy=100
44 integer,parameter :: MaxHdim=200
45 ! parameter (MaxHdim=200000)
46 integer,parameter :: maxinde=200
48 integer :: ierror,errcode,status(MPI_STATUS_SIZE)
50 ! include "COMMON.CONTROL"
51 ! include "COMMON.IOUNITS"
52 ! include "COMMON.FREE"
53 ! include "COMMON.ENERGIES"
54 ! include "COMMON.FFIELD"
55 ! include "COMMON.SBRIDGE"
56 ! include "COMMON.PROT"
57 ! include "COMMON.ENEPS"
58 integer,parameter :: MaxPoint=MaxStr,&
59 MaxPointProc=MaxStr_Proc
60 real(kind=8),parameter :: finorm_max=1.0d0
61 real(kind=8) :: potfac,expfac,vf
62 ! real(kind=8) :: potfac,entmin,entmax,expfac,vf
64 integer :: i,ii,j,jj,k,kk,l,m,ind,iter,t,tmax,ient,ientmax,iln
65 integer :: start,end,iharm,ib,iib,nbin1,nbin,nbin_rms,nbin_rgy,&
66 nbin_rmsrgy,liczbaW,iparm,nFi,indrgy,indrms
67 ! 4/17/17 AKS & AL: histent is obsolete
68 integer :: htot(0:MaxHdim)!,histent(0:2000)
69 real(kind=8) :: v(MaxPointProc,MaxR,MaxT_h,nParmSet) !(MaxPointProc,MaxR,MaxT_h,Max_Parm)
70 real(kind=8) :: energia(0:n_ene)
71 !el real(kind=8) :: energia(0:max_ene)
73 integer :: tmax_t,upindE_p
74 real(kind=8) :: fi_p(MaxR,MaxT_h,nParmSet), &
75 fi_p_min(MaxR,MaxT_h,nParmSet) !(MaxR,MaxT_h,Max_Parm)
76 real(kind=8),dimension(0:nGridT,nParmSet) :: sumW_p,sumE_p,&
77 sumEbis_p,sumEsq_p !(0:nGridT,Max_Parm)
78 real(kind=8),dimension(MaxQ1,0:nGridT,nParmSet) :: sumQ_p,&
79 sumQsq_p,sumEQ_p,sumEprim_p !(MaxQ1,0:nGridT,Max_Parm)
80 real(kind=8) :: hfin_p(0:MaxHdim,maxT_h),&
81 hfin_ent_p(0:MaxHdim),histE_p(0:maxindE),sumH,&
82 hrmsrgy_p(0:MaxBinRgy,0:MaxBinRms,maxT_h)
83 real(kind=8) :: rgymin_t,rmsmin_t,rgymax_t,rmsmax_t
84 real(kind=8) :: potEmin_t,potEmin_t_all(maxT_h,Max_Parm)!,entmin_p,entmax_p
85 ! integer :: histent_p(0:2000)
86 logical :: lprint=.true.
88 real(kind=8) :: delta_T=1.0d0,iientmax
89 real(kind=8) :: rgymin,rmsmin,rgymax,rmsmax
90 real(kind=8),dimension(0:nGridT,nParmSet) :: sumW,sumE,&
91 sumEsq,sumEprim,sumEbis !(0:NGridT,Max_Parm)
92 real(kind=8),dimension(MaxQ1,0:nGridT,nParmSet) :: sumQ,&
93 sumQsq,sumEQ !(MaxQ1,0:NGridT,Max_Parm)
94 real(kind=8) :: betaT,weight,econstr
95 real(kind=8) :: fi(MaxR,MaxT_h,nParmSet),& !(MaxR,maxT_h,Max_Parm)
96 ddW,dd1,dd2,hh,dmin,denom,finorm,avefi,pom,&
97 hfin(0:MaxHdim,maxT_h),histE(0:maxindE),&
98 hrmsrgy(0:MaxBinRgy,0:MaxBinRms,maxT_h),&
100 hfin_ent(0:MaxHdim),vmax,aux,fi_min(MaxR,maxT_h,nParmSet), &
101 potEmin_all(maxT_h,Max_Parm),potEmin_min,entfac_min
102 real(kind=8) :: fT(6),fTprim(6),fTbis(6),quot,quotl1,quotl,kfacl,&
103 eprim,ebis,temper,kfac=2.4d0,T0=300.0d0,startGridT=200.0d0,&
104 eplus,eminus,logfac,tanhT,tt
105 real(kind=8) :: etot,evdw,evdw_t,evdw2,ees,evdw1,ebe,etors,&
106 escloc,ehpb,ecorr,ecorr5,ecorr6,eello_turn4,eello_turn3,&
107 eello_turn6,eel_loc,edihcnstr,etors_d,estr,evdw2_14,esccor, &
108 ecationcation,ecation_prot, evdwpp,eespp ,evdwpsb,eelpsb, &
109 evdwsb, eelsb, estr_nucl,ebe_nucl,esbloc,etors_nucl,etors_d_nucl,&
110 ecorr_nucl, ecorr3_nucl,epeppho, escpho, epepbase,escbase
113 integer :: ind_point(maxpoint),upindE,indE
114 character(len=16) :: plik
115 character(len=1) :: licz1
116 character(len=2) :: licz2
117 character(len=3) :: licz3
118 character(len=128) :: nazwa
123 write(licz2,'(bz,i2.2)') islice
125 write (iout,'(//80(1h-)/"Solving WHAM equations for slice",&
126 i2/80(1h-)//)') islice
127 write (iout,*) "delta",delta," nbin1",nbin1
128 write (iout,*) "MaxN",MaxN," MaxQ",MaxQ," MaHdim",MaxHdim
135 potEmin_all(j,i)=1.0d15
152 if (potE(i,j).le.potEmin) potEmin=potE(i,j)
154 if (q(nQ+1,i).lt.rmsmin) rmsmin=q(nQ+1,i)
155 if (q(nQ+1,i).gt.rmsmax) rmsmax=q(nQ+1,i)
156 if (q(nQ+2,i).lt.rgymin) rgymin=q(nQ+2,i)
157 if (q(nQ+2,i).gt.rgymax) rgymax=q(nQ+2,i)
160 ind=(q(j,i)-dmin+1.0d-8)/delta
162 ind_point(i)=ind_point(i)+ind
164 ind_point(i)=ind_point(i)+nbin1**(j-1)*ind
166 ! write (iout,*) "i",i," j",j," q",q(j,i)," ind_point",
169 if (ind_point(i).lt.0 .or. ind_point(i).gt.MaxHdim) then
170 write (iout,*) "Error - index exceeds range for point",i,&
171 " q=",q(j,i)," ind",ind_point(i)
173 write (iout,*) "Processor",me1
175 call MPI_Abort(MPI_COMM_WORLD, Ierror, Errcode )
180 if (ind_point(i).gt.tmax) tmax=ind_point(i)
181 htot(ind_point(i))=htot(ind_point(i))+1
183 write (iout,*) "i",i,"q",(q(j,i),j=1,nQ)," ind",ind_point(i),&
184 " htot",htot(ind_point(i))
191 write (iout,'(a)') "Numbers of counts in Q bins"
193 if (htot(t).gt.0) then
194 write (iout,'(i15,$)') t
197 jj = mod(liczbaW,nbin1)
198 liczbaW=liczbaW/nbin1
199 write (iout,'(i5,$)') jj
201 write (iout,'(i8)') htot(t)
205 write (iout,'(a,i3)') "Number of data points for parameter set",&
207 write (iout,'(i7,$)') ((snk(m,ib,iparm,islice),m=1,nr(ib,iparm)),&
209 write (iout,'(i8)') stot(islice)
215 call MPI_AllReduce(tmax,tmax_t,1,MPI_INTEGER,MPI_MAX,&
218 ! call MPI_AllReduce(potEmin,potEmin_t,1,MPI_DOUBLE_PRECISION,&
219 ! MPI_MIN,WHAM_COMM,IERROR) !????
220 call MPI_AllReduce(rmsmin,rmsmin_t,1,MPI_DOUBLE_PRECISION,&
221 MPI_MIN,WHAM_COMM,IERROR)
222 call MPI_AllReduce(rmsmax,rmsmax_t,1,MPI_DOUBLE_PRECISION,&
223 MPI_MAX,WHAM_COMM,IERROR)
224 call MPI_AllReduce(rgymin,rgymin_t,1,MPI_DOUBLE_PRECISION,&
225 MPI_MIN,WHAM_COMM,IERROR)
226 call MPI_AllReduce(rgymax,rgymax_t,1,MPI_DOUBLE_PRECISION,&
227 MPI_MAX,WHAM_COMM,IERROR)
228 ! potEmin=potEmin_t !/2 try now??
233 write (iout,*) "potEmin",potEmin
235 rmsmin=deltrms*dint(rmsmin/deltrms)
236 rmsmax=deltrms*dint(rmsmax/deltrms)
237 rgymin=deltrms*dint(rgymin/deltrgy)
238 rgymax=deltrms*dint(rgymax/deltrgy)
239 nbin_rms=(rmsmax-rmsmin)/deltrms
240 nbin_rgy=(rgymax-rgymin)/deltrgy
241 write (iout,*) "rmsmin",rmsmin," rmsmax",rmsmax," rgymin",rgymin,&
242 " rgymax",rgymax," nbin_rms",nbin_rms," nbin_rgy",nbin_rgy
249 write (iout,*) "nFi",nFi
250 ! Compute the Boltzmann factor corresponing to restrain potentials in different
257 ! write (9,'(3i5,f10.5)') i,(iparm,potE(i,iparm),iparm=1,nParmSet)
260 write (iout,'(2i5,21f8.2)') i,iparm,&
261 (enetb(k,i,iparm),k=1,21)
263 call restore_parm(iparm)
265 write (iout,*) wsc,wscp,welec,wvdwpp,wang,wtor,wscloc,&
266 wcorr,wcorr5,wcorr6,wturn4,wturn3,wturn6,wel_loc,&
267 wtor_d,wsccor,wbond,wcatcat
270 !el old rascale weights
272 ! if (rescale_modeW.eq.1) then
273 ! quot=1.0d0/(beta_h(ib,iparm)*1.987D-3*T0)
280 ! fT(l)=kfacl/(kfacl-1.0d0+quotl)
283 ! tt = 1.0d0/(beta_h(ib,iparm)*1.987D-3)
284 ! ft(6)=(320.0d0+80.0d0*dtanh((tt-320.0d0)/80.0d0))/320.0d0
285 !#elif defined(FUNCT)
286 ! ft(6)=1.0d0/(beta_h(ib,iparm)*1.987D-3*T0)
290 ! else if (rescale_modeW.eq.2) then
291 ! quot=1.0d0/(T0*beta_h(ib,iparm)*1.987D-3)
295 ! fT(l)=1.12692801104297249644d0/ &
296 ! dlog(dexp(quotl)+dexp(-quotl))
299 ! tt = 1.0d0/(beta_h(ib,iparm)*1.987D-3)
300 ! ft(6)=(320.0d0+80.0d0*dtanh((tt-320.0d0)/80.0d0))/320.0d0
301 !#elif defined(FUNCT)
302 ! ft(6)=1.0d0/(beta_h(ib,iparm)*1.987D-3*T0)
306 ! write (iout,*) 1.0d0/(beta_h(ib,iparm)*1.987D-3),ft
307 ! else if (rescale_modeW.eq.0) then
312 ! write (iout,*) "Error in WHAM_CALC: wrong RESCALE_MODE",&
317 ! el end old rescale weights
318 call rescale_weights(1.0d0/(beta_h(ib,iparm)*1.987D-3))
320 ! call etot(enetb(0,i,iparm))
321 evdw=enetb(1,i,iparm)
322 ! evdw_t=enetb(21,i,iparm)
323 evdw_t=enetb(20,i,iparm)
325 ! evdw2_14=enetb(17,i,iparm)
326 evdw2_14=enetb(18,i,iparm)
327 evdw2=enetb(2,i,iparm)+evdw2_14
329 evdw2=enetb(2,i,iparm)
334 evdw1=enetb(16,i,iparm)
339 ecorr=enetb(4,i,iparm)
340 ecorr5=enetb(5,i,iparm)
341 ecorr6=enetb(6,i,iparm)
342 eel_loc=enetb(7,i,iparm)
343 eello_turn3=enetb(8,i,iparm)
344 eello_turn4=enetb(9,i,iparm)
345 eello_turn6=enetb(10,i,iparm)
346 ebe=enetb(11,i,iparm)
347 escloc=enetb(12,i,iparm)
348 etors=enetb(13,i,iparm)
349 etors_d=enetb(14,i,iparm)
350 ehpb=enetb(15,i,iparm)
351 ! estr=enetb(18,i,iparm)
352 estr=enetb(17,i,iparm)
353 ! esccor=enetb(19,i,iparm)
354 esccor=enetb(21,i,iparm)
355 ! edihcnstr=enetb(20,i,iparm)
356 edihcnstr=enetb(19,i,iparm)
357 ecationcation=enetb(41,i,iparm)
358 ecation_prot=enetb(42,i,iparm)
359 evdwpp = enetb(26,i,iparm)
360 eespp = enetb(27,i,iparm)
361 evdwpsb = enetb(28,i,iparm)
362 eelpsb = enetb(29,i,iparm)
363 evdwsb = enetb(30,i,iparm)
364 eelsb = enetb(31,i,iparm)
365 estr_nucl = enetb(32,i,iparm)
366 ebe_nucl = enetb(33,i,iparm)
367 esbloc = enetb(34,i,iparm)
368 etors_nucl = enetb(35,i,iparm)
369 etors_d_nucl = enetb(36,i,iparm)
370 ecorr_nucl = enetb(37,i,iparm)
371 ecorr3_nucl = enetb(38,i,iparm)
372 epeppho= enetb(49,i,iparm)
373 escpho= enetb(48,i,iparm)
374 epepbase= enetb(47,i,iparm)
375 escbase= enetb(46,i,iparm)
378 write (iout,'(3i5,6f5.2,15f12.3)') i,ib,iparm,(ft(l),l=1,6),&
379 evdw+evdw_t,evdw2,ees,evdw1,ecorr,eel_loc,estr,ebe,escloc,&
380 etors,etors_d,eello_turn3,eello_turn4,esccor,ecationcation
384 ! etot=wsc*(evdw+ft(6)*evdw_t)+wscp*evdw2+ft(1)*welec*ees &
386 ! +wang*ebe+ft(1)*wtor*etors+wscloc*escloc &
387 ! +wstrain*ehpb+nss*ebr+ft(3)*wcorr*ecorr+ft(4)*wcorr5*ecorr5 &
388 ! +ft(5)*wcorr6*ecorr6+ft(3)*wturn4*eello_turn4 &
389 ! +ft(2)*wturn3*eello_turn3 &
390 ! +ft(5)*wturn6*eturn6+ft(2)*wel_loc*eel_loc &
391 ! +edihcnstr+ft(2)*wtor_d*etors_d+ft(1)*wsccor*esccor &
394 ! etot=wsc*(evdw+ft(6)*evdw_t)+wscp*evdw2 &
395 ! +ft(1)*welec*(ees+evdw1) &
396 ! +wang*ebe+ft(1)*wtor*etors+wscloc*escloc &
397 ! +wstrain*ehpb+nss*ebr+ft(3)*wcorr*ecorr+ft(4)*wcorr5*ecorr5 &
398 ! +ft(5)*wcorr6*ecorr6+ft(3)*wturn4*eello_turn4 &
399 ! +ft(2)*wturn3*eello_turn3 &
400 ! +ft(5)*wturn6*eturn6+ft(2)*wel_loc*eel_loc+edihcnstr &
401 ! +ft(2)*wtor_d*etors_d+ft(1)*wsccor*esccor &
406 etot=wsc*evdw+wscp*evdw2+welec*ees &
408 +wang*ebe+wtor*etors+wscloc*escloc &
409 +wstrain*ehpb+wcorr*ecorr+wcorr5*ecorr5 &
410 +wcorr6*ecorr6+wturn4*eello_turn4 &
411 +wturn3*eello_turn3 &
412 +wturn6*eello_turn6+wel_loc*eel_loc &
413 +edihcnstr+wtor_d*etors_d+wsccor*esccor &
414 +wbond*estr+wcatprot*ecation_prot+wcatcat*ecationcation&
415 +wbond_nucl*estr_nucl+wang_nucl*ebe_nucl&
416 +wvdwpp_nucl*evdwpp+welpp*eespp+wvdwpsb*evdwpsb+welpsb*eelpsb&
417 +wvdwsb*evdwsb+welsb*eelsb+wsbloc*esbloc+wtor_nucl*etors_nucl&
418 +wtor_d_nucl*etors_d_nucl+wcorr_nucl*ecorr_nucl+wcorr3_nucl*ecorr3_nucl&
420 +wpepbase*epepbase+wscpho*escpho+wpeppho*epeppho
424 etot=wsc*evdw+wscp*evdw2 &
426 +wang*ebe+wtor*etors+wscloc*escloc &
427 +wstrain*ehpb+wcorr*ecorr+wcorr5*ecorr5 &
428 +wcorr6*ecorr6+wturn4*eello_turn4 &
429 +wturn3*eello_turn3 &
430 +wturn6*eello_turn6+wel_loc*eel_loc+edihcnstr &
431 +wtor_d*etors_d+wsccor*esccor &
432 +wbond*estr+wcatprot*ecation_prot+wcatcat*ecationcation&
433 +wbond_nucl*estr_nucl+wang_nucl*ebe_nucl&
434 +wvdwpp_nucl*evdwpp+welpp*eespp+wvdwpsb*evdwpsb+welpsb*eelpsb&
435 +wvdwsb*evdwsb+welsb*eelsb+wsbloc*esbloc+wtor_nucl*etors_nucl&
436 +wtor_d_nucl*etors_d_nucl+wcorr_nucl*ecorr_nucl+wcorr3_nucl*ecorr3_nucl&
438 +wpepbase*epepbase+wscpho*escpho+wpeppho*epeppho
444 write (iout,*) i,iparm,1.0d0/(beta_h(ib,iparm)*1.987D-3),&
448 if (iparm.eq.1 .and. ib.eq.1) then
449 write (iout,*)"Conformation",i
452 energia(k)=enetb(k,i,iparm)
454 ! call enerprint(energia(0),fT)
455 call enerprint(energia(0))
462 Econstr=Econstr+Kh(j,kk,ib,iparm) &
463 *(ddW-q0(j,kk,ib,iparm))**2
466 -beta_h(ib,iparm)*(etot-potEmin+Econstr)
468 write (iout,'(4i5,4e15.5)') i,kk,ib,iparm,&
469 etot,potEmin,etot-potEmin,v(i,kk,ib,iparm)
475 ! Simple iteration to calculate free energies corresponding to all simulation
479 ! Compute new free-energy values corresponding to the righ-hand side of the
480 ! equation and their derivatives.
481 write (iout,*) "------------------------fi"
491 vf=v(t,l,k,i)+f(l,k,i)
492 if (vf.gt.vmax) vmax=vf
500 aux=f(l,k,i)+v(t,l,k,i)-vmax
501 if (aux.gt.-200.0d0) &
502 denom=denom+snk(l,k,i,islice)*dexp(aux)
506 entfac(t)=-dlog(denom)-vmax
507 if (entfac(t).lt.entfac_min) entfac_min=entfac(t)
509 write (iout,*) t,"vmax",vmax," denom",denom,"entfac",entfac(t)
514 do ii=1,nR(iib,iparm)
516 fi_p_min(ii,iib,iparm)=-1.0d5
518 ! fi_p(ii,iib,iparm)=fi_p(ii,iib,iparm) &
519 ! +dexp(v(t,ii,iib,iparm)+entfac(t))
520 aux=v(t,ii,iib,iparm)+entfac(t)
521 if (aux.gt.fi_p_min(ii,iib,iparm)) fi_p_min(ii,iib,iparm)=aux
525 write (iout,'(4i5,4e15.5)') t,ii,iib,iparm,&
526 v(t,ii,iib,iparm),entfac(t),fi_p(ii,iib,iparm),fi_p_min(ii,iib,iparm)
531 ! fi(ii,iib,iparm)=0.0d0
533 ! fi(ii,iib,iparm)=fi(ii,iib,iparm) &
534 ! +dexp(v(t,ii,iib,iparm)+entfac(t))
535 aux=v(t,ii,iib,iparm)+entfac(t)
536 if (aux.gt.fi_min(ii,iib,iparm))
537 & fi_min(ii,iib,iparm)=aux
547 write (iout,*) "fi before MPI_Reduce me",me,' master',master
549 do ib=1,nT_h(nparmset)
550 write (iout,*) "iparm",iparm," ib",ib
551 write (iout,*) "beta=",beta_h(ib,iparm)
552 write (iout,'(8e15.5)') (fi_p(i,ib,iparm),i=1,nR(ib,iparm))
553 write (iout,'(8e15.5)') (fi_p_min(i,ib,iparm),i=1,nR(ib,iparm))
557 call MPI_AllReduce(fi_p_min,fi_min,MaxR*MaxT_h*nParmSet, &
558 MPI_DOUBLE_PRECISION,MPI_MAX,WHAM_COMM,IERROR)
561 write (iout,*) "fi_min after AllReduce"
564 write (iout,*) (i,j,k,fi_min(k,j,i),k=1,nR(j,i))
572 do ii=1,nR(iib,iparm)
574 fi_p(ii,iib,iparm)=0.0d0
576 fi_p(ii,iib,iparm)=fi_p(ii,iib,iparm) &
577 +dexp(v(t,ii,iib,iparm)+entfac(t)-fi_min(ii,iib,iparm))
579 write (iout,'(4i5,4e15.5)') t,ii,iib,iparm, &
580 v(t,ii,iib,iparm),entfac(t),fi_min(ii,iib,iparm), &
585 fi(ii,iib,iparm)=0.0d0
587 fi(ii,iib,iparm)=fi(ii,iib,iparm) &
588 +dexp(v(t,ii,iib,iparm)+entfac(t)-fi_min(ii,iib,iparm))
597 write (iout,*) "fi before MPI_Reduce me",me,' master',master
599 do ib=1,nT_h(nparmset)
600 write (iout,*) "iparm",iparm," ib",ib
601 write (iout,*) "beta=",beta_h(ib,iparm)
602 write (iout,'(8e15.5)') (fi_p(i,ib,iparm),i=1,nR(ib,iparm))
607 write (iout,*) "REDUCE size",maxR,MaxT_h,nParmSet, &
609 write (iout,*) "MPI_COMM_WORLD",MPI_COMM_WORLD, &
610 " WHAM_COMM",WHAM_COMM
613 write (iout,*) "REDUCE size",maxR,MaxT_h,nParmSet,&
615 write (iout,*) "MPI_COMM_WORLD",MPI_COMM_WORLD,&
616 " WHAM_COMM",WHAM_COMM
617 call MPI_Reduce(fi_p(1,1,1),fi(1,1,1),maxR*MaxT_h*nParmSet,&
618 MPI_DOUBLE_PRECISION,&
619 MPI_SUM,Master,WHAM_COMM,IERROR)
621 write (iout,*) "fi after MPI_Reduce nparmset",nparmset
623 write (iout,*) "iparm",iparm
625 write (iout,*) "beta=",beta_h(ib,iparm)
626 write (iout,'(8e15.5)') (fi(i,ib,iparm),i=1,nR(ib,iparm))
630 if (me1.eq.Master) then
636 fi(i,ib,iparm)=-dlog(fi(i,ib,iparm))-fi_min(i,ib,iparm)
637 avefi=avefi+fi(i,ib,iparm)
643 write (iout,*) "Parameter set",iparm
645 write (iout,*) "beta=",beta_h(ib,iparm)
647 fi(i,ib,iparm)=fi(i,ib,iparm)-avefi
649 write (iout,'(8f10.5)') (fi(i,ib,iparm),i=1,nR(ib,iparm))
650 write (iout,'(8f10.5)') (f(i,ib,iparm),i=1,nR(ib,iparm))
654 ! Compute the norm of free-energy increments.
659 finorm=finorm+dabs(fi(i,ib,iparm)-f(i,ib,iparm))
660 f(i,ib,iparm)=fi(i,ib,iparm)
665 write (iout,*) 'Iteration',iter,' finorm',finorm
669 call MPI_Bcast(f(1,1,1),MaxR*MaxT_h*nParmSet,&
670 MPI_DOUBLE_PRECISION,Master,&
672 call MPI_Bcast(finorm,1,MPI_DOUBLE_PRECISION,Master,&
675 ! Exit, if the increment norm is smaller than pre-assigned tolerance.
676 if (finorm.lt.fimin) then
677 write (iout,*) 'Iteration converged'
684 ! Now, put together the histograms from all simulations, in order to get the
685 ! unbiased total histogram.
686 !C Determine the minimum free energies
692 !c write (9,'(3i5,f10.5)') i,(iparm,potE(i,iparm),iparm=1,nParmSet)
695 write (iout,'(2i5,21f8.2)') i,iparm, &
696 (enetb(k,i,iparm),k=1,26)
698 call restore_parm(iparm)
700 write (iout,*) wsc,wscp,welec,wvdwpp,wang,wtor,wscloc, &
701 wcorr,wcorr5,wcorr6,wturn4,wturn3,wturn6,wel_loc, &
705 if (rescale_modeW.eq.1) then
706 quot=1.0d0/(beta_h(ib,iparm)*1.987D-3*T0)
713 fT(l)=kfacl/(kfacl-1.0d0+quotl)
716 tt = 1.0d0/(beta_h(ib,iparm)*1.987D-3)
717 ft(6)=(320.0d0+80.0d0*dtanh((tt-320.0d0)/80.0d0))/320.0d0
719 ft(6)=1.0d0/(beta_h(ib,iparm)*1.987D-3*T0)
723 else if (rescale_modeW.eq.2) then
724 quot=1.0d0/(T0*beta_h(ib,iparm)*1.987D-3)
728 fT(l)=1.12692801104297249644d0/ &
729 dlog(dexp(quotl)+dexp(-quotl))
732 tt = 1.0d0/(beta_h(ib,iparm)*1.987D-3)
733 ft(6)=(320.0d0+80.0d0*dtanh((tt-320.0d0)/80.0d0))/320.0d0
735 ft(6)=1.0d0/(beta_h(ib,iparm)*1.987D-3*T0)
739 !c write (iout,*) 1.0d0/(beta_h(ib,iparm)*1.987D-3),ft
740 else if (rescale_modeW.eq.0) then
745 write (iout,*) "Error in WHAM_CALC: wrong RESCALE_MODE", &
750 evdw=enetb(1,i,iparm)
751 ! evdw_t=enetb(21,i,iparm)
752 evdw_t=enetb(20,i,iparm)
754 ! evdw2_14=enetb(17,i,iparm)
755 evdw2_14=enetb(18,i,iparm)
756 evdw2=enetb(2,i,iparm)+evdw2_14
758 evdw2=enetb(2,i,iparm)
763 evdw1=enetb(16,i,iparm)
768 ecorr=enetb(4,i,iparm)
769 ecorr5=enetb(5,i,iparm)
770 ecorr6=enetb(6,i,iparm)
771 eel_loc=enetb(7,i,iparm)
772 eello_turn3=enetb(8,i,iparm)
773 eello_turn4=enetb(9,i,iparm)
774 eello_turn6=enetb(10,i,iparm)
775 ebe=enetb(11,i,iparm)
776 escloc=enetb(12,i,iparm)
777 etors=enetb(13,i,iparm)
778 etors_d=enetb(14,i,iparm)
779 ehpb=enetb(15,i,iparm)
780 ! estr=enetb(18,i,iparm)
781 estr=enetb(17,i,iparm)
782 ! esccor=enetb(19,i,iparm)
783 esccor=enetb(21,i,iparm)
784 ! edihcnstr=enetb(20,i,iparm)
785 edihcnstr=enetb(19,i,iparm)
786 ! ehomology_constr=enetb(22,i,iparm)
787 ! esaxs=enetb(26,i,iparm)
788 ecationcation=enetb(41,i,iparm)
789 ecation_prot=enetb(42,i,iparm)
790 evdwpp = enetb(26,i,iparm)
791 eespp = enetb(27,i,iparm)
792 evdwpsb = enetb(28,i,iparm)
793 eelpsb = enetb(29,i,iparm)
794 evdwsb = enetb(30,i,iparm)
795 eelsb = enetb(31,i,iparm)
796 estr_nucl = enetb(32,i,iparm)
797 ebe_nucl = enetb(33,i,iparm)
798 esbloc = enetb(34,i,iparm)
799 etors_nucl = enetb(35,i,iparm)
800 etors_d_nucl = enetb(36,i,iparm)
801 ecorr_nucl = enetb(37,i,iparm)
802 ecorr3_nucl = enetb(38,i,iparm)
803 epeppho= enetb(49,i,iparm)
804 escpho= enetb(48,i,iparm)
805 epepbase= enetb(47,i,iparm)
806 escbase= enetb(46,i,iparm)
809 etot=wsc*(evdw+ft(6)*evdw_t)+wscp*evdw2+ft(1)*welec*ees &
811 +wang*ebe+ft(1)*wtor*etors+wscloc*escloc &
812 +wstrain*ehpb+ft(3)*wcorr*ecorr+ft(4)*wcorr5*ecorr5 &
813 +ft(5)*wcorr6*ecorr6+ft(3)*wturn4*eello_turn4 &
814 +ft(2)*wturn3*eello_turn3 &
815 +ft(5)*wturn6*eello_turn6+ft(2)*wel_loc*eel_loc &
816 +edihcnstr+ft(2)*wtor_d*etors_d+ft(1)*wsccor*esccor &
817 +wbond*estr+wcatprot*ecation_prot+wcatcat*ecationcation &
818 +wbond_nucl*estr_nucl+wang_nucl*ebe_nucl&
819 +wvdwpp_nucl*evdwpp+welpp*eespp+wvdwpsb*evdwpsb+welpsb*eelpsb&
820 +wvdwsb*evdwsb+welsb*eelsb+wsbloc*esbloc+wtor_nucl*etors_nucl&
821 *ft(1)+wtor_d_nucl*ft(2)*etors_d_nucl+wcorr_nucl*ecorr_nucl &
822 +wcorr3_nucl*ecorr3_nucl&
824 +ft(1)*wpepbase*epepbase+wscpho*escpho+wpeppho*epeppho
827 etot=wsc*(evdw+ft(6)*evdw_t)+wscp*evdw2 &
828 +ft(1)*welec*(ees+evdw1) &
829 +wang*ebe+ft(1)*wtor*etors+wscloc*escloc &
830 +wstrain*ehpb+ft(3)*wcorr*ecorr+ft(4)*wcorr5*ecorr5 &
831 +ft(5)*wcorr6*ecorr6+ft(3)*wturn4*eello_turn4 &
832 +ft(2)*wturn3*eello_turn3 &
833 +ft(5)*wturn6*eello_turn6+ft(2)*wel_loc*eel_loc+edihcnstr &
834 +ft(2)*wtor_d*etors_d+ft(1)*wsccor*esccor &
835 +wbond*estr+wcatprot*ecation_prot+wcatcat*ecationcation&
836 +wbond_nucl*estr_nucl+wang_nucl*ebe_nucl&
837 +wvdwpp_nucl*evdwpp+welpp*eespp+wvdwpsb*evdwpsb+welpsb*eelpsb&
838 +wvdwsb*evdwsb+welsb*eelsb+wsbloc*esbloc+wtor_nucl*etors_nucl&
839 *ft(1)+wtor_d_nucl*ft(2)*etors_d_nucl+wcorr_nucl*ecorr_nucl &
840 +wcorr3_nucl*ecorr3_nucl&
842 +ft(1)*wpepbase*epepbase+wscpho*escpho+wpeppho*epeppho
845 write (iout,*) "WTF,",etot,potEmin_all(ib,iparm),entfac(i)/beta_h(ib,iparm)
846 etot=etot-entfac(i)/beta_h(ib,iparm)
847 if(etot.lt.potEmin_all(ib,iparm)) potEmin_all(ib,iparm)=etot
853 write (iout,*) "The potEmin array before reduction"
855 write (iout,*) "Parameter set",i
857 write (iout,*) j,PotEmin_all(j,i)
860 write (iout,*) "potEmin_min",potEmin_min
863 !C Determine the minimum energes for all parameter sets and temperatures
864 call MPI_AllReduce(potEmin_all(1,1),potEmin_t_all(1,1), &
865 maxT_h*nParmSet,MPI_DOUBLE_PRECISION,MPI_MIN,WHAM_COMM,IERROR)
868 potEmin_all(j,i)=potEmin_t_all(j,i)
872 potEmin_min=potEmin_all(1,1)
875 if (potEmin_all(j,i).lt.potEmin_min) &
876 potEmin_min=potEmin_all(j,i)
880 write (iout,*) "The potEmin array"
882 write (iout,*) "Parameter set",i
884 write (iout,*) j,1.0d0/(1.987d-3*beta_h(j,i)), &
888 write (iout,*) "potEmin_min",potEmin_min
900 write (iout,*) "--------------hist"
904 sumW_p(i,iparm)=0.0d0
905 sumE_p(i,iparm)=0.0d0
906 sumEbis_p(i,iparm)=0.0d0
907 sumEsq_p(i,iparm)=0.0d0
909 sumQ_p(j,i,iparm)=0.0d0
910 sumQsq_p(j,i,iparm)=0.0d0
911 sumEQ_p(j,i,iparm)=0.0d0
921 sumEbis(i,iparm)=0.0d0
922 sumEsq(i,iparm)=0.0d0
924 sumQ(j,i,iparm)=0.0d0
925 sumQsq(j,i,iparm)=0.0d0
926 sumEQ(j,i,iparm)=0.0d0
932 ! 8/26/05 entropy distribution
937 !! ent=-dlog(entfac(t))
939 ! if (ent.lt.entmin_p) entmin_p=ent
940 ! if (ent.gt.entmax_p) entmax_p=ent
942 ! write (iout,*) "entmin",entmin_p," entmax",entmax_p
943 !! write (iout,*) "entmin_p",entmin_p," entmax_p",entmax_p
945 ! call MPI_Allreduce(entmin_p,entmin,1,MPI_DOUBLE_PRECISION,MPI_MIN,&
947 ! call MPI_Allreduce(entmax_p,entmax,1,MPI_DOUBLE_PRECISION,MPI_MAX,&
949 ! write (iout,*) "entmin",entmin," entmax",entmax
950 ! write (iout,*) "entmin_p",entmin_p," entmax_p",entmax_p
951 ! ientmax=entmax-entmin
952 !iientmax=entmax-entmin !el
953 !write (iout,*) "ientmax",ientmax,entmax,entmin
954 !write (iout,*) "iientmax",iientmax
955 ! if (ientmax.gt.2000) ientmax=2000
956 ! write (iout,*) "entmin",entmin," entmax",entmax," ientmax",ientmax
959 !! ient=-dlog(entfac(t))-entmin
960 ! ient=entfac(t)-entmin
961 ! if (ient.le.2000) histent_p(ient)=histent_p(ient)+1
963 ! call MPI_Allreduce(histent_p(0),histent(0),ientmax+1,MPI_INTEGER,&
964 ! MPI_SUM,WHAM_COMM,IERROR)
965 ! if (me1.eq.Master) then
966 ! write (iout,*) "Entropy histogram"
968 ! write(iout,'(f15.4,i10)') entmin+i,histent(i)
974 ! do t=1,ntot(islice)
976 ! if (ent.lt.entmin) entmin=ent
977 ! if (ent.gt.entmax) entmax=ent
979 ! ientmax=-dlog(entmax)-entmin
980 ! if (ientmax.gt.2000) ientmax=2000
981 ! do t=1,ntot(islice)
982 ! ient=entfac(t)-entmin
983 ! if (ient.le.2000) histent(ient)=histent(ient)+1
985 ! write (iout,*) "Entropy histogram"
987 ! write(iout,'(2f15.4)') entmin+i,histent(i)
992 write (iout,*) "me1",me1," scount",scount(me1) !d
1018 hrmsrgy(j,i,ib)=0.0d0
1020 hrmsrgy_p(j,i,ib)=0.0d0
1032 hfin_ent_p(ind)=hfin_ent_p(ind)+dexp(entfac(t))
1034 hfin_ent(ind)=hfin_ent(ind)+dexp(entfac(t))
1036 ! write (iout,'(2i5,20f8.2)') "debug",t,t,(enetb(k,t,iparm),k=1,21)
1037 call restore_parm(iparm)
1038 ! evdw=enetb(21,t,iparm)
1039 evdw=enetb(20,t,iparm)
1040 evdw_t=enetb(1,t,iparm)
1042 ! evdw2_14=enetb(17,t,iparm)
1043 evdw2_14=enetb(18,t,iparm)
1044 evdw2=enetb(2,t,iparm)+evdw2_14
1046 evdw2=enetb(2,t,iparm)
1050 ees=enetb(3,t,iparm)
1051 evdw1=enetb(16,t,iparm)
1053 ees=enetb(3,t,iparm)
1056 ecorr=enetb(4,t,iparm)
1057 ecorr5=enetb(5,t,iparm)
1058 ecorr6=enetb(6,t,iparm)
1059 eel_loc=enetb(7,t,iparm)
1060 eello_turn3=enetb(8,t,iparm)
1061 eello_turn4=enetb(9,t,iparm)
1062 eello_turn6=enetb(10,t,iparm)
1063 ebe=enetb(11,t,iparm)
1064 escloc=enetb(12,t,iparm)
1065 etors=enetb(13,t,iparm)
1066 etors_d=enetb(14,t,iparm)
1067 ehpb=enetb(15,t,iparm)
1068 ! estr=enetb(18,t,iparm)
1069 estr=enetb(17,t,iparm)
1070 ! esccor=enetb(19,t,iparm)
1071 esccor=enetb(21,t,iparm)
1072 ! edihcnstr=enetb(20,t,iparm)
1073 edihcnstr=enetb(19,t,iparm)
1075 ecationcation=enetb(41,t,iparm)
1076 ecation_prot=enetb(42,t,iparm)
1077 evdwpp = enetb(26,t,iparm)
1078 eespp = enetb(27,t,iparm)
1079 evdwpsb = enetb(28,t,iparm)
1080 eelpsb = enetb(29,t,iparm)
1081 evdwsb = enetb(30,t,iparm)
1082 eelsb = enetb(31,t,iparm)
1083 estr_nucl = enetb(32,t,iparm)
1084 ebe_nucl = enetb(33,t,iparm)
1085 esbloc = enetb(34,t,iparm)
1086 etors_nucl = enetb(35,t,iparm)
1087 etors_d_nucl = enetb(36,t,iparm)
1088 ecorr_nucl = enetb(37,t,iparm)
1089 ecorr3_nucl = enetb(38,t,iparm)
1090 epeppho= enetb(49,t,iparm)
1091 escpho= enetb(48,t,iparm)
1092 epepbase= enetb(47,t,iparm)
1093 escbase= enetb(46,t,iparm)
1097 betaT=startGridT+k*delta_T
1099 !write(iout,*)"kkkkkkkk",betaT,startGridT,k,delta_T
1101 !d ft=2*T0/(T0+betaT)
1102 if (rescale_modeW.eq.1) then
1110 denom=kfacl-1.0d0+quotl
1112 ftprim(l)=-l*ft(l)*quotl1/(T0*denom)
1113 ftbis(l)=l*kfacl*quotl1* &
1114 (2*l*quotl-(l-1)*denom)/(quot*t0*t0*denom**3)
1117 ft(6)=(320.0d0+80.0d0*dtanh((betaT-320.0d0)/80.0d0))/ &
1119 ftprim(6)=1.0d0/(320.0d0*dcosh((betaT-320.0d0)/80.0d0)**2)
1120 ftbis(6)=-2.0d0*dtanh((betaT-320.0d0)/80.0d0) &
1121 /(320.0d0*80.0d0*dcosh((betaT-320.0d0)/80.0d0)**3)
1122 #elif defined(FUNCT)
1131 else if (rescale_modeW.eq.2) then
1139 logfac=1.0d0/dlog(eplus+eminus)
1140 tanhT=(eplus-eminus)/(eplus+eminus)
1141 fT(l)=1.12692801104297249644d0*logfac
1142 ftprim(l)=-l*quotl1*ft(l)*tanhT*logfac/T0
1143 ftbis(l)=(l-1)*ftprim(l)/(quot*T0)- &
1144 2*l*quotl1/T0*logfac* &
1145 (2*l*quotl1*ft(l)/(T0*(eplus+eminus)**2) &
1149 ft(6)=(320.0d0+80.0d0*dtanh((betaT-320.0d0)/80.0d0))/ &
1151 ftprim(6)=1.0d0/(320.0d0*dcosh((betaT-320.0d0)/80.0d0)**2)
1152 ftbis(6)=-2.0d0*dtanh((betaT-320.0d0)/80.0d0) &
1153 /(320.0d0*80.0d0*dcosh((betaT-320.0d0)/80.0d0)**3)
1154 #elif defined(FUNCT)
1163 else if (rescale_modeW.eq.0) then
1169 write (iout,*) "Error in WHAM_CALC: wrong RESCALE_MODE",&
1174 ! write (iout,*) "ftprim",ftprim
1175 ! write (iout,*) "ftbis",ftbis
1176 betaT=1.0d0/(1.987D-3*betaT)
1178 etot=wsc*(evdw+ft(6)*evdw_t)+wscp*evdw2+ft(1)*welec*ees &
1180 +wang*ebe+ft(1)*wtor*etors+wscloc*escloc &
1181 +wstrain*ehpb+ft(3)*wcorr*ecorr+ft(4)*wcorr5*ecorr5 &
1182 +ft(5)*wcorr6*ecorr6+ft(3)*wturn4*eello_turn4 &
1183 +ft(2)*wturn3*eello_turn3 &
1184 +ft(5)*wturn6*eello_turn6+ft(2)*wel_loc*eel_loc &
1185 +edihcnstr+ft(2)*wtor_d*etors_d+ft(1)*wsccor*esccor &
1186 +wbond*estr+wcatprot*ecation_prot+wcatcat*ecationcation &
1187 +wbond_nucl*estr_nucl+wang_nucl*ebe_nucl&
1188 +wvdwpp_nucl*evdwpp+welpp*eespp+wvdwpsb*evdwpsb+welpsb*eelpsb&
1189 +wvdwsb*evdwsb+welsb*eelsb+wsbloc*esbloc+wtor_nucl*etors_nucl&
1190 *ft(1)+wtor_d_nucl*ft(2)*etors_d_nucl+wcorr_nucl*ecorr_nucl &
1191 +wcorr3_nucl*ecorr3_nucl&
1193 +ft(1)*wpepbase*epepbase+wscpho*escpho+wpeppho*epeppho
1195 eprim=ftprim(6)*evdw_t+ftprim(1)*welec*ees &
1196 +ftprim(1)*wtor*etors+ &
1197 ftprim(3)*wcorr*ecorr+ftprim(4)*wcorr5*ecorr5+ &
1198 ftprim(5)*wcorr6*ecorr6+ftprim(3)*wturn4*eello_turn4+ &
1199 ftprim(2)*wturn3*eello_turn3+ftprim(5)*wturn6*eello_turn6+ &
1200 ftprim(2)*wel_loc*eel_loc+ftprim(2)*wtor_d*etors_d+ &
1201 ftprim(1)*wsccor*esccor +ftprim(1)*wtor_nucl*etors_nucl&
1202 +wtor_d_nucl*ftprim(2)*etors_d_nucl+ftprim(1)*wpepbase*epepbase
1203 ebis=ftbis(1)*welec*ees+ftbis(1)*wtor*etors+ &
1204 ftbis(3)*wcorr*ecorr+ftbis(4)*wcorr5*ecorr5+ &
1205 ftbis(5)*wcorr6*ecorr6+ftbis(3)*wturn4*eello_turn4+ &
1206 ftbis(2)*wturn3*eello_turn3+ftbis(5)*wturn6*eello_turn6+ &
1207 ftbis(2)*wel_loc*eel_loc+ftbis(2)*wtor_d*etors_d+ &
1208 ftbis(1)*wsccor*esccor+ftbis(1)*wtor_nucl*etors_nucl&
1209 +wtor_d_nucl*ftbis(2)*etors_d_nucl+ftbis(1)*wpepbase*epepbase
1211 etot=wsc*(evdw+ft(6)*evdw_t)+wscp*evdw2 &
1212 +ft(1)*welec*(ees+evdw1) &
1213 +wang*ebe+ft(1)*wtor*etors+wscloc*escloc &
1214 +wstrain*ehpb+ft(3)*wcorr*ecorr+ft(4)*wcorr5*ecorr5 &
1215 +ft(5)*wcorr6*ecorr6+ft(3)*wturn4*eello_turn4 &
1216 +ft(2)*wturn3*eello_turn3 &
1217 +ft(5)*wturn6*eello_turn6+ft(2)*wel_loc*eel_loc+edihcnstr &
1218 +ft(2)*wtor_d*etors_d+ft(1)*wsccor*esccor &
1219 +wbond*estr+wcatprot*ecation_prot+wcatcat*ecationcation&
1220 +wbond_nucl*estr_nucl+wang_nucl*ebe_nucl&
1221 +wvdwpp_nucl*evdwpp+welpp*eespp+wvdwpsb*evdwpsb+welpsb*eelpsb&
1222 +wvdwsb*evdwsb+welsb*eelsb+wsbloc*esbloc+wtor_nucl*etors_nucl&
1223 *ft(1)+wtor_d_nucl*ft(2)*etors_d_nucl+wcorr_nucl*ecorr_nucl &
1224 +wcorr3_nucl*ecorr3_nucl&
1226 +ft(1)*wpepbase*epepbase+wscpho*escpho+wpeppho*epeppho
1228 eprim=ftprim(6)*evdw_t+ftprim(1)*welec*(ees+evdw1) &
1229 +ftprim(1)*wtor*etors+ &
1230 ftprim(3)*wcorr*ecorr+ftprim(4)*wcorr5*ecorr5+ &
1231 ftprim(5)*wcorr6*ecorr6+ftprim(3)*wturn4*eello_turn4+ &
1232 ftprim(2)*wturn3*eello_turn3+ftprim(5)*wturn6*eello_turn6+ &
1233 ftprim(2)*wel_loc*eel_loc+ftprim(2)*wtor_d*etors_d+ &
1234 ftprim(1)*wsccor*esccor+ftprim(1)*wtor_nucl*etors_nucl&
1235 +wtor_d_nucl*ftprim(2)*etors_d_nucl+ftprim(1)*wpepbase*epepbase
1236 ebis=ftbis(1)*welec*(ees+evdw1)+ftbis(1)*wtor*etors+ &
1237 ftbis(3)*wcorr*ecorr+ftbis(4)*wcorr5*ecorr5+ &
1238 ftbis(5)*wcorr6*ecorr6+ftbis(3)*wturn4*eello_turn4+ &
1239 ftbis(2)*wturn3*eello_turn3+ftbis(5)*wturn6*eello_turn6+ &
1240 ftbis(2)*wel_loc*eel_loc+ftbis(2)*wtor_d*etors_d+ &
1241 ftbis(1)*wsccor*esccor+ftbis(1)*wtor_nucl*etors_nucl&
1242 +wtor_d_nucl*ftbis(2)*etors_d_nucl*ftbis(1)*wpepbase*epepbase
1245 weight=dexp(-betaT*(etot-potEmin)+entfac(t))
1247 write (iout,*) "iparm",iparm," t",t," betaT",betaT,&
1248 " etot",etot," entfac",entfac(t),&
1249 " weight",weight," ebis",ebis
1251 etot=etot-temper*eprim
1253 sumW_p(k,iparm)=sumW_p(k,iparm)+weight
1254 sumE_p(k,iparm)=sumE_p(k,iparm)+etot*weight
1255 sumEbis_p(k,iparm)=sumEbis_p(k,iparm)+ebis*weight
1256 sumEsq_p(k,iparm)=sumEsq_p(k,iparm)+etot**2*weight
1258 sumQ_p(j,k,iparm)=sumQ_p(j,k,iparm)+q(j,t)*weight
1259 sumQsq_p(j,k,iparm)=sumQsq_p(j,k,iparm)+q(j,t)**2*weight
1260 sumEQ_p(j,k,iparm)=sumEQ_p(j,k,iparm) &
1264 sumW(k,iparm)=sumW(k,iparm)+weight
1265 sumE(k,iparm)=sumE(k,iparm)+etot*weight
1266 sumEbis(k,iparm)=sumEbis(k,iparm)+ebis*weight
1267 sumEsq(k,iparm)=sumEsq(k,iparm)+etot**2*weight
1269 sumQ(j,k,iparm)=sumQ(j,k,iparm)+q(j,t)*weight
1270 sumQsq(j,k,iparm)=sumQsq(j,k,iparm)+q(j,t)**2*weight
1271 sumEQ(j,k,iparm)=sumEQ(j,k,iparm) &
1276 indE = aint(potE(t,iparm)-aint(potEmin))
1277 if (indE.ge.0 .and. indE.le.maxinde) then
1278 if (indE.gt.upindE_p) upindE_p=indE
1279 histE_p(indE)=histE_p(indE)+dexp(-entfac(t))
1283 potEmin=potEmin_all(ib,iparm)
1284 expfac=dexp(-beta_h(ib,iparm)*(etot-potEmin)+entfac(t))
1285 hfin_p(ind,ib)=hfin_p(ind,ib)+ &
1286 dexp(-beta_h(ib,iparm)*(etot-potEmin)+entfac(t))
1288 indrgy=dint((q(nQ+2,t)-rgymin)/deltrgy)
1289 indrms=dint((q(nQ+1,t)-rmsmin)/deltrms)
1290 hrmsrgy_p(indrgy,indrms,ib)= &
1291 hrmsrgy_p(indrgy,indrms,ib)+expfac
1296 potEmin=potEmin_all(ib,iparm)
1297 expfac=dexp(-beta_h(ib,iparm)*(etot-potEmin)+entfac(t))
1298 hfin(ind,ib)=hfin(ind,ib)+ &
1299 dexp(-beta_h(ib,iparm)*(etot-potEmin)+entfac(t))
1301 indrgy=dint((q(nQ+2,t)-rgymin)/deltrgy)
1302 indrms=dint((q(nQ+1,t)-rmsmin)/deltrms)
1303 hrmsrgy(indrgy,indrms,ib)= &
1304 hrmsrgy(indrgy,indrms,ib)+expfac
1310 if (histout) call MPI_Reduce(hfin_p(0,ib),hfin(0,ib),nbin,&
1311 MPI_DOUBLE_PRECISION,MPI_SUM,Master,WHAM_COMM,IERROR)
1313 call MPI_Reduce(hrmsrgy_p(0,0,ib),hrmsrgy(0,0,ib),&
1314 (MaxBinRgy+1)*(nbin_rms+1),MPI_DOUBLE_PRECISION,MPI_SUM,Master,&
1318 call MPI_Reduce(upindE_p,upindE,1,&
1319 MPI_INTEGER,MPI_MAX,Master,WHAM_COMM,IERROR)
1320 call MPI_Reduce(histE_p(0),histE(0),maxindE,&
1321 MPI_DOUBLE_PRECISION,MPI_SUM,Master,WHAM_COMM,IERROR)
1323 if (me1.eq.master) then
1327 write (iout,'(6x,$)')
1328 write (iout,'(f20.2,$)') (1.0d0/(1.987D-3*beta_h(ib,iparm)),&
1332 write (iout,'(/a)') 'Final histograms'
1334 if (nslice.eq.1) then
1335 if (separate_parset) then
1336 write(licz3,"(bz,i3.3)") myparm
1337 histname=prefix(:ilen(prefix))//'_par'//licz3//'.hist'
1339 histname=prefix(:ilen(prefix))//'.hist'
1342 if (separate_parset) then
1343 write(licz3,"(bz,i3.3)") myparm
1344 histname=prefix(:ilen(prefix))//'_par'//licz3// &
1345 '_slice_'//licz2//'.hist'
1347 histname=prefix(:ilen(prefix))//'_slice_'//licz2//'.hist'
1350 #if defined(AIX) || defined(PGI)
1351 open (ihist,file=histname,position='append')
1353 open (ihist,file=histname,access='append')
1361 sumH=sumH+hfin(t,ib)
1363 if (sumH.gt.0.0d0) then
1365 jj = mod(liczbaW,nbin1)
1366 liczbaW=liczbaW/nbin1
1367 write (iout,'(f6.3,$)') dmin+(jj+0.5d0)*delta
1369 write (ihist,'(f6.3,$)') dmin+(jj+0.5d0)*delta
1372 write (iout,'(e20.10,$)') hfin(t,ib)
1373 if (histfile) write (ihist,'(e20.10,$)') hfin(t,ib)
1375 write (iout,'(i5)') iparm
1376 if (histfile) write (ihist,'(i5)') iparm
1383 if (nslice.eq.1) then
1384 if (separate_parset) then
1385 write(licz3,"(bz,i3.3)") myparm
1386 histname=prefix(:ilen(prefix))//"_par"//licz3//'.ent'
1388 histname=prefix(:ilen(prefix))//'.ent'
1391 if (separate_parset) then
1392 write(licz3,"(bz,i3.3)") myparm
1393 histname=prefix(:ilen(prefix))//'par_'//licz3// &
1394 '_slice_'//licz2//'.ent'
1396 histname=prefix(:ilen(prefix))//'_slice_'//licz2//'.ent'
1399 #if defined(AIX) || defined(PGI)
1400 open (ihist,file=histname,position='append')
1402 open (ihist,file=histname,access='append')
1404 write (ihist,'(a)') "# Microcanonical entropy"
1406 write (ihist,'(f8.0,$)') dint(potEmin)+i
1407 if (histE(i).gt.0.0e0) then
1408 write (ihist,'(f15.5,$)') dlog(histE(i))
1410 write (ihist,'(f15.5,$)') 0.0d0
1416 write (iout,*) "Microcanonical entropy"
1418 write (iout,'(f8.0,$)') dint(potEmin)+i
1419 if (histE(i).gt.0.0e0) then
1420 write (iout,'(f15.5,$)') dlog(histE(i))
1422 write (iout,'(f15.5,$)') 0.0d0
1427 if (nslice.eq.1) then
1428 if (separate_parset) then
1429 write(licz3,"(bz,i3.3)") myparm
1430 histname=prefix(:ilen(prefix))//'_par'//licz3//'.rmsrgy'
1432 histname=prefix(:ilen(prefix))//'.rmsrgy'
1435 if (separate_parset) then
1436 write(licz3,"(bz,i3.3)") myparm
1437 histname=prefix(:ilen(prefix))//'_par'//licz3// &
1438 '_slice_'//licz2//'.rmsrgy'
1440 histname=prefix(:ilen(prefix))//'_slice_'//licz2//'.rmsrgy'
1443 #if defined(AIX) || defined(PGI)
1444 open (ihist,file=histname,position='append')
1446 open (ihist,file=histname,access='append')
1450 write(ihist,'(2f8.2,$)') &
1451 rgymin+deltrgy*j,rmsmin+deltrms*i
1453 if (hrmsrgy(j,i,ib).gt.0.0d0) then
1454 write(ihist,'(e14.5,$)') &
1455 -dlog(hrmsrgy(j,i,ib))/beta_h(ib,iparm) &
1458 write(ihist,'(e14.5,$)') 1.0d6
1461 write (ihist,'(i2)') iparm
1469 call MPI_Reduce(hfin_ent_p(0),hfin_ent(0),nbin,&
1470 MPI_DOUBLE_PRECISION,MPI_SUM,Master,WHAM_COMM,IERROR)
1471 call MPI_Reduce(sumW_p(0,1),sumW(0,1),(nGridT+1)*nParmSet,&
1472 MPI_DOUBLE_PRECISION,MPI_SUM,Master,WHAM_COMM,IERROR)
1473 call MPI_Reduce(sumE_p(0,1),sumE(0,1),(nGridT+1)*nParmSet,&
1474 MPI_DOUBLE_PRECISION,MPI_SUM,Master,WHAM_COMM,IERROR)
1475 call MPI_Reduce(sumEbis_p(0,1),sumEbis(0,1),(nGridT+1)*nParmSet,&
1476 MPI_DOUBLE_PRECISION,MPI_SUM,Master,WHAM_COMM,IERROR)
1477 call MPI_Reduce(sumEsq_p(0,1),sumEsq(0,1),(nGridT+1)*nParmSet,&
1478 MPI_DOUBLE_PRECISION,MPI_SUM,Master,WHAM_COMM,IERROR)
1479 call MPI_Reduce(sumQ_p(1,0,1),sumQ(1,0,1),&
1480 MaxQ1*(nGridT+1)*nParmSet,MPI_DOUBLE_PRECISION,MPI_SUM,Master,&
1482 call MPI_Reduce(sumQsq_p(1,0,1),sumQsq(1,0,1),&
1483 MaxQ1*(nGridT+1)*nParmSet,MPI_DOUBLE_PRECISION,MPI_SUM,Master,&
1485 call MPI_Reduce(sumEQ_p(1,0,1),sumEQ(1,0,1),&
1486 MaxQ1*(nGridT+1)*nParmSet,MPI_DOUBLE_PRECISION,MPI_SUM,Master,&
1488 if (me.eq.master) then
1490 write (iout,'(/a)') 'Thermal characteristics of folding'
1491 if (nslice.eq.1) then
1494 nazwa=prefix(:ilen(prefix))//"_slice_"//licz2
1497 if (nparmset.eq.1 .and. .not.separate_parset) then
1498 nazwa=nazwa(:iln)//".thermal"
1499 else if (nparmset.eq.1 .and. separate_parset) then
1500 write(licz3,"(bz,i3.3)") myparm
1501 nazwa=nazwa(:iln)//"_par_"//licz3//".thermal"
1504 if (nparmset.gt.1) then
1505 write(licz3,"(bz,i3.3)") iparm
1506 nazwa=nazwa(:iln)//"_par_"//licz3//".thermal"
1509 if (separate_parset) then
1510 write (iout,'(a,i3)') "Parameter set",myparm
1512 write (iout,'(a,i3)') "Parameter set",iparm
1515 betaT=1.0d0/(1.987D-3*(startGridT+i*delta_T))
1516 if (betaT.ge.beta_h(1,iparm)) then
1517 potEmin=potEmin_all(1,iparm)
1518 else if (betaT.lt.beta_h(nT_h(iparm),iparm)) then
1519 potEmin=potEmin_all(nT_h(iparm),iparm)
1521 do l=1,nT_h(iparm)-1
1522 if (betaT.le.beta_h(l,iparm) .and. &
1523 betaT.gt.beta_h(l+1,iparm)) then
1524 potEmin=potEmin_all(l,iparm)
1530 sumE(i,iparm)=sumE(i,iparm)/sumW(i,iparm)
1531 sumEbis(i,iparm)=(startGridT+i*delta_T)*sumEbis(i,iparm)/ &
1533 sumEsq(i,iparm)=(sumEsq(i,iparm)/sumW(i,iparm) &
1534 -sumE(i,iparm)**2)/(1.987D-3*(startGridT+i*delta_T)**2)
1536 sumQ(j,i,iparm)=sumQ(j,i,iparm)/sumW(i,iparm)
1537 sumQsq(j,i,iparm)=sumQsq(j,i,iparm)/sumW(i,iparm) &
1539 sumEQ(j,i,iparm)=sumEQ(j,i,iparm)/sumW(i,iparm) &
1540 -sumQ(j,i,iparm)*sumE(i,iparm)
1542 sumW(i,iparm)=-dlog(sumW(i,iparm))*(1.987D-3* &
1543 (startGridT+i*delta_T))+potEmin
1544 write (iout,'(f7.1,2f15.5,$)') startGridT+i*delta_T,&
1545 sumW(i,iparm),sumE(i,iparm)
1546 write (iout,'(f10.5,$)') (sumQ(j,i,iparm),j=1,nQ+2)
1547 write (iout,'(e15.5,$)') sumEsq(i,iparm)-sumEbis(i,iparm),&
1548 (sumQsq(j,i,iparm),j=1,nQ+2),(sumEQ(j,i,iparm),j=1,nQ+2)
1550 write (34,'(f7.1,2f15.5,$)') startGridT+i*delta_T,&
1551 sumW(i,iparm),sumE(i,iparm)
1552 write (34,'(f10.5,$)') (sumQ(j,i,iparm),j=1,nQ+2)
1553 write (34,'(e15.5,$)') sumEsq(i,iparm)-sumEbis(i,iparm),&
1554 (sumQsq(j,i,iparm),j=1,nQ+2),(sumEQ(j,i,iparm),j=1,nQ+2)
1562 if (hfin_ent(t).gt.0.0d0) then
1564 jj = mod(liczbaW,nbin1)
1565 write (iout,'(f6.3,e20.10," ent")') dmin+(jj+0.5d0)*delta,&
1567 if (histfile) write (ihist,'(f6.3,e20.10," ent")') &
1568 dmin+(jj+0.5d0)*delta,&
1572 if (histfile) close(ihist)
1576 ! Write data for zscore
1577 if (nslice.eq.1) then
1578 zscname=prefix(:ilen(prefix))//".zsc"
1580 zscname=prefix(:ilen(prefix))//"_slice_"//licz2//".zsc"
1582 #if defined(AIX) || defined(PGI)
1583 open (izsc,file=prefix(:ilen(prefix))//'.zsc',position='append')
1585 open (izsc,file=prefix(:ilen(prefix))//'.zsc',access='append')
1587 write (izsc,'("NQ=",i1," NPARM=",i1)') nQ,nParmSet
1589 write (izsc,'("NT=",i1)') nT_h(iparm)
1591 write (izsc,'("TEMP=",f6.1," NR=",i2," SNK=",$)') &
1592 1.0d0/(beta_h(ib,iparm)*1.987D-3),nR(ib,iparm)
1593 jj = min0(nR(ib,iparm),7)
1594 write (izsc,'(i8,$)') (snk(i,ib,iparm,islice),i=1,jj)
1595 write (izsc,'(a1,$)') (" ",i=22+8*jj+1,79)
1596 write (izsc,'("&")')
1597 if (nR(ib,iparm).gt.7) then
1598 do ii=8,nR(ib,iparm),9
1599 jj = min0(nR(ib,iparm),ii+8)
1600 write (izsc,'(i8,$)') (snk(i,ib,iparm,islice),i=ii,jj)
1601 write (izsc,'(a1,$') (" ",i=(jj-ii+1)*8+1,79)
1602 write (izsc,'("&")')
1605 write (izsc,'("FI=",$)')
1606 jj=min0(nR(ib,iparm),7)
1607 write (izsc,'(f10.5,$)') (fi(i,ib,iparm),i=1,jj)
1608 write (izsc,'(a1,$)') (" ",i=3+10*jj+1,79)
1609 write (izsc,'("&")')
1610 if (nR(ib,iparm).gt.7) then
1611 do ii=8,nR(ib,iparm),9
1612 jj = min0(nR(ib,iparm),ii+8)
1613 write (izsc,'(f10.5,$)') (fi(i,ib,iparm),i=ii,jj)
1614 if (jj.eq.nR(ib,iparm)) then
1617 write (izsc,'(a1,$)') (" ",i=10*(jj-ii+1)+1,79)
1618 write (izsc,'(t80,"&")')
1623 write (izsc,'("KH=",$)')
1624 write (izsc,'(f7.2,$)') (Kh(j,i,ib,iparm),j=1,nQ)
1625 write (izsc,'(" Q0=",$)')
1626 write (izsc,'(f7.5,$)') (q0(j,i,ib,iparm),j=1,nQ)
1637 end subroutine WHAMCALC
1638 !-----------------------------------------------------------------------------
1639 end module wham_calc