unres
[unres.git] / source / unres / src-HCD-5D / unres.F
index f556eb6..4c60573 100644 (file)
@@ -59,7 +59,8 @@ c      call memmon_print_usage()
 C Read force field parameters and job setup data
       call readrtns
 C
-c      write (iout,*) "After readrtns"
+      write (iout,*) "After readrtns"
+      call flush(iout)
       call cartprint
       call intout
       if (me.eq.king .or. .not. out1file) then
@@ -86,9 +87,14 @@ C Fine-grain slaves just do energy and gradient components.
         call ergastulum ! slave workhouse in Latin
       else
 #endif
+      if (indpdb.eq.0 .and. .not.read_cart) call chainbuild
+      if (indpdb.ne.0 .or. read_cart) then
+        dc(1,0)=c(1,1)
+        dc(2,0)=c(2,1)
+        dc(3,0)=c(3,1)
+      endif
       if (modecalc.eq.0) then
         write (iout,*) "Calling exec_eeval_or_minim"
-        call cartprint
         call exec_eeval_or_minim
       else if (modecalc.eq.1) then
         call exec_regularize
@@ -207,11 +213,11 @@ c      include 'COMMON.CONTACTS'
       include 'COMMON.REMD'
       include 'COMMON.MD'
       include 'COMMON.SBRIDGE'
-      integer i,icall,iretcode,nfun
+      integer i,it,icall,iretcode,nfun
       common /srutu/ icall
       integer nharp,iharp(4,maxres/3)
       integer nft_sc
-      logical fail
+      logical fail,secondary_str /.true./
       double precision energy(0:n_ene),etot,etota
       double precision energy_long(0:n_ene),energy_short(0:n_ene)
       double precision rms,frac,frac_nn,co
@@ -223,8 +229,8 @@ c      include 'COMMON.CONTACTS'
       common /lbfgstat/ status,niter,nfun
 #endif
       integer ilen
-      if (indpdb.eq.0)     call chainbuild
-      if (indpdb.ne.0) then
+      if (indpdb.eq.0 .and. .not.read_cart) call chainbuild
+      if (indpdb.ne.0 .or. read_cart) then
       dc(1,0)=c(1,1)
       dc(2,0)=c(2,1)
       dc(3,0)=c(3,1)
@@ -237,6 +243,24 @@ c      include 'COMMON.CONTACTS'
       write (iout,*) "Energy evaluation/minimization"
       call chainbuild_cart
 c      print *,'dc',dc(1,0),dc(2,0),dc(3,0)
+      if (nran_start.gt.0) then
+        write (iout,*) 
+     & "Chains will be regenerated starting from residue",nran_start
+        do it=1,100
+        call gen_rand_conf_mchain(nran_start,*10)
+        write (iout,*) "Conformation successfully generated",it
+        goto 11
+   10   write (iout,*) "Problems with regenerating chains",it
+        enddo
+   11   continue
+        write (iout,*) "Cartesian coords after chain rebuild"
+        call cartprint
+        call chainbuild_cart
+        write (iout,*) "Cartesian coords after chainbuild_ecart"
+        call cartprint
+        call int_from_cart1(.false.)
+        call intout
+      endif
       if (split_ene) then
        print *,"Processor",myrank," after chainbuild"
        icall=1
@@ -268,10 +292,12 @@ c      print *,"after etotal"
       etota = energy(0)
       etot =etota
       call enerprint(energy(0))
+      if (secondary_str) then
       call hairpin(.true.,nharp,iharp)
-c        print *,'after hairpin'
+      print *,'after hairpin'
       call secondary2(.true.)
-c        print *,'after secondary'
+      endif
+      print *,'after secondary'
       if (minim) then
 crc overlap test
         if (indpdb.ne.0 .and. .not.dccart) then 
@@ -283,9 +309,12 @@ crc overlap test
         endif
 
         if (overlapsc) then 
-c          print *, 'Calling OVERLAP_SC'
+          write (iout,*) 'Calling OVERLAP_SC'
           call overlap_sc(fail)
-c          print *,"After overlap_sc"
+          write (iout,*) "After overlap_sc"
+c        cartname=prefix(:ilen(prefix))//'.x'
+c        potE=etot
+c        call cartoutx(0.0d0)
         endif 
 
         if (searchsc) then 
@@ -324,22 +353,16 @@ c          print *,'Calling MINIMIZE.'
 #endif
         print *,'# eval/s',evals
         print *,'refstr=',refstr
+        if (secondary_str) then
         call hairpin(.false.,nharp,iharp)
-        print *,'after hairpin'
+c        print *,'after hairpin'
         call secondary2(.true.)
-        print *,'after secondary'
+c        print *,'after secondary'
+        endif
         call etotal(energy(0))
         etot = energy(0)
         call enerprint(energy(0))
-
         call intout
-        if (out_int) call briefout(0,etot)
-        if (out_cart) then
-          cartname=prefix(:ilen(prefix))//'.x'
-          potE=etot
-          call cartoutx(0.0d0)
-        endif
-        if (refstr) call rms_nac_nnc(rms,frac,frac_nn,co,.true.)
 #ifdef LBFGS
           write (iout,'(a,a9)') 'LBFGS return code:',status
           write (iout,'(a,i20)') '# of energy evaluations:',nfun+1
@@ -349,10 +372,13 @@ c          print *,'Calling MINIMIZE.'
           write (iout,'(a,i20)') '# of energy evaluations:',nfun+1
           write (iout,'(a,f16.3)')'# of energy evaluations/sec:',evals
 #endif
-      else
-        print *,'refstr=',refstr
-        if (refstr) call rms_nac_nnc(rms,frac,frac_nn,co,.true.)
-        call briefout(0,etot)
+      endif
+      if (refstr) call rms_nac_nnc(rms,frac,frac_nn,co,.true.)
+      if (out_int) call briefout(0,etot)
+      if (out_cart) then
+        cartname=prefix(:ilen(prefix))//'.x'
+        potE=etot
+        call cartoutx(0.0d0)
       endif
       if (outpdb) call pdbout(etot,titel(:50),ipdb)
       if (outmol2) call mol2out(etot,titel(:32))