-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathinitram.sh
executable file
·560 lines (423 loc) · 13.1 KB
/
initram.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
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
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
#!/bin/bash
PROGRAM=initram.sh
VERSION=0.1
VERSTAG=20150906-13-TAW
AUTHOR="Tsjerk A. Wassenaar, PhD"
YEAR="2014"
AFFILIATION="
Computational Biology
Friedrich-Alexander University Erlangen-Nuernberg
Staudstrasse 5
91058 Erlangen
Germany
"
CMD="$0 $@"
DESCRIPTION=$(cat << __DESCRIPTION__
This is a convenience script to convert a coarse-grained system
into a united-atom or all-atom representation by projection
and subsequent relaxation. The script is a wrapper around
backward.py, which is called for the projection of the coarse-
grained system to unit-atom or all-atom, and GROMACS, which is
used for energy minimization and further relaxation using
molecular dynamics.
The script requires a COARSE-GRAINED input structure and a
corresponding ATOMISTIC topology file. The topology file will
be used to define the target particle list, allowing setting
protonation states, virtual sites, and even mutations by
providing an alternative topology. Atom list, atom names and
residue names from the topology file take precedence over the
ones in the structure file.
The script has a number of options to control the backmapping
process. The default options are chosen to give a robust protocol,
which can be used for backmapping of virtually any system. This
protocol is tested for systems containing protein, membrane and
solvent, with a total target size of up to a million particles.
The default protocol consists of the following steps:
1. Projection
2. Energy minimization (500 steps), excluding non-bonded interactions
between atoms in selected groups, e.g. membrane and protein.
3. Energy minimization (500 steps)
4. Position restrained NVT simulation (300K), with time step 0.2 fs
5. Position restrained NVT simulation (300K), with time step 0.5 fs
6. Position restrained NVT simulation (300K), with time step 1.0 fs
7. Position restrained NVT simulation (300K), with time step 2.0 fs
These steps can be modified using the options, as listed below.
It is possible to extend the protocol using a number of user-supplied
run parameter (.mdp) files. These will be run after step 7. Multiple
mdp files can be supplied, which will be processed in the order given
(e.g., -mdp param1.mdp -mdp param2.mdp).
At the end of the process timing information is given summarizing the
time per step and the cumulative run time.
__DESCRIPTION__
)
# These will be looked for before running
DEPENDENCIES=(backward.py grompp mdrun)
# Get script directory
#
# A: Test if program name contains a slash (1)
# If so, change directory to program directory (2)
# B: Echo working directory, which will always be
# the program directory
#
# |---------------A---------------| |B|
# |--------1--------| |---2----|
SDIR=$( [[ $0 != ${0%/*} ]] && cd ${0%/*}; pwd )
# - main options:
INP=
TOP=
AAS=
OUT=backmapped.gro
OTP=backmapped.top
NDX=backmapped.ndx
RAW=projected.gro
BW=0-backward.gro
CG=martini
AA=gromos54a7
SOL=SOL
NUM=1
EMNP=1
NP=0
KICK=0.05
NOPBC=
KEEP=false
TRJ=false
EMSTEPS=500
NBSTEPS=500
MDSTEPS=500
DT=0.0002,0.0005,0.001,0.002
MDP=()
POSRE=true
# - em/md options
OPTIONS=$(cat << __OPTIONS__
## OPTIONS ##
INITRAM options:
-f Input coarse grained structure *FILE: None
-p Input atomistic target topology *FILE: None
-a Input atomistic structure *FILE: None
-po Output processed topology *FILE: $OTP
-o Output atomistic structure *FILE: $OUT
-from Coarse grained force field *STR: $CG
-to Target forcefield *STR: $AA
-sol Solvent residue name *STR: $SOL
-n Number of runs *INT: $NUM
-np Number of processors/threads *INT: $NP
-emnp Number of processors/threads for EM *INT: $EMNP
-fc Position restraint force constant *FLOAT: None
-kick Random kick size *FLOAT: $KICK
-keep Do not delete intermediate files *BOOL: false
-trj Write a trajectory for each stage of relaxation *BOOL: false
-em Number of steps for EM with bonded interactions only *INT: $EMSTEPS
-nb Number of steps for EM with nonbonded interactions *INT: $NBSTEPS
-md Number of steps for MD cycles *INT: $MDSTEPS
-dt Time steps for successive MD cycles (comma separated list) *STR: $DT
-nopr Disable position restraints *BOOL: false
-mdp User provided MDP file for post-hoc simulations *FILE: None
Multiple instances possible
__OPTIONS__
)
USAGE ()
{
cat << __USAGE__
$PROGRAM version $VERSION:
$DESCRIPTION
$OPTIONS
(c)$YEAR $AUTHOR
$AFFILIATION
__USAGE__
}
BAD_OPTION ()
{
echo
echo "Unknown option "$1" found on command-line"
echo "It may be a good idea to read the usage:"
echo -e $USAGE
exit 1
}
while [ -n "$1" ]; do
case $1 in
-h) USAGE ; exit 0 ;;
# File options
-f) INP=$2 ; shift 2; continue ;;
-p) TOP=$2 ; shift 2; continue ;;
-a) AAS=$2 ; shift 2; continue ;;
-po) OTP=$2 ; shift 2; continue ;;
-o) OUT=$2 ; shift 2; continue ;;
-n) NUM=$2 ; shift 2; continue ;;
-np) NP=$2 ; shift 2; continue ;;
-emnp) EMNP=$2 ; shift 2; continue ;;
-from) CG=$2 ; shift 2; continue ;;
-to) AA=$2 ; shift 2; continue ;;
-sol) SOL=$2 ; shift 2; continue ;;
-kick) KICK=$2 ; shift 2; continue ;;
-nopbc) NOPBC=-nopbc ; shift ; continue ;;
-keep) KEEP=true ; shift ; continue ;;
-trj) TRJ=true ; shift ; continue ;;
-em) EMSTEPS=$2 ; shift 2; continue ;;
-nb) NBSTEPS=$2 ; shift 2; continue ;;
-md) MDSTEPS=$2 ; shift 2; continue ;;
-dt) DT=$2 ; shift 2; continue ;;
-nopr) POSRE=false ; shift ; continue ;;
-mdp) MDP[${#MDP[@]}]=$2 ; shift 2; continue ;;
*) BAD_OPTION $1;;
esac
done
cat << __RUNINFO__
$PROGRAM version $VERSION:
(c)$YEAR $AUTHOR
$AFFILIATION
Now executing...
$CMD
__RUNINFO__
# Bookkeeping
# Check input
[[ -z $INP ]] && echo FATAL ERROR: MISSING INPUT STRUCTURE FILE && exit 1
[[ -z $TOP ]] && echo FATAL ERROR: MISSING INPUT TOPOLOGY FILE && exit 1
# Check grompp/mdrun
if command -v grompp >/dev/null 2>&1
then
GROMPP=grompp
elif command -v grompp_mpi >/dev/null 2>&1
then
GROMPP=grompp_mpi
elif command -v gmx >/dev/null 2>&1
then
GROMPP="gmx grompp"
elif command -v gmx_mpi >/dev/null 2>&1
then
GROMPP="gmx_mpi grompp"
else
echo FATAL ERROR: grompp not found
exit 1
fi
if command -v mdrun >/dev/null 2>&1
then
MDRUN=mdrun
elif command -v mdrun_mpi >/dev/null 2>&1
then
MDRUN=mdrun_mpi
elif command -v gmx >/dev/null 2>&1
then
MDRUN="gmx mdrun"
elif command -v gmx_mpi >/dev/null 2>&1
then
MDRUN="gmx_mpi mdrun"
else
echo FATAL ERROR: mdrun not found
exit 1
fi
# Gromacs version
GMXVERSION=($($GROMPP -h 2>&1 | sed -n '/^.*VERSION/{s///p;q;}'))
ifs=$IFS
IFS=.
GMXVERSION=($GMXVERSION)
IFS=$ifs
echo GROMACS VERSION: ${GMXVERSION[@]}
if [[ $GMXVERSION -lt 5 ]]
then
CUTOFFSCHEME=""
else
CUTOFFSCHEME="cutoff_scheme = group"
fi
# Check for MPI
if [[ $(uname -s) == "Darwin" ]]
then
LDD="otool -L"
else
LDD=ldd
fi
MPI=$($LDD $(command -v $GROMPP) | grep -q -i MPI && echo true || echo false)
echo MPI: $MPI
# Array for temporary files
GARBAGE=()
# Function for trashing temporary files
trash()
{
for item in $@; do GARBAGE[${#GARBAGE[@]}]=$item; done
}
# Define for position restraints
[[ -z $AAS ]] && POSRE=true
$POSRE && MDPDEF=-DPOSRES || MDPDEF=
# Starting time
START=$(date +%s)
###########################################
## STEP 1: GENERATING STARTING STRUCTURE ##
###########################################
GRO=$BW
B="$SDIR/backward.py -f $INP -raw $RAW -o $GRO -kick $KICK -sol -p $TOP -po $OTP -n $NDX -from $CG -to $AA $NOPBC -solname $SOL"
echo $B; $B || exit
BM=$(date +%s)
trash $RAW $GRO
###############################################
## STEP 2: EM WITHOUT NONBONDED INTERACTIONS ##
###############################################
# Step counter
i=1
# Basename
BASE=$i-EM
# Run parameter file
mdp=$BASE.mdp
# If TRJ is true then write each frame
$TRJ && NSTXTCOUT=1 || NSTXTCOUT=0
cat << __MDP__ > $mdp
define=-DFLEXIBLE
integrator=steep
nsteps=$EMSTEPS
emstep=0.1
pbc=xyz
$CUTOFFSCHEME
; Table extension is needed initially
table-extension=2
; During first steps nonbonded interactions
; are excluded within groups membrane and protein
energygrps=Protein Membrane Solvent
energygrp_excl=Protein Protein Membrane Membrane
; Usually no trajectory is written,
; but this can be changed (-trj)
nstxout=$NSTXTCOUT
__MDP__
# Set up for running
G="$GROMPP -f $mdp -c $GRO -n $NDX -p $OTP -o $BASE -maxwarn 2"
echo $G; $G || exit
if $MPI
then
NT=
else
NT="-nt $EMNP"
fi
# Run
M="$MDRUN -deffnm $BASE -v $NT"
echo $M; $M
# Timing
EM1=$(date +%s)
# Mark files for deletion
trash $BASE.*
# Bookkeeping (increment run counter)
GRO=$((i++))-EM.gro
############################################
## STEP 3: EM WITH NONBONDED INTERACTIONS ##
############################################
# Basename for this cycle
BASE=$i-EM
# Turn all nonbonded interactions on and set the table_extension to default
# Change the number of steps
sed -e '/^nsteps/s/=.*$/='$NBSTEPS'/' -e '/^ *table-extension/s/^/;/' -e '/^ *energygrp_excl/s/^/;/' $mdp > $BASE.mdp
mdp=$BASE.mdp
# Set up for running
G="$GROMPP -f $mdp -c $GRO -n $NDX -p $OTP -o $BASE -maxwarn 2"
echo $G; $G || exit
# Run
M="$MDRUN -deffnm $BASE -v $NT"
echo $M; $M
# Timing
EM2=$(date +%s)
# Mark files for deletion
trash $BASE.*
# Bookkeeping (increment run counter)
GRO=$i-EM.gro
##########################################
## STEP 4: MD WITH INCREASING TIME STEP ##
##########################################
if [[ -n $AAS ]]
then
# Fit the structure and use it as reference for position restraints
$SDIR/qfit.py $AAS $GRO > posref.gro
PR="-r posref.gro"
else
PR="-r $BW"
fi
# Array for collecting timing information
PRMD=()
# Set file tag
$POSRE && tag=mdpr || tag=mdnopr
# Unpack the list of time steps
ifs=$IFS
IFS=,
DT=($DT)
IFS=$ifs
if $MPI
then
NT=
else
NT="-nt $NP"
fi
for DELTA_T in ${DT[@]}
do
BASE=$((++i))-$tag-$DELTA_T
mdp=$BASE.mdp
cat << __MDP__ > $mdp
define = $MDPDEF
integrator = md
nsteps = $MDSTEPS
dt = $DELTA_T
pbc = xyz
rcoulomb = 0.9
rlist = 0.9
rvdw = 0.9
tcoupl = v-rescale
ref_t = 200
tau_t = 0.1
tc_grps = System
gen_vel = yes
gen_temp = 300
constraints = all-bonds
nstxtcout = $NSTXTCOUT
__MDP__
# Set up run
G="$GROMPP -f $mdp -c $GRO -p $OTP -o $BASE -maxwarn 2 $PR"
echo $G; $G || exit
# Perform run
M="$MDRUN -deffnm $BASE -v $NT"
echo $M; $M
# Collect timing information
PRMD[${#PRMD[@]}]=$(date +%s)
# Collect garbage
trash $BASE.*
# Increment counter
GRO=$BASE.gro
done
#############################################
## STEP 5: MD WITH USER PROVIDED MDP FILES ##
#############################################
MD=()
for mdp in ${MDP[@]}
do
m=${mdp%.mdp}
tag=$((++i))-md-${m##*/}
G="$GROMPP -f $mdp -c $GRO -p $OTP -o $tag -maxwarn 2 $PR"
echo $G; $G || exit
M="$MDRUN -deffnm $tag -v $NT"
echo $M; $M
GRO=$tag.gro
MD[${#MD[@]}]=$(date +%s)
done
# Copy last structure for output
cp $GRO $OUT
# Trash files if not keeping them
if ! $KEEP
then
trash *mdout.mdp*
echo Removing files:
echo ${GARBAGE[@]}
rm ${GARBAGE[@]}
fi
echo
echo "Timing (seconds):"
echo ===========================
printf "%-15s %5d %5d\n" Backmapping: $((BM-START)) $((BM-START))
printf "%-15s %5d %5d\n" EM1: $((EM1-BM)) $((EM1-START))
printf "%-15s %5d %5d\n" EM2: $((EM2-EM1)) $((EM2-START))
P=$EM2
for ((i=0; i<${#DT[@]}; i++))
do
T=${PRMD[$i]}
printf "%-15s %5d %5d\n" PRMD-${DT[$i]}: $((T-P)) $((T-START))
P=$T
done
for ((i=0; i<${#MDP[@]}; i++))
do
T=${MD[$i]}
printf "%-15s %5d %5d\n" MD-${MDP[$i]}: $((T-P)) $((T-START))
P=$T
done
echo ---------------------------
printf "%-15s %5d\n\n\n" Total: $((T-START))