checkgrad added to ctest
[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="145.1742"        # - expected total energy
21  cutoffdiff="0.01"                      # 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="154.9622"                # - 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="-47.88137"                       # 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="5.258893"                        # 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  refe="74.2623"
61  stat=`awk '{if ( $1 != "#" ) {n++;a=a+$5;a2=a2+$5^2}}END{print a/n,sqrt((a2-a^2/n)/n)}' $file_stat`
62  array=(${stat// / })
63  echo 'average total energy ' ${array[0]}
64  echo 'standard deviation ' ${array[1]}
65  if [ `echo "a=${array[0]}-${refe};if(0>a)a*=-1;a>5.0"|bc -l` != "0" ]; then
66   echo 'difference ' `echo "a=${array[0]}-${refe};if(0>a)a*=-1;a"|bc -l` "from reference ave etot ${refe} greater than 5.0"
67   exit 1
68  elif [ `echo "a=${array[1]};a>0.15"|bc -l` != "0" ]; then
69   echo 'standard deviation greater than 0.15'
70   exit 1
71  else
72   exit 0
73  fi
74 elif [ "$1" == "1L2Y_L" ] || [ "$1" == "1L2Y_NH" ]; then
75  if [ ! -s $file_stat ]; then
76   echo 'FATAL error - stat file empty'
77   exit 2
78  fi
79  chi2=`./matplotlib_fit_hist.py $file_stat 111`
80  echo 'Chi2 for fitting theoretical temperature distribution ' ${chi2}
81  echo  "<DartMeasurementFile name=\"Temperature distribution $1\" type=\"image/png\">`pwd`/${file_stat}.png</DartMeasurementFile>"
82  
83  if [ `echo "a=${chi2};a>0.001"|bc -l` != "0" ]; then
84     echo 'chi2 greater than 0.001'
85     exit 1
86  else
87     exit 0
88  fi
89 elif [ "$1" == "1L2Y_B" ]; then
90  if [ ! -s $file_stat ]; then
91   echo 'FATAL error - stat file empty'
92   exit 2
93  fi
94  chi2=`./matplotlib_fit_hist.py $file_stat 111`
95  echo 'Chi2 for fitting theoretical temperature distribution ' ${chi2}
96  echo  "<DartMeasurementFile name=\"Temperature distribution $1\" type=\"image/png\">`pwd`/${file_stat}.png</DartMeasurementFile>"
97  
98  if [ `echo "a=${chi2};a>0.01"|bc -l` != "0" ]; then
99     echo 'chi2 greater than 0.01'
100     exit 1
101  else
102     exit 0
103  fi
104
105
106 elif [ "$1" == "1L2Y_remd" ]; then
107  rm -rf remd_all.stat
108  tail -q -n +1000 1L2Y_remd*.stat >remd_all.stat
109  if [ ! -s remd_all.stat ]; then
110   echo 'FATAL error - stat files empty'
111   exit 2
112  fi
113  ./matplotlib_hist.py
114
115  echo  "<DartMeasurementFile name=\"Histograms $1\" type=\"image/png\">`pwd`/1L2Y_remd_ene_hist.png</DartMeasurementFile>"
116  echo  "<DartMeasurementFile name=\"Energy $1\" type=\"image/png\">`pwd`/1L2Y_remd_Tene.png</DartMeasurementFile>" 
117  grep ACC 1L2Y_remd.out_GB000 |tail -7
118  exchange=`grep ACC 1L2Y_remd.out_GB000 |tail -7|awk '{a=a+$4}END{print a/NR}'`
119  echo "average exchange = ${exchange}"
120  if [ `echo "a=${exchange};a<0.2"|bc -l` != "0" ]; then
121     echo 'ERROR average exchange smaller than 0.2'
122     exit 1
123  else
124     exit 0
125  fi
126
127 elif [ "$1" == "1DKZcut-ber" ]; then
128  chi2=`./matplotlib_fit_hist.py $file_stat 519`
129  echo 'Chi2 for fitting theoretical temperature distribution ' ${chi2}
130  echo  "<DartMeasurementFile name=\"Temperature distribution $1\" type=\"image/png\">`pwd`/${file_stat}.png</DartMeasurementFile>"
131  
132  if [ `echo "a=${chi2};a>0.01"|bc -l` != "0" ]; then
133     echo 'chi2 greater than 0.01'
134     exit 1
135  else
136     exit 0
137  fi
138
139 elif [ "$1" == "1DKZcut-lang" ]; then
140  chi2=`./matplotlib_fit_hist.py $file_stat 519`
141  echo 'Chi2 for fitting theoretical temperature distribution ' ${chi2}
142  echo  "<DartMeasurementFile name=\"Temperature distribution $1\" type=\"image/png\">`pwd`/${file_stat}.png</DartMeasurementFile>"
143  
144  if [ `echo "a=${chi2};a>0.001"|bc -l` != "0" ]; then
145     echo 'chi2 greater than 0.001'
146     exit 1
147  else
148     exit 0
149  fi
150
151 elif [ "$1" == "1DKZcut-min" ]; then
152  extremediff="10.0"                     # extreme energy difference, comething went terribly wrong
153  expectenergy="332.1213"                # - expected total energy
154  cutoffdiff="3.0"                       # energy cutoff variation - more then this rises warning  
155  
156  sumsl_return=`grep SUMSL $file|awk '{print $4}'`
157  echo 'SUMSL return code' $sumsl_return
158  if [ "$sumsl_return" != "4" ]; then
159    echo 'ERROR = SUMSL return code' $sumsl_return 'is not 4'
160    echo 'but not failing this test, it is known problem with esccor'
161 #   exit 1
162  fi
163
164 elif [ "$1" == "1DKZcut-ene" ]; then
165  extremediff="10000.0"                  # extreme energy difference, comething went terribly wrong
166  expectenergy="-452.4430"       # - expected total energy
167  cutoffdiff="0.01"                      # energy cutoff variation - more then this rises warning  
168
169 elif [ "$1" == "1DKZcut-micro" ]; then
170  refe="-173.573"
171  stat=`awk '{if ( $1 != "#" ) {n++;a=a+$5;a2=a2+$5^2}}END{print a/n,sqrt((a2-a^2/n)/n)}' $file_stat`
172  array=(${stat// / })
173  echo 'average total energy ' ${array[0]}
174  echo 'standard deviation ' ${array[1]}
175  if [ `echo "a=${array[0]}-(${refe});if(0>a)a*=-1;a>5.0"|bc -l` != "0" ]; then
176   echo 'difference ' `echo "a=${array[0]}-${refe};if(0>a)a*=-1;a"|bc -l` "from reference ave etot ${refe} greater than 5.0"
177   exit 1
178  elif [ `echo "a=${array[1]};a>0.005"|bc -l` != "0" ]; then
179   echo 'standard deviation greater than 0.005'
180   exit 1
181  else
182   exit 0
183  fi
184
185 elif [ "$1" == "1ei0_min" ]; then
186  extremediff="10.0"                     # extreme energy difference, comething went terribly wrong
187  expectenergy="151.3218"                # - expected total energy
188  cutoffdiff="6.0"                       # energy cutoff variation - more then this rises warning  
189  
190  refe="134.8382"
191  startene=`grep ETOT $file|head -1| awk '{print $2*1.0}'`
192  echo "initial energy=${startene} reference=${refe}"
193  if [ `echo "a=${startene}-(${refe});if(0>a)a*=-1;a>0.01"|bc -l` != "0" ]; then
194   echo 'difference ' `echo "a=${startene}-${refe};if(0>a)a*=-1;a"|bc -l` "from reference etot ${refe} greater than 0.01"
195   exit 1
196  fi
197  
198  sumsl_return=`grep SUMSL $file|awk '{print $4}'`
199  echo 'SUMSL return code' $sumsl_return
200  if [ "$sumsl_return" != "4" ]; then
201    echo 'ERROR = SUMSL return code' $sumsl_return 'is not 4'
202    echo 'but not failing this test, it is known problem with dissulfides'
203 #   exit 1
204  fi
205
206 elif [ "$1" == "prota_CHECKGRAD" ]; then
207  diff=`awk -f checkgrad.awk $file |grep 'Largest abs(numerical/analytical)='|awk '{printf "%15.10f",$3}'`
208  awk -f checkgrad.awk $file 
209  
210  if [ `echo "a=${diff};a>0.0001"|bc -l` != "0" ]; then
211     echo 'ERROR largest abs(numerical/analytical)' ${diff}
212     echo ' greater than 0.0001'
213     exit 1
214  else
215     exit 0
216  fi
217
218                
219 else
220  exit 1
221 fi
222
223
224
225 function floating(){
226     echo $1 | sed -e 's/[eE]+/*10^/'
227 }
228
229 #---------------------------------------------------------------------------
230 # MAIN CODE
231 #---------------------------------------------------------------------------
232
233 # Check if file exist
234 if [ ! -f $file ]; then
235     echo "CRITICAL: out file do not exist"
236     exit 2
237 fi
238
239 # Check if energy value is not a number
240 grepene=`grep ETOT $file|tail -1| awk '{print $2}'`
241 if [[ $grepene == "NaN" ]]; then
242     echo "CRITICAL: energy is NaN"
243     exit 2
244 fi
245
246 # Check if energy value is extremely different from expected
247 blaene=`floating $grepene`
248 myene=`echo $blaene |bc`
249 diff=`echo $myene"+("$expectenergy")"|bc`
250 absdiff=`echo $diff| sed 's/-//'`
251
252 true1=`echo "$absdiff >= $extremediff"|bc`
253 if [ $true1 -eq 1 ]; then
254     echo "CRITICAL: energy is loo large $absdiff, ene= $myene"
255     exit 2
256 fi
257
258 # Check if Energy value is as expected
259 true2=`echo "$absdiff<=$cutoffdiff"|bc`
260 if [ $true2 -eq 1 ]; then
261     echo "OK: absdiff= $absdiff, ene= $myene"
262     exit 0
263 else
264     echo "WARNING: energy is somewhat different $absdiff, ene= $myene"
265     exit 1
266 fi
267