Adam's update from okeanos
[unres.git] / source / unres / src-HCD-5D / gradient_p.F
index 82b8c34..adafa53 100644 (file)
@@ -335,6 +335,11 @@ c---------------------------------------------------------------------------
       integer i,j,kk
 #ifdef DEBUG
       write (iout,*)"Converting virtual-bond gradient to CA/SC gradient"
+      write (iout,*) "dC/dX gradient"
+      do i=0,nres
+        write (iout,'(i5,3f10.5,5x,3f10.5)') i,(gcart(j,i),j=1,3),
+     &      (gxcart(j,i),j=1,3)
+      enddo
 #endif
       do i=nres,1,-1
         do j=1,3
@@ -345,17 +350,24 @@ c---------------------------------------------------------------------------
 !            (gcart_new(j,i),j=1,3),(gxcart(j,i),j=1,3)
       enddo
 ! Correction: dummy residues
-      if (nnt.gt.1) then
-        do j=1,3
-          gcart(j,nnt)=gcart(j,nnt)+gcart(j,1)
-        enddo
-      endif
-      if (nct.lt.nres) then
-        do j=1,3
-!          gcart_new(j,nct)=gcart_new(j,nct)+gcart_new(j,nres)
-          gcart(j,nct)=gcart(j,nct)+gcart(j,nres)
-        enddo
-      endif
+      do i=2,nres
+        if (itype(i-1).eq.ntyp1 .and. itype(i).ne.ntyp1) then
+          gcart(:,i)=gcart(:,i)+gcart(:,i-1)
+        else if (itype(i-1).ne.ntyp1 .and. itype(i).eq.ntyp1) then
+          gcart(:,i-1)=gcart(:,i-1)+gcart(:,i)
+        endif
+      enddo
+c      if (nnt.gt.1) then
+c        do j=1,3
+c          gcart(j,nnt)=gcart(j,nnt)+gcart(j,1)
+c        enddo
+c      endif
+c      if (nct.lt.nres) then
+c        do j=1,3
+c!          gcart_new(j,nct)=gcart_new(j,nct)+gcart_new(j,nres)
+c          gcart(j,nct)=gcart(j,nct)+gcart(j,nres)
+c        enddo
+c      endif
 #ifdef DEBUG
       write (iout,*) "CA/SC gradient"
       do i=1,nres