dodanie parametrow do nanotube
[unres.git] / source / unres / src_MD-M / MD_A-MTS.F
index 3a45231..6650c5a 100644 (file)
@@ -323,6 +323,8 @@ c-------------------------------------------------------------------------------
       common /stochcalc/ stochforcvec
       integer itime
       logical scale
+      double precision HNose1,HNose,HNose_nh,H,vtnp(maxres6)
+      double precision vtnp_(maxres6),vtnp_a(maxres6)
 c
       scale=.true.
       icount_scale=0
@@ -366,7 +368,19 @@ c First step of the velocity Verlet algorithm
 #endif
         else if (lang.eq.1) then
           call sddir_verlet1
+C        else if (tnp1) then
+C          call tnp1_step1
+C        else if (tnp) then
+C          call tnp_step1
         else
+          if (tnh) then
+            call nhcint(EK,scale_nh,wdti,wdti2,wdti4,wdti8)
+            do i=0,2*nres
+             do j=1,3
+              d_t_old(j,i)=d_t_old(j,i)*scale_nh
+             enddo
+            enddo
+          endif
           call verlet1
         endif    
 c Build the chain from the newly calculated coordinates        
@@ -411,6 +425,7 @@ c Calculate energy and forces
         t_etotal=t_etotal+tcpu()-tt0
 #endif
 #endif
+        E_old=potE
         potE=potEcomp(0)-potEcomp(20)
         call cartgrad
 c Get the new accelerations
@@ -515,8 +530,21 @@ c Second step of the velocity Verlet algorithm
 #endif
           else if (lang.eq.1) then
             call sddir_verlet2
+C>           else if (tnp1) then
+C>             call tnp1_step2
+C>           else if (tnp) then
+C>             call tnp_step2
           else
            call verlet2
+            if (tnh) then
+              call kinetic(EK)
+              call nhcint(EK,scale_nh,wdti,wdti2,wdti4,wdti8)
+              do i=0,2*nres
+               do j=1,3
+                d_t(j,i)=d_t(j,i)*scale_nh
+               enddo
+              enddo
+            endif
           endif                    
           if (rattle) call rattle2
           totT=totT+d_time
@@ -546,6 +574,15 @@ c Restore the matrices of tinker integrator if the time step has been restored
           scale=.false.
         endif
       enddo
+      if (tnp .or. tnp1) then 
+       do i=0,2*nres
+        do j=1,3
+          d_t_old(j,i)=d_t(j,i)
+          d_t(j,i)=d_t(j,i)/s_np
+        enddo
+       enddo 
+      endif
+
 c Calculate the kinetic and the total energy and the kinetic temperature
       call kinetic(EK)
       totE=EK+potE
@@ -562,12 +599,67 @@ c Backup the coordinates, velocities, and accelerations
       do i=0,2*nres
         do j=1,3
           dc_old(j,i)=dc(j,i)
-          d_t_old(j,i)=d_t(j,i)
+          if(.not.(tnp .or. tnp1)) d_t_old(j,i)=d_t(j,i)
           d_a_old(j,i)=d_a(j,i)
         enddo
       enddo 
       if (ntwe.ne.0) then
       if (mod(itime,ntwe).eq.0 .and. large) then
+       if(tnp .or. tnp1) then
+        HNose1=Hnose(EK,s_np,potE,pi_np,Q_np,t_bath,dimen3)
+        H=(HNose1-H0)*s_np
+cd        write (iout,'(a,10f)') "hhh",EK,s_np,potE,pi_np,H0
+cd     &   ,EK+potE+pi_np**2/(2*Q_np)+dimen3*0.001986d0*t_bath*log(s_np)
+cd        write (iout,*) "HHH H=",H,abs(HNose1-H0)/H0
+          hhh=h
+       endif
+
+       if(tnh) then
+        HNose1=Hnose_nh(EK,potE)
+        H=HNose1-H0
+        hhh=h
+cd        write (iout,*) "HHH H=",H,abs(HNose1-H0)/H0
+       endif
+
+       if (large) then
+        itnp=0
+        do j=1,3
+         itnp=itnp+1
+         vtnp(itnp)=d_t(j,0)
+        enddo
+        do i=nnt,nct-1 
+         do j=1,3    
+          itnp=itnp+1
+          vtnp(itnp)=d_t(j,i)
+         enddo
+        enddo
+        do i=nnt,nct
+         if (itype(i).ne.10) then
+          inres=i+nres
+          do j=1,3  
+           itnp=itnp+1  
+           vtnp(itnp)=d_t(j,inres)
+          enddo
+         endif      
+        enddo 
+
+c Transform velocities from UNRES coordinate space to cartesian and Gvec
+c eigenvector space
+
+        do i=1,dimen3
+          vtnp_(i)=0.0d0
+          vtnp_a(i)=0.0d0
+          do j=1,dimen3
+            vtnp_(i)=vtnp_(i)+Gvec(j,i)*vtnp(j)
+            vtnp_a(i)=vtnp_a(i)+A(i,j)*vtnp(j)
+          enddo
+          vtnp_(i)=vtnp_(i)*dsqrt(geigen(i))
+        enddo
+
+        do i=1,dimen3
+         write (iout,'("WWW",i3,3f10.5)') i,vtnp(i),vtnp_(i),vtnp_a(i)
+        enddo
+
         write (iout,*) "Velocities, step 2"
         do i=0,nres
           write (iout,'(i3,3f10.5,3x,3f10.5)') i,(d_t(j,i),j=1,3),
@@ -575,6 +667,7 @@ c Backup the coordinates, velocities, and accelerations
         enddo
       endif
       endif
+      endif
       return
       end
 c-------------------------------------------------------------------------------
@@ -619,6 +712,7 @@ c-------------------------------------------------------------------------------
       double precision stochforcvec(MAXRES6)
       common /stochcalc/ stochforcvec
       integer itime
+      double precision vtnp(maxres6), vtnp_(maxres6), vtnp_a(maxres6)
       logical scale
       common /cipiszcze/ itt
       itt=itime
@@ -644,7 +738,26 @@ c        call cartprint
 c
 c Perform the initial RESPA step (increment velocities)
 c      write (iout,*) "*********************** RESPA ini"
-      call RESPA_vel
+      if (tnp1) then
+          call tnp_respa_step1
+      else if (tnp) then
+          call tnp_respa_step1
+      else
+          if (tnh.and..not.xiresp) then
+            call nhcint(EK,scale_nh,wdti,wdti2,wdti4,wdti8)
+            do i=0,2*nres
+             do j=1,3
+              d_t(j,i)=d_t(j,i)*scale_nh
+             enddo
+            enddo 
+          endif
+          call RESPA_vel
+      endif
+
+cd       if(tnp .or. tnp1) then
+cd        write (iout,'(a,3f)') "EE1 NP S, pi",totT, s_np, pi_np
+cd       endif
+
       if (ntwe.ne.0) then
       if (mod(itime,ntwe).eq.0 .and. large) then
         write (iout,*) "Velocities, end"
@@ -661,6 +774,7 @@ c Compute the short-range forces
       tt0 = tcpu()
 #endif
 C 7/2/2009 commented out
+       if (tnp.or.tnp1) potE=energia_short(0)
 c      call zerograd
 c      call etotal_short(energia_short)
 c      call cartgrad
@@ -689,7 +803,8 @@ C 7/2/2009 Copy accelerations due to short-lange forces from previous MD step
       do i=0,2*nres
         do j=1,3
           dc_old(j,i)=dc(j,i)
-          d_t_old(j,i)=d_t(j,i)
+C          d_t_old(j,i)=d_t(j,i)
+          if(.not.(tnp .or. tnp1)) d_t_old(j,i)=d_t(j,i)
           d_a_old(j,i)=d_a(j,i)
         enddo
       enddo 
@@ -741,7 +856,21 @@ c First step of the velocity Verlet algorithm
 #endif
         else if (lang.eq.1) then
           call sddir_verlet1
+         else if (tnp1) then
+           call tnp1_respa_i_step1
+         else if (tnp) then
+           call tnp_respa_i_step1
         else
+          if (tnh.and.xiresp) then
+            call kinetic(EK)
+            call nhcint(EK,scale_nh,wdtii,wdtii2,wdtii4,wdtii8)
+            do i=0,2*nres
+             do j=1,3
+              d_t_old(j,i)=d_t_old(j,i)*scale_nh
+             enddo
+            enddo 
+cd            write(iout,*) "SSS1",itsplit,EK,scale_nh
+          endif
           call verlet1
         endif
 c Build the chain from the newly calculated coordinates        
@@ -771,6 +900,9 @@ c Calculate energy and forces
         call etotal_short(energia_short)
         if (large.and. mod(itime,ntwe).eq.0) 
      &    call enerprint(energia_short)
+        E_old=potE
+        potE=energia_short(0)
+
 #ifdef TIMING_ENE
 #ifdef MPI
         t_eshort=t_eshort+MPI_Wtime()-tt0
@@ -847,15 +979,40 @@ c Second step of the velocity Verlet algorithm
 #endif
         else if (lang.eq.1) then
           call sddir_verlet2
+        else if (tnp1) then
+            call tnp1_respa_i_step2
+        else if (tnp) then
+            call tnp_respa_i_step2
         else
           call verlet2
+          if (tnh.and.xiresp) then
+            call kinetic(EK)
+            call nhcint(EK,scale_nh,wdtii,wdtii2,wdtii4,wdtii8)
+            do i=0,2*nres
+             do j=1,3
+              d_t(j,i)=d_t(j,i)*scale_nh
+             enddo
+            enddo 
+cd            write(iout,*) "SSS2",itsplit,EK,scale_nh
+          endif
         endif
         if (rattle) call rattle2
+        if (tnp .or. tnp1) then 
+         do i=0,2*nres
+          do j=1,3
+            d_t_old(j,i)=d_t(j,i)
+            if (tnp) d_t(j,i)=d_t(j,i)/s_np
+            if (tnp1) d_t(j,i)=d_t(j,i)/s_np
+          enddo
+         enddo 
+        endif
+
+
 c Backup the coordinates, velocities, and accelerations
         do i=0,2*nres
           do j=1,3
             dc_old(j,i)=dc(j,i)
-            d_t_old(j,i)=d_t(j,i)
+            if(.not.(tnp .or. tnp1)) d_t_old(j,i)=d_t(j,i)
             d_a_old(j,i)=d_a(j,i)
           enddo
         enddo 
@@ -875,6 +1032,8 @@ c Compute long-range forces
       call etotal_long(energia_long)
       if (large.and. mod(itime,ntwe).eq.0) 
      &    call enerprint(energia_long)
+      E_long=energia_long(0)
+      potE=energia_short(0)+energia_long(0)
 #ifdef TIMING_ENE
 #ifdef MPI
         t_elong=t_elong+MPI_Wtime()-tt0
@@ -911,7 +1070,32 @@ c        call cartprint
       endif
 c Compute the final RESPA step (increment velocities)
 c      write (iout,*) "*********************** RESPA fin"
-      call RESPA_vel
+C      call RESPA_vel
+      if (tnp1) then
+          call tnp_respa_step2
+      else if (tnp) then
+          call tnp_respa_step2
+      else
+          call RESPA_vel
+          if (tnh.and..not.xiresp) then
+            call kinetic(EK)
+            call nhcint(EK,scale_nh,wdti,wdti2,wdti4,wdti8)
+            do i=0,2*nres
+             do j=1,3
+              d_t(j,i)=d_t(j,i)*scale_nh
+             enddo
+            enddo 
+          endif
+      endif
+
+        if (tnp .or. tnp1) then 
+         do i=0,2*nres
+          do j=1,3
+            d_t(j,i)=d_t_old(j,i)/s_np
+          enddo
+         enddo 
+        endif
+
 c Compute the complete potential energy
       do i=0,n_ene
         potEcomp(i)=energia_short(i)+energia_long(i)
@@ -937,6 +1121,73 @@ c Backup the coordinates, velocities, and accelerations
      &      (d_t(j,i+nres),j=1,3)
         enddo
       endif
+      if (mod(itime,ntwe).eq.0) then
+
+       if(tnp .or. tnp1) then
+#ifndef G77
+        write (iout,'(a3,7f20.10)') "TTT",EK,s_np,potE,pi_np,Csplit,
+     &                          E_long,energia_short(0)
+#else
+        write (iout,'(a3,7f20.10)') "TTT",EK,s_np,potE,pi_np,Csplit,
+     &                          E_long,energia_short(0)
+#endif
+        HNose1=Hnose(EK,s_np,potE,pi_np,Q_np,t_bath,dimen3)
+        H=(HNose1-H0)*s_np
+cd        write (iout,'(a,10f)') "hhh",EK,s_np,potE,pi_np,H0
+cd     &   ,EK+potE+pi_np**2/(2*Q_np)+dimen3*0.001986d0*t_bath*log(s_np)
+cd        write (iout,*) "HHH H=",H,abs(HNose1-H0)/H0
+          hhh=h
+cd        write (iout,'(a,3f)') "EE2 NP S, pi",totT, s_np, pi_np
+       endif
+
+       if(tnh) then
+        HNose1=Hnose_nh(EK,potE)
+        H=HNose1-H0
+cd        write (iout,*) "HHH H=",H,abs(HNose1-H0)/H0
+        hhh=h
+       endif
+
+
+       if (large) then
+       itnp=0
+       do j=1,3
+        itnp=itnp+1
+        vtnp(itnp)=d_t(j,0)
+       enddo
+       do i=nnt,nct-1  
+        do j=1,3    
+          itnp=itnp+1
+          vtnp(itnp)=d_t(j,i)
+        enddo
+       enddo
+       do i=nnt,nct
+        if (itype(i).ne.10) then
+          inres=i+nres
+          do j=1,3  
+           itnp=itnp+1  
+           vtnp(itnp)=d_t(j,inres)
+          enddo
+        endif      
+       enddo 
+c Transform velocities from UNRES coordinate space to cartesian and Gvec
+c eigenvector space
+
+        do i=1,dimen3
+          vtnp_(i)=0.0d0
+          vtnp_a(i)=0.0d0
+          do j=1,dimen3
+            vtnp_(i)=vtnp_(i)+Gvec(j,i)*vtnp(j)
+            vtnp_a(i)=vtnp_a(i)+A(i,j)*vtnp(j)
+          enddo
+          vtnp_(i)=vtnp_(i)*dsqrt(geigen(i))
+        enddo
+
+        do i=1,dimen3
+         write (iout,'("WWW",i3,3f10.5)') i,vtnp(i),vtnp_(i),vtnp_a(i)
+        enddo
+
+       endif
+      endif
       endif
       return
       end
@@ -1663,6 +1914,20 @@ c Removing the velocity of the center of mass
 #endif
 #endif
       potE=potEcomp(0)
+      if(tnp .or. tnp1) then
+       s_np=1.0
+       pi_np=0.0
+       HNose1=Hnose(EK,s_np,potE,pi_np,Q_np,t_bath,dimen3)
+       H0=Hnose1
+       write(iout,*) 'H0= ',H0
+      endif
+
+      if(tnh) then
+       HNose1=Hnose_nh(EK,potE)
+       H0=HNose1
+       write (iout,*) 'H0= ',H0
+      endif
+
       call cartgrad
       call lagrangian
       call max_accel
@@ -1734,6 +1999,16 @@ c        write (iout,*) "dc_old",i,(dc_old(j,i),j=1,3)
         t_eshort=t_eshort+tcpu()-tt0
 #endif
 #endif
+        if(tnp .or. tnp1) then
+         E_short=energia_short(0)
+         HNose1=Hnose(EK,s_np,E_short,pi_np,Q_np,t_bath,dimen3)
+         Csplit=Hnose1
+c         Csplit =110
+c_new_var_csplit          Csplit=H0-E_long 
+c          Csplit = H0-energia_short(0)
+          write(iout,*) 'Csplit= ',Csplit
+        endif
+
         call cartgrad
         call lagrangian
         if(.not.out1file .and. large) then
@@ -2492,3 +2767,667 @@ c          ddt2=ddt2+vrand_mat2(i,j)*stochforcvecV(j)
       return
       end
 #endif
+      double precision function HNose(ek,s,e,pi,Q,t_bath,dimenl)
+      implicit none
+      double precision ek,s,e,pi,Q,t_bath,Rb
+      integer dimenl
+      Rb=0.001986d0
+      HNose=ek+e+pi**2/(2*Q)+dimenl*Rb*t_bath*log(s)
+c      print '(6f15.5,i5,a2,2f15.5)',ek,s,e,pi,Q,t_bath,dimenl,"--",
+c     &      pi**2/(2*Q),dimenl*Rb*t_bath*log(s)
+      return
+      end
+c-----------------------------------------------------------------
+      double precision function HNose_nh(eki,e)
+      implicit real*8 (a-h,o-z)
+      include 'DIMENSIONS'
+      include 'COMMON.MD'
+      HNose_nh=eki+e+dimen3*Rb*t_bath*xlogs(1)+qmass(1)*vlogs(1)**2/2
+      do i=2,nnos
+        HNose_nh=HNose_nh+qmass(i)*vlogs(i)**2/2+Rb*t_bath*xlogs(i)
+      enddo
+c      write(4,'(5e15.5)') 
+c     &       vlogs(1),xlogs(1),HNose,eki,e
+      return
+      end
+c-----------------------------------------------------------------
+      SUBROUTINE NHCINT(akin,scale,wdti,wdti2,wdti4,wdti8)
+      implicit real*8 (a-h,o-z)
+      include 'DIMENSIONS'
+      include 'COMMON.MD'
+      double precision akin,gnkt,dt,aa,gkt,scale
+      double precision wdti(maxyosh),wdti2(maxyosh),
+     &                 wdti4(maxyosh),wdti8(maxyosh)
+      integer i,iresn,iyosh,inos,nnos1
+
+      dt=d_time
+      nnos1=nnos+1
+      GKT = Rb*t_bath
+      GNKT = dimen3*GKT
+      akin=akin*2
+
+      
+C THIS ROUTINE DOES THE NOSE-HOOVER PART OF THE
+C INTEGRATION FROM t=0 TO t=DT/2
+C GET THE TOTAL KINETIC ENERGY
+      SCALE = 1.D0
+c      CALL GETKINP(MASS,VX,VY,VZ,AKIN)
+C UPDATE THE FORCES
+      GLOGS(1) = (AKIN - GNKT)/QMASS(1)
+C START THE MULTIPLE TIME STEP PROCEDURE
+      DO IRESN = 1,NRESN
+       DO IYOSH = 1,NYOSH
+C UPDATE THE THERMOSTAT VELOCITIES
+        VLOGS(NNOS) = VLOGS(NNOS) + GLOGS(NNOS)*WDTI4(IYOSH)
+        DO INOS = 1,NNOS-1
+         AA = EXP(-WDTI8(IYOSH)*VLOGS(NNOS1-INOS) )
+         VLOGS(NNOS-INOS) = VLOGS(NNOS-INOS)*AA*AA
+     &          + WDTI4(IYOSH)*GLOGS(NNOS-INOS)*AA
+        ENDDO
+C UPDATE THE PARTICLE VELOCITIES
+        AA = EXP(-WDTI2(IYOSH)*VLOGS(1) )
+        SCALE = SCALE*AA
+C UPDATE THE FORCES
+        GLOGS(1) = (SCALE*SCALE*AKIN - GNKT)/QMASS(1)
+C UPDATE THE THERMOSTAT POSITIONS
+        DO INOS = 1,NNOS
+         XLOGS(INOS) = XLOGS(INOS) + VLOGS(INOS)*WDTI2(IYOSH)
+        ENDDO
+C UPDATE THE THERMOSTAT VELOCITIES
+        DO INOS = 1,NNOS-1
+         AA = EXP(-WDTI8(IYOSH)*VLOGS(INOS+1) )
+         VLOGS(INOS) = VLOGS(INOS)*AA*AA
+     &      + WDTI4(IYOSH)*GLOGS(INOS)*AA
+         GLOGS(INOS+1) = (QMASS(INOS)*VLOGS(INOS)*VLOGS(INOS)
+     &      -GKT)/QMASS(INOS+1)
+        ENDDO
+        VLOGS(NNOS) = VLOGS(NNOS) + GLOGS(NNOS)*WDTI4(IYOSH)
+       ENDDO
+      ENDDO
+C UPDATE THE PARTICLE VELOCITIES
+c outside of this subroutine
+c      DO I = 1,N
+c       VX(I) = VX(I)*SCALE
+c       VY(I) = VY(I)*SCALE
+c       VZ(I) = VZ(I)*SCALE
+c      ENDDO
+      RETURN
+      END
+c-----------------------------------------------------------------
+      subroutine tnp1_respa_i_step1
+c Applying Nose-Poincare algorithm - step 1 to coordinates
+c JPSJ 70 75 (2001) S. Nose
+c
+c d_t is not updated here
+c
+      implicit real*8 (a-h,o-z)
+      include 'DIMENSIONS'
+      include 'COMMON.CONTROL'
+      include 'COMMON.VAR'
+      include 'COMMON.MD'
+      include 'COMMON.CHAIN'
+      include 'COMMON.DERIV'
+      include 'COMMON.GEO'
+      include 'COMMON.LOCAL'
+      include 'COMMON.INTERACT'
+      include 'COMMON.IOUNITS'
+      include 'COMMON.NAMES'
+      double precision adt,adt2,tmp
+        
+      tmp=1+pi_np/(2*Q_np)*0.5*d_time
+      s12_np=s_np*tmp**2
+      pistar=pi_np/tmp
+      s12_dt=d_time/s12_np
+      d_time_s12=d_time*0.5*s12_np
+
+      do j=1,3
+        d_t_new(j,0)=d_t_old(j,0)+d_a_old(j,0)*d_time_s12
+        dc(j,0)=dc_old(j,0)+d_t_new(j,0)*s12_dt
+      enddo
+      do i=nnt,nct-1   
+        do j=1,3    
+          d_t_new(j,i)=d_t_old(j,i)+d_a_old(j,i)*d_time_s12
+          dc(j,i)=dc_old(j,i)+d_t_new(j,i)*s12_dt
+        enddo
+      enddo
+      do i=nnt,nct
+        if (itype(i).ne.10) then
+          inres=i+nres
+          do j=1,3    
+           d_t_new(j,inres)=d_t_old(j,inres)+d_a_old(j,inres)*d_time_s12
+           dc(j,inres)=dc_old(j,inres)+d_t_new(j,inres)*s12_dt
+          enddo
+        endif      
+      enddo 
+      return
+      end
+c---------------------------------------------------------------------
+      subroutine tnp1_respa_i_step2
+c  Step 2 of the velocity Verlet algorithm: update velocities
+      implicit real*8 (a-h,o-z)
+      include 'DIMENSIONS'
+      include 'COMMON.CONTROL'
+      include 'COMMON.VAR'
+      include 'COMMON.MD'
+      include 'COMMON.CHAIN'
+      include 'COMMON.DERIV'
+      include 'COMMON.GEO'
+      include 'COMMON.LOCAL'
+      include 'COMMON.INTERACT'
+      include 'COMMON.IOUNITS'
+      include 'COMMON.NAMES'
+
+      double precision d_time_s12
+
+      do i=0,2*nres
+       do j=1,3
+        d_t(j,i)=d_t_new(j,i)
+       enddo
+      enddo
+
+      call kinetic(EK)
+      EK=EK/s12_np**2
+
+      d_time_s12=0.5d0*s12_np*d_time
+
+      do j=1,3
+        d_t(j,0)=d_t_new(j,0)+d_a(j,0)*d_time_s12
+      enddo
+      do i=nnt,nct-1
+        do j=1,3
+          d_t(j,i)=d_t_new(j,i)+d_a(j,i)*d_time_s12
+        enddo
+      enddo
+      do i=nnt,nct
+        if (itype(i).ne.10) then
+          inres=i+nres
+          do j=1,3
+            d_t(j,inres)=d_t_new(j,inres)+d_a(j,inres)*d_time_s12
+          enddo
+        endif
+      enddo 
+
+      pistar=pistar+(EK-0.5*(E_old+potE)
+     &       -dimen3*Rb*t_bath*log(s12_np)+Csplit-dimen3*Rb*t_bath)*d_time
+      tmp=1+pistar/(2*Q_np)*0.5*d_time
+      s_np=s12_np*tmp**2
+      pi_np=pistar/tmp
+
+      return
+      end
+c-------------------------------------------------------
+
+      subroutine tnp1_step1
+c Applying Nose-Poincare algorithm - step 1 to coordinates
+c JPSJ 70 75 (2001) S. Nose
+c
+c d_t is not updated here
+c
+      implicit real*8 (a-h,o-z)
+      include 'DIMENSIONS'
+      include 'COMMON.CONTROL'
+      include 'COMMON.VAR'
+      include 'COMMON.MD'
+      include 'COMMON.CHAIN'
+      include 'COMMON.DERIV'
+      include 'COMMON.GEO'
+      include 'COMMON.LOCAL'
+      include 'COMMON.INTERACT'
+      include 'COMMON.IOUNITS'
+      include 'COMMON.NAMES'
+      double precision adt,adt2,tmp
+        
+      tmp=1+pi_np/(2*Q_np)*0.5*d_time
+      s12_np=s_np*tmp**2
+      pistar=pi_np/tmp
+      s12_dt=d_time/s12_np
+      d_time_s12=d_time*0.5*s12_np
+
+      do j=1,3
+        d_t_new(j,0)=d_t_old(j,0)+d_a_old(j,0)*d_time_s12
+        dc(j,0)=dc_old(j,0)+d_t_new(j,0)*s12_dt
+      enddo
+      do i=nnt,nct-1   
+        do j=1,3    
+          d_t_new(j,i)=d_t_old(j,i)+d_a_old(j,i)*d_time_s12
+          dc(j,i)=dc_old(j,i)+d_t_new(j,i)*s12_dt
+        enddo
+      enddo
+      do i=nnt,nct
+        if (itype(i).ne.10) then
+          inres=i+nres
+          do j=1,3    
+           d_t_new(j,inres)=d_t_old(j,inres)+d_a_old(j,inres)*d_time_s12
+           dc(j,inres)=dc_old(j,inres)+d_t_new(j,inres)*s12_dt
+          enddo
+        endif      
+      enddo 
+      return
+      end
+c---------------------------------------------------------------------
+      subroutine tnp1_step2
+c  Step 2 of the velocity Verlet algorithm: update velocities
+      implicit real*8 (a-h,o-z)
+      include 'DIMENSIONS'
+      include 'COMMON.CONTROL'
+      include 'COMMON.VAR'
+      include 'COMMON.MD'
+      include 'COMMON.CHAIN'
+      include 'COMMON.DERIV'
+      include 'COMMON.GEO'
+      include 'COMMON.LOCAL'
+      include 'COMMON.INTERACT'
+      include 'COMMON.IOUNITS'
+      include 'COMMON.NAMES'
+
+      double precision d_time_s12
+
+      do i=0,2*nres
+       do j=1,3
+        d_t(j,i)=d_t_new(j,i)
+       enddo
+      enddo
+
+      call kinetic(EK)
+      EK=EK/s12_np**2
+
+      d_time_s12=0.5d0*s12_np*d_time
+
+      do j=1,3
+        d_t(j,0)=d_t_new(j,0)+d_a(j,0)*d_time_s12
+      enddo
+      do i=nnt,nct-1
+        do j=1,3
+          d_t(j,i)=d_t_new(j,i)+d_a(j,i)*d_time_s12
+        enddo
+      enddo
+      do i=nnt,nct
+        if (itype(i).ne.10) then
+          inres=i+nres
+          do j=1,3
+            d_t(j,inres)=d_t_new(j,inres)+d_a(j,inres)*d_time_s12
+          enddo
+        endif
+      enddo 
+
+cd      write(iout,*) 'pistar',pistar,EK,E_old,potE,s12_np
+      pistar=pistar+(EK-0.5*(E_old+potE)
+     &       -dimen3*Rb*t_bath*log(s12_np)+H0-dimen3*Rb*t_bath)*d_time
+      tmp=1+pistar/(2*Q_np)*0.5*d_time
+      s_np=s12_np*tmp**2
+      pi_np=pistar/tmp
+
+      return
+      end
+
+c-----------------------------------------------------------------
+      subroutine tnp_respa_i_step1
+c Applying Nose-Poincare algorithm - step 1 to coordinates
+c J.Comput.Phys. 151 114 (1999) S.D.Bond B.J.Leimkuhler B.B.Laird
+c
+c d_t is not updated here, it is destroyed
+c
+      implicit real*8 (a-h,o-z)
+      include 'DIMENSIONS'
+      include 'COMMON.CONTROL'
+      include 'COMMON.VAR'
+      include 'COMMON.MD'
+      include 'COMMON.CHAIN'
+      include 'COMMON.DERIV'
+      include 'COMMON.GEO'
+      include 'COMMON.LOCAL'
+      include 'COMMON.INTERACT'
+      include 'COMMON.IOUNITS'
+      include 'COMMON.NAMES'
+      double precision C_np,d_time_s,tmp,d_time_ss
+
+      d_time_s=d_time*0.5*s_np        
+ct2      d_time_s=d_time*0.5*s12_np
+
+      do j=1,3
+        d_t_new(j,0)=d_t_old(j,0)+d_a_old(j,0)*d_time_s
+      enddo
+      do i=nnt,nct-1   
+        do j=1,3    
+          d_t_new(j,i)=d_t_old(j,i)+d_a_old(j,i)*d_time_s
+        enddo
+      enddo
+      do i=nnt,nct
+        if (itype(i).ne.10) then
+          inres=i+nres
+          do j=1,3    
+           d_t_new(j,inres)=d_t_old(j,inres)+d_a_old(j,inres)*d_time_s
+          enddo
+        endif      
+      enddo 
+
+      do i=0,2*nres
+       do j=1,3
+        d_t(j,i)=d_t_new(j,i)
+       enddo
+      enddo
+
+      call kinetic(EK)
+      EK=EK/s_np**2
+
+      C_np=0.5*d_time*(dimen3*Rb*t_bath*(1.0+log(s_np))-EK+potE-Csplit)
+     &                     -pi_np
+
+      pistar=-2.0*C_np/(1.0+sqrt(1.0-C_np*d_time/Q_np))
+      tmp=0.5*d_time*pistar/Q_np
+      s12_np=s_np*(1.0+tmp)/(1.0-tmp)
+
+      d_time_ss=0.5*d_time*(1.0/s12_np+1.0/s_np)
+ct2      d_time_ss=d_time/s12_np
+c      d_time_ss=0.5*d_time*(1.0/sold_np+1.0/s_np) 
+
+      do j=1,3
+        dc(j,0)=dc_old(j,0)+d_t_new(j,0)*d_time_ss
+      enddo
+      do i=nnt,nct-1   
+        do j=1,3    
+          dc(j,i)=dc_old(j,i)+d_t_new(j,i)*d_time_ss
+        enddo
+      enddo
+      do i=nnt,nct
+        if (itype(i).ne.10) then
+          inres=i+nres
+          do j=1,3    
+           dc(j,inres)=dc_old(j,inres)+d_t_new(j,inres)*d_time_ss
+          enddo
+        endif      
+      enddo 
+
+      return
+      end
+c---------------------------------------------------------------------
+
+      subroutine tnp_respa_i_step2
+c  Step 2 of the velocity Verlet algorithm: update velocities
+      implicit real*8 (a-h,o-z)
+      include 'DIMENSIONS'
+      include 'COMMON.CONTROL'
+      include 'COMMON.VAR'
+      include 'COMMON.MD'
+      include 'COMMON.CHAIN'
+      include 'COMMON.DERIV'
+      include 'COMMON.GEO'
+      include 'COMMON.LOCAL'
+      include 'COMMON.INTERACT'
+      include 'COMMON.IOUNITS'
+      include 'COMMON.NAMES'
+
+      double precision d_time_s
+
+      EK=EK*(s_np/s12_np)**2
+      HNose1=Hnose(EK,s12_np,potE,pistar,Q_np,t_bath,dimen3)
+      pi_np=pistar+0.5*d_time*(2*EK-dimen3*Rb*t_bath
+     &                              -HNose1+Csplit)         
+
+cr      print '(a,5f)','i_step2',EK,potE,HNose1,pi_np,E_long
+      d_time_s=d_time*0.5*s12_np
+c      d_time_s=d_time*0.5*s_np
+
+      do j=1,3
+        d_t(j,0)=d_t_new(j,0)+d_a(j,0)*d_time_s
+      enddo
+      do i=nnt,nct-1
+        do j=1,3
+          d_t(j,i)=d_t_new(j,i)+d_a(j,i)*d_time_s
+        enddo
+      enddo
+      do i=nnt,nct
+        if (itype(i).ne.10) then
+          inres=i+nres
+          do j=1,3
+            d_t(j,inres)=d_t_new(j,inres)+d_a(j,inres)*d_time_s
+          enddo
+        endif
+      enddo 
+
+      s_np=s12_np
+
+      return
+      end
+c-----------------------------------------------------------------
+      subroutine tnp_respa_step1
+c Applying Nose-Poincare algorithm - step 1 to vel for RESPA
+c J.Comput.Phys. 151 114 (1999) S.D.Bond B.J.Leimkuhler B.B.Laird
+c
+c d_t is not updated here, it is destroyed
+c
+      implicit real*8 (a-h,o-z)
+      include 'DIMENSIONS'
+      include 'COMMON.CONTROL'
+      include 'COMMON.VAR'
+      include 'COMMON.MD'
+      include 'COMMON.CHAIN'
+      include 'COMMON.DERIV'
+      include 'COMMON.GEO'
+      include 'COMMON.LOCAL'
+      include 'COMMON.INTERACT'
+      include 'COMMON.IOUNITS'
+      include 'COMMON.NAMES'
+      double precision C_np,d_time_s,tmp,d_time_ss
+      double precision energia(0:n_ene)
+
+      d_time_s=d_time*0.5*s_np        
+
+      do j=1,3
+        d_t_old(j,0)=d_t_old(j,0)+d_a(j,0)*d_time_s
+      enddo
+      do i=nnt,nct-1   
+        do j=1,3    
+          d_t_old(j,i)=d_t_old(j,i)+d_a(j,i)*d_time_s
+        enddo
+      enddo
+      do i=nnt,nct
+        if (itype(i).ne.10) then
+          inres=i+nres
+          do j=1,3    
+           d_t_old(j,inres)=d_t_old(j,inres)+d_a(j,inres)*d_time_s
+          enddo
+        endif      
+      enddo 
+
+
+c      C_np=0.5*d_time*(dimen3*Rb*t_bath*(1.0+log(s_np))-EK+potE-H0)
+c     &                     -pi_np
+c
+c      pistar=-2.0*C_np/(1.0+sqrt(1.0-C_np*d_time/Q_np))
+c      tmp=0.5*d_time*pistar/Q_np
+c      s12_np=s_np*(1.0+tmp)/(1.0-tmp)
+c      write(iout,*) 'tnp_respa_step1',s_np,s12_np,EK,potE,C_np,pistar,tmp
+
+ct1      pi_np=pistar
+c      sold_np=s_np
+c      s_np=s12_np
+
+c-------------------------------------
+c test of reviewer's comment
+       pi_np=pi_np-0.5*d_time*(E_long+Csplit-H0)
+cr       print '(a,3f)','1 pi_np,s_np',pi_np,s_np,E_long
+c-------------------------------------
+
+      return
+      end
+c---------------------------------------------------------------------
+      subroutine tnp_respa_step2
+c  Step 2 of the velocity Verlet algorithm: update velocities for RESPA
+      implicit real*8 (a-h,o-z)
+      include 'DIMENSIONS'
+      include 'COMMON.CONTROL'
+      include 'COMMON.VAR'
+      include 'COMMON.MD'
+      include 'COMMON.CHAIN'
+      include 'COMMON.DERIV'
+      include 'COMMON.GEO'
+      include 'COMMON.LOCAL'
+      include 'COMMON.INTERACT'
+      include 'COMMON.IOUNITS'
+      include 'COMMON.NAMES'
+
+      double precision d_time_s
+
+ct1      s12_np=s_np
+ct2      pistar=pi_np
+
+ct      call kinetic(EK)
+ct      HNose1=Hnose(EK,s12_np,potE,pistar,Q_np,t_bath,dimen3)
+ct      pi_np=pistar+0.5*d_time*(2*EK-dimen3*Rb*t_bath)
+ct     &                              -0.5*d_time*(HNose1-H0)         
+
+c-------------------------------------
+c test of reviewer's comment
+      pi_np=pi_np-0.5*d_time*(E_long+Csplit-H0)
+cr      print '(a,3f)','2 pi_np,s_np',pi_np,s_np,E_long
+c-------------------------------------
+      d_time_s=d_time*0.5*s_np
+
+      do j=1,3
+        d_t_old(j,0)=d_t_old(j,0)+d_a(j,0)*d_time_s
+      enddo
+      do i=nnt,nct-1
+        do j=1,3
+          d_t_old(j,i)=d_t_old(j,i)+d_a(j,i)*d_time_s
+        enddo
+      enddo
+      do i=nnt,nct
+        if (itype(i).ne.10) then
+          inres=i+nres
+          do j=1,3
+            d_t_old(j,inres)=d_t_old(j,inres)+d_a(j,inres)*d_time_s
+          enddo
+        endif
+      enddo 
+
+cd      s_np=s12_np
+
+      return
+      end
+c---------------------------------------------------------------------
+      subroutine tnp_step1
+c Applying Nose-Poincare algorithm - step 1 to coordinates
+c J.Comput.Phys. 151 114 (1999) S.D.Bond B.J.Leimkuhler B.B.Laird
+c
+c d_t is not updated here, it is destroyed
+c
+      implicit real*8 (a-h,o-z)
+      include 'DIMENSIONS'
+      include 'COMMON.CONTROL'
+      include 'COMMON.VAR'
+      include 'COMMON.MD'
+      include 'COMMON.CHAIN'
+      include 'COMMON.DERIV'
+      include 'COMMON.GEO'
+      include 'COMMON.LOCAL'
+      include 'COMMON.INTERACT'
+      include 'COMMON.IOUNITS'
+      include 'COMMON.NAMES'
+      double precision C_np,d_time_s,tmp,d_time_ss
+
+      d_time_s=d_time*0.5*s_np        
+
+      do j=1,3
+        d_t_new(j,0)=d_t_old(j,0)+d_a_old(j,0)*d_time_s
+      enddo
+      do i=nnt,nct-1   
+        do j=1,3    
+          d_t_new(j,i)=d_t_old(j,i)+d_a_old(j,i)*d_time_s
+        enddo
+      enddo
+      do i=nnt,nct
+        if (itype(i).ne.10) then
+          inres=i+nres
+          do j=1,3    
+           d_t_new(j,inres)=d_t_old(j,inres)+d_a_old(j,inres)*d_time_s
+          enddo
+        endif      
+      enddo 
+
+      do i=0,2*nres
+       do j=1,3
+        d_t(j,i)=d_t_new(j,i)
+       enddo
+      enddo
+
+      call kinetic(EK)
+      EK=EK/s_np**2
+
+      C_np=0.5*d_time*(dimen3*Rb*t_bath*(1.0+log(s_np))-EK+potE-H0)
+     &                     -pi_np
+
+      pistar=-2.0*C_np/(1.0+sqrt(1.0-C_np*d_time/Q_np))
+      tmp=0.5*d_time*pistar/Q_np
+      s12_np=s_np*(1.0+tmp)/(1.0-tmp)
+c      write(iout,*) 'tnp_step1',s_np,s12_np,EK,potE,C_np,pistar,tmp
+
+      d_time_ss=0.5*d_time*(1.0/s12_np+1.0/s_np)
+
+      do j=1,3
+        dc(j,0)=dc_old(j,0)+d_t_new(j,0)*d_time_ss
+      enddo
+      do i=nnt,nct-1   
+        do j=1,3    
+          dc(j,i)=dc_old(j,i)+d_t_new(j,i)*d_time_ss
+        enddo
+      enddo
+      do i=nnt,nct
+        if (itype(i).ne.10) then
+          inres=i+nres
+          do j=1,3    
+           dc(j,inres)=dc_old(j,inres)+d_t_new(j,inres)*d_time_ss
+          enddo
+        endif      
+      enddo 
+
+      return
+      end
+c-----------------------------------------------------------------
+      subroutine tnp_step2
+c  Step 2 of the velocity Verlet algorithm: update velocities
+      implicit real*8 (a-h,o-z)
+      include 'DIMENSIONS'
+      include 'COMMON.CONTROL'
+      include 'COMMON.VAR'
+      include 'COMMON.MD'
+      include 'COMMON.CHAIN'
+      include 'COMMON.DERIV'
+      include 'COMMON.GEO'
+      include 'COMMON.LOCAL'
+      include 'COMMON.INTERACT'
+      include 'COMMON.IOUNITS'
+      include 'COMMON.NAMES'
+
+      double precision d_time_s
+
+      EK=EK*(s_np/s12_np)**2
+      HNose1=Hnose(EK,s12_np,potE,pistar,Q_np,t_bath,dimen3)
+      pi_np=pistar+0.5*d_time*(2*EK-dimen3*Rb*t_bath)
+     &                              -0.5*d_time*(HNose1-H0)         
+
+cd      write(iout,'(a,4f)') 'mmm',EK,potE,HNose1,pi_np
+      d_time_s=d_time*0.5*s12_np
+
+      do j=1,3
+        d_t(j,0)=d_t_new(j,0)+d_a(j,0)*d_time_s
+      enddo
+      do i=nnt,nct-1
+        do j=1,3
+          d_t(j,i)=d_t_new(j,i)+d_a(j,i)*d_time_s
+        enddo
+      enddo
+      do i=nnt,nct
+        if (itype(i).ne.10) then
+          inres=i+nres
+          do j=1,3
+            d_t(j,inres)=d_t_new(j,inres)+d_a(j,inres)*d_time_s
+          enddo
+        endif
+      enddo 
+
+      s_np=s12_np
+
+      return
+      end
+