#!/bin/sh

if [ -z "$1" ] ; then
    echo "No argument supplied - number of atoms required"
    exit 1
else
    echo doing $1 atoms
fi

natoms=$1
lines=`wc redopoints | awk '{print $1}'`
echo lines in redopints file $lines
lines2=$((lines-natoms))
twonts=$((lines2 / natoms))
npaths=$((twonts / 2))
echo number of ts in reopoints file is $nts
count=1
cp redopoints temp
while [ $count -le $npaths ] ; do
   
   echo doing path $count of $npaths - lines left `wc temp`
   mkdir -p $count
   cp odata.path $count/odata
   cp perm.allow min.in coords.prmtop coords.inpcrd $count
   cp sbatch.optim $count
   sed -e "1,${natoms} d" temp > temp2
   head -$natoms temp2 > $count/start
   cd $count
   sbatch sbatch.optim
   cd ..
   sed -e "1,${natoms} d" temp2 > temp
   echo lines in temp2: `wc temp2`
   ((count++))

done

