#!/bin/bash
-echo "#### `basename $2` # `basename $1` ####"
-e1=`./e_coh $1 | grep cohesive | awk '{ print $5 }'`
-e2=`./e_coh $2 | grep cohesive | awk '{ print $5 }'`
-count=`./e_coh $2 | grep total\: | awk '{ print $6 }'`
+if [ $# = 2 ]; then
-echo "$e1 $e2 $count" | \
- awk '{ print "formation energy: "($2-$1)*$3 " eV" }'
+echo "Calculation of formation energy (Method 1, single species)"
+echo " Result: `basename $2`, Initial conf: `basename $1`"
+echo
+
+e1only=`./e_coh $1 | grep cohesive | grep only | awk '{ print $5 }'`
+e2only=`./e_coh $2 | grep cohesive | grep only | awk '{ print $5 }'`
+e1and=`./e_coh $1 | grep cohesive | grep and | awk '{ print $6 }'`
+e2and=`./e_coh $2 | grep cohesive | grep and | awk '{ print $6 }'`
+count=`./e_coh $2 | grep ^\ \ Si: | awk '{ print $6 }'`
+
+echo "$e1only $e2only $count" | \
+ awk '{ print " formation energy M1 (Si and C): "($2-$1)*$3 " eV" }'
+echo "$e1and $e2and $count" | \
+ awk '{ print " formation energy M1 (C only): "($2-$1)*$3 " eV" }'
+echo
+
+fi
+
+if [ $# = 3 ]; then
+
+echo "Calculation of formation energy (Method 2, two species)"
+
+e3=`./e_coh $3 | grep cohesive | grep and | awk '{ print $6 }'`
+sicnt=`./e_coh $3 | grep ^\ \ Si: | awk '{ print $2 }' | sed 's/,//'`
+ccnt=`./e_coh $3 | grep ^\ \ Si: | awk '{ print $4 }' | sed 's/,//'`
+et=`echo $e3 $sicnt $ccnt | awk '{ print $1*($2+$3) }'`
+echo " Interstitial configuration: `basename $3` -> $et"
+e1=`./e_coh $1 | grep cohesive | grep and | awk '{ print $6 }'`
+e2=`./e_coh $2 | grep cohesive | grep only | awk '{ print $5 }'`
+echo " Cohesive energies:"
+echo " `basename $1` -> $e1 ($sicnt)"
+echo " `basename $2` -> $e2 ($ccnt)"
+
+((count = sicnt + ccnt))
+
+echo "$et $sicnt $e1 $ccnt $e2" | \
+ awk '{ print " formation energy M2: "$1-$2*$3-$4*$5 " eV" }'
+echo
+
+fi