Merge branch 'prerelease-3.2.1'
[unres.git] / ctest / prota_unres_energy_check.sh
diff --git a/ctest/prota_unres_energy_check.sh b/ctest/prota_unres_energy_check.sh
new file mode 100755 (executable)
index 0000000..a4185c5
--- /dev/null
@@ -0,0 +1,267 @@
+#!/bin/bash
+#
+# Writen by Dawid JagieÅ‚a and Adam Sieradzan
+# and Cezary Czaplewski
+#
+#
+#----------------------------------------
+# variables
+
+if [[ "$2" =~ "MPI" ]]; then
+ file=$1.out_GB000
+ file_stat=$1_GB000.stat
+else
+ file=$1.out_GB                                        # Output file to search energy value from
+ file_stat=$1_GB.stat
+fi
+
+if [ "$1" == "prota_ENE" ]; then
+ extremediff="10000.0"                 # extreme energy difference, comething went terribly wrong
+ expectenergy="145.1742"       # - expected total energy
+ cutoffdiff="0.01"                     # energy cutoff variation - more then this rises warning  
+elif [ "$1" == "prota_MIN_CART" ]; then
+ extremediff="10.0"                    # extreme energy difference, comething went terribly wrong
+ expectenergy="154.9622"               # - expected total energy
+ cutoffdiff="0.1"                      # energy cutoff variation - more then this rises warning  
+ sumsl_return=`grep SUMSL $file|awk '{print $4}'`
+ echo 'SUMSL return code' $sumsl_return
+ if [ "$sumsl_return" != "4" ]; then
+   echo 'ERROR = SUMSL return code' $sumsl_return 'is not 4'
+   exit 1
+ fi
+elif [ "$1" == "1l2y_MIN_INT" ]; then
+ extremediff="10.0"                    # extreme energy difference, comething went terribly wrong
+ expectenergy="-47.88137"                      # expected total energy
+ cutoffdiff="0.1"                      # energy cutoff variation - more then this rises warning  
+ sumsl_return=`grep SUMSL $file|awk '{print $4}'`
+ echo 'SUMSL return code' $sumsl_return
+ if [ "$sumsl_return" != "4" ]; then
+   echo 'ERROR = SUMSL return code' $sumsl_return 'is not 4'
+   exit 1
+ fi
+elif [ "$1" == "1l2y_MIN_REGULAR_INT" ]; then
+ extremediff="10.0"                    # extreme energy difference, comething went terribly wrong
+ expectenergy="5.258893"                       # expected total energy
+#
+# something wrong with REGULAR and sometimes gives code 8 and different energy
+# for now 8 is only warning and cutoffdiff is large
+#
+ cutoffdiff="6.0"                      # energy cutoff variation - more then this rises warning  
+ sumsl_return=`grep "SUMSL return code:" $file|awk '{print $4}'`
+ echo 'SUMSL return code' $sumsl_return
+ if [ "$sumsl_return" != "4" ]; then
+   echo 'WARNING = SUMSL return code' $sumsl_return 'is not 4'
+ fi
+
+elif [ "$1" == "1l2y_micro" ]; then
+ refe="74.2623"
+ stat=`awk '{if ( $1 != "#" ) {n++;a=a+$5;a2=a2+$5^2}}END{print a/n,sqrt((a2-a^2/n)/n)}' $file_stat`
+ array=(${stat// / })
+ echo 'average total energy ' ${array[0]}
+ echo 'standard deviation ' ${array[1]}
+ if [ `echo "a=${array[0]}-${refe};if(0>a)a*=-1;a>5.0"|bc -l` != "0" ]; then
+  echo 'difference ' `echo "a=${array[0]}-${refe};if(0>a)a*=-1;a"|bc -l` "from reference ave etot ${refe} greater than 5.0"
+  exit 1
+ elif [ `echo "a=${array[1]};a>0.15"|bc -l` != "0" ]; then
+  echo 'standard deviation greater than 0.15'
+  exit 1
+ else
+  exit 0
+ fi
+elif [ "$1" == "1L2Y_L" ] || [ "$1" == "1L2Y_NH" ]; then
+ if [ ! -s $file_stat ]; then
+  echo 'FATAL error - stat file empty'
+  exit 2
+ fi
+ chi2=`./matplotlib_fit_hist.py $file_stat 111`
+ echo 'Chi2 for fitting theoretical temperature distribution ' ${chi2}
+ echo  "<DartMeasurementFile name=\"Temperature distribution $1\" type=\"image/png\">`pwd`/${file_stat}.png</DartMeasurementFile>"
+ if [ `echo "a=${chi2};a>0.001"|bc -l` != "0" ]; then
+    echo 'chi2 greater than 0.001'
+    exit 1
+ else
+    exit 0
+ fi
+elif [ "$1" == "1L2Y_B" ]; then
+ if [ ! -s $file_stat ]; then
+  echo 'FATAL error - stat file empty'
+  exit 2
+ fi
+ chi2=`./matplotlib_fit_hist.py $file_stat 111`
+ echo 'Chi2 for fitting theoretical temperature distribution ' ${chi2}
+ echo  "<DartMeasurementFile name=\"Temperature distribution $1\" type=\"image/png\">`pwd`/${file_stat}.png</DartMeasurementFile>"
+ if [ `echo "a=${chi2};a>0.01"|bc -l` != "0" ]; then
+    echo 'chi2 greater than 0.01'
+    exit 1
+ else
+    exit 0
+ fi
+
+
+elif [ "$1" == "1L2Y_remd" ]; then
+ rm -rf remd_all.stat
+ tail -q -n +1000 1L2Y_remd*.stat >remd_all.stat
+ if [ ! -s remd_all.stat ]; then
+  echo 'FATAL error - stat files empty'
+  exit 2
+ fi
+ ./matplotlib_hist.py
+
+ echo  "<DartMeasurementFile name=\"Histograms $1\" type=\"image/png\">`pwd`/1L2Y_remd_ene_hist.png</DartMeasurementFile>"
+ echo  "<DartMeasurementFile name=\"Energy $1\" type=\"image/png\">`pwd`/1L2Y_remd_Tene.png</DartMeasurementFile>" 
+ grep ACC 1L2Y_remd.out_GB000 |tail -7
+ exchange=`grep ACC 1L2Y_remd.out_GB000 |tail -7|awk '{a=a+$4}END{print a/NR}'`
+ echo "average exchange = ${exchange}"
+ if [ `echo "a=${exchange};a<0.2"|bc -l` != "0" ]; then
+    echo 'ERROR average exchange smaller than 0.2'
+    exit 1
+ else
+    exit 0
+ fi
+
+elif [ "$1" == "1DKZcut-ber" ]; then
+ chi2=`./matplotlib_fit_hist.py $file_stat 519`
+ echo 'Chi2 for fitting theoretical temperature distribution ' ${chi2}
+ echo  "<DartMeasurementFile name=\"Temperature distribution $1\" type=\"image/png\">`pwd`/${file_stat}.png</DartMeasurementFile>"
+ if [ `echo "a=${chi2};a>0.01"|bc -l` != "0" ]; then
+    echo 'chi2 greater than 0.01'
+    exit 1
+ else
+    exit 0
+ fi
+
+elif [ "$1" == "1DKZcut-lang" ]; then
+ chi2=`./matplotlib_fit_hist.py $file_stat 519`
+ echo 'Chi2 for fitting theoretical temperature distribution ' ${chi2}
+ echo  "<DartMeasurementFile name=\"Temperature distribution $1\" type=\"image/png\">`pwd`/${file_stat}.png</DartMeasurementFile>"
+ if [ `echo "a=${chi2};a>0.001"|bc -l` != "0" ]; then
+    echo 'chi2 greater than 0.001'
+    exit 1
+ else
+    exit 0
+ fi
+
+elif [ "$1" == "1DKZcut-min" ]; then
+ extremediff="10.0"                    # extreme energy difference, comething went terribly wrong
+ expectenergy="332.1213"               # - expected total energy
+ cutoffdiff="3.0"                      # energy cutoff variation - more then this rises warning  
+ sumsl_return=`grep SUMSL $file|awk '{print $4}'`
+ echo 'SUMSL return code' $sumsl_return
+ if [ "$sumsl_return" != "4" ]; then
+   echo 'ERROR = SUMSL return code' $sumsl_return 'is not 4'
+   echo 'but not failing this test, it is known problem with esccor'
+#   exit 1
+ fi
+
+elif [ "$1" == "1DKZcut-ene" ]; then
+ extremediff="10000.0"                 # extreme energy difference, comething went terribly wrong
+ expectenergy="-452.4430"      # - expected total energy
+ cutoffdiff="0.01"                     # energy cutoff variation - more then this rises warning  
+
+elif [ "$1" == "1DKZcut-micro" ]; then
+ refe="-173.573"
+ stat=`awk '{if ( $1 != "#" ) {n++;a=a+$5;a2=a2+$5^2}}END{print a/n,sqrt((a2-a^2/n)/n)}' $file_stat`
+ array=(${stat// / })
+ echo 'average total energy ' ${array[0]}
+ echo 'standard deviation ' ${array[1]}
+ if [ `echo "a=${array[0]}-(${refe});if(0>a)a*=-1;a>5.0"|bc -l` != "0" ]; then
+  echo 'difference ' `echo "a=${array[0]}-${refe};if(0>a)a*=-1;a"|bc -l` "from reference ave etot ${refe} greater than 5.0"
+  exit 1
+ elif [ `echo "a=${array[1]};a>0.005"|bc -l` != "0" ]; then
+  echo 'standard deviation greater than 0.005'
+  exit 1
+ else
+  exit 0
+ fi
+
+elif [ "$1" == "1ei0_min" ]; then
+ extremediff="10.0"                    # extreme energy difference, comething went terribly wrong
+ expectenergy="151.3218"               # - expected total energy
+ cutoffdiff="6.0"                      # energy cutoff variation - more then this rises warning  
+ refe="134.8382"
+ startene=`grep ETOT $file|head -1| awk '{print $2*1.0}'`
+ echo "initial energy=${startene} reference=${refe}"
+ if [ `echo "a=${startene}-(${refe});if(0>a)a*=-1;a>0.01"|bc -l` != "0" ]; then
+  echo 'difference ' `echo "a=${startene}-${refe};if(0>a)a*=-1;a"|bc -l` "from reference etot ${refe} greater than 0.01"
+  exit 1
+ fi
+ sumsl_return=`grep SUMSL $file|awk '{print $4}'`
+ echo 'SUMSL return code' $sumsl_return
+ if [ "$sumsl_return" != "4" ]; then
+   echo 'ERROR = SUMSL return code' $sumsl_return 'is not 4'
+   echo 'but not failing this test, it is known problem with dissulfides'
+#   exit 1
+ fi
+
+elif [ "$1" == "prota_CHECKGRAD" ] || [ "$1" == "1DKZcut-checkgrad" ]; then
+ diff=`gawk -f checkgrad.awk $file |grep 'Largest abs(1-numerical/analytical)='|awk '{printf "%15.10f",$3}'`
+ gawk -f checkgrad.awk $file 
+ if [ `echo "a=${diff};a>0.0002"|bc -l` != "0" ]; then
+    echo 'ERROR largest abs(numerical/analytical)' ${diff}
+    echo ' greater than 0.0002'
+    exit 1
+ else
+    exit 0
+ fi
+
+               
+else
+ exit 1
+fi
+
+
+
+function floating(){
+    echo $1 | sed -e 's/[eE]+/*10^/'
+}
+
+#---------------------------------------------------------------------------
+# MAIN CODE
+#---------------------------------------------------------------------------
+
+# Check if file exist
+if [ ! -f $file ]; then
+    echo "CRITICAL: out file do not exist"
+    exit 2
+fi
+
+# Check if energy value is not a number
+grepene=`grep ETOT $file|tail -1| awk '{print $2}'`
+if [[ $grepene == "NaN" ]]; then
+    echo "CRITICAL: energy is NaN"
+    exit 2
+fi
+
+# Check if energy value is extremely different from expected
+blaene=`floating $grepene`
+myene=`echo $blaene |bc`
+diff=`echo $myene"+("$expectenergy")"|bc`
+absdiff=`echo $diff| sed 's/-//'`
+
+true1=`echo "$absdiff >= $extremediff"|bc`
+if [ $true1 -eq 1 ]; then
+    echo "CRITICAL: energy is loo large $absdiff, ene= $myene"
+    exit 2
+fi
+
+# Check if Energy value is as expected
+true2=`echo "$absdiff<=$cutoffdiff"|bc`
+if [ $true2 -eq 1 ]; then
+    echo "OK: absdiff= $absdiff, ene= $myene"
+    exit 0
+else
+    echo "WARNING: energy is somewhat different $absdiff, ene= $myene"
+    exit 1
+fi
+