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 !EL /04/2017 No longer needed, dynamic allocation of arrays
83 ! if (nprocs.gt.MaxProcs+1) then
84 ! write (2,*) "Error - too many processors",&
86 ! write (2,*) "Increase MaxProcs and recompile"
87 ! call MPI_Finalize(IERROR)
91 !elwrite(iout,*) "before parmread"
92 allocate(printang(max_cut))
93 allocate(printpdb(max_cut))
94 allocate(printmol2(max_cut))
96 !elwrite(iout,*) "before parmread"
98 !elwrite(iout,*) "before parmread"
101 !elwrite(iout,*) "after read control"
103 ! if (refstr) call read_ref_structure(*30)
110 ! write (iout,*) "Before permut"
111 ! write (iout,*) "symetr", symetr
114 ! write (iout,*) "after permut"
116 print *,'MAIN: nnt=',nnt,' nct=',nct
122 IF (RCUTOFF(I).LT.0.0) THEN
123 RCUTOFF(I)=ABS(RCUTOFF(I))
129 write (iout,*) 'Number of cutoffs:',NCUT
130 write (iout,*) 'Cutoff values:'
132 WRITE(IOUT,'(8HRCUTOFF(,I2,2H)=,F8.1,2i2)')ICUT,RCUTOFF(ICUT),&
133 printpdb(icut),printmol2(icut)
138 allocate(list_conf(maxconf))
142 call read_coords(ncon,*20)
144 allocate(list_conf_(maxconf))
146 list_conf_(i)=list_conf(i)
148 deallocate(list_conf)
149 allocate(list_conf(ncon))
151 list_conf(i)=list_conf_(i)
153 deallocate(list_conf_)
155 !el call alloc_clust_arrays(ncon)
157 write (iout,*) 'from read_coords: ncon',ncon
159 write (iout,*) "nT",nT
161 write (iout,*) "iT",iT
163 call work_partition(.true.,ncon)
165 !elwrite(iout,*)"after work partition, ncon_work=", ncon_work,ncon
167 call probabl(iT,ncon_work,ncon,*20)
169 !elwrite(iout,*)"after probabl, ncon_work=", ncon_work,ncon
171 if (ncon_work.lt.2) then
172 write (iout,*) "Too few conformations; clustering skipped"
176 ndis=ncon_work*(ncon_work-1)/2
177 call work_partition(.true.,ndis)
179 !el call alloc_clust_arrays(ncon_work)
180 allocate(ICC(ncon_work))
181 allocate(DISS(maxdist))
186 WRITE (iout,'(A80)') TITEL
189 ! CALCULATE DISTANCES
191 call daread_ccoords(1,ncon_work)
194 if (mod(i,100).eq.0) print *,'Calculating RMS i=',i
197 c(l,k)=allcart(l,k,i)
207 IND=IOFFSET(NCON_work,I,J)
209 if (ind.ge.indstart(me) .and. ind.le.indend(me)) then
212 DISS(IND1)=DIFCONF(I,J)
213 ! write (iout,'(2i4,i10,f10.5)') i,j,ind,DISS(IND)
220 WRITE (iout,'(/a,1pe14.5,a/)') &
221 'Time for distance calculation:',T2-T1,' sec.'
223 PRINT '(a)','End of distance computation'
225 allocate(diss_(maxdist))
226 allocate(scount_(0:nprocs))
236 call MPI_Gatherv(diss_(1),scount_(me),MPI_REAL,diss(1),&
237 scount(0),idispl(0),MPI_REAL,Master,MPI_COMM_WORLD, IERROR)
238 if (me.eq.master) then
243 open(80,file='/tmp/distance',form='unformatted')
250 IND=IOFFSET(NCON,I,J)
251 write (jrms,'(2i5,2f10.5)') i,j,diss(IND),&
257 ! Print out the RMS deviation matrix.
259 if (print_dist) CALL DISTOUT(NCON_work)
261 ! call hierarchical clustering HC from F. Murtagh
265 write(iout,*) "-------------------------------------------"
266 write(iout,*) "HIERARCHICAL CLUSTERING using"
268 write(iout,*) "WARD'S MINIMUM VARIANCE METHOD"
269 elseif (iopt.eq.2) then
270 write(iout,*) "SINGLE LINK METHOD"
271 elseif (iopt.eq.3) then
272 write(iout,*) "COMPLETE LINK METHOD"
273 elseif (iopt.eq.4) then
274 write(iout,*) "AVERAGE LINK (OR GROUP AVERAGE) METHOD"
275 elseif (iopt.eq.5) then
276 write(iout,*) "MCQUITTY'S METHOD"
277 elseif (iopt.eq.6) then
278 write(iout,*) "MEDIAN (GOWER'S) METHOD"
279 elseif (iopt.eq.7) then
280 write(iout,*) "CENTROID METHOD"
282 write(iout,*) "IOPT=",iopt," IS INVALID, use 1-7"
283 write(*,*) "IOPT=",iopt," IS INVALID, use 1-7"
287 write(iout,*) "hc.f by F. Murtagh, ESA/ESO/STECF, Garching"
288 write(iout,*) "February 1986"
289 write(iout,*) "References:"
290 write(iout,*) "1. Multidimensional clustering algorithms"
291 write(iout,*) " Fionn Murtagh"
292 write(iout,*) " Vienna : Physica-Verlag, 1985."
293 write(iout,*) "2. Multivariate data analysis"
294 write(iout,*) " Fionn Murtagh and Andre Heck"
295 write(iout,*) " Kluwer Academic Publishers, 1987"
296 write(iout,*) "-------------------------------------------"
300 write (iout,*) "The TOTFREE array"
302 write (iout,'(2i5,f10.5)') i,list_conf(i),totfree(i)
305 allocate(CRIT(N),MEMBR(N)) !(maxconf)
306 allocate(CRITVAL(N-1)) !(maxconf-1)
307 allocate(IA(N),IB(N))
308 allocate(ICLASS(N,N-1)) !(maxconf,maxconf-1)
309 allocate(HVALS(N-1)) !(maxconf-1)
310 allocate(IORDER(N-1),HEIGHT(N-1)) !(maxconf-1)
311 allocate(nn(N)) !(maxconf)
312 allocate(DISNN(N)) !(maxconf)
313 allocate(FLAG(N)) !(maxconf)
316 CALL HC(N,M,LEN,IOPT,IA,IB,CRIT,MEMBR,NN,DISNN,FLAG,DISS)
318 write (iout,*) "n",n," ncon_work",ncon_work," lev",lev
320 write (iout,*) "Too few conformations to cluster."
323 CALL HCASS(N,IA,IB,CRIT,LEV,ICLASS,HVALS,IORDER,CRITVAL,HEIGHT)
324 ! CALL HCDEN(LEV,IORDER,HEIGHT,CRITVAL)
326 allocate(licz(maxgr))
327 allocate(iass(maxgr))
328 allocate(nconf(maxgr,maxingr))
329 allocate(totfree_gr(maxgr))
338 licz(iclass(j,i))=licz(iclass(j,i))+1
339 nconf(iclass(j,i),licz(iclass(j,i)))=j
340 ! write (iout,*) i,j,iclass(j,i),licz(iclass(j,i)),
341 ! & nconf(iclass(j,i),licz(iclass(j,i)))
347 IF (HEIGHT(L).EQ.IDUM) GOTO 190
350 write(IOUT,*) "i+1",i+1," idum",idum," critval",CRITVAL(IDUM),&
351 " icut",icut," cutoff",rcutoff(icut)
352 IF (CRITVAL(IDUM).LT. RCUTOFF(ICUT)) THEN
353 WRITE (iout,'(/a,f10.5)') 'AT CUTOFF:',rcutoff(icut)
354 write (iout,'(a,f8.2)') 'Maximum distance found:',&
356 CALL SRTCLUST(ICUT,ncon_work,iT)
358 CALL WRTCLUST(ncon_work,ICUT,PRINTANG,PRINTPDB,PRINTMOL2,iT)
360 if (icut.gt.ncut) goto 191
369 licz(iclass(j,i))=licz(iclass(j,i))+1
370 nconf(iclass(j,i),licz(iclass(j,i)))=j
371 !d write (iout,*) i,j,iclass(j,i),licz(iclass(j,i)),&
372 !d nconf(iclass(j,i),licz(iclass(j,i)))
373 !d print *,j,iclass(j,i),
374 !d & licz(iclass(j,i)),nconf(iclass(j,i),licz(iclass(j,i)))
385 WRITE (iout,'(/a,1pe14.5,a/)') &
386 'Total time for clustering:',T2-T1,' sec.'
393 close(icbase,status="delete")
395 !el call MPI_Finalize(MPI_COMM_WORLD,IERROR)
396 call MPI_Finalize(IERROR)
398 stop '********** Program terminated normally.'
399 20 write (iout,*) "Error reading coordinates"
401 !el call MPI_Finalize(MPI_COMM_WORLD,IERROR)
402 call MPI_Finalize(IERROR)
405 30 write (iout,*) "Error reading reference structure"
407 !el call MPI_Finalize(MPI_COMM_WORLD,IERROR)
408 call MPI_Finalize(IERROR)
412 !---------------------------------------------------------------------------
414 !---------------------------------------------------------------------------
415 real(kind=8) function difconf(icon,jcon)
419 use io_units, only: iout
420 use io_base, only: permut
421 use geometry_data, only: nres,c,cref,tabperm
422 use energy_data, only: nct,nnt
423 use control_data, only: symetr,lside,nend,nstart
424 use regularize_, only: fitsq
426 ! include 'DIMENSIONS'
427 ! include 'sizesclu.dat'
428 ! include 'COMMON.CONTROL'
429 ! include 'COMMON.CLUSTER'
430 ! include 'COMMON.CHAIN'
431 ! include 'COMMON.INTERACT'
432 ! include 'COMMON.VAR'
433 ! include 'COMMON.IOUNITS'
435 real(kind=8) :: przes(3),obrot(3,3)
436 real(kind=8) :: xx(3,2*nres),yy(3,2*nres) !(3,maxres2)
437 integer :: i,ii,j,icon,jcon,kkk,nperm,chalen,zzz
438 integer :: iaperm,ibezperm,run
439 real(kind=8) :: rms,rmsmina
440 ! write (iout,*) "tu dochodze"
446 ! write (iout,*) "nperm",nperm
448 ! write (iout,*) "tabperm", tabperm(1,1)
452 chalen=int((nend-nstart+2)/symetr)
454 do i=nstart,(nstart+chalen-1)
456 ! write (iout,*) "tutaj",zzz
458 iaperm=(zzz-1)*chalen+i
459 ibezperm=(run-1)*chalen+i
461 xx(j,ii)=allcart(j,iaperm,jcon)
462 yy(j,ii)=cref(j,ibezperm,kkk)
467 do i=nstart,(nstart+chalen-1)
470 iaperm=(zzz-1)*chalen+i
471 ibezperm=(run-1)*chalen+i
472 ! if (itype(i).ne.10) then
475 xx(j,ii)=allcart(j,iaperm+nres,jcon)
476 yy(j,ii)=cref(j,ibezperm+nres,kkk)
481 call fitsq(rms,xx(1,1),yy(1,1),ii,przes,obrot,non_conv)
483 chalen=int((nct-nnt+2)/symetr)
485 do i=nnt,(nnt+chalen-1)
487 ! write (iout,*) "tu szukaj", zzz,run,kkk
488 iaperm=(zzz-1)*chalen+i
489 ibezperm=(run-1)*chalen+i
492 c(j,i)=allcart(j,iaperm,jcon)
496 call fitsq(rms,c(1,nstart),cref(1,nstart,kkk),nend-nstart+1,&
501 print *,'error, rms^2 = ',rms,icon,jcon
504 if (non_conv) print *,non_conv,icon,jcon
505 if (rmsmina.gt.rms) rmsmina=rms
507 difconf=dsqrt(rmsmina)
510 !------------------------------------------------------------------------------
511 subroutine distout(ncon)
514 use hc_, only:ioffset
515 use io_units, only: iout
517 ! include 'DIMENSIONS'
518 ! include 'sizesclu.dat'
520 integer,parameter :: ncol=10
521 ! include 'COMMON.IOUNITS'
522 ! include 'COMMON.CLUSTER'
523 integer :: i,j,k,jlim,jlim1,nlim,ind
524 real(kind=4) :: b(ncol)
526 write (iout,'(a)') 'The distance matrix'
528 nlim=min0(i+ncol-1,ncon)
529 write (iout,1000) (k,k=i,nlim)
530 write (iout,'(8h--------,10a)') ('-------',k=i,nlim)
531 1000 format (/8x,10(i4,3x))
532 1020 format (/1x,80(1h-)/)
543 IND=IOFFSET(NCON,j,k)
545 IND=IOFFSET(NCON,k,j)
548 write (iout,1010) j,(b(k),k=1,jlim-i+1)
551 1010 format (i5,3x,10(f6.2,1x))
553 end subroutine distout
554 !------------------------------------------------------------------------------
556 !------------------------------------------------------------------------------
557 SUBROUTINE SRTCLUST(ICUT,NCON,IB)
560 use io_units, only: iout
561 ! implicit real*8 (a-h,o-z)
562 ! include 'DIMENSIONS'
563 ! include 'sizesclu.dat'
564 ! include 'COMMON.CLUSTER'
565 ! include 'COMMON.FREE'
566 ! include 'COMMON.IOUNITS'
568 real(kind=8),dimension(:),allocatable :: prob !(maxgr)
569 real(kind=8) :: emin,ene,en1,sumprob
570 integer :: igr,i,ii,li1,li2,ligr,ico,jco,ind1,ind2
571 integer :: jgr,li,nco,ib,ncon,icut
573 ! Compute free energies of clusters
575 allocate(prob(maxgr))
578 emin=totfree(nconf(igr,1))
579 totfree_gr(igr)=1.0d0
582 totfree_gr(igr)=totfree_gr(igr)+dexp(-totfree(ii)+emin)
584 ! write (iout,*) "igr",igr," totfree",emin,
585 ! & " totfree_gr",totfree_gr(igr)
586 totfree_gr(igr)=emin-dlog(totfree_gr(igr))
587 ! write (iout,*) igr," efree",totfree_gr(igr)/beta_h(ib)
590 ! SORT CONFORMATIONS IN GROUPS ACC. TO ENERGY
622 NCONF(IGR,I)=NCONF(JGR,I)
633 write (iout,'("Free energies and probabilities of clusters at",f6.1," K")')&
634 1.0d0/(1.987d-3*beta_h(ib)) !'
638 prob(i)=dexp(-(totfree_gr(i)-totfree_gr(1)))
639 sumprob=sumprob+prob(i)
642 prob(i)=prob(i)/sumprob
645 write (iout,'("clust efree prob sumprob")')
647 sumprob=sumprob+prob(i)
648 write (iout,'(i5,f8.1,2f8.5)') i,totfree_gr(i)/beta_h(ib),&
654 82 IASS(NCONF(IGR,I))=IGR
658 iass_tot(i,icut)=iass(i)
659 ! write (iout,*) icut,i,iass(i),iass_tot(i,icut)
663 END SUBROUTINE SRTCLUST
664 !------------------------------------------------------------------------------
665 !------------------------------------------------------------------------------