#!/bin/bash
-free_si_250=-0.70036911
-free_si_650=-0.70021403
-free_c_650=-1.3535731
-
file=$1
[ -d $1 ] && file=$1/OUTCAR
+echo "parsing file $file ..."
+
sicnt=`grep 'ions per' $file | awk '{ print $5 }'`
ccnt=`grep 'ions per' $file | awk '{ print $6 }'`
-
+[ -z $ccnt ] && ccnt=0
((total=sicnt+ccnt))
-
-echo "parsing file $file ..."
echo " Si: $sicnt, C: $ccnt, total: $total"
+cutoff=`grep ENCUT $file | awk '{ print $3 }' | awk -F. '{ print $1 }'`
+echo " cutoff: $cutoff eV"
+
+pawpp=`grep POTCAR $file | tail -1 | awk '{ print $2 }'`
+if [ "$pawpp" = "PAW_GGA" ]; then
+ ext=_paw_gga
+ echo " GGA and PAW"
+fi
+if [ "$pawpp" = "PAW" ]; then
+ ext=_paw
+ echo " LDA and PAW"
+fi
+if [ "$pawpp" = "US" ]; then
+ help=`grep GGA $file | grep eV | tail -1 | awk '{ print $1i }'`
+ if [ -z $help ]; then
+ ext=_gga
+ echo " GGA and PP"
+ else
+ ext=""
+ echo " LDA and PP"
+ fi
+fi
+
cnt=0
tcnt=0
energy=`grep energy\ without $file | tail -1 | awk '{ print $8 }'`
+sifile=free_atoms/si_free_${cutoff}${ext}/OUTCAR
+cfile=free_atoms/c_free_${cutoff}${ext}/OUTCAR
+
+if [ ! -f $sifile ]; then
+ echo
+ echo "$sifile not found ..."
+ echo
+ exit
+fi
+
+if [ ! -f $cfile ]; then
+ echo
+ echo "$cfile not found ..."
+ echo
+ exit
+fi
+
+free_si=`grep energy\ without $sifile | tail -1 | awk '{ print $8 }'`
+free_c=`grep energy\ without $cfile | tail -1 | awk '{ print $8 }'`
+echo " Si correction: $free_si eV, C correction: $free_c eV"
+
+
echo $energy $total | \
awk '{ print " total e: " $1 " eV, per atom: " $1/$2 " eV"}'
-echo "$energy $total $free_si_250" | \
- awk '{ print " cohesive energy (Si only 250): " ($1-$2*$3)/$2 " eV" }'
-echo "$energy $sicnt $ccnt $free_si_650 $free_c_650" | \
- awk '{ print " cohesive energy (Si and C 650): " ($1-$2*$4-$3*$5)/($2+$3) " eV" }'
+echo "$energy $sicnt $ccnt $free_si $free_c" | \
+ awk '{ print " cohesive energy (Si and C): " ($1-$2*$4-$3*$5)/($2+$3) " eV" }'
+echo "$energy $sicnt $free_c" | \
+ awk '{ print " cohesive energy (C only): " ($1-$2*$3)/$2 " eV" }'
+#echo "$energy $total $free_si_250" | \
+# awk '{ print " cohesive energy (Si only 250): " ($1-$2*$3)/$2 " eV" }'
+#echo "$energy $sicnt $free_c_650" | \
+# awk '{ print " cohesive energy (C only 650): " ($1-$2*$3)/($2) " eV" }'
+#echo "$energy $sicnt $ccnt $free_si_650 $free_c_650" | \
+# awk '{ print " cohesive energy (Si and C 650): " ($1-$2*$4-$3*$5)/($2+$3) " eV" }'
#echo "$energy $total" | \
# awk '{ print " Si:C -> cohesive energy: "$1/$2 " eV" }'