File: functions

package info (click to toggle)
ergo 3.5-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 17,044 kB
  • ctags: 6,813
  • sloc: cpp: 91,488; ansic: 15,728; sh: 6,416; makefile: 1,287; yacc: 123; lex: 108
file content (173 lines) | stat: -rw-r--r-- 6,256 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/sh


# Prefer gawk - we know exactly what it can do.
# awk on Sun does not support functions, need to use nawk for this
if gawk '{print 1}'</dev/null > /dev/null 2>&1; then
   AWK=gawk
elif nawk '{print 1}'</dev/null > /dev/null 2>&1; then
   AWK=nawk
else
   AWK=awk
fi


# check_final_energy:
# $1 - expected energy
# $2 - max deviation
check_final_energy() {
[ "$2" = "" ] &&  echo "not enough parameters to check_final_energy."
$AWK 'function e(v,r){#print "check_final_energy: checking ",v, r;
return(v>r||v<-r)}
/FINAL ENERGY/{c=1; printf "computed  %15.9f\nreference %15.9f\n", $4, '$1'; exit (e($4-('$1'),'$2'))} END{if(!c) exit(1)}
' ergoscf.out
}

# check_dipole: (checking dipole moment from SCF calculation)
# $1 - x, y, or z
# $2 - expected dipole moment component
# $3 - max deviation
check_dipole() {
[ "$3" = "" ] &&  echo "not enough parameters to check_dipole."
$AWK 'function e(v,r){#print "check_dipole: checking ",v, r;
return(v>r||v<-r)}
/INSC SCF: dipole_moment_'$1'/{c=1; printf "computed  %15.9f\nreference %15.9f\n", $7, '$2'; exit (e($7-('$2'),'$3'))} END{if(!c) exit(1)}
' ergoscf.out
}

# check_dipole_ci: (checking dipole moment from CI calculation)
# $1 - x, y, or z
# $2 - expected dipole moment component
# $3 - max deviation
check_dipole_ci() {
[ "$3" = "" ] &&  echo "not enough parameters to check_dipole_ci."
$AWK 'function e(v,r){#print "check_dipole_ci: checking ",v, r;
return(v>r||v<-r)}
/INCI CI: dipole_moment_'$1'/{c=1; printf "computed  %15.9f\nreference %15.9f\n", $7, '$2'; exit (e($7-('$2'),'$3'))} END{if(!c) exit(1)}
' ergoscf.out
}

# check_mulliken_charge:
# $1 - atom index
# $2 - expected Mulliken atomic charge
# $3 - max deviation
check_mulliken_charge() {
[ "$3" = "" ] &&  echo "not enough parameters to check_mulliken_charge."
$AWK 'function e(v,r){#print "check_mulliken_charge: checking ",v, r;
return(v>r||v<-r)}
/INSC Mulliken charge of atom '$1'/{c=1; printf "computed  %15.9f\nreference %15.9f\n", $8, '$2'; exit (e($8-('$2'),'$3'))} END{if(!c) exit(1)}
' ergoscf.out
}

# check_mulliken_spin:
# $1 - atom index
# $2 - expected Mulliken atomic spin density
# $3 - max deviation
check_mulliken_spin() {
[ "$3" = "" ] &&  echo "not enough parameters to check_mulliken_spin."
$AWK 'function e(v,r){#print "check_mulliken_spin: checking ",v, r;
return(v>r||v<-r)}
/INSC Mulliken spin density of atom '$1'/{c=1; printf "computed  %15.9f\nreference %15.9f\n", $9, '$2'; exit (e($9-('$2'),'$3'))} END{if(!c) exit(1)}
' ergoscf.out
}

# check_final_ci_energy:
# $1 - expected CI energy
# $2 - max deviation
check_final_ci_energy() {
[ "$2" = "" ] &&  echo "not enough parameters to check_final_ci_energy."
$AWK 'function e(v,r){#print "check_final_energy: checking ",v, r;
return(v>r||v<-r)}
/FINAL CI ENERGY/{c=1; printf "computed  %15.9f\nreference %15.9f\n", $6, '$1'; exit (e($6-('$1'),'$2'))} END{if(!c) exit(1)}
' ergoscf.out
}

# check_final_ci_corr_energy:
# $1 - expected CI correlation energy
# $2 - max deviation
check_final_ci_corr_energy() {
[ "$2" = "" ] &&  echo "not enough parameters to check_final_ci_corr_energy."
$AWK 'function e(v,r){#print "check_final_energy: checking ",v, r;
return(v>r||v<-r)}
/FINAL CI CORRELATION ENERGY/{c=1; printf "computed  %15.9f\nreference %15.9f\n", $7, '$1'; exit (e($7-('$1'),'$2'))} END{if(!c) exit(1)}
' ergoscf.out
}

# check_final_S2:
# $1 - expected <S2>
# $2 - max deviation
check_final_S2() {
[ "$2" = "" ] &&  echo "not enough parameters to check_final_S2."
$AWK 'function e(v,r){#print "check_final_S2: checking ",v, r; 
return(v>r||v<-r)}
/FINAL <S2>/{c=1; printf "computed  %15.9f\nreference %15.9f\n", $5, '$1'; exit (e($5-('$1'),'$2'))} END{if(!c) exit(1)}
' ergoscf.out
}

# check_tdhf_dipole_at_time
# $1 - time as integer
# $2 - expected dipole value at that time
# $3 - max deviation
check_tdhf_dipole_at_time()
{
[ "$3" = "" ] &&  echo "not enough parameters for check_tdhf_dipole_at_time."
# echo check_tdhf_dipole_at_time, params: $1 $2 $3
$AWK 'function e(v,r){return(v>r||v<-r)}
function valwithreversedsign(v){return(-v)}
/^INED Data for dipole plot/ && $6=='$1'{c=1; printf "computed  %15.9f\nreference %15.9f\n", $7, valwithreversedsign('$2'); exit (e($7-(valwithreversedsign('$2')),'$3'))} END{if(!c) { print "Not found";exit(1)}}
' ergoscf.out
}

# check_lr_eigenvalue:
# $1 - eigenvalue number
# $2 - expected eigenvalue
# $3 - max deviation
check_lr_eigenvalue()
{
[ "$3" = "" ] &&  echo "not enough parameters to check_lr_eigenvalue."
$AWK 'function e(v,r){return(v>r||v<-r)}
/^ERMA Eigenvalue / && $3=="'$1':"{c=1; printf "computed  %15.9f\nreference %15.9f\n", $4, '$2'; exit (e($4-('$2'),'$3'))} END{if(!c) { print "Not found";exit(1)}}
' ergoscf.out
}

# check_polarisability:
# $1 - left-hand-side operator (X,Y,Z)
# $2 - right-hand-side operator (X,Y,Z)
# $3 - frequency
# $4 - reference value
# $5 - max deviation
check_polarisability()
{
[ "$5" = "" ] &&  echo "not enough parameters to check_polarizability."
$AWK 'function e(v,r){return(v>r||v<-r)}
/^REMA Response / && $4 == "'$1'" && $6 == "'$2'" && $10 ~ /^'$3'0*:/ {
c=1; #print;printf "computed  %15.9f\nreference %15.9f\n", $11, '$4';
  exit (e($11-('$4'),'$5'))} END{if(!c) { print "Not found";exit(1)}}
' ergoscf.out
}

# check_gradient_component_by_finite_diff:
# $1 - atom index to check
# $2 - coord index to check ( 0 1 2 <--> x y z )
# $3 - epsilon (diff in coords used for finite difference)
# $4 - max deviation
check_gradient_component_by_finite_diff() {
[ "$2" = "" ] &&  echo "not enough parameters to check_final_energy."
$AWK 'function e(v,r){#print "check_gradient_component_by_finite_diff: checking ",v, r;
return(v>r||v<-r)}
BEGIN {c = 0}
/FINAL ENERGY/{c++; vec[c] = $4}
/INSC Atom / && $3=="'$1':" {gradvalues[0] = $4 ; gradvalues[1] = $5 ; gradvalues[2] = $6}
END {gradientvaluefd = (vec[1]-vec[2])/(2*'$3') ; printf "computed          %13.9f\nfinite-diff value %13.9f\n", gradientvaluefd, gradvalues['$2']; exit (e(gradientvaluefd-gradvalues['$2'], '$4'))}
' ergoscf.out.sav1 ergoscf.out.sav2 ergoscf.out.gradient
}

# print_sum_of_values:
# $1 - first value
# $2 - second value
print_sum_of_values()
{
[ "$2" = "" ] &&  echo "not enough parameters to print_sum_of_values."
$AWK 'BEGIN {printf "%18.12f\n", '$1'+'$2'}'
}