+ do j=1,3
+ ccm(j)=ccm(j)/nrestot
+ enddo
+#ifdef DEBUG
+ write (iout,'(a,3f10.5)') "ccm ",(ccm(j),j=1,3)
+ write (iout,'(a,3f10.5)') "ccm_prev",(ccm_prev(j),j=1,3)
+ write (iout,'(a,3f10.5)') "diff ",(ccm(j)-ccm_prev(j),j=1,3)
+ write (iout,*) "shift_coord"
+ do i=1,nchain
+ write (iout,'(i5,3f10.5)') i,(shift_coord(j,i),j=1,3)
+ enddo
+#endif;
+#ifdef PREVIOUS
+c
+c Shift the system by box dimensions so that its CM be closest to the
+c CM of the pevious snapshot
+c
+ if (previous) then
+ do j=1,3
+ change=.true.
+ do while (change)
+ if (ccm(j)-ccm_prev(j).gt.boxsize(j)/2) then
+ do ichain=1,nchain
+ shift_coord(j,ichain)=shift_coord(j,ichain)-boxsize(j)
+ enddo
+ ccm(j)=ccm(j)-boxsize(j)
+ else if (ccm(j)-ccm_prev(j).lt.-boxsize(j)/2) then
+ do ichain=1,nchain
+ shift_coord(j,ichain)=shift_coord(j,ichain)+boxsize(j)
+ enddo
+ ccm(j)=ccm(j)+boxsize(j)
+ else
+ change=.false.
+ endif
+ enddo
+ enddo
+ do j=1,3
+ ccm_prev(j)=ccm(j)
+ enddo
+ else
+ previous=.true.
+ do j=1,3
+ ccm_prev(j)=ccm(j)
+ enddo
+ endif
+#else
+c Simply shift the CM of the whole oligomer to the origin of the
+c coordinate system
+ do ichain=1,nchain
+ do j=1,3
+ shift_coord(j,ichain)=shift_coord(j,ichain)-ccm(j)
+ enddo
+ enddo
+#endif
+#ifdef DEBUG
+ write (iout,*) "shift_coord"
+ do i=1,nchain
+ write (iout,'(i5,3f10.5)') i,(shift_coord(j,i),j=1,3)
+ enddo
+#endif
+ do ichain=1,nchain
+ do i=chain_border1(1,ichain),chain_border1(2,ichain)
+ do j=1,3
+ c(j,i)=c(j,i)+shift_coord(j,ichain)
+ c(j,i+nres)=c(j,i+nres)+shift_coord(j,ichain)
+ enddo
+ enddo
+ enddo
+