-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgmxcpi
executable file
·218 lines (205 loc) · 6.63 KB
/
gmxcpi
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
#!/bin/bash
idx=""
jobid="${JOB_ID}"
jobidin=""
while getopts "i:j:k:h" opt; do
case ${opt} in
h)
echo "Usage: $(basename $0) [-h] [-i index] [-j jobid] [-k jobid_in]"
exit 0
;;
i)
idx="${OPTARG}"
;;
j)
jobid="${OPTARG}"
;;
k)
jobidin="${OPTARG}"
;;
?|*)
echo "No such option available."
;;
esac
done
echo "Idx = ${idx}"
pref="${idx:+${idx}_}"
suff="${jobid:+_${jobid}}"
suffin="${jobidin:+_${jobidin}}"
if [ -z "${pref}" ]; then
echo "Must specify a step index"
exit 127
fi
# Check for presence of all required files
if [ ! -f ${pref}topol.top ]; then
echo "Missing ${pref}topol.top" >&2
exit 126 # Unsigned byte => -1
else
echo "Using topology file ${pref}topol.top" >&2
file_top="${pref}topol.top"
fi
if [ ! -f ${pref}step.mdp ]; then
echo "Missing ${pref}step.mdp" >&2
exit 125 # Unsigned byte => -2
else
echo "Using MD parameters in ${pref}step.mdp" >&2
file_mdp="${pref}step.mdp"
fi
if [ ! -f ${pref}confout${suffin}.gro ]; then
echo "Missing ${pref}confout${suffin}.gro" >&2
echo "Checking to see if similar exist" >&2
read -a files <<<$(ls -rt1 ./${pref}confout*.gro | xargs)
if [ ${#files[@]} -gt 0 ]; then
echo "Checking files found:" >&2
for ((i=0;i<${#files[@]};i++))
do
echo "(${i}) ${files[i]}" >&2
done
echo "Using most recent: ${files[0]}" >&2
echo -n "Okay? (y/N): "
read ans
if [ "${ans}" = "y" ] || [ "${ans}" = "Y" ]; then
echo "Okay. Using GRO file ${files[0]}" >&2
file_gro="${files[0]}"
else
if [[ ${ans} =~ ^[0-9]+$ ]]; then
if [ ${ans} -ge ${#files[@]} ]; then
echo "Bad file index. Bye." >&2
exit 125
else
echo "Using file ${ans}, ${files[${ans}]}"
file_gro="${files[${ans}]}"
fi
else
echo "Cannot resolve which confin.gro to use" >&2
exit 124 # Unsigned byte => -3
fi
fi
else
echo "Could not find any alternative matching files"
exit 123 # Unsigned byte => -4
fi
else
file_gro="${pref}confout${suffin}.gro"
fi
if [ ! -f ${pref}traj${suffin}.trr ]; then
echo "Missing ${pref}traj${suffin}.trr" >&2
echo "Checking to see if similar exist" >&2
read -a files <<<$(ls -rt1 ./${pref}traj*.trr | xargs)
if [ ${#files[@]} -gt 0 ]; then
echo "Checking files found:" >&2
for ((i=0;i<${#files[@]};i++))
do
echo "(${i}) ${files[i]}" >&2
done
echo "Using most recent: ${files[0]}" >&2
echo -n "Okay? (y/N): "
read ans
if [ "${ans}" = "y" ] || [ "${ans}" = "Y" ]; then
echo "Okay. Using TRR file ${files[0]}" >&2
file_trr="${files[0]}"
else
if [[ ${ans} =~ ^[0-9]+$ ]]; then
if [ ${ans} -ge ${#files[@]} ]; then
echo "Bad file index. Bye." >&2
exit 125
else
echo "Using file ${ans}, ${files[${ans}]}"
file_trr="${files[${ans}]}"
fi
else
echo "Cannot resolve which traj.trr to use" >&2
exit 124 # Unsigned byte => -3
fi
fi
else
echo "Could not find any alternative matching files"
exit 123 # Unsigned byte => -4
fi
else
file_trr="${pref}traj${suffin}.trr"
fi
if [ ! -e "$((idx+1))_topol.top" ]; then
echo "Copying ${file_top} => $((idx+1))_topol.top" >&2
cp ${file_top} $((idx+1))_topol.top
else
echo "File $((idx+1))_topol.top already exists" >&2
echo -n "Overwrite? (y/N): " >&2
read ans
if [ "${ans}" = "y" ] || [ "${ans}" = "Y" ]; then
cp ${file_top} $((idx+1))_topol.top
else
echo "Continuing with file already present" >&2
fi
fi
if [ ! -e "$((idx+1))_step.mdp" ]; then
echo "Copying ${file_mdp} => $((idx+1))_step.mdp" >&2
cp ${file_mdp} $((idx+1))_step.mdp
else
echo "File $((idx+1))_step.mdp already exists" >&2
echo -n "Overwrite? (y/N): " >&2
read ans
if [ "${ans}" = "y" ] || [ "${ans}" = "Y" ]; then
cp ${file_mdp} $((idx+1))_step.mdp
else
echo "Continuing with file already present" >&2
fi
fi
cp ${file_mdp} $((idx+1))_step.mdp
if [ ! -e "$((idx+1))_confin.gro" ]; then
echo "Linked ${file_gro} => $((idx+1))_confin.gro" >&2
ln -s ${file_gro} $((idx+1))_confin.gro
else
echo "Link already exists" >&2
echo -n "Remove and relink? (y/N): "
read ans
if [ "${ans}" = "y" ] || [ "${ans}" = "Y" ]; then
rm $((idx+1))_confin.gro
ln -s ${file_gro} $((idx+1))_confin.gro
else
echo "Cannot continue without this link as input" >&2
exit 122
fi
fi
if [ ! -e "$((idx+1))_trajin.trr" ]; then
echo "Linked ${file_trr} => $((idx+1))_trajin.trr" >&2
ln -s ${file_trr} $((idx+1))_trajin.trr
else
echo "Link already exists" >&2
echo -n "Remove and relink? (y/N): "
read ans
if [ "${ans}" = "y" ] || [ "${ans}" = "Y" ]; then
rm $((idx+1))_trajin.trr
ln -s ${file_trr} $((idx+1))_trajin.trr
else
echo "Cannot continue without this link as input" >&2
exit 122
fi
fi
fntmpin="${pref}sge-mdrun"
echo -n "Copy and update submit scripts? (y/N): " >&2
read ans
if [ "${ans}" = "y" ] || [ "${ans}" = "Y" ]; then
sed -r -e '/^#\$ \-N /s/'${idx}'/'$((idx+1))'/g' -e '/^[ \t]*idx="[^"]".*/s/'${idx}'/'$((idx+1))'/g' ${pref}sge-mdrun > .$((idx+1))_sge-mdrun.tmp
fntmpin=".$((idx+1))_sge-mdrun.tmp"
fi
echo -n "Update parallel methodology for this run? (y/N): " >&2
read ans
if [ "${ans}" = "y" ] || [ "${ans}" = "Y" ]; then
echo -n "Enter number of threads for thread MPI (0 for no tMPI): " >&2
read ans
if [ "${ans}" -gt 0 ]; then
echo "Adding -nt ${ans} switch to EXENAME_MDRUN" >&2
sed -r -e '/^[ \t]*EXENAME_MDRUN="\$\{MDRUN\} (-nt [0-9]+)?"/s/\$\{MDRUN\} (-nt [0-9]+)?/${MDRUN} -nt '${ans}'/g' ${fntmpin} > $((idx+1))_sge-mdrun
else
echo "Removing -nt switch from arguments" >&2
sed -r -e '/^[ \t]*EXENAME_MDRUN="\$\{MDRUN\} (-nt [0-9]+)?"/s/\$\{MDRUN\} (-nt [0-9]+)?/${MDRUN} /g' ${fntmpin} > $((idx+1))_sge-mdrun
fi
fi
if [ -f ".$((idx+1))_sge-mdrun.tmp" ]; then
echo -n "Cleaning up temporary files... " >&2
rm -rf ".$((idx+1))_sge-mdrun.tmp"
echo "Done." >&2
fi
echo "Finished" >&2
# vim: tabstop=4:softtabstop=4:shiftwidth=4:expandtab:smarttab