-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsubqchem
executable file
·330 lines (285 loc) · 6.79 KB
/
subqchem
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
#!/bin/bash
dir=$(pwd)
PGM_NAME="subqchem submit script"
PGM_VERSION="1.1"
BINARY_LOCATION=""
### SET DEFAULT VARIABLES
ncores_default=2
nnodes_default=1
jobtime_default=480
#memory=2
jobhold=""
holdid=""
debug=""
queue=""
user=$USER
copyall="no"
function usage {
cat <<-EOF
$PGM_NAME $PGM_VERSION
Usage: $PGM_NAME [-j JOB_ID] [-t TIME] [-m SIZE] [-N NAME] [-p CPUS] [-n NODES] [-a COPY BACK ALL FILES] INPUT_FILE
EOF
exit 2
}
function printExit {
case $1 in
[iI]) echo INFO: "$2" ;;
[wW]) echo WARNING: "$2" ;;
[eE])
echo ERROR: "$2"
exit 1
;;
*) echo "$1" ;;
esac
}
function testFile {
if [ ! -r "$1" -o ! -f "$1" ]; then
if [ "$2" = "return" ]; then
returncode="1"
else
printExit E "Inputfile \"$1\" was not found."
fi
else
returncode="0"
fi
return "$returncode"
}
### PROCESS OPTIONS
while getopts adhj:m:N:p:n:q:t: options; do
case $options in
N)
jobnamefix=$OPTARG
;;
p)
ncores=$OPTARG
;;
n)
nnodes=$OPTARG
;;
a)
copyall="yes"
;;
m)
memory=$OPTARG
;;
j)
holdid=$OPTARG
jobhold=1
echo "Not yet implemented."
exit 1
;;
q)
queue=$OPTARG
;;
d)
debug=1
;;
h)
usage
exit 0
;;
t)
jobtime=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG"
exit 1
;;
\:)
echo "Option -$OPTARG requires an argument."
exit 1
;;
*)
usage
exit 1
;;
esac
done
shift $((OPTIND - 1))
### CHECK FOR INPUT ARGUMENTS
if [ -z "$1" ]; then
echo "No filename specified."
exit 1
else
myname=$1
fi
### CREATE DEFAULT JOBNAME
jobname_default="$(echo $dir | sed "s/\/data\/$USER\//d/" | sed "s/\/home\/$USER\//h/ ; s/\//./g").$myname"
### PROCESS VARIABLES
if [ -z "$jobnamefix" ]; then
jobnamefix=$jobname_default
fi
if [ -z "$ncores" ]; then
ncores=$ncores_default
fi
if [ -z "$nnodes" ]; then
nnodes=$nnodes_default
fi
if [ -z "$memory" ]; then
memory=8
fi
if [ -z "$jobtime" ]; then
jobtime=$jobtime_default
fi
### CONSTRUCT OUTPUT FILENAME
if [ -z "$1" ]; then
usage
printExit E "No filename specified."
else
myname=$1
fi
#
# Assemble the names for the input, output and error file.
#
inputsuffix=(.com .in .gjf .mol .umol)
outputsuffix=(.log .out .log)
choices=${#inputsuffix[*]}
found=""
if [ "${myname##*.}" != "$myname" ]; then
for ((suffix = 0; suffix < choices; suffix++)); do
if [ ".${myname##*.}" = "${inputsuffix[$suffix]}" ]; then
testFile "$myname"
found="1"
jobname=${myname%${inputsuffix[$suffix]}}
if [ "${jobname:0:1}" = "/" ]; then
infile=$jobname${inputsuffix[$suffix]}
outfile=$jobname${outputsuffix[$suffix]}
scriptfile=$jobname.sh
else
infile=$PWD/$jobname${inputsuffix[$suffix]}
outfile=$PWD/$jobname${outputsuffix[$suffix]}
scriptfile=$PWD/$jobname.sh
fi
break
fi
done
fi
if [ -z "$found" ]; then
jobname="$myname"
for ((suffix = 0; suffix < choices; suffix++)); do
if testFile "$jobname${inputsuffix[$suffix]}" "return"; then
if [ -n "$found" ]; then
printExit E "The name \"$myname\" is ambiguous, because more than one file with the possible suffixes [ ${inputsuffix[*]} ] exist."
else
found="1"
if [ "${jobname:0:1}" = "/" ]; then
infile=$jobname${inputsuffix[$suffix]}
outfile=$jobname${outputsuffix[$suffix]}
scriptfile=$jobname.sh
else
infile=$PWD/$jobname${inputsuffix[$suffix]}
outfile=$PWD/$jobname${outputsuffix[$suffix]}
scriptfile=$PWD/$jobname.sh
fi
fi
fi
done
if [ -z "$found" ]; then
if testFile "$myname" "return"; then
printExit E "Your file \"$myname\" was found, but you have to append a suffix { ${inputsuffix[*]} } for clearness."
else
printExit E "No file \"$myname\" ending in [ ${inputsuffix[*]} ] was found."
fi
fi
fi
### SET QUEUE TO DEFAULT IF $QUEUE IS EMPTY
if [ -z "$queue" ]; then
if [ "$jobtime" -le 2 ]; then
queue="batch"
elif [ "$jobtime" -gt 2 ] && [ "$jobtime" -le 72 ]; then
queue="batch"
elif [ "$jobtime" -gt 72 ]; then
queue="batch"
fi
fi
## GET MAIL
#mail=`cat /home/${USER}/.forward`
### set %mem and %nproc according to qsub
echo "Trying to figure out ncores and memory from infile..."
if grep --ignore-case threads $infile; then
coreset=$(grep -m 1 --ignore-case threads $infile | awk '{print $2}')
ncores=$coreset
echo "Found threads and setting ncores accordingly"
else
echo "Threads not found, using ncores=$ncores from command-line/default"
fi
echo ""
if grep --ignore-case mem_total $infile; then
memset=$(grep -m 1 --ignore-case mem_total $infile | awk '{print $2}')
memory=$(echo "$memset/1000+2" | bc)
echo "Found mem_total and setting memory accordingly."
else
echo "mem_total not found, using memory=$memory from command-line/default"
fi
echo ""
### CREATE OPTION STRING FOR QSUB
if [ -z "$jobhold" ]; then
optionstring=""
else
optionstring="-W depend=afterok:$holdid"
fi
inname=$(basename $infile)
outname=$(basename $outfile)
pbs_logfile=$(echo $inname | sed "s/.in/.pbslog/")
pbs_errorfile=$(echo $inname | sed "s/.in/.pbserr/")
#echo pbs_outname $pbs_outname pbs_errorname $pbs_errorname
scriptname=$(basename $scriptfile)
savedir=$(echo $outname | sed "s/.out/_files/")
#somehow this takes the last 19 characters of the jobname
jobident=$(echo $jobnamefix | sed 's/.*\(...................\)/\1/')
### CREATE INPUT SCRIPT FOR QSUB
test -e $scriptfile && mv $scriptfile ${scriptfile}_OLD
cat <<EOT >>$scriptfile
#!/bin/bash
# PBS Job
#PBS -V
#PBS -N $jobident
#PBS -m ae
#PBS -q $queue
#PBS -l nodes=1:ppn=$ncores
#PBS -l walltime=$jobtime:0:0
#PBS -l mem=${memory}G
#PBS -o $pbs_logfile
#PBS -e $pbs_errorfile
echo "Job is running on the compute node:"
echo "\$PBS_NODEFILE"
echo ""
echo "The local scratch directory (located on the compute node) is:"
echo "/tmp1/$user/"
echo ""
module load q-chem/gcc+mkl/5.4.2
#export QCAUX=/home/mewes/SOFTWARE/QC_AUX
#export QCSCRATCH=/tmp1/$user/
#export QCPLATFORM=LINUX_Ix86
cd
# Backup old out files if existing
[ -e ${outfile}_OLD ] && cp $outfile ${outfile}_OLDER
[ -e $outfile ] && cp $outfile ${outfile}_OLD
cd $dir
# Execute the program
if [ "$copyall" = "yes" ] ; then
\$QC/bin/qchem -save $inname $outname $savedir
else
\$QC/bin/qchem $inname $outname
fi
EOT
if [ $copyall ]; then
cat <<EOT >>$scriptfile
#Copy plots back from Scratch
cp -r /tmp1/$user/$savedir/plots .
EOT
fi
if [ -z $debug ]; then
cat <<EOT
Submitting job with settings:
Name: $jobident, #CPU: $ncores, #Nodes: $nnodes, mem: ${memory}GB, cpy-all? ${copyall}.
EOT
qsub $optionstring $scriptfile
else
cat <<EOT
Submit file created but not submitted.
Name: $inname, #CPU: $ncores, #Nodes: $nnodes, mem: ${memory}GB, cpy-all? ${copyall}.
Submit with qsub $scriptname!
EOT
fi
exit 0