3 ! Program to cluster united-residue MCM results.
12 use io_base, only: permut
13 use geometry_data, only: nres,theta,phi,alph,omeg,&
15 use energy_data, only: nnt,nct
16 use control_data, only: symetr,outpdb,outmol2,titel,&
17 iopt,print_dist,MaxProcs
18 use control, only: tcpu,initialize
20 use wham_data, only: punch_dist
21 use io_wham, only: parmread
23 ! include 'DIMENSIONS'
24 ! include 'sizesclu.dat'
29 integer :: IERROR,ERRCODE !STATUS(MPI_STATUS_SIZE)
32 ! include "COMMON.MPI"
34 ! include 'COMMON.TIME1'
35 ! include 'COMMON.INTERACT'
36 ! include 'COMMON.NAMES'
37 ! include 'COMMON.GEO'
38 ! include 'COMMON.HEADER'
39 ! include 'COMMON.CONTROL'
40 ! include 'COMMON.CHAIN'
41 ! include 'COMMON.VAR'
42 ! include 'COMMON.CLUSTER'
43 ! include 'COMMON.IOUNITS'
44 ! include 'COMMON.FREE'
46 logical,dimension(:),allocatable :: printang !(max_cut)
47 integer,dimension(:),allocatable :: printpdb !(max_cut)
48 integer,dimension(:),allocatable :: printmol2 !(max_cut)
49 character(len=240) lineh
50 REAL(kind=4),dimension(:),allocatable :: CRIT,MEMBR !(maxconf)
51 REAL(kind=4),dimension(:),allocatable :: CRITVAL !(maxconf-1)
52 INTEGER,dimension(:),allocatable :: IA,IB !(maxconf)
53 INTEGER,dimension(:,:),allocatable :: ICLASS !(maxconf,maxconf-1)
54 INTEGER,dimension(:),allocatable :: HVALS !(maxconf-1)
55 INTEGER,dimension(:),allocatable :: IORDER,HEIGHT !(maxconf-1)
56 integer,dimension(:),allocatable :: nn !(maxconf)
58 real(kind=4),dimension(:),allocatable :: DISNN !(maxconf)
59 LOGICAL,dimension(:),allocatable :: FLAG !(maxconf)
60 integer :: i,j,k,l,m,n,len,lev,idum,ii,ind,jj,icut,ncon,&
62 real(kind=8) :: t1,t2,difconf
64 real(kind=8),dimension(:),allocatable :: varia !(maxvar)
65 real(kind=8),dimension(:),allocatable :: list_conf_ !(maxvar)
66 real(kind=8) :: hrtime,mintime,sectime
70 real(kind=4),dimension(:),allocatable :: diss_ !(maxdist)
71 integer,dimension(:),allocatable :: scount_ !(maxdist)
73 call MPI_Init( IERROR )
74 call MPI_Comm_rank( MPI_COMM_WORLD, me, IERROR )
75 call MPI_Comm_size( MPI_COMM_WORLD, nprocs, IERROR )
78 write(iout,*) "SEVERE ERROR - Can't initialize MPI."
79 call mpi_finalize(ierror)
82 if (nprocs.gt.MaxProcs+1) then
83 write (2,*) "Error - too many processors",&
85 write (2,*) "Increase MaxProcs and recompile"
86 call MPI_Finalize(IERROR)
90 !elwrite(iout,*) "before parmread"
91 allocate(printang(max_cut))
92 allocate(printpdb(max_cut))
93 allocate(printmol2(max_cut))
95 !elwrite(iout,*) "before parmread"
97 !elwrite(iout,*) "before parmread"
100 !elwrite(iout,*) "after read control"
102 ! if (refstr) call read_ref_structure(*30)
109 ! write (iout,*) "Before permut"
110 ! write (iout,*) "symetr", symetr
113 ! write (iout,*) "after permut"
115 print *,'MAIN: nnt=',nnt,' nct=',nct
121 IF (RCUTOFF(I).LT.0.0) THEN
122 RCUTOFF(I)=ABS(RCUTOFF(I))
128 write (iout,*) 'Number of cutoffs:',NCUT
129 write (iout,*) 'Cutoff values:'
131 WRITE(IOUT,'(8HRCUTOFF(,I2,2H)=,F8.1,2i2)')ICUT,RCUTOFF(ICUT),&
132 printpdb(icut),printmol2(icut)
137 allocate(list_conf(maxconf))
141 call read_coords(ncon,*20)
143 allocate(list_conf_(maxconf))
145 list_conf_(i)=list_conf(i)
147 deallocate(list_conf)
148 allocate(list_conf(ncon))
150 list_conf(i)=list_conf_(i)
152 deallocate(list_conf_)
154 !el call alloc_clust_arrays(ncon)
156 write (iout,*) 'from read_coords: ncon',ncon
158 write (iout,*) "nT",nT
160 write (iout,*) "iT",iT
162 call work_partition(.true.,ncon)
164 !elwrite(iout,*)"after work partition, ncon_work=", ncon_work,ncon
166 call probabl(iT,ncon_work,ncon,*20)
168 !elwrite(iout,*)"after probabl, ncon_work=", ncon_work,ncon
170 if (ncon_work.lt.2) then
171 write (iout,*) "Too few conformations; clustering skipped"
175 ndis=ncon_work*(ncon_work-1)/2
176 call work_partition(.true.,ndis)
178 !el call alloc_clust_arrays(ncon_work)
179 allocate(ICC(ncon_work))
180 allocate(DISS(maxdist))
185 WRITE (iout,'(A80)') TITEL
188 ! CALCULATE DISTANCES
190 call daread_ccoords(1,ncon_work)
193 if (mod(i,100).eq.0) print *,'Calculating RMS i=',i
196 c(l,k)=allcart(l,k,i)
206 IND=IOFFSET(NCON_work,I,J)
208 if (ind.ge.indstart(me) .and. ind.le.indend(me)) then
211 DISS(IND1)=DIFCONF(I,J)
212 ! write (iout,'(2i4,i10,f10.5)') i,j,ind,DISS(IND)
219 WRITE (iout,'(/a,1pe14.5,a/)') &
220 'Time for distance calculation:',T2-T1,' sec.'
222 PRINT '(a)','End of distance computation'
224 allocate(diss_(maxdist))
225 allocate(scount_(0:nprocs))
235 call MPI_Gatherv(diss_(1),scount_(me),MPI_REAL,diss(1),&
236 scount(0),idispl(0),MPI_REAL,Master,MPI_COMM_WORLD, IERROR)
237 if (me.eq.master) then
242 open(80,file='/tmp/distance',form='unformatted')
249 IND=IOFFSET(NCON,I,J)
250 write (jrms,'(2i5,2f10.5)') i,j,diss(IND),&
256 ! Print out the RMS deviation matrix.
258 if (print_dist) CALL DISTOUT(NCON_work)
260 ! call hierarchical clustering HC from F. Murtagh
264 write(iout,*) "-------------------------------------------"
265 write(iout,*) "HIERARCHICAL CLUSTERING using"
267 write(iout,*) "WARD'S MINIMUM VARIANCE METHOD"
268 elseif (iopt.eq.2) then
269 write(iout,*) "SINGLE LINK METHOD"
270 elseif (iopt.eq.3) then
271 write(iout,*) "COMPLETE LINK METHOD"
272 elseif (iopt.eq.4) then
273 write(iout,*) "AVERAGE LINK (OR GROUP AVERAGE) METHOD"
274 elseif (iopt.eq.5) then
275 write(iout,*) "MCQUITTY'S METHOD"
276 elseif (iopt.eq.6) then
277 write(iout,*) "MEDIAN (GOWER'S) METHOD"
278 elseif (iopt.eq.7) then
279 write(iout,*) "CENTROID METHOD"
281 write(iout,*) "IOPT=",iopt," IS INVALID, use 1-7"
282 write(*,*) "IOPT=",iopt," IS INVALID, use 1-7"
286 write(iout,*) "hc.f by F. Murtagh, ESA/ESO/STECF, Garching"
287 write(iout,*) "February 1986"
288 write(iout,*) "References:"
289 write(iout,*) "1. Multidimensional clustering algorithms"
290 write(iout,*) " Fionn Murtagh"
291 write(iout,*) " Vienna : Physica-Verlag, 1985."
292 write(iout,*) "2. Multivariate data analysis"
293 write(iout,*) " Fionn Murtagh and Andre Heck"
294 write(iout,*) " Kluwer Academic Publishers, 1987"
295 write(iout,*) "-------------------------------------------"
299 write (iout,*) "The TOTFREE array"
301 write (iout,'(2i5,f10.5)') i,list_conf(i),totfree(i)
304 allocate(CRIT(N),MEMBR(N)) !(maxconf)
305 allocate(CRITVAL(N-1)) !(maxconf-1)
306 allocate(IA(N),IB(N))
307 allocate(ICLASS(N,N-1)) !(maxconf,maxconf-1)
308 allocate(HVALS(N-1)) !(maxconf-1)
309 allocate(IORDER(N-1),HEIGHT(N-1)) !(maxconf-1)
310 allocate(nn(N)) !(maxconf)
311 allocate(DISNN(N)) !(maxconf)
312 allocate(FLAG(N)) !(maxconf)
315 CALL HC(N,M,LEN,IOPT,IA,IB,CRIT,MEMBR,NN,DISNN,FLAG,DISS)
317 write (iout,*) "n",n," ncon_work",ncon_work," lev",lev
319 write (iout,*) "Too few conformations to cluster."
322 CALL HCASS(N,IA,IB,CRIT,LEV,ICLASS,HVALS,IORDER,CRITVAL,HEIGHT)
323 ! CALL HCDEN(LEV,IORDER,HEIGHT,CRITVAL)
325 allocate(licz(maxgr))
326 allocate(iass(maxgr))
327 allocate(nconf(maxgr,maxingr))
328 allocate(totfree_gr(maxgr))
337 licz(iclass(j,i))=licz(iclass(j,i))+1
338 nconf(iclass(j,i),licz(iclass(j,i)))=j
339 ! write (iout,*) i,j,iclass(j,i),licz(iclass(j,i)),
340 ! & nconf(iclass(j,i),licz(iclass(j,i)))
346 IF (HEIGHT(L).EQ.IDUM) GOTO 190
349 write(IOUT,*) "i+1",i+1," idum",idum," critval",CRITVAL(IDUM),&
350 " icut",icut," cutoff",rcutoff(icut)
351 IF (CRITVAL(IDUM).LT. RCUTOFF(ICUT)) THEN
352 WRITE (iout,'(/a,f10.5)') 'AT CUTOFF:',rcutoff(icut)
353 write (iout,'(a,f8.2)') 'Maximum distance found:',&
355 CALL SRTCLUST(ICUT,ncon_work,iT)
357 CALL WRTCLUST(ncon_work,ICUT,PRINTANG,PRINTPDB,PRINTMOL2,iT)
359 if (icut.gt.ncut) goto 191
368 licz(iclass(j,i))=licz(iclass(j,i))+1
369 nconf(iclass(j,i),licz(iclass(j,i)))=j
370 !d write (iout,*) i,j,iclass(j,i),licz(iclass(j,i)),&
371 !d nconf(iclass(j,i),licz(iclass(j,i)))
372 !d print *,j,iclass(j,i),
373 !d & licz(iclass(j,i)),nconf(iclass(j,i),licz(iclass(j,i)))
384 WRITE (iout,'(/a,1pe14.5,a/)') &
385 'Total time for clustering:',T2-T1,' sec.'
392 close(icbase,status="delete")
394 !el call MPI_Finalize(MPI_COMM_WORLD,IERROR)
395 call MPI_Finalize(IERROR)
397 stop '********** Program terminated normally.'
398 20 write (iout,*) "Error reading coordinates"
400 !el call MPI_Finalize(MPI_COMM_WORLD,IERROR)
401 call MPI_Finalize(IERROR)
404 30 write (iout,*) "Error reading reference structure"
406 !el call MPI_Finalize(MPI_COMM_WORLD,IERROR)
407 call MPI_Finalize(IERROR)
411 !---------------------------------------------------------------------------
413 !---------------------------------------------------------------------------
414 real(kind=8) function difconf(icon,jcon)
418 use io_units, only: iout
419 use io_base, only: permut
420 use geometry_data, only: nres,c,cref,tabperm
421 use energy_data, only: nct,nnt
422 use control_data, only: symetr,lside,nend,nstart
423 use regularize_, only: fitsq
425 ! include 'DIMENSIONS'
426 ! include 'sizesclu.dat'
427 ! include 'COMMON.CONTROL'
428 ! include 'COMMON.CLUSTER'
429 ! include 'COMMON.CHAIN'
430 ! include 'COMMON.INTERACT'
431 ! include 'COMMON.VAR'
432 ! include 'COMMON.IOUNITS'
434 real(kind=8) :: przes(3),obrot(3,3)
435 real(kind=8) :: xx(3,2*nres),yy(3,2*nres) !(3,maxres2)
436 integer :: i,ii,j,icon,jcon,kkk,nperm,chalen,zzz
437 integer :: iaperm,ibezperm,run
438 real(kind=8) :: rms,rmsmina
439 ! write (iout,*) "tu dochodze"
445 ! write (iout,*) "nperm",nperm
447 ! write (iout,*) "tabperm", tabperm(1,1)
451 chalen=int((nend-nstart+2)/symetr)
453 do i=nstart,(nstart+chalen-1)
455 ! write (iout,*) "tutaj",zzz
457 iaperm=(zzz-1)*chalen+i
458 ibezperm=(run-1)*chalen+i
460 xx(j,ii)=allcart(j,iaperm,jcon)
461 yy(j,ii)=cref(j,ibezperm,kkk)
466 do i=nstart,(nstart+chalen-1)
469 iaperm=(zzz-1)*chalen+i
470 ibezperm=(run-1)*chalen+i
471 ! if (itype(i).ne.10) then
474 xx(j,ii)=allcart(j,iaperm+nres,jcon)
475 yy(j,ii)=cref(j,ibezperm+nres,kkk)
480 call fitsq(rms,xx(1,1),yy(1,1),ii,przes,obrot,non_conv)
482 chalen=int((nct-nnt+2)/symetr)
484 do i=nnt,(nnt+chalen-1)
486 ! write (iout,*) "tu szukaj", zzz,run,kkk
487 iaperm=(zzz-1)*chalen+i
488 ibezperm=(run-1)*chalen+i
491 c(j,i)=allcart(j,iaperm,jcon)
495 call fitsq(rms,c(1,nstart),cref(1,nstart,kkk),nend-nstart+1,&
500 print *,'error, rms^2 = ',rms,icon,jcon
503 if (non_conv) print *,non_conv,icon,jcon
504 if (rmsmina.gt.rms) rmsmina=rms
506 difconf=dsqrt(rmsmina)
509 !------------------------------------------------------------------------------
510 subroutine distout(ncon)
513 use hc_, only:ioffset
514 use io_units, only: iout
516 ! include 'DIMENSIONS'
517 ! include 'sizesclu.dat'
519 integer,parameter :: ncol=10
520 ! include 'COMMON.IOUNITS'
521 ! include 'COMMON.CLUSTER'
522 integer :: i,j,k,jlim,jlim1,nlim,ind
523 real(kind=4) :: b(ncol)
525 write (iout,'(a)') 'The distance matrix'
527 nlim=min0(i+ncol-1,ncon)
528 write (iout,1000) (k,k=i,nlim)
529 write (iout,'(8h--------,10a)') ('-------',k=i,nlim)
530 1000 format (/8x,10(i4,3x))
531 1020 format (/1x,80(1h-)/)
542 IND=IOFFSET(NCON,j,k)
544 IND=IOFFSET(NCON,k,j)
547 write (iout,1010) j,(b(k),k=1,jlim-i+1)
550 1010 format (i5,3x,10(f6.2,1x))
552 end subroutine distout
553 !------------------------------------------------------------------------------
555 !------------------------------------------------------------------------------
556 SUBROUTINE SRTCLUST(ICUT,NCON,IB)
559 use io_units, only: iout
560 ! implicit real*8 (a-h,o-z)
561 ! include 'DIMENSIONS'
562 ! include 'sizesclu.dat'
563 ! include 'COMMON.CLUSTER'
564 ! include 'COMMON.FREE'
565 ! include 'COMMON.IOUNITS'
567 real(kind=8),dimension(:),allocatable :: prob !(maxgr)
568 real(kind=8) :: emin,ene,en1,sumprob
569 integer :: igr,i,ii,li1,li2,ligr,ico,jco,ind1,ind2
570 integer :: jgr,li,nco,ib,ncon,icut
572 ! Compute free energies of clusters
574 allocate(prob(maxgr))
577 emin=totfree(nconf(igr,1))
578 totfree_gr(igr)=1.0d0
581 totfree_gr(igr)=totfree_gr(igr)+dexp(-totfree(ii)+emin)
583 ! write (iout,*) "igr",igr," totfree",emin,
584 ! & " totfree_gr",totfree_gr(igr)
585 totfree_gr(igr)=emin-dlog(totfree_gr(igr))
586 ! write (iout,*) igr," efree",totfree_gr(igr)/beta_h(ib)
589 ! SORT CONFORMATIONS IN GROUPS ACC. TO ENERGY
621 NCONF(IGR,I)=NCONF(JGR,I)
632 write (iout,'("Free energies and probabilities of clusters at",f6.1," K")')&
633 1.0d0/(1.987d-3*beta_h(ib)) !'
637 prob(i)=dexp(-(totfree_gr(i)-totfree_gr(1)))
638 sumprob=sumprob+prob(i)
641 prob(i)=prob(i)/sumprob
644 write (iout,'("clust efree prob sumprob")')
646 sumprob=sumprob+prob(i)
647 write (iout,'(i5,f8.1,2f8.5)') i,totfree_gr(i)/beta_h(ib),&
653 82 IASS(NCONF(IGR,I))=IGR
657 iass_tot(i,icut)=iass(i)
658 ! write (iout,*) icut,i,iass(i),iass_tot(i,icut)
662 END SUBROUTINE SRTCLUST
663 !------------------------------------------------------------------------------
664 !------------------------------------------------------------------------------