Merge branch 'UCGM' of mmka.chem.univ.gda.pl:unres4 into UCGM
[unres4.git] / source / cluster / main_clust.F
index 15e0bd0..650250e 100644 (file)
@@ -61,8 +61,9 @@ C
 
       call initialize
       call openunits
-      call parmread
       call read_control
+      call parmread
+!      call read_control
       call molread
 c      if (refstr) call read_ref_structure(*30)
       do i=1,nres
@@ -79,6 +80,12 @@ c      write (iout,*) "after permut"
 c      call flush(iout)
       print *,'MAIN: nnt=',nnt,' nct=',nct
 
+        if (nclust.gt.0) then
+          PRINTANG(1)=.TRUE.
+          PRINTPDB(1)=outpdb
+          printmol2(1)=outmol2
+          ncut=0
+      else
       DO I=1,NCUT
         PRINTANG(I)=.FALSE.
         PRINTPDB(I)=0
@@ -90,12 +97,21 @@ c      call flush(iout)
           printmol2(i)=outmol2
         ENDIF
       ENDDO
+      endif
+      if (ncut.gt.0) then
       write (iout,*) 'Number of cutoffs:',NCUT
       write (iout,*) 'Cutoff values:'
       DO ICUT=1,NCUT
         WRITE(IOUT,'(8HRCUTOFF(,I2,2H)=,F8.1,2i2)')ICUT,RCUTOFF(ICUT),
      &    printpdb(icut),printmol2(icut)
       ENDDO
+       else if (nclust.gt.0) then
+       write (iout,'("Number of clusters requested",i5)') nclust
+       else
+      if (me.eq.Master)
+     & write (iout,*) "ERROR: Either nclust or ncut must be >0"
+       stop
+       endif
       DO I=1,NRES-3  
         MULT(I)=1
       ENDDO
@@ -113,7 +129,7 @@ c      call flush(iout)
 #endif
 
       call probabl(iT,ncon_work,ncon,*20)
-
+      write(iout,*) "after probabl"
       if (ncon_work.lt.2) then
         write (iout,*) "Too few conformations; clustering skipped"
         exit
@@ -122,6 +138,7 @@ c      call flush(iout)
       ndis=ncon_work*(ncon_work-1)/2
       call work_partition(.true.,ndis)
 #endif
+      write(iout,*) "after work partition"
 
       DO I=1,NCON_work
         ICC(I)=I
@@ -132,6 +149,7 @@ C
 C CALCULATE DISTANCES
 C
       call daread_ccoords(1,ncon_work)
+      write(iout,*) "after daread_ccords"
       ind1=0
       DO I=1,NCON_work-1
         if (mod(i,100).eq.0) print *,'Calculating RMS i=',i
@@ -241,19 +259,28 @@ C
         goto 192
       endif
       CALL HCASS(N,IA,IB,CRIT,LEV,ICLASS,HVALS,IORDER,CRITVAL,HEIGHT)
-c      CALL HCDEN(LEV,IORDER,HEIGHT,CRITVAL)
+!c      CALL HCDEN(LEV,IORDER,HEIGHT,CRITVAL)
+!c 3/3/16 AL: added explicit number of cluters
+      if (nclust.gt.0) then
+        is=nclust-1
+        ie=nclust-1
+        icut=1
+      else
+        is=1
+        ie=lev-1
+      endif
 
       do i=1,maxgr
         licz(i)=0
       enddo
       icut=1
-      i=1
-      NGR=i+1
+      i=is
+      NGR=is+1
       do j=1,n
         licz(iclass(j,i))=licz(iclass(j,i))+1
         nconf(iclass(j,i),licz(iclass(j,i)))=j
-c        write (iout,*) i,j,iclass(j,i),licz(iclass(j,i)),
-c     &    nconf(iclass(j,i),licz(iclass(j,i)))
+!c        write (iout,*) i,j,iclass(j,i),licz(iclass(j,i)),
+!c     &    nconf(iclass(j,i),licz(iclass(j,i)))
       enddo        
       do i=1,lev-1
 
@@ -264,8 +291,8 @@ c     &    nconf(iclass(j,i),licz(iclass(j,i)))
  190     IDUM=L
          write(IOUT,*) "i+1",i+1," idum",idum," critval",CRITVAL(IDUM),
      &    " icut",icut," cutoff",rcutoff(icut)
-         IF (CRITVAL(IDUM).LT. RCUTOFF(ICUT)) THEN
-          WRITE (iout,'(/a,f10.5)') 'AT CUTOFF:',rcutoff(icut)
+         IF (nclust.gt.0.or.CRITVAL(IDUM).LT. RCUTOFF(ICUT)) THEN
+          if (nclust.le.0) WRITE (iout,'(/a,f10.5)') 'AT CUTOFF:',rcutoff(icut)
           write (iout,'(a,f8.2)') 'Maximum distance found:',
      &              CRITVAL(IDUM)
           CALL SRTCLUST(ICUT,ncon_work,iT)