first and last GLY in seq gives correct energy in unres and wham
[unres.git] / source / unres / src_MD / readrtns.F
index 684c376..fd00153 100644 (file)
@@ -44,7 +44,8 @@ C Print restraint information
      &write (iout,'(a,i5,a)') "The following",nhpb-nss,
      & " distance constraints have been imposed"
       do i=nss+1,nhpb
-        write (iout,'(3i6,f10.5)') i-nss,ihpb(i),jhpb(i),forcon(i)
+        write (iout,'(3i6,i2,3f10.5)') i-nss,ihpb(i),jhpb(i),
+     &     ibecarb(i),dhpb(i),dhpb1(i),forcon(i)
       enddo
 #ifdef MPI
       endif
@@ -137,7 +138,7 @@ C Set up the time limit (caution! The time must be input in minutes!)
       call readi(controlcard,'MAXGEN',maxgen,10000)
       call readi(controlcard,'MAXOVERLAP',maxoverlap,1000)
       call readi(controlcard,"KDIAG",kdiag,0)
-      call readi(controlcard,"RESCALE_MODE",rescale_mode,1)
+      call readi(controlcard,"RESCALE_MODE",rescale_mode,2)
       if(me.eq.king .or. .not. out1file .and. fg_rank.eq.0)
      & write (iout,*) "RESCALE_MODE",rescale_mode
       split_ene=index(controlcard,'SPLIT_ENE').gt.0
@@ -859,12 +860,36 @@ C 12/1/95 Added weight for the multi-body term WCORR
       call reada(weightcard,"V2SS",v2ss,7.61d0)
       call reada(weightcard,"V3SS",v3ss,13.7d0)
       call reada(weightcard,"EBR",ebr,-5.50D0)
+      dyn_ss=(index(weightcard,'DYN_SS').gt.0)
+      do i=1,maxres
+        dyn_ss_mask(i)=.false.
+      enddo
+      do i=1,maxres-1
+        do j=i+1,maxres
+          dyn_ssbond_ij(i,j)=1.0d300
+        enddo
+      enddo
+      call reada(weightcard,"HT",Ht,0.0D0)
+      if (dyn_ss) then
+        ss_depth=ebr/wsc-0.25*eps(1,1)
+        Ht=Ht/wsc-0.25*eps(1,1)
+        akcm=akcm*wstrain/wsc
+        akth=akth*wstrain/wsc
+        akct=akct*wstrain/wsc
+        v1ss=v1ss*wstrain/wsc
+        v2ss=v2ss*wstrain/wsc
+        v3ss=v3ss*wstrain/wsc
+      else
+        ss_depth=ebr/wstrain-0.25*eps(1,1)*wsc/wstrain
+      endif
+
       if(me.eq.king.or..not.out1file) then
        write (iout,*) "Parameters of the SS-bond potential:"
        write (iout,*) "D0CM",d0cm," AKCM",akcm," AKTH",akth,
      & " AKCT",akct
        write (iout,*) "V1SS",v1ss," V2SS",v2ss," V3SS",v3ss
-       write (iout,*) "EBR",ebr
+       write (iout,*) "EBR",ebr," SS_DEPTH",ss_depth
+       write (iout,*)" HT",Ht
        print *,'indpdb=',indpdb,' pdbref=',pdbref
       endif
       if (indpdb.gt.0 .or. pdbref) then
@@ -892,6 +917,9 @@ c        print *,'Finished reading pdb data'
         call contact(.false.,ncont_ref,icont_ref,co)
 
         if (sideadd) then 
+C Following 2 lines for diagnostics; comment out if not needed
+         write (iout,*) "Before sideadd"
+         call intout
          if(me.eq.king.or..not.out1file)
      &    write(iout,*)'Adding sidechains'
          maxsi=1000
@@ -908,7 +936,12 @@ c        print *,'Finished reading pdb data'
      &              i,' after ',nsi,' trials'
           endif
          enddo
+C 10/03/12 Adam: Recalculate coordinates with new side chain positions
+         call chainbuild
         endif  
+C Following 2 lines for diagnostics; comment out if not needed
+c        write (iout,*) "After sideadd"
+c        call intout
       endif
       if (indpdb.eq.0) then
 C Read sequence if not taken from the pdb file.
@@ -923,6 +956,20 @@ C Convert sequence to numeric code
         do i=1,nres
           itype(i)=rescode(i,sequence(i),iscode)
         enddo
+        if (itype(2).eq.10.and.itype(1).eq.ntyp1) then
+          write (iout,*) 
+     &     "Glycine is the first full residue, initial dummy deleted"
+          do i=1,nres
+            itype(i)=itype(i+1)
+          enddo
+          nres=nres-1
+        endif
+        if (itype(nres-1).eq.10.and.itype(nres).eq.ntyp1) then
+          write (iout,*) 
+     &     "Glycine is the last full residue, terminal dummy deleted"
+          nres=nres-1
+        endif
+
 C Assign initial virtual bond lengths
         do i=2,nres
           vbld(i)=vbl
@@ -1075,11 +1122,6 @@ czscore          call geom_to_var(nvar,coord_exp_zs(1,1))
           enddo
           call contact(.true.,ncont_ref,icont_ref,co)
         endif
-c        write (iout,*) "constr_dist",constr_dist,nstart_sup,nsup
-        call flush(iout)
-        if (constr_dist.gt.0) call read_dist_constr
-c        write (iout,*) "After read_dist_constr nhpb",nhpb
-        call hpb_partition
         if(me.eq.king.or..not.out1file)
      &   write (iout,*) 'Contact order:',co
         if (pdbref) then
@@ -1096,6 +1138,13 @@ c        write (iout,*) "After read_dist_constr nhpb",nhpb
         enddo
         endif
       endif
+c        write (iout,*) "constr_dist",constr_dist,nstart_sup,nsup
+      if (constr_dist.gt.0) then
+        call read_dist_constr
+      endif
+      if (nhpb.gt.0) call hpb_partition
+c      write (iout,*) "After read_dist_constr nhpb",nhpb
+c      call flush(iout)
       if (indpdb.eq.0 .and. modecalc.ne.2 .and. modecalc.ne.4
      &    .and. modecalc.ne.8 .and. modecalc.ne.9 .and. 
      &    modecalc.ne.10) then
@@ -1214,18 +1263,35 @@ C Generate distance constraints, if the PDB structure is to be regularized.
         write (iout,'(/a,i3,a)') 
      &  'The chain contains',ns,' disulfide-bridging cysteines.'
         write (iout,'(20i4)') (iss(i),i=1,ns)
+       if (dyn_ss) then
+          write(iout,*)"Running with dynamic disulfide-bond formation"
+       else
         write (iout,'(/a/)') 'Pre-formed links are:' 
        do i=1,nss
          i1=ihpb(i)-nres
          i2=jhpb(i)-nres
          it1=itype(i1)
          it2=itype(i2)
-         if (me.eq.king.or..not.out1file)
-     &    write (iout,'(2a,i3,3a,i3,a,3f10.3)')
+          write (iout,'(2a,i3,3a,i3,a,3f10.3)')
      &    restyp(it1),'(',i1,') -- ',restyp(it2),'(',i2,')',dhpb(i),
      &    ebr,forcon(i)
        enddo
        write (iout,'(a)')
+       endif
+      endif
+      if (ns.gt.0.and.dyn_ss) then
+          do i=nss+1,nhpb
+            ihpb(i-nss)=ihpb(i)
+            jhpb(i-nss)=jhpb(i)
+            forcon(i-nss)=forcon(i)
+            dhpb(i-nss)=dhpb(i)
+          enddo
+          nhpb=nhpb-nss
+          nss=0
+          call hpb_partition
+          do i=1,ns
+            dyn_ss_mask(iss(i))=.true.
+          enddo
       endif
       if (i2ndstr.gt.0) call secstrp2dihc
 c      call geom_to_var(nvar,x)
@@ -1289,10 +1355,12 @@ C Check whether the specified bridging residues are cystines.
       do i=1,ns
        if (itype(iss(i)).ne.1) then
          if (me.eq.king.or..not.out1file) write (iout,'(2a,i3,a)') 
-     &   'Do you REALLY think that the residue ',restyp(iss(i)),i,
+     &   'Do you REALLY think that the residue ',
+     &    restyp(itype(iss(i))),i,
      &   ' can form a disulfide bridge?!!!'
          write (*,'(2a,i3,a)') 
-     &   'Do you REALLY think that the residue ',restyp(iss(i)),i,
+     &   'Do you REALLY think that the residue ',
+     &    restyp(itype(iss(i))),i,
      &   ' can form a disulfide bridge?!!!'
 #ifdef MPI
         call MPI_Finalize(MPI_COMM_WORLD,ierror)
@@ -1303,7 +1371,8 @@ C Check whether the specified bridging residues are cystines.
 C Read preformed bridges.
       if (ns.gt.0) then
       read (inp,*) nss,(ihpb(i),jhpb(i),i=1,nss)
-      write (iout,*) 'nss=',nss,' ihpb,jhpb: ',(ihpb(i),jhpb(i),i=1,nss)
+      if(fg_rank.eq.0)
+     & write(iout,*)'nss=',nss,' ihpb,jhpb: ',(ihpb(i),jhpb(i),i=1,nss)
       if (nss.gt.0) then
         nhpb=nss
 C Check if the residues involved in bridges are in the specified list of
@@ -1810,6 +1879,9 @@ c----------------------------------------------------------------------------
       call readi(minimcard,'MINFUN',minfun,maxmin)
       call reada(minimcard,'TOLF',tolf,1.0D-2)
       call reada(minimcard,'RTOLF',rtolf,1.0D-4)
+      print_min_stat=min0(index(minimcard,'PRINT_MIN_STAT'),1)
+      print_min_res=min0(index(minimcard,'PRINT_MIN_RES'),1)
+      print_min_ini=min0(index(minimcard,'PRINT_MIN_INI'),1)
       write (iout,'(/80(1h*)/20x,a/80(1h*))') 
      &         'Options in energy minimization:'
       write (iout,'(4(a,i5),a,1pe14.5,a,1pe14.5)')
@@ -2192,6 +2264,7 @@ c      print *,"Processor",myrank," fg_rank",fg_rank
 #if defined(AIX) || defined(PGI)
       if (me.eq.king .or. .not. out1file) 
      &   open(iout,file=outname,status='unknown')
+c#define DEBUG
 #ifdef DEBUG
       if (fg_rank.gt.0) then
         write (liczba,'(i3.3)') myrank/nfgtasks
@@ -2200,6 +2273,7 @@ c      print *,"Processor",myrank," fg_rank",fg_rank
      &   status='unknown')
       endif
 #endif
+c#undef DEBUG
       if(me.eq.king) then
        open(igeom,file=intname,status='unknown',position='append')
        open(ipdb,file=pdbname,status='unknown')
@@ -2211,14 +2285,17 @@ c1out       open(iout,file=outname,status='unknown')
 #else
       if (me.eq.king .or. .not.out1file)
      &    open(iout,file=outname,status='unknown')
+c#define DEBUG
 #ifdef DEBUG
       if (fg_rank.gt.0) then
+        print "Processor",fg_rank," opening output file"
         write (liczba,'(i3.3)') myrank/nfgtasks
         write (ll,'(bz,i3.3)') fg_rank
         open(iout,file="debug"//liczba(:ilen(liczba))//"."//ll,
      &   status='unknown')
       endif
 #endif
+c#undef DEBUG
       if(me.eq.king) then
        open(igeom,file=intname,status='unknown',access='append')
        open(ipdb,file=pdbname,status='unknown')
@@ -2401,6 +2478,18 @@ c      write (iout,*) "IPAIR"
 c      do i=1,npair_
 c        write (iout,*) i,ipair_(1,i),ipair_(2,i),wpair_(i)
 c      enddo
+      if (.not.refstr .and. nfrag.gt.0) then
+        write (iout,*) 
+     &  "ERROR: no reference structure to compute distance restraints"
+        write (iout,*)
+     &  "Restraints must be specified explicitly (NDIST=number)"
+        stop 
+      endif
+      if (nfrag.lt.2 .and. npair.gt.0) then 
+        write (iout,*) "ERROR: Less than 2 fragments specified",
+     &   " but distance restraints between pairs requested"
+        stop 
+      endif 
       call flush(iout)
       do i=1,nfrag_
         if (ifrag_(1,i).lt.nstart_sup) ifrag_(1,i)=nstart_sup
@@ -2411,7 +2500,7 @@ c        write (iout,*) i,ifrag_(1,i),ifrag_(2,i),wfrag_(i)
         if (wfrag_(i).gt.0.0d0) then
         do j=ifrag_(1,i),ifrag_(2,i)-1
           do k=j+1,ifrag_(2,i)
-            write (iout,*) "j",j," k",k
+c            write (iout,*) "j",j," k",k
             ddjk=dist(j,k)
             if (constr_dist.eq.1) then
             nhpb=nhpb+1
@@ -2475,21 +2564,29 @@ c        write (iout,*) i,ifrag_(1,i),ifrag_(2,i),wfrag_(i)
         endif
       enddo 
       do i=1,ndist_
-        read (inp,*) ihpb(nhpb+1),jhpb(nhpb+1),forcon(nhpb+1)
+        read (inp,*) ihpb(nhpb+1),jhpb(nhpb+1),dhpb(i),dhpb1(i),
+     &     ibecarb(i),forcon(nhpb+1)
         if (forcon(nhpb+1).gt.0.0d0) then
           nhpb=nhpb+1
-          dhpb(nhpb)=dist(ihpb(nhpb),jhpb(nhpb))
+          if (ibecarb(i).gt.0) then
+            ihpb(i)=ihpb(i)+nres
+            jhpb(i)=jhpb(i)+nres
+          endif
+          if (dhpb(nhpb).eq.0.0d0) 
+     &       dhpb(nhpb)=dist(ihpb(nhpb),jhpb(nhpb))
+        endif
+      enddo
 #ifdef MPI
-          if (.not.out1file .or. me.eq.king)
-     &    write (iout,'(a,3i5,f8.2,f10.1)') "+dist.constr ",
-     &     nhpb,ihpb(nhpb),jhpb(nhpb),dhpb(nhpb),forcon(nhpb)
-#else
-          write (iout,'(a,3i5,f8.2,f10.1)') "+dist.constr ",
-     &     nhpb,ihpb(nhpb),jhpb(nhpb),dhpb(nhpb),forcon(nhpb)
+      if (.not.out1file .or. me.eq.king) then
 #endif
-        endif
+      do i=1,nhpb
+          write (iout,'(a,3i5,2f8.2,i2,f10.1)') "+dist.constr ",
+     &     i,ihpb(i),jhpb(i),dhpb(i),dhpb1(i),ibecarb(i),forcon(i)
       enddo
       call flush(iout)
+#ifdef MPI
+      endif
+#endif
       return
       end
 c-------------------------------------------------------------------------------