ctest for remd
[unres.git] / ctest / prota_unres_energy_check.sh
1 #!/bin/bash
2 #
3 # Writen by Dawid JagieÅ‚a and Adam Sieradzan
4 # and Cezary Czaplewski
5 #
6 #
7 #----------------------------------------
8 # variables
9
10 if [[ "$2" =~ "MPI" ]]; then
11  file=$1.out_GB000
12  file_stat=$1_GB000.stat
13 else
14  file=$1.out_GB                                 # Output file to search energy value from
15  file_stat=$1_GB.stat
16 fi
17
18 if [ "$1" == "prota_ENE" ]; then
19  extremediff="10000.0"                  # extreme energy difference, comething went terribly wrong
20  expectenergy="-56066670.000000"        # expected total energy
21  cutoffdiff="0.1"                       # energy cutoff variation - more then this rises warning  
22 elif [ "$1" == "prota_MIN_CART" ]; then
23  extremediff="10.0"                     # extreme energy difference, comething went terribly wrong
24  expectenergy="123.8713"                # expected total energy
25  cutoffdiff="0.1"                       # energy cutoff variation - more then this rises warning  
26  
27  sumsl_return=`grep SUMSL $file|awk '{print $4}'`
28  echo 'SUMSL return code' $sumsl_return
29  if [ "$sumsl_return" != "4" ]; then
30    echo 'ERROR = SUMSL return code' $sumsl_return 'is not 4'
31    exit 1
32  fi
33 elif [ "$1" == "1l2y_MIN_INT" ]; then
34  extremediff="10.0"                     # extreme energy difference, comething went terribly wrong
35  expectenergy="-49.435"                 # expected total energy
36  cutoffdiff="0.1"                       # energy cutoff variation - more then this rises warning  
37  
38  sumsl_return=`grep SUMSL $file|awk '{print $4}'`
39  echo 'SUMSL return code' $sumsl_return
40  if [ "$sumsl_return" != "4" ]; then
41    echo 'ERROR = SUMSL return code' $sumsl_return 'is not 4'
42    exit 1
43  fi
44 elif [ "$1" == "1l2y_MIN_REGULAR_INT" ]; then
45  extremediff="10.0"                     # extreme energy difference, comething went terribly wrong
46  expectenergy="-1.192"                  # expected total energy
47 #
48 # something wrong with REGULAR and sometimes gives code 8 and different energy
49 # for now 8 is only warning and cutoffdiff is large
50 #
51  cutoffdiff="6.0"                       # energy cutoff variation - more then this rises warning  
52  
53  sumsl_return=`grep "SUMSL return code:" $file|awk '{print $4}'`
54  echo 'SUMSL return code' $sumsl_return
55  if [ "$sumsl_return" != "4" ]; then
56    echo 'WARNING = SUMSL return code' $sumsl_return 'is not 4'
57  fi
58
59 elif [ "$1" == "1l2y_micro" ]; then
60  stat=`awk '{if ( $1 != "#" ) {n++;a=a+$5;a2=a2+$5^2}}END{print a/n,sqrt((a2-a^2/n)/n)}' $file_stat`
61  array=(${stat// / })
62  echo 'average total energy ' ${array[0]}
63  echo 'standard deviation ' ${array[1]}
64  if [ `echo "a=${array[0]}-103.162;if(0>a)a*=-1;a>5.0"|bc -l` != "0" ]; then
65   echo 'difference ' `echo "a=${array[0]}-103.162;if(0>a)a*=-1;a"|bc -l` 'from reference ave etot 103.162 greater than 5.0'
66   exit 1
67  elif [ `echo "a=${array[1]};a>0.01"|bc -l` != "0" ]; then
68   echo 'standard deviation greater than 0.01'
69   exit 1
70  else
71   exit 0
72  fi
73 elif [ "$1" == "1L2Y_L" ] || [ "$1" == "1L2Y_NH" ]; then
74  chi2=`./matplotlib_fit_hist.py $file_stat`
75  echo 'Chi2 for fitting theoretical temperature distribution ' ${chi2}
76  echo  "<DartMeasurementFile name=\"Temperature distribution $1\" type=\"image/png\">`pwd`/${file_stat}.png</DartMeasurementFile>"
77  
78  if [ `echo "a=${chi2};a>0.001"|bc -l` != "0" ]; then
79     echo 'chi2 greater than 0.001'
80     exit 1
81  else
82     exit 0
83  fi
84 elif [ "$1" == "1L2Y_B" ]; then
85  chi2=`./matplotlib_fit_hist.py $file_stat`
86  echo 'Chi2 for fitting theoretical temperature distribution ' ${chi2}
87  echo  "<DartMeasurementFile name=\"Temperature distribution $1\" type=\"image/png\">`pwd`/${file_stat}.png</DartMeasurementFile>"
88  
89  if [ `echo "a=${chi2};a>0.01"|bc -l` != "0" ]; then
90     echo 'chi2 greater than 0.01'
91     exit 1
92  else
93     exit 0
94  fi
95
96
97 elif [ "$1" == "1L2Y_remd" ]; then
98  tail -q -n +5 1L2Y_remd*.stat >remd_all.stat
99  ./matplotlib_hist.py
100
101  echo  "<DartMeasurementFile name=\"Histograms $1\" type=\"image/png\">`pwd`/1L2Y_remd_ene_hist.png</DartMeasurementFile>"
102  echo  "<DartMeasurementFile name=\"Energy $1\" type=\"image/png\">`pwd`/1L2Y_remd_Tene.png</DartMeasurementFile>" 
103  grep ACC 1L2Y_remd.out_GB000 |tail -7
104  exchange=`grep ACC 1L2Y_remd.out_GB000 |tail -7|awk '{a=a+$4}END{print a/NR}'`
105  echo "average exchange = ${exchange}"
106  if [ `echo "a=${exchange};a<0.1"|bc -l` != "0" ]; then
107     echo 'ERROR average exchange smaller than 0.1'
108     exit 1
109  else
110     exit 0
111  fi
112                
113 else
114  exit 1
115 fi
116
117
118
119 function floating(){
120     echo $1 | sed -e 's/[eE]+/*10^/'
121 }
122
123 #---------------------------------------------------------------------------
124 # MAIN CODE
125 #---------------------------------------------------------------------------
126
127 # Check if file exist
128 if [ ! -f $file ]; then
129     echo "CRITICAL: out file do not exist"
130     exit 2
131 fi
132
133 # Check if energy value is not a number
134 grepene=`grep ETOT $file|tail -1| awk '{print $2}'`
135 if [[ $grepene == "NaN" ]]; then
136     echo "CRITICAL: energy is NaN"
137     exit 2
138 fi
139
140 # Check if energy value is extremely different from expected
141 blaene=`floating $grepene`
142 myene=`echo $blaene |bc`
143 diff=`echo $myene"+("$expectenergy")"|bc`
144 absdiff=`echo $diff| sed 's/-//'`
145
146 true1=`echo "$absdiff >= $extremediff"|bc`
147 if [ $true1 -eq 1 ]; then
148     echo "CRITICAL: energy is loo large $absdiff, ene= $myene"
149     exit 2
150 fi
151
152 # Check if Energy value is as expected
153 true2=`echo "$absdiff<=$cutoffdiff"|bc`
154 if [ $true2 -eq 1 ]; then
155     echo "OK: absdiff= $absdiff, ene= $myene"
156     exit 0
157 else
158     echo "WARNING: energy is somewhat different $absdiff, ene= $myene"
159     exit 1
160 fi
161