Newer
Older
#!/bin/bash
########### COLOURS
source $MWSHPATH/colours.sh
source $MWSHPATH/out.sh
colBold="\033[1m"
colHead="\033[1;4m"
colClear="\033[0m"
########### NON-GROMACS
function finishUp {
if [ $1 -eq 0 ] ; then
echo -e $colSuccess"Exiting $1"$colClear
else
echo -e $colError"Exiting $1"$colClear
fi
if [[ -z ${SLURM_JOBID} ]] ; then
if [[ $- == *i* ]] ; then
return $1
else
exit $1
fi
else
mkdir ${SLURM_SUBMIT_DIR}/${SLURM_JOBID}_${SLURM_JOB_NAME}
cp -r * ${SLURM_SUBMIT_DIR}/${SLURM_JOBID}_${SLURM_JOB_NAME}/
mv ${SLURM_SUBMIT_DIR}/${SLURM_JOBID}_${SLURM_JOB_NAME}.? ${SLURM_SUBMIT_DIR}/${SLURM_JOBID}_${SLURM_JOB_NAME}/
rm -rf "/users/mw00368/parallel_scratch/"${SLURM_JOBID}_${SLURM_JOB_NAME}/
exit $1
fi
}
function cleanDir {
rm -f \#*
rm -f *.gro
rm -f topol*.top
rm -f topol*.itp
rm -f posre*.itp
rm -f ions.tpr
rm -f *.log
rm -f mdout.mdp
rm -f *.xvg
rm -f *.png
rm -f *.gif
rm -f *.cpt
rm -f *.edr
rm -f *.tpr
rm -f *.trr
rm -f *.xtc
rm -f *.bak
rm -f __temp__*
}
function gmxRet {
GMX_RET=$1; echo -ne "Done, exit code: "
if [ $GMX_RET -eq 0 ] ; then
echo -e $colSuccess"$GMX_RET "$colClear$(/usr/bin/date)
else
echo -e $colError"$GMX_RET "$colClear$(/usr/bin/date)
fi
if [ $GMX_RET -ne 0 ] ; then finishUp $THIS_SECTION; fi
return 0
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
}
function removeWater {
echo -e $colBold"Removing water from PDB."$colClear
grep -v HOH $1 > $2
}
# breakCheck $thisSection $START_AFTER $STOP_AFTER
function breakCheck {
THIS_SECTION=$1
# if this state is less than $START_AFTER
if [ $1 -lt $2 ] ; then
# echo "Not started. Omitting $1."
return 1
fi
# if this state is greater than $STOP_AFTER
if [ $1 -gt $3 ] ; then
# echo "Program finished."
finishUp 0
fi
# echo "Running $1."
return 0
}
# fancyOut <HEADER>
ECHO_STR=" >>> "
function fancyOut {
echo -e $colBold$ECHO_STR$1" [ "$(/usr/bin/date)" ] "$colClear
}
########### GROMACS
function gromax {
COMMAND=$1
# echo $COMMAND
shift
if [[ "$1" == "-l" ]] ; then
shift
LOGNUM=$1
shift
fi
echo -ne $colBold"Running $COMMAND $LOGNUM... "
case "$COMMAND" in
# gyrate)
# VARIABLE=$1
# shift
# echo "$VARIABLE 0" | gmx_mpi $COMMAND $@ > _$COMMAND$LOGNUM.log 2>&1
# GMX_RET=$?
# ;;
energy|trjconv|gyrate)
if [[ "$1" == "-inter" ]] ; then
shift
gmx_mpi $COMMAND $@
GMX_RET=$?
elif [[ "$1" == "-2groups" ]] ; then
shift
VAR1=$1
VAR2=$2
shift
shift
echo "$VAR1 $VAR2" | gmx_mpi $COMMAND $@ > _$COMMAND$LOGNUM.log 2>&1
GMX_RET=$?
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
else
VARIABLE=$1
shift
echo "$VARIABLE 0" | gmx_mpi $COMMAND $@ > _$COMMAND$LOGNUM.log 2>&1
GMX_RET=$?
fi
;;
genion)
if [[ "$1" == "-inter" ]] ; then
shift
gmx_mpi $COMMAND $@
GMX_RET=$?
else
VARIABLE=$1
shift
echo "$VARIABLE" | gmx_mpi $COMMAND $@ > _$COMMAND$LOGNUM.log 2>&1
GMX_RET=$?
fi
;;
rms)
if [[ "$1" == "-inter" ]] ; then
shift
gmx_mpi $COMMAND $@
GMX_RET=$?
else
VARIABLE=$1
shift
echo "$VARIABLE $VARIABLE" | gmx_mpi $COMMAND $@ > _$COMMAND$LOGNUM.log 2>&1
GMX_RET=$?
fi
;;
pdb2gmx)
while test $# -gt 0; do
case "$1" in
-2ter)
shift
TER1=$1
shift
TER2=$1
shift
echo "$TER1 $TER2" | gmx_mpi pdb2gmx $@ -ter > _$COMMAND$LOGNUM.log 2>&1
GMX_RET=$?
break
;;
-nter)
shift
TERS="$1"
echo "<<<""$TERS"">>>"
shift
echo "$TERS" | gmx_mpi pdb2gmx $@ -ter > _$COMMAND$LOGNUM.log 2>&1
GMX_RET=$?
break
;;
-inter)
shift
gmx_mpi pdb2gmx $@ -ter
GMX_RET=$?
break
;;
*)
gmx_mpi pdb2gmx $@ > _$COMMAND$LOGNUM.log 2>&1
GMX_RET=$?
break
;;
esac
done
;;
*)
# echo $COMMAND $@
gmx_mpi $COMMAND $@ > _$COMMAND$LOGNUM.log 2>&1
GMX_RET=$?
;;
esac
gmxRet $GMX_RET
return 0
}
########### ANALYSIS
# echo amp_stats.py --dna-hydrogen-bonds $@
amp_stats.py --dna-hydrogen-bonds $@ > _ampStats$LOGNUM.log 2>&1
function listGroups {
echo -e $colBold"Atom Groups in $colFile"$1$colClear$colBold":"$colClear
echo "q" | gmx_mpi make_ndx -f $1 > _make_ndx.log 2>&1
echo -ne $colVarName
grep -oP --color=never "(?<=\[ ).*(?= \])" index.ndx
echo -ne $colClear
}
function totalCharge {
QTOT=$(grep qtot $1 | tail -n1 | grep -oP '(?<=qtot).*')
echo -e $colFile$2$colClear$colVarName" Total charge $colClear="$colResult"$QTOT"$colClear
return "$QTOT"
}
function numAtomsInResidue {
nA=$(grep $1 $2 | wc -l)
return "$nA"
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
}
function groupStats {
nSys=$(grep "Group" $1 | grep " $2)" | grep -oP "(?<=has ).*(?= elements)")
varOut $2 $nSys atoms
}
function genionSummary {
nRep=$(grep "solute molecules in topology file" _genion*.log | sed "s/Replacing/Replaced/")
echo $nRep
# echo "Replaced "$nRep" with " $(grep -P "(?= by ).*(?=ions.)" _genion*.log)
# Processing topology
# Replacing 46 solute molecules in topology file (topol.top) by 46 NA and 0 CL ions.
}
function numAtomsInDNA {
numAtomsInResidue "DG" $1; nG=$?
numAtomsInResidue "DC" $1; nC=$?
numAtomsInResidue "DT" $1; nT=$?
numAtomsInResidue "DA" $1; nA=$?
let "nTot = $nG + $nC + $nT + $nA"
return $nTot
}
function numAtomsInProtein {
numAtomsInResidue "ALA" $1; nTot=$?
echo $nTot
numAtomsInResidue "CYS" $1; let "nTot = $nTot + $?"
echo $nTot
numAtomsInResidue "ASP" $1; let "nTot = $nTot + $?"
echo $nTot
numAtomsInResidue "GLU" $1; let "nTot = $nTot + $?"
echo $nTot
numAtomsInResidue "PHE" $1; let "nTot = $nTot + $?"
echo $nTot
numAtomsInResidue "GLY" $1; let "nTot = $nTot + $?"
echo $nTot
numAtomsInResidue "HIS" $1; let "nTot = $nTot + $?"
echo $nTot
numAtomsInResidue "ILE" $1; let "nTot = $nTot + $?"
echo $nTot
numAtomsInResidue "LYS" $1; let "nTot = $nTot + $?"
echo $nTot
numAtomsInResidue "LEU" $1; let "nTot = $nTot + $?"
echo $nTot
numAtomsInResidue "MET" $1; let "nTot = $nTot + $?"
echo $nTot
numAtomsInResidue "ASN" $1; let "nTot = $nTot + $?"
echo $nTot
numAtomsInResidue "PRO" $1; let "nTot = $nTot + $?"
echo $nTot
numAtomsInResidue "GLN" $1; let "nTot = $nTot + $?"
echo $nTot
numAtomsInResidue "ARG" $1; let "nTot = $nTot + $?"
echo $nTot
numAtomsInResidue "SER" $1; let "nTot = $nTot + $?"
echo $nTot
numAtomsInResidue "THR" $1; let "nTot = $nTot + $?"
echo $nTot
numAtomsInResidue "VAL" $1; let "nTot = $nTot + $?"
echo $nTot
numAtomsInResidue "TRP" $1; let "nTot = $nTot + $?"
echo $nTot
numAtomsInResidue "TYR" $1; let "nTot = $nTot + $?"
echo $nTot
return $nTot
}
function minimStats {
COMMAND=$1
LOGNUM=$2
tail -n7 _$COMMAND$LOGNUM.log | head -n4
}
function xvg2png {
GPSTRING=""
TITLE_SET=0
while test $# -gt 0; do
case "$1" in
-h|--help)
echo -e "Usage for "$colFunc"xvg2png"$colClear":"
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
echo -e "\n""Basic:"
flagOut "-f|--filename" "<STRING>" "Plot <STRING>.xvg"
flagOut "-o|--output" "<STRING>" "Produce <STRING>.png"
flagOut "-t|--title" "<STRING>" "Graph title"
flagOut "-xl|--xlabel" "<STRING>" "Set the x-label"
flagOut "-yl|--ylabel" "<STRING>" "Set the y-label"
flagOut "-xt|--xtics" "<FLOAT>" "Set the frequency of the x ticks"
flagOut "-yt|--ytics" "<FLOAT>" "Set the frequency of the y ticks"
flagOut "-xs|--xscientific" "" "Show the x-axis values in scientific format"
flagOut "-ys|--yscientific" "" "Show the y-axis values in scientific format"
flagOut "-xmin" "<FLOAT>" "Set the lower bound of the x-axis range"
flagOut "-xmax" "<FLOAT>" "Set the upper bound of the x-axis range"
flagOut "-ymin" "<FLOAT>" "Set the lower bound of the y-axis range"
flagOut "-ymax" "<FLOAT>" "Set the upper bound of the y-axis range"
flagOut "-l|--lognum" "<INTEGER>" "Set the logfile to '_gp<INTEGER>.log'"
echo -e "\n""Two xvg's on the same axes:"
flagOut "-dp|--double-plot" "<STRING>" "Produce <STRING>.png"
flagOut "-f2|--filename2" "<STRING>" "Also plot <STRING>.xvg"
flagOut "-t1|--title1" "<STRING>" "Title for first datafile"
flagOut "-t2|--title2" "<STRING>" "Title for second datafile"
echo -e "\n""Analysis:"
flagOut "-ra|--running-average" "" "Running average of last five data points"
flagOut "-cf|--constfit" "" "Fit y=c to the data"
flagOut "-fmin" "<FLOAT>" "Set the lower bound of the fitting range"
flagOut "-fmax" "<FLOAT>" "Set the upper bound of the fitting range"
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
# finishUp 0
return
exit
;;
-f|-f1|--filename|--filename1)
shift
PLOTFILE=$1
GPSTRING=$GPSTRING"filename='$1';"
shift
;;
-f2|--filename2)
shift
GPSTRING=$GPSTRING"filename2='$1';"
shift
;;
-o|--output)
shift
GPSTRING=$GPSTRING"output='$1';"
shift
;;
-t|--title)
shift
GPSTRING=$GPSTRING"title='$1';"
TITLE_SET=1
shift
;;
-t1|--title1)
shift
GPSTRING=$GPSTRING"title1='$1';"
shift
;;
-t2|--title2)
shift
GPSTRING=$GPSTRING"title2='$1';"
shift
;;
-dp|--doubleplot)
shift
GPSTRING=$GPSTRING"doubleplot=1;"
;;
-xl|--xlabel)
shift
GPSTRING=$GPSTRING"xlab='$1';"
shift
;;
-yl|--ylabel)
shift
GPSTRING=$GPSTRING"ylab='$1';"
shift
;;
-xt|--xtics)
shift
GPSTRING=$GPSTRING"xtic=$1;"
shift
;;
-yt|--ytics)
shift
GPSTRING=$GPSTRING"ytic=$1;"
shift
;;
-xs|--xscientific)
shift
GPSTRING=$GPSTRING"xsci=1;"
;;
-ys|--yscientific)
shift
GPSTRING=$GPSTRING"ysci=1;"
;;
-ra|--running-average)
shift
GPSTRING=$GPSTRING"runavg=1;"
;;
-xmin)
shift
GPSTRING=$GPSTRING"xmin=$1;"
shift
;;
-xmax)
shift
GPSTRING=$GPSTRING"xmax=$1;"
shift
;;
-ymin)
shift
GPSTRING=$GPSTRING"ymin=$1;"
shift
;;
-ymax)
shift
GPSTRING=$GPSTRING"ymax=$1;"
shift
;;
-cf|--constfit)
shift
GPSTRING=$GPSTRING"constfit=1;"
;;
-fmin|--fitmin)
shift
GPSTRING=$GPSTRING"fitmin=$1;"
shift
;;
-fmax|--fitmax)
shift
GPSTRING=$GPSTRING"fitmax=$1;"
shift
;;
-l|--lognum)
shift
LOGNUM=$1
shift
;;
*)
echo -e $colError"Unrecognised flag: "$colArg$1$colClear
shift
finishUp 2
;;
esac
done
NUM_MATCH=$(grep "@ s0 legend" $PLOTFILE".xvg" | grep -oP '(?<=").*(?=")' | wc -l)
if [ $NUM_MATCH -eq 0 ] ; then
SELECT=$(grep " title" $PLOTFILE".xvg" | grep -oP '(?<=").*(?=")')
else
SELECT=$(grep "@ s0 legend" $PLOTFILE".xvg" | grep -oP '(?<=").*(?=")')
fi
gnuplot -e "$GPSTRING" $GROMAX/xvg2png.gp > _gp$LOGNUM.log 2>&1
gmxRet $?
}