2 C Program to cluster united-residue MCM results.
9 integer IERROR,ERRCODE,STATUS(MPI_STATUS_SIZE)
12 include 'COMMON.TIME1'
13 include 'COMMON.INTERACT'
14 include 'COMMON.NAMES'
16 include 'COMMON.HEADER'
17 include 'COMMON.CONTROL'
18 include 'COMMON.CHAIN'
20 include 'COMMON.CLUSTER'
21 include 'COMMON.IOUNITS'
23 logical printang(max_cut)
24 integer printpdb(max_cut)
25 integer printmol2(max_cut)
26 character*240 lineh,scrachdir2d
27 REAL CRIT(maxconf),MEMBR(maxconf)
28 REAL CRITVAL(maxconf-1)
29 INTEGER IA(maxconf),IB(maxconf)
30 INTEGER ICLASS(maxconf,maxconf-1),HVALS(maxconf-1)
31 INTEGER IORDER(maxconf-1),HEIGHT(maxconf-1)
32 integer nn,ndis,scount_buf
33 real*4 DISNN, diss_buf(maxdist)
34 DIMENSION NN(maxconf),DISNN(maxconf)
36 integer i,j,k,l,m,n,len,lev,idum,ii,ind,ioffset,jj,icut,ncon,
37 & it,ncon_work,ind1,kkk, ijk,is,ie,ilen
38 double precision t1,t2,tcpu,difconf
40 double precision varia(maxvar)
41 double precision hrtime,mintime,sectime
45 call MPI_Init( IERROR )
46 call MPI_Comm_rank( MPI_COMM_WORLD, me, IERROR )
47 call MPI_Comm_size( MPI_COMM_WORLD, nprocs, IERROR )
50 write(iout,*) "SEVERE ERROR - Can't initialize MPI."
51 call mpi_finalize(ierror)
54 if (nprocs.gt.MaxProcs+1) then
55 write (2,*) "Error - too many processors",
57 write (2,*) "Increase MaxProcs and recompile"
58 call MPI_Finalize(IERROR)
69 c if (refstr) call read_ref_structure(*30)
76 c write (iout,*) "Before permut"
77 c write (iout,*) "symetr", symetr
80 c write (iout,*) "after permut"
82 print *,'MAIN: nnt=',nnt,' nct=',nct
94 IF (RCUTOFF(I).LT.0.0) THEN
95 RCUTOFF(I)=ABS(RCUTOFF(I))
103 write (iout,*) 'Number of cutoffs:',NCUT
104 write (iout,*) 'Cutoff values:'
106 WRITE(IOUT,'(8HRCUTOFF(,I2,2H)=,F8.1,2i2)')ICUT,RCUTOFF(ICUT),
107 & printpdb(icut),printmol2(icut)
109 else if (nclust.gt.0) then
110 write (iout,'("Number of clusters requested",i5)') nclust
113 & write (iout,*) "ERROR: Either nclust or ncut must be >0"
122 call read_coords(ncon,*20)
123 write (iout,*) 'from read_coords: ncon',ncon
125 write (iout,*) "nT",nT
127 write (iout,*) "iT",iT
129 call work_partition(.true.,ncon)
132 call probabl(iT,ncon_work,ncon,*20)
134 if (ncon_work.lt.2) then
135 write (iout,*) "Too few conformations; clustering skipped"
139 ndis=ncon_work*(ncon_work-1)/2
140 call work_partition(.true.,ndis)
142 write(iout,*) "AFTET wort_part",NCON_work
146 WRITE (iout,'(A80)') TITEL
149 C CALCULATE DISTANCES
151 call daread_ccoords(1,ncon_work)
154 if (mod(i,100).eq.0) print *,'Calculating RMS i=',i
157 c(l,k)=allcart(l,k,i)
167 IND=IOFFSET(NCON_work,I,J)
169 if (ind.ge.indstart(me) .and. ind.le.indend(me)) then
172 DISS(IND1)=DIFCONF(I,J)
173 c write (iout,'(2i4,i10,f10.5)') i,j,ind,DISS(IND)
180 WRITE (iout,'(/a,1pe14.5,a/)')
181 & 'Time for distance calculation:',T2-T1,' sec.'
183 PRINT '(a)','End of distance computation'
185 scount_buf=scount(me)
188 diss_buf(ijk)=diss(ijk)
193 c WRITE (iout,*) "Wchodze do call MPI_Gatherv"
194 call MPI_Gatherv(diss_buf(1),scount_buf,MPI_REAL,diss(1),
195 & scount(0),idispl(0),MPI_REAL,Master,MPI_COMM_WORLD, IERROR)
196 if (me.eq.master) then
198 scrachdir2d=scratchdir(:ilen(scratchdir))//'distance'
199 open(80,file=scrachdir2d,form='unformatted')
206 IND=IOFFSET(NCON,I,J)
207 write (jrms,'(2i5,2f10.5)') i,j,diss(IND),
208 & energy(j)-energy(i)
213 C Print out the RMS deviation matrix.
215 if (print_dist) CALL DISTOUT(NCON_work)
217 C call hierarchical clustering HC from F. Murtagh
221 write(iout,*) "-------------------------------------------"
222 write(iout,*) "HIERARCHICAL CLUSTERING using"
224 write(iout,*) "WARD'S MINIMUM VARIANCE METHOD"
225 elseif (iopt.eq.2) then
226 write(iout,*) "SINGLE LINK METHOD"
227 elseif (iopt.eq.3) then
228 write(iout,*) "COMPLETE LINK METHOD"
229 elseif (iopt.eq.4) then
230 write(iout,*) "AVERAGE LINK (OR GROUP AVERAGE) METHOD"
231 elseif (iopt.eq.5) then
232 write(iout,*) "MCQUITTY'S METHOD"
233 elseif (iopt.eq.6) then
234 write(iout,*) "MEDIAN (GOWER'S) METHOD"
235 elseif (iopt.eq.7) then
236 write(iout,*) "CENTROID METHOD"
238 write(iout,*) "IOPT=",iopt," IS INVALID, use 1-7"
239 write(*,*) "IOPT=",iopt," IS INVALID, use 1-7"
243 write(iout,*) "hc.f by F. Murtagh, ESA/ESO/STECF, Garching"
244 write(iout,*) "February 1986"
245 write(iout,*) "References:"
246 write(iout,*) "1. Multidimensional clustering algorithms"
247 write(iout,*) " Fionn Murtagh"
248 write(iout,*) " Vienna : Physica-Verlag, 1985."
249 write(iout,*) "2. Multivariate data analysis"
250 write(iout,*) " Fionn Murtagh and Andre Heck"
251 write(iout,*) " Kluwer Academic Publishers, 1987"
252 write(iout,*) "-------------------------------------------"
256 write (iout,*) "The TOTFREE array"
258 write (iout,'(2i5,f10.5)') i,list_conf(i),totfree(i)
262 CALL HC(N,M,LEN,IOPT,IA,IB,CRIT,MEMBR,NN,DISNN,FLAG,DISS)
264 write (iout,*) "n",n," ncon_work",ncon_work," lev",lev
266 write (iout,*) "Too few conformations to cluster."
269 CALL HCASS(N,IA,IB,CRIT,LEV,ICLASS,HVALS,IORDER,CRITVAL,HEIGHT)
270 c CALL HCDEN(LEV,IORDER,HEIGHT,CRITVAL)
272 c 3/3/16 AL: added explicit number of cluters
273 if (nclust.gt.0) then
288 licz(iclass(j,i))=licz(iclass(j,i))+1
289 nconf(iclass(j,i),licz(iclass(j,i)))=j
290 c write (iout,*) i,j,iclass(j,i),licz(iclass(j,i)),
291 c & nconf(iclass(j,i),licz(iclass(j,i)))
297 IF (HEIGHT(L).EQ.IDUM) GOTO 190
300 c write(IOUT,*) "i+1",i+1," idum",idum," critval",CRITVAL(IDUM),
301 c & " icut",icut," cutoff",rcutoff(icut)
302 IF (nclust.gt.0.or.CRITVAL(IDUM).LT. RCUTOFF(ICUT)) THEN
304 & WRITE (iout,'(/a,f10.5)') 'AT CUTOFF:',rcutoff(icut)
305 write (iout,'(a,f8.2)') 'Maximum distance found:',
307 CALL SRTCLUST(ICUT,ncon_work,iT)
309 CALL WRTCLUST(ncon_work,ICUT,PRINTANG,PRINTPDB,PRINTMOL2,iT)
311 if (icut.gt.ncut) goto 191
319 licz(iclass(j,ii))=licz(iclass(j,ii))+1
320 nconf(iclass(j,ii),licz(iclass(j,ii)))=j
321 c write (iout,*) i,j,iclass(j,i),licz(iclass(j,i)),
322 c & nconf(iclass(j,i),licz(iclass(j,i)))
323 cd print *,j,iclass(j,i),
324 cd & licz(iclass(j,i)),nconf(iclass(j,i),licz(iclass(j,i)))
335 WRITE (iout,'(/a,1pe14.5,a/)')
336 & 'Total time for clustering:',T2-T1,' sec.'
344 close(icbase,status="delete")
346 call MPI_Finalize(IERROR)
348 stop '********** Program terminated normally.'
349 20 write (iout,*) "Error reading coordinates"
351 call MPI_Finalize(IERROR)
354 30 write (iout,*) "Error reading reference structure"
356 call MPI_Finalize(IERROR)
360 c---------------------------------------------------------------------------
361 double precision function difconf(icon,jcon)
364 include 'sizesclu.dat'
365 include 'COMMON.CONTROL'
366 include 'COMMON.CLUSTER'
367 include 'COMMON.CHAIN'
368 include 'COMMON.INTERACT'
370 include 'COMMON.IOUNITS'
372 double precision przes(3),obrot(3,3)
373 double precision xx(3,maxres2),yy(3,maxres2)
374 integer i,ii,j,icon,jcon,kkk,nperm,chalen,zzz
375 integer iaperm,ibezperm,run
376 double precision rms,rmsmina
377 c write (iout,*) "tu dochodze"
383 c write (iout,*) "nperm",nperm
385 c write (iout,*) "tabperm", tabperm(1,1)
389 chalen=int((nend-nstart+2)/symetr)
391 do i=nstart,(nstart+chalen-1)
393 c write (iout,*) "tutaj",zzz
395 iaperm=(zzz-1)*chalen+i
396 ibezperm=(run-1)*chalen+i
398 xx(j,ii)=allcart(j,iaperm,jcon)
399 yy(j,ii)=cref(j,ibezperm,kkk)
404 do i=nstart,(nstart+chalen-1)
407 iaperm=(zzz-1)*chalen+i
408 ibezperm=(run-1)*chalen+i
409 c if (itype(i).ne.10) then
412 xx(j,ii)=allcart(j,iaperm+nres,jcon)
413 yy(j,ii)=cref(j,ibezperm+nres,kkk)
418 call fitsq(rms,xx(1,1),yy(1,1),ii,przes,obrot,non_conv)
420 chalen=int((nct-nnt+2)/symetr)
422 do i=nnt,(nnt+chalen-1)
424 c write (iout,*) "tu szukaj", zzz,run,kkk
425 iaperm=(zzz-1)*chalen+i
426 ibezperm=(run-1)*chalen+i
429 c(j,i)=allcart(j,iaperm,jcon)
433 call fitsq(rms,c(1,nstart),cref(1,nstart,kkk),nend-nstart+1,
438 print *,'error, rms^2 = ',rms,icon,jcon
441 if (non_conv) print *,non_conv,icon,jcon
442 if (rmsmina.gt.rms) rmsmina=rms
444 difconf=dsqrt(rmsmina)
447 C------------------------------------------------------------------------------
448 subroutine distout(ncon)
451 include 'sizesclu.dat'
454 include 'COMMON.IOUNITS'
455 include 'COMMON.CLUSTER'
456 integer i,j,k,jlim,jlim1,nlim,ind,ioffset
459 write (iout,'(a)') 'The distance matrix'
461 nlim=min0(i+ncol-1,ncon)
462 write (iout,1000) (k,k=i,nlim)
463 write (iout,'(8h--------,10a)') ('-------',k=i,nlim)
464 1000 format (/8x,10(i4,3x))
465 1020 format (/1x,80(1h-)/)
476 IND=IOFFSET(NCON,j,k)
478 IND=IOFFSET(NCON,k,j)
481 write (iout,1010) j,(b(k),k=1,jlim-i+1)
484 1010 format (i5,3x,10(f6.2,1x))