do i=iturn3_start,iturn3_end
if (itype(i).eq.ntyp1 .or. itype(i+1).eq.ntyp1
& .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)