ctest for internal coordinates and regular minimization
[unres.git] / ctest / prota_unres_energy_check.sh
1 #!/bin/bash
2 #
3 # Writen by Dawid JagieÅ‚a and Adam Sieradzan
4 #
5 #
6 #----------------------------------------
7 # variables
8
9 if [[ "$2" =~ "MPI" ]]; then
10  file=$1.out_GB000
11  file_stat=$1_GB000.stat
12 else
13  file=$1.out_GB                                 # Output file to search energy value from
14  file_stat=$1_GB.stat
15 fi
16
17 if [ "$1" == "prota_ENE" ]; then
18  extremediff="10000.0"                  # extreme energy difference, comething went terribly wrong
19  expectenergy="-56066670.000000"        # expected total energy
20  cutoffdiff="0.1"                       # energy cutoff variation - more then this rises warning  
21 elif [ "$1" == "prota_MIN_CART" ]; then
22  extremediff="10.0"                     # extreme energy difference, comething went terribly wrong
23  expectenergy="123.8713"                # expected total energy
24  cutoffdiff="0.1"                       # energy cutoff variation - more then this rises warning  
25  
26  sumsl_return=`grep SUMSL $file|awk '{print $4}'`
27  echo 'SUMSL return code' $sumsl_return
28  if [ "$sumsl_return" != "4" ]; then
29    echo 'ERROR = SUMSL return code' $sumsl_return 'is not 4'
30    exit 1
31  fi
32 elif [ "$1" == "1l2y_MIN_INT" ]; then
33  extremediff="10.0"                     # extreme energy difference, comething went terribly wrong
34  expectenergy="-49.435"                 # expected total energy
35  cutoffdiff="0.1"                       # energy cutoff variation - more then this rises warning  
36  
37  sumsl_return=`grep SUMSL $file|awk '{print $4}'`
38  echo 'SUMSL return code' $sumsl_return
39  if [ "$sumsl_return" != "4" ]; then
40    echo 'ERROR = SUMSL return code' $sumsl_return 'is not 4'
41    exit 1
42  fi
43 elif [ "$1" == "1l2y_MIN_REGULAR_INT" ]; then
44  extremediff="10.0"                     # extreme energy difference, comething went terribly wrong
45  expectenergy="-1.192"                  # expected total energy
46 #
47 # something wrong with REGULAR and sometimes gives code 8 and different energy
48 # for now 8 is only warning and cutoffdiff is large
49 #
50  cutoffdiff="6.0"                       # energy cutoff variation - more then this rises warning  
51  
52  sumsl_return=`grep "SUMSL return code:" $file|awk '{print $4}'`
53  echo 'SUMSL return code' $sumsl_return
54  if [ "$sumsl_return" != "4" ]; then
55    echo 'WARNING = SUMSL return code' $sumsl_return 'is not 4'
56  fi
57
58 elif [ "$1" == "1l2y_micro" ]; then
59  stat=`awk '{if ( $1 != "#" ) {n++;a=a+$5;a2=a2+$5^2}}END{print a/n,sqrt((a2-a^2/n)/n)}' $file_stat`
60  array=(${stat// / })
61  echo 'average total energy ' ${array[0]}
62  echo 'standard deviation ' ${array[1]}
63  if [ `echo "a=${array[0]}-103.162;if(0>a)a*=-1;a>5.0"|bc -l` != "0" ]; then
64   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'
65   exit 1
66  elif [ `echo "a=${array[1]};a>0.01"|bc -l` != "0" ]; then
67   echo 'standard deviation greater than 0.01'
68   exit 1
69  else
70   exit 0
71  fi
72 else
73  exit 1
74 fi
75
76
77
78 function floating(){
79     echo $1 | sed -e 's/[eE]+/*10^/'
80 }
81
82 #---------------------------------------------------------------------------
83 # MAIN CODE
84 #---------------------------------------------------------------------------
85
86 # Check if file exist
87 if [ ! -f $file ]; then
88     echo "CRITICAL: out file do not exist"
89     exit 2
90 fi
91
92 # Check if energy value is not a number
93 grepene=`grep ETOT $file|tail -1| awk '{print $2}'`
94 if [[ $grepene == "NaN" ]]; then
95     echo "CRITICAL: energy is NaN"
96     exit 2
97 fi
98
99 # Check if energy value is extremely different from expected
100 blaene=`floating $grepene`
101 myene=`echo $blaene |bc`
102 diff=`echo $myene"+("$expectenergy")"|bc`
103 absdiff=`echo $diff| sed 's/-//'`
104
105 true1=`echo "$absdiff >= $extremediff"|bc`
106 if [ $true1 -eq 1 ]; then
107     echo "CRITICAL: energy is loo large $absdiff, ene= $myene"
108     exit 2
109 fi
110
111 # Check if Energy value is as expected
112 true2=`echo "$absdiff<=$cutoffdiff"|bc`
113 if [ $true2 -eq 1 ]; then
114     echo "OK: absdiff= $absdiff, ene= $myene"
115     exit 0
116 else
117     echo "WARNING: energy is somewhat different $absdiff, ene= $myene"
118     exit 1
119 fi
120