-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamk.sh
367 lines (357 loc) · 14.2 KB
/
amk.sh
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
#!/bin/bash
source utils.sh
#On exit remove tmp files
tmp_files=(ConnMat tmp* ScalMat *.arc *.mop fort.* partial_opt ts_opt *_dyn* *_backup rotate.dat minn black_list* bfgs.log none.out forces.xyz velocities.xyz restraints.xyz energies.txt freq.molden min.xyz ts_opt.xyz ts.xyz min_opt.xyz v0 grad.*)
trap 'err_report2 $LINENO $gauss_line' ERR
trap cleanup EXIT INT
##Defining paths and names
cwd=$PWD
sharedir=${AMK}/share
exe=$(basename $0)
if [ $# -eq 0 ]; then usages "One argument is required" ; fi
inputfile=$1
# Printing the references of the method
print_ref
##Define input file and create symbolic link-->amk.dat
define_inputfile
###Reading stuff from inputfile
read_input
###keywords check
keywords_check
### check files and write some stuff
xyzfiles_check
###Peforming some calcs for the various samplings
sampling_calcs
### print method and screening sections
amkscript=1
print_method_screening
#################################
## Starting the calculations
#################################
echo ""
echo "CALCULATIONS START HERE"
#####for association and vdw get the association complexes
if [ $sampling -ge 30 ]; then
exec_assoc
###for association stop here
if [ $sampling -eq 30 ]; then
echo ""
echo "END OF THE CALCULATIONS"
echo "Check your ${frA}-${frB} structure in file ${molecule}.xyz"
echo ""
exit
fi
fi
###ExtForce--> genenerate forces
if [ $sampling -eq 3 ]; then
ba=$(echo "$nb" | awk 'BEGIN{ba=0};/batch/{ba=1};END{print ba}')
if [ $ba -eq 0 ]; then
echo ExtForce sampling must be submitted with llcalcs.sh or amk_parallel.sh
exit 1
else
mdc=2
nba0=$(echo "$nb" | sed 's/batch//')
nba=$(echo "$nba0" | awk '{a=$1/'$nforces' ;if(a==int(a)) print a; else print int(a+1)}' )
fstp=$((nba0-nforces*nba))
fstp0=$((1-nforces))
force=$((30*nforces+fstp*30))
nbondsform=$(awk 'NR=='$nba'{n=0;for(i=1;i<=NF;i++) if($i=="f") ++n };END{print n}' ${tsdirll}/ts_bonds.inp )
if [ $nbondsform -gt 0 ]; then
awk 'NR=='$nba'{n=0;for(i=1;i<=NF;i++) if($i=="f") print $(i+1),$(i+2),'$force' }' ${tsdirll}/ts_bonds.inp > fort.69
else
if (( $(echo "$fstp > $fstp0" |bc -l) )); then
echo "No bonds formed-->Only the first batch is employed"
exit 1
fi
fi
nbondsbreak=$(awk 'NR=='$nba'{n=0;for(i=1;i<=NF;i++) if($i=="b") ++n };END{print n}' ${tsdirll}/ts_bonds.inp )
if [ $nbondsbreak -gt 0 ]; then
awk 'NR=='$nba'{n=0;for(i=1;i<=NF;i++) if($i=="b") print $(i+1),$(i+2),"110" }' ${tsdirll}/ts_bonds.inp > fort.68
fi
fi
createMat.py ${molecule}.xyz 1
else
##select starting structure
sel_mol.sh $inputfile $multiple_minima
frag_check
##lift MD-constraint in subsequent iterations (diels_bias for instance)
if [ -f $kmcfilell ] && [ -f $minfilell ] && [ $mdc -ge 1 ] && [ $ndis -eq 1 ]; then mdc=0 ; fi
fi
##template for the dynamics
generate_dynamics_template
##make temporary folders
make_temp_folders
###Opt the starting structure and get e0 and emaxts
opt_start
####
if [ $mdc -ge 1 ]; then itrajn=5 ; fi
###Loop over the trajectories
for i in $(seq 1 $itrajn)
do
named=${molecule}_dyn${i}
echo ""
##Empty temporary folders
rm -rf partial_opt/* ts_opt/*
####
#This is only for internal dynamics (MOPAC)
####
if [ $mdc -ge 1 ] && [ $i -gt 1 ]; then
echo "Searching for reactive events with:"
else
echo ""
echo "+-+-+-+-+-+-+-+-+- Trajectory ${i} +-+-+-+-+-+-+-+-+-"
if [ $md -eq 0 ]; then
echo "Performing BXDE MD"
if [ "$program_md" = "qcore" ]; then sed 's/carga/'$charge'/' ${sharedir}/grad > grad.dat ; fi
bxde.py $inputfile &> ${named}.log
if [ ! -f traj.xyz ]; then
echo "traj.xyz does not exist"
continue
else
mv traj.xyz coordir/${named}.xyz
if [ $postp_alg -eq 2 ]; then mv bond_order.txt coordir/${named}.bo ; fi
fi
elif [ $md -eq 1 ]; then
echo "Performing standard MD"
echo "$dytem1" > ${named}.mop
initialqv_mopac_samp1.sh ${molecule}_freq.out $seed $excite $nlms $lstnm | nm.exe >> ${named}.mop
mopac ${named}.mop &> ${named}.log
if [ ! -f ${named}.xyz ]; then
echo "${named}.xyz does not exist"
continue
else
mv ${named}.xyz coordir
fi
elif [ $md -eq 2 ]; then
echo "Performing standard MD"
if [ "$program_md" = "mopac" ]; then
echo "$dytem1" > ${named}.mop
if [ $sampling -eq 3 ]; then thmass=-1 ; fi
initialqv_mopac_samp2.sh ${molecule}_freq.out $excite $nlms $lstnm $thmass | termo.exe | sed 's/ 1.d/1.d/g' >> ${named}.mop
mopac ${named}.mop &> ${named}.log
if [ ! -f ${named}.xyz ]; then
echo "${named}.xyz does not exist"
continue
else
mv ${named}.xyz coordir
fi
elif [ "$program_md" = "qcore" ]; then
rm -rf traj.xyz
sed 's/carga/'$charge'/' ${sharedir}/MD > ${named}.qcore
sed -i 's/500/'$nfs'/' ${named}.qcore
awk 'NR!=2{print $0};NR==2{print ""};END{print '"$excite"'"\n0\n0"}' opt_start.xyz | termo.exe | awk 'BEGIN{c=4.5710047e-9;print '$natom'"\n"};NF==3{print $1*c,$2*c,$3*c}' >v0
entos.py ${named}.qcore > ${named}.out 2>&1
if [ ! -f traj.xyz ]; then
echo "traj.xyz does not exist"
continue
else
mv traj.xyz coordir/${named}.xyz
fi
fi
else
echo "Reading external dynamics results from coordir"
fi
fi
if [ $postp_alg -eq 0 ]; then
echo "End of traj "$i
echo "Only trajs. No post-processing algorithm applied to search for TSs"
break
elif [ $postp_alg -eq 1 ]; then
postp_file=bbfs
elif [ $postp_alg -eq 2 ]; then
postp_file=bots
fi
###########
#From here everything is common for internal and external dynamics
###########
if [ $i -eq 1 ]; then
echo " *+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*" > ${postp_file}.out
echo " $postp_file algorithm results " >> ${postp_file}.out
echo " *+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*" >> ${postp_file}.out
echo "" >> ${postp_file}.out
fi
echo " Trajectory $i" >> ${postp_file}.out
if [ $postp_alg -eq 1 ]; then
if [ $mdc -eq 0 ]; then
snapshots_mopac.sh coordir/${named}.xyz $irange | bbfs.exe >> ${postp_file}.out
elif [ $mdc -ge 1 ]; then
namedc=${molecule}_dyn1
irange=$((20-4*(i - 1) ))
irangeo2=$(echo "scale=0; $irange/2" | bc )
echo "Time window (fs) = $irange "
snapshots_mopac.sh coordir/${namedc}.xyz $irange | bbfs.exe >> ${postp_file}.out
fi
elif [ $postp_alg -eq 2 ]; then
bots.py $natom $cutoff $stdf ${named} >> ${postp_file}.out
fi
path=$(awk '/Number of paths/{np=$4};END{print np}' ${postp_file}.out )
if [ $path -eq 0 ]; then
echo "This traj has no paths "
continue
fi
echo "Npaths=" $path
chapath[0]=0
for ip in $(seq $path)
do
# Find the highest energy point
if [ $postp_alg -eq 1 ]; then
ijc=$(awk '/Joint path=/{if($2=='$ip') ijc=$5};END{print ijc}' ${postp_file}.out)
else
ijc=0
fi
jp=$((ip - 1))
##If previous path was multiple, continue
chapath[$ip]=$ijc
if [ ${chapath[$jp]} -eq 1 ]; then continue ; fi
##
if [ $ijc -eq 0 ]; then
echo "Path" $ip" (Single): $nppp attempt(s) to locate the ts"
ll=$((wrkmode-1))
dlt=$((wrkmode+1))
ul=1
elif [ $ijc -eq 1 ]; then
echo "Path" $ip" (Multiple): several attempts to locate the ts"
ll=$((1 - irangeo2))
dlt=$(echo "scale=2; $irange/6" | bc | awk '{print int($1+0.5)}')
ul=$irangeo2
fi
npo=0
for itspt in $(seq $ll $dlt $ul)
do
npo=$((npo + 1))
ctspt=$((100*ip + irangeo2 + itspt))
echo "$min_template" > partial_opt/pes$ctspt
if [ $postp_alg -eq 1 ]; then
cat partial_opt/fort.$ctspt >> partial_opt/pes$ctspt
else
cat partial_opt/fort.$ip >> partial_opt/pes$ctspt
fi
if [ "$program_md" = "mopac" ]; then
mopac partial_opt/pes$ctspt 2> /dev/null
geo_pes=$(get_geom_mopac.sh partial_opt/pes${ctspt}.out)
if [ "$geo_pes" = "Error" ]; then continue ; fi
elif [ "$program_md" = "qcore" ]; then
echo $natom > min.xyz
echo "" >> min.xyz
if [ $postp_alg -eq 1 ]; then
awk '{print $1,$2,$4,$6}' partial_opt/fort.$ctspt >> min.xyz
labels=$(awk '{if($3=="0") {printf "%s%s",sep,NR; sep=","}};END{print ""}' partial_opt/fort.$ctspt)
else
awk '{print $1,$2,$4,$6}' partial_opt/fort.$ip >> min.xyz
labels=$(awk '{if($3=="0") {printf "%s%s",sep,NR; sep=","}};END{print ""}' partial_opt/fort.$ip)
fi
sed 's/labels/'"$labels"'/g;s/carga/'$charge'/' ${sharedir}/opt_frozen > partial_opt/pes_qcore
entos.py partial_opt/pes_qcore > partial_opt/pes_qcore.out
if [ ! -f min_opt.xyz ]; then
printf " Pt%2s: failed-->Partial Opt failed\n" $npo
continue
fi
fi
name=ts${i}_${ip}_${ctspt}
fileden=ts_opt/${name}.den
if [ "$program_opt" = "mopac" ]; then
echo "$ts_template" > ts_opt/$name
echo "$geo_pes" | awk 'NF==4{print $0}' >> ts_opt/$name
echo "$freq_template" | sed 's/oldgeo/oldgeo oldens/' >> ts_opt/$name
mopac ts_opt/$name 2> /dev/null
file=ts_opt/${name}.out
#If too many variables, run ts int
if [ $(awk 'BEGIN{f=0};/Too many variables/{f=1};END{print f}' $file) -eq 1 ]; then
sed -i 's/ts /ts int /g' ts_opt/$name
mopac ts_opt/$name 2> /dev/null
fi
###
elif [ "$program_opt" = "qcore" ]; then
mv min_opt.xyz ts.xyz
sed 's/carga/'$charge'/' ${sharedir}/optTS > ts_opt/ts.dat
entos.py ts_opt/ts.dat > ts_opt/${name}.out
if [ ! -f ts_opt.xyz ]; then
printf " Pt%2s: failed-->No XYZ file found for the TS\n" $npo
echo Error >> ts_opt/${name}.out
continue
else
cat ts_opt.xyz >> ts_opt/${name}.out
fi
file=ts_opt/${name}.out
else
#construct g09 input file
chkfile=ts_opt/ts$name
calc=ts
geo="$(echo "$geo_pes" | awk 'NF==4{print $0};END{print ""}')"
level=ll
g09_input
echo -e "$ig09\n\n" > ts_opt/${name}.dat
g09 <ts_opt/${name}.dat >ts_opt/${name}.log && gauss_line=$(echo $LINENO)
file=ts_opt/${name}.log
ok=$(awk 'BEGIN{fok=0;ok=0;err=0};/Frequencies/{++nfreq;if($3<0 && $4>0 && nfreq==1) fok=1};/Error termi/{++err};END{if(err==0 && fok==1) ok=1; print ok}' $file)
# ok=$(awk 'BEGIN{ok=0};/Frequencies/{++nfreq;if($3<0 && $4>0 && nfreq==1) ok=1};END{print ok}' $file)
if [ $ok -eq 1 ]; then
get_energy_g09_${LLcalc}.sh $file 1 > tmp_gauss
get_freq_g09.sh $file >> tmp_gauss
else
printf " Pt%2s: failed-->EF algorithm was unable to optimize a TS\n" $npo
continue
fi
fi
fe="$(mopac_freq_ts.sh $file $prog)"
fi="$(echo "$fe" | awk '{printf "%10.0f",$1}')"
ei="$(echo "$fe" | awk '{printf "%14.6f",$2}')"
if [[ ("$fi" -eq -1) ]]; then
printf " Pt%2s: failed-->Lowest real freq is negative\n" $npo
continue
elif [[ ("$fi" -eq -2) ]]; then
printf " Pt%2s: failed-->Sum of 2 lowest real freqs < 10cm-1\n" $npo
continue
elif [[ ("$fi" -eq -3) ]]; then
printf " Pt%2s: failed-->Stationary point is a minimum\n" $npo
continue
elif [[ ("$fi" -eq -4) ]]; then
printf " Pt%2s: failed-->EF algorithm was unable to optimize a TS\n" $npo
continue
elif (( $(echo "$ei > $emaxts" |bc -l) )); then
printf " Pt%2s: TS optimized but not added-->E=%20s > %20s \n" $npo $ei $emaxts
continue
fi
if [[ ("$fi" -ge "$imag") ]]; then
string="$(echo "$fe" | awk '{printf "%10.0f %10.4f %10.0f %10.0f %10.0f %10.0f",$1,$2,$3,$4,$5,$6}')"
# GLB added lock to tslist so that duplicate numbers are not created
(
flock -x 200 || exit 1
if [ -f "$tslistll" ]; then
ok=$(diff.sh $string $tslistll $prog)
if [[ ("$ok" -eq "-1") ]]; then
nt=$(awk '{nt=$2};END{print nt + 1}' $tslistll )
name=ts${nt}_${nb}
printf "ts%5s%18s%70s traj= %4s Path= %10s\n" $nt $name "$string" $i $nb >> $tslistll
cp ${file} ${tsdirll}/${name}.out
if [ -f ${fileden} ]; then cp ${fileden} ${tsdirll}/${name}.den ; fi
printf " Pt%2s: TS optimized and added to ts list\n" $npo
if [ "$program_opt" = "qcore" ]; then mv freq.molden $tsdirll/${name}.molden ; fi
if [ "$program_opt" = "mopac" ]; then get_NM_mopac.sh $tsdirll/${name}.out $tsdirll/${name} ; fi
else
printf " Pt%2s: TS optimized but not added-->redundant with ts %4s\n" $npo $ok
fi
else
nt=1
name=ts${nt}_${nb}
printf "ts%5s%18s%70s traj= %4s Path= %10s\n" $nt $name "$string" $i $nb >> $tslistll
cp ${file} ${tsdirll}/${name}.out
if [ -f ${fileden} ]; then cp ${fileden} ${tsdirll}/${name}.den ; fi
printf " Pt%2s: TS optimized and added to ts list\n" $npo
if [ "$program_opt" = "qcore" ]; then mv freq.molden $tsdirll/${name}.molden ; fi
if [ "$program_opt" = "mopac" ]; then get_NM_mopac.sh $tsdirll/${name}.out $tsdirll/${name} ; fi
fi
) 200>>${tslistll}.lock
#if [ $mdc -eq 1 ]; then exit ; fi
break
else
printf " Pt%2s: TS optimized but not added-->imag=%4si cm-1 < %4si cm-1\n" $npo $fi $imag
fi
done
done
done
if [ $sampling -ne 30 ]; then
echo ""
echo "END OF THE CALCULATIONS"
echo ""
fi