ESSENTIAL CHANGE - BUG FIX in ENERGY to have old Correlation
[unres.git] / source / unres / src_MD-M / energy_p_new_barrier.F
index bfb0b65..3e1eb6e 100644 (file)
@@ -275,6 +275,8 @@ C      print *,"przed lipidami"
 C      print *,"za lipidami"
       if (AFMlog.gt.0) then
         call AFMforce(Eafmforce)
+      else if (selfguide.gt.0) then
+        call AFMvel(Eafmforce)
       endif
 #ifdef TIMING
       time_enecalc=time_enecalc+MPI_Wtime()-time00
@@ -2717,6 +2719,17 @@ c       write(iout,*)  'b1=',b1(1,i-2)
 c       write (iout,*) 'theta=', theta(i-1)
        enddo
 #else
+        if (i.gt. nnt+2 .and. i.lt.nct+2) then
+          iti = itortyp(itype(i-2))
+        else
+          iti=ntortyp+1
+        endif
+c        if (i.gt. iatel_s+1 .and. i.lt.iatel_e+4) then
+        if (i.gt. nnt+1 .and. i.lt.nct+1) then
+          iti1 = itortyp(itype(i-1))
+        else
+          iti1=ntortyp+1
+        endif
         b1(1,i-2)=b(3,iti)
         b1(2,i-2)=b(5,iti)
         b2(1,i-2)=b(2,iti)
@@ -2871,6 +2884,7 @@ c        if (i.gt. iatel_s+1 .and. i.lt.iatel_e+4) then
         do k=1,2
           mu(k,i-2)=Ub2(k,i-2)+b1(k,i-1)
         enddo
+C        write (iout,*) 'mumu',i,b1(1,i-1),Ub2(1,i-2)
 c        write (iout,*) 'mu ',mu(:,i-2),i-2
 cd        write (iout,*) 'mu1',mu1(:,i-2)
 cd        write (iout,*) 'mu2',mu2(:,i-2)
@@ -3283,11 +3297,18 @@ C 14/01/2014 TURN3,TUNR4 does no go under periodic boundry condition
         if (i.le.1) cycle
 C        write(iout,*) "tu jest i",i
         if (itype(i).eq.ntyp1 .or. itype(i+1).eq.ntyp1
+C changes suggested by Ana to avoid out of bounds
+     & .or.((i+4).gt.nres)
+     & .or.((i-1).le.0)
+C end of changes by Ana
      &  .or. itype(i+2).eq.ntyp1
-     &  .or. itype(i+3).eq.ntyp1
-     &  .or. itype(i-1).eq.ntyp1
-     &  .or. itype(i+4).eq.ntyp1
-     &  ) cycle
+     &  .or. itype(i+3).eq.ntyp1) cycle
+        if(i.gt.1)then
+          if(itype(i-1).eq.ntyp1)cycle
+        end if
+        if(i.LT.nres-3)then
+          if (itype(i+4).eq.ntyp1) cycle
+        end if
         dxi=dc(1,i)
         dyi=dc(2,i)
         dzi=dc(3,i)
@@ -3311,6 +3332,10 @@ C        write(iout,*) "tu jest i",i
       do i=iturn4_start,iturn4_end
         if (i.le.1) cycle
         if (itype(i).eq.ntyp1 .or. itype(i+1).eq.ntyp1
+C changes suggested by Ana to avoid out of bounds
+     & .or.((i+5).gt.nres)
+     & .or.((i-1).le.0)
+C end of changes suggested by Ana
      &    .or. itype(i+3).eq.ntyp1
      &    .or. itype(i+4).eq.ntyp1
      &    .or. itype(i+5).eq.ntyp1
@@ -3375,6 +3400,10 @@ c
       do i=iatel_s,iatel_e
         if (i.le.1) cycle
         if (itype(i).eq.ntyp1 .or. itype(i+1).eq.ntyp1
+C changes suggested by Ana to avoid out of bounds
+     & .or.((i+2).gt.nres)
+     & .or.((i-1).le.0)
+C end of changes by Ana
      &  .or. itype(i+2).eq.ntyp1
      &  .or. itype(i-1).eq.ntyp1
      &                ) cycle
@@ -3429,6 +3458,10 @@ c        write (iout,*) 'i',i,' ielstart',ielstart(i),' ielend',ielend(i)
 C          write (iout,*) i,j
          if (j.le.1) cycle
           if (itype(j).eq.ntyp1.or. itype(j+1).eq.ntyp1
+C changes suggested by Ana to avoid out of bounds
+     & .or.((j+2).gt.nres)
+     & .or.((j-1).le.0)
+C end of changes by Ana
      & .or.itype(j+2).eq.ntyp1
      & .or.itype(j-1).eq.ntyp1
      &) cycle
@@ -3966,7 +3999,7 @@ C Contribution to the local-electrostatic energy coming from the i-j pair
      &     +a33*muij(4)
 c          write (iout,*) 'i',i,' j',j,itype(i),itype(j),
 c     &                     ' eel_loc_ij',eel_loc_ij
-c          write(iout,*) 'muije=',muij(1),muij(2),muij(3),muij(4)
+C          write(iout,*) 'muije=',i,j,muij(1),muij(2),muij(3),muij(4)
 C Calculate patrial derivative for theta angle
 #ifdef NEWCORR
          geel_loc_ij=a22*gmuij1(1)
@@ -10273,7 +10306,8 @@ C AFM soubroutine for constant force
 C      print *,'AFM',Eafmforce
       return
       end
-C AFM soubroutine for constant velocity
+C---------------------------------------------------------
+C AFM subroutine with pseudoconstant velocity
        subroutine AFMvel(Eafmforce)
        implicit real*8 (a-h,o-z)
       include 'DIMENSIONS'
@@ -10289,8 +10323,11 @@ C AFM soubroutine for constant velocity
       include 'COMMON.CONTROL'
       include 'COMMON.SPLITELE'
       include 'COMMON.SBRIDGE'
-      include 'COMMON.MD'
       real*8 diffafm(3)
+C Only for check grad COMMENT if not used for checkgrad
+C      totT=3.0d0
+C--------------------------------------------------------
+C      print *,"wchodze"
       dist=0.0d0
       Eafmforce=0.0d0
       do i=1,3
@@ -10298,14 +10335,18 @@ C AFM soubroutine for constant velocity
       dist=dist+diffafm(i)**2
       enddo
       dist=dsqrt(dist)
-      Eafmforce=-(dist-distafminit)
+      Eafmforce=0.5d0*forceAFMconst
+     & *(distafminit+totTafm*velAFMconst-dist)**2
+C      Eafmforce=-forceAFMconst*(dist-distafminit)
       do i=1,3
-      gradafm(i,afmend-1)=-(velconst*diffafm(i)/dist-d_t(i,afmend-1))
-     & /d_time
-      gradafm(i,afmbeg-1)=(velconst*diffafm(i)/dist-d_t(i,afmbeg-1))
-     & /d_time
+      gradafm(i,afmend-1)=-forceAFMconst*
+     &(distafminit+totTafm*velAFMconst-dist)
+     &*diffafm(i)/dist
+      gradafm(i,afmbeg-1)=forceAFMconst*
+     &(distafminit+totTafm*velAFMconst-dist)
+     &*diffafm(i)/dist
       enddo
-C      print *,'AFM',Eafmforce
+C      print *,'AFM',Eafmforce,totTafm*velAFMconst,dist
       return
       end
-      
+