#!/usr/bin/env bash
LMPSEXEC=lmp
N=31
LATLO=2.2
STRIDE=0.05
OUTFILE="elat.out"

rm -f $OUTFILE
for (( i = 0; i < ${N}; i++ ));
do

  latconst=$( echo $LATLO+$i*$STRIDE | bc )
  echo -n  $latconst "   ">> $OUTFILE

  cat > in.al << EOF
units metal 
dimension 3 
boundary p p p 
atom_style atomic 
lattice     bcc ${latconst}
region  box block 0 1 0 1 0 1 units lattice
create_box  1 box
create_atoms 1 box
replicate 1 1 1
pair_style eam/alloy 
pair_coeff * * ./Fe_mm.eam.fs Fe
neighbor 2.0 bin 
neigh_modify delay 10 check yes 
thermo_style custom step pe lx ly lz press pxx pyy pzz pe
run 0

variable natoms equal "count(all)" 
variable teng equal "pe"
variable length equal "lx"
variable ecoh equal "v_teng/v_natoms"
print "Total energy (eV) = \${teng};"
EOF

  $LMPSEXEC -var latconst $latconst < in.al > temp.out
  grep "Total energy" temp.out | cut -d' ' -f 5 >> $OUTFILE
  rm temp.out in.al

done
