subroutine oligomer implicit none include "DIMENSIONS" include "COMMON.CHAIN" include "COMMON.INTERACT" include "COMMON.IOUNITS" integer i,ii,ipi,ipj,ipmin,j,jmin,k,ix,iy,iz, & ixmin,iymin,izmin,ir_start,ir_end integer iper(maxchain),iaux double precision dchain,dchainmin,cmchain(3,20) cmchain=0.0d0 do i=1,nchain ii=0 do j=chain_border(1,i),chain_border(2,i) if (itype(j).eq.ntyp1) cycle ii=ii+1 do k=1,3 cmchain(k,i)=cmchain(k,i)+c(k,j) enddo enddo do k=1,3 cmchain(k,i)=cmchain(k,i)/ii enddo enddo do i=1,nchain iper(i)=i enddo do i=1,nchain-1 dchainmin=1.0d10 do j=i+1,nchain ipi=iper(i) ipj=iper(j) do ix=-1,1 do iy=-1,1 do iz=-1,1 dchain=(cmchain(1,ipj)-cmchain(1,ipi)+ix*boxxsize)**2+ & (cmchain(2,ipj)-cmchain(2,ipi)+iy*boxysize)**2+ & (cmchain(3,ipj)-cmchain(3,ipi)+iz*boxzsize)**2 c write (iout,*) "i",i," ipi",ipi," j",j," ipj",ipj," d", c & dsqrt(dchain)," dmin",dsqrt(dchainmin)," jmin",jmin if (dchain.lt.dchainmin) then dchainmin=dchain ixmin=ix iymin=iy izmin=iz jmin=j endif enddo enddo enddo enddo if (ixmin.eq.0 .and. iymin.eq.0 .and. izmin.eq.0) cycle ipj=iper(jmin) cmchain(1,ipj)=cmchain(1,ipj)+ixmin*boxxsize cmchain(2,ipj)=cmchain(2,ipj)+iymin*boxysize cmchain(3,ipj)=cmchain(3,ipj)+izmin*boxzsize ir_start=chain_border(1,ipj) if (ir_start.gt.1) ir_start=ir_start-1 ir_end=chain_border(2,ipj) if (ir_end.lt.nres) ir_end=ir_end+1 do k=ir_start,ir_end c(1,k)=c(1,k)+ixmin*boxxsize c(2,k)=c(2,k)+iymin*boxysize c(3,k)=c(3,k)+izmin*boxzsize c(1,k+nres)=c(1,k+nres)+ixmin*boxxsize c(2,k+nres)=c(2,k+nres)+iymin*boxysize c(3,k+nres)=c(3,k+nres)+izmin*boxzsize enddo c write (iout,*) "jmin",jmin," ipj",ipj, c & " ixmin",ixmin," iymin",iymin," izmin",izmin iaux=iper(i+1) iper(i+1)=iper(jmin) iper(jmin)=iaux enddo return end