forked from marrink-lab/gromit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmartinate.sh
executable file
·2324 lines (1848 loc) · 72.2 KB
/
martinate.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
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
PROGRAM=martinate.sh
VERSION=0.1
VERSTAG=devel-160502-0800-TAW
AUTHOR="Tsjerk A. Wassenaar, PhD"
YEAR="2016"
AFFILIATION="
University of Groningen
The Netherlands"
CMD="$0 $@"
DESCRIPTION=$(cat << __DESCRIPTION__
This is a convenience script to set up, equilibrate and run coarse
grained (and multiscaled) systems, using the Martini force field.
It is built as a wrapper around martinize.py and insane.py, allowing
automated processing of membrane proteins, with full control of membrane
composition. If no input file is provided, only a membrane is built.
Otherwise, if a protein is given and -L is not set, the protein is
solvated and run, but if -L is set, a membrane is built in addition.
Options given that do not match an option in this script are passed to
martinize.py.
__DESCRIPTION__
)
# These will be looked for before running, and can be set from the cmdline, e.g.:
# -gmxrc /usr/local/gromacs-5.1/bin/GMXRC
# If not set, the default name will be searched for in
# 1. the environment (if PROGEVAR is given)
# 2. the directory where this calling script (martinate) is located
# 3. the PATH
DEPENDENCIES=( dssp gmxrc martinize insane )
PROGEXEC=( dssp GMXRC martinize.py insane.py)
PROGEVAR=( DSSP GMXRC)
# Residue groups used for classifying atoms in the structure file.
# Ions are typically considered positioned after solvent.
# Membrane is the complementary group to the rest.
# The structure file is assumed to have the following composition:
# - Protein
# - Nucleic acids
# - Membrane
# - Solvent
# - Ions
# All groups are optional (as long as there are some)
amino_acids=(ALA CYS ASP GLU PHE GLY HIS HIH ILE LYS LEU MET ASN PRO HYP GLN ARG SER THR VAL TRP TYR)
nucleic_acids=(DG DA DC DT)
solvent_names=(W WF PW BMW SOL)
# The Gromacs RC file for use on the WeNMR GRID
# The existence of this file is checked later to
# to see if this is a GRID run.
# Note that the GMXRC file can also be specified with -gmxrc
# This is just a convenience hack.
GRIDRC="${VO_ENMR_EU_SW_DIR}/BCBR/gromacs/4.5.3-rtc/bin/GMXRC.bash"
GRID=false
# Starting step
STEPS=(AA CG SOLVENT EM NVT-PR NPT PREPRODUCTION TPR PRODUCTION ANALYSIS END)
get_step_fun() { for ((i=0; i<${#STEPS[@]}; i++)) do [[ ${STEPS[$i]} =~ ^$1 ]] && return $i; done; }
STEP=AA
STOP=PRODUCTION
# Macros to echo stuff only if the step is to be executed -- more about steps further down
RED='\x1b[1;31m'
YEL='\x1b[1;33m'
OFF='\x1b[0m'
LINES() { sed -e 's/^/ /;s/$/ /;h;s/./-/g;p;x;p;x;' <<< "$@"; }
SHOUT() { [[ $STEP == $NOW ]] && echo && LINES "$@" | sed 's/^/#/'; }
WARN() { [[ $STEP == $NOW ]] && echo -e "$RED" && LINES "$@" | sed 's/^/# WARNING: /' && echo -e "$OFF"; }
FATAL() { [[ $STEP == $NOW ]] && echo -e "$RED" && LINES "$@" | sed 's/^/# FATAL: /' && echo -e "$OFF"; exit 1; }
NOTE() { [[ $STEP == $NOW ]] && echo -e "$YEL" && LINES "$@" | sed 's/^/# NOTE: /' && echo -e "$OFF"; }
LINE() { [[ $STEP == $NOW ]] && echo && sed -e 's/^/ /;s/$/ /p;s/./-/g;' <<< "$@" | sed 's/^/#/'; }
ECHO() { [[ $STEP == $NOW ]] && echo "$@"; }
# MARTINI Force field parameters
MARTINI=martini22
DRY=
# Solvents
# NOTE: with standard Martini water, exclude AA/CG interactions
SOLVENTS=( dry polarizable PW pw bmw W simple standard martini )
SOLNAMES=( NO PW PW PW BMW W W W W )
SOLTYPE=( NO polarizable polarizable polarizable polarizable plain plain plain plain )
EPSR_CG=( 15 2.50 2.50 2.50 1.30 15 15 15 15 ) # CG-CG dielectric constant
EPSR_AA=( 0 1.45 1.45 1.45 1.00 0 0 0 0 ) # CG-AA dielectric constant
SOLVFF=( dry p p p bmw ) # MARTINI subversion and solvent tag
# Options:
# Downstream programs:
# - membrane and periodic boundary conditions (insane options):
INSANE=()
# - martinizing
MARTINIZE=()
# This program:
# - protein:
PDB=
TOP=
NDX=
NOHETATM=true
VSITE=false
# - multiscaling
ForceField=gromos45a3
MULTI=()
ALL=false
M=false
NCH=0
SOL=
HybridIons=false
# - nonbonded interactions
EPSR=
EPSRF=78
LJDP=6
LJRP=12
LJSW=-1
RC=1.4
# - other
DIR=.
NP=1
FORCE=false
MAXH=-1 # Maximum duration of run
NOEXEC=
JUNK=()
PROGOPTS=()
MDPOPTS=()
DAFT=
SCRATCH= # Scratch directory
KEEP=false
# - simulation parameters
DELT=0.020 # Time step in picoseconds
TIME=0 # Nanoseconds
AT=0.5 # Write output every 0.5 ns
EMSTEPS=500 # Number of steps for EM
Temperature=310 # Degree Kelvin
Pressure=1 # Bar
Salinity=0.1536 # Concentration NaCl
SEED=$$
# Directories and executables
# This gives the directory where the script is located
SDIR=$( [[ $0 != ${0%/*} ]] && cd ${0%/*}; pwd )
OPTIONS=$(cat << __OPTIONS__
# File options:
-f Input PDB file *FILE: None
-top Input topology file *FILE: None
-cg Coarse grained force field *STR: $MARTINI
-ndx Index file *STR: None
# Multiscaling:
-m Chains for multiscaling. Other chains will be coarse grained. *STR: None
-M Multiscale all chains, except those specified with -m *BOOL: False
-ff Atomistic force field for multiscaling *STR: $ForceField
# Conditions:
-sol Solvent to use *STR: $SOL
-epsr Dielectric constant of the medium *FLOAT: $EPSR
-T Temperature *FLOAT: $TEMP (K)
-P Pressure *FLOAT: $PRES (bar)
-salt Salt (NaCl) Concentration *FLOAT: $Salinity (M)
# Simulation control:
-time Simulation length in ns *FLOAT: $TIME (ns)
-at Output resolution *FLOAT: $AT (ns)
-np Number of processors to run on *INT: $NP
-vsite Use virtual sites *BOOL: False
# Script control options:
-step Step at which to start or resume the setup *STR: $STEP
-stop Step at which to stop execution *STR: $STOP
-force Force overwriting existing files *BOOL: False
-noexec Do not actually simulate *BOOL: False
-keep Keep all rubbish generated; do not clean up *BOOL: False
# Other options:
-daft Index file with DAFT energy groups. Invokes DAFT run. *FILE: None
-dry Use dry martini *STR: None
Arguments not listed are passed through to martinize.py
Check '$MARTINIZE -h' for a listing
__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:"
USAGE
exit 1
}
# Functions for handling argument lists for downstream programs
# 1. Expanding options from '-opt=val1\,val2' to '-opt val1 val2', not changing long options (--long-opt=val)
function expandOptList() { for i in $@; do [[ $i =~ --+ ]] && echo $i || (j=${i/=/ }; echo ${j//\\,/ }); done; }
# 2. Condensing options from '-opt1=val1,val2 -opt2=val3,val4' to '-opt1=val1\,val2,-opt2=val3\,val4'
function condenseOptList() { echo $(sed 's/,/\,/g;s/ */,/g;' <<< $@); }
# 3. Reading condensed options from the command line
function readOptList() { sed "s/\\\,/##/g;s/,/ /g;s/##/,/g;s/--[^{]\+{\(.*\)}/\1/;" <<< $1; }
# Collect errors, warnings and notes to (re)present to user at the end
# Spaces are replaced by the unlikely combination QQQ to keep the
# messages together.
errors_array=()
store_error_fun() { a="$@"; errors_array+=(${x// /QQQ}); FATAL "$@"; }
warnings_array=()
store_warning_fun() { a=$@; warnings_array+=(${x// /QQQ}); WARN "$@"; }
notes_array=()
store_note_fun() { a=$@; notes_array+=(${x// /QQQ}); NOTE "$@"; }
while [ -n "$1" ]; do
# Check for program option
depset=false
NDEP=${#DEPENDENCIES[@]}
for ((i=0; i<$NDEP; i++))
do
if [[ $1 == "-${DEPENDENCIES[$i]}" ]]
then
PROGEXEC[$i]=$2
shift 2
depset=true
fi
done
# If we set a dependency, skip to the next cycle
$depset && continue
# Check for other options
case $1 in
-h) USAGE ; exit 0 ;;
# File options
-f) PDB=$2 ; shift 2; continue ;;
-cg) MARTINI=$2 ; shift 2; continue ;;
-top) TOP=$2 ; shift 2; continue ;;
-ndx) NDX=$2 ; shift 2; continue ;;
-hetatm) NOHETATM=false ; shift 1; continue ;;
-sol) SOL=$2 ; shift 2; continue ;;
-epsr) EPSR=$2 ; shift 2; continue ;;
-epsrf) EPSRF=$2 ; shift 2; continue ;;
-ljdp) LJDP=$2 ; shift 2; continue ;;
-ljrp) LJRP=$2 ; shift 2; continue ;;
-ljsw) LJSW=$2 ; shift 2; continue ;;
-rc) RC=$2 ; shift 2; continue ;;
-m) MULTI[$((NCH++))]=$2; M=true ; shift 2; continue ;;
-M) ALL=true; M=true ; shift 1; continue ;;
-ff) ForceField=$2 ; shift 2; continue ;;
-T) Temperature=$2 ; shift 2; continue ;;
-P) Pressure=$2 ; shift 2; continue ;;
-salt) Salinity=$2 ; shift 2; continue ;;
-dt) DELT=$2 ; shift 2; continue ;;
-time) TIME=$2 ; shift 2; continue ;;
-at) AT=$2 ; shift 2; continue ;;
-em) EMSTEPS=$2 ; shift 2; continue ;;
-dir) DIR=$2 ; shift 2; continue ;;
# -gmxrc) GMXRC=$2 ; shift 2; continue ;;
# -dssp) DSSP=$2 ; shift 2; continue ;;
-step) STEP=$2 ; shift 2; continue ;;
-stop) STOP=$2 ; shift 2; continue ;;
-np) NP=$2 ; shift 2; continue ;;
-maxh) MAXH=$2 ; shift 2; continue ;;
-vsite) VSITE=true ; shift 1; continue ;;
-force) FORCE=true ; shift 1; continue ;;
-daft) DAFT=$2 ; shift 2; continue ;;
-dry) DRY=$2 ; shift 2; continue ;;
-keep) KEEP=true ; shift 1; continue ;;
-noexec) NOEXEC=echo ; shift 1; continue ;;
--mdp-*) MDPOPTS[${#MDPOPTS[@]}]=${1#--mdp-} ; shift 1; continue ;;
# Options for downstream programs
# If the options are given on the command line, they are expanded and each
# option will be formatted as --program-opt=val
--martinize-*) MARTINIZE+=(${1#--martinize}) ; shift ; continue;;
--insane-*) INSANE+=(${1#--insane}) ; shift ; continue;;
# If the options are passed by another program, they will be formatted like
# --program{-opt1=val1,-opt2=val2\,val3}
# In this case the option needs to be parsed explicitly:
--martinize*) MARTINIZE+=($(readOptList $1)) ; shift ; continue;;
--insane*) INSANE+=($(readOptList $1)) ; shift ; continue;;
# Other program-specific options
--*) PROGOPTS[${#PROGOPTS[@]}]=$1 ; shift 1; continue ;;
# All options should be covered above. Anything else raises an error here.
*) BAD_OPTION "$1";;
esac
done
cat << __RUNINFO__
$PROGRAM version $VERSION:
(c)$YEAR $AUTHOR
$AFFILIATION
Now executing...
$CMD
__RUNINFO__
echo $CMD > cmd.log
NOW=$STEP
#--------------------------------------------------------------------
#---GROMACS AND RELATED STUFF
#--------------------------------------------------------------------
## 0. Finding programs
dependency_not_found_error()
{
FATAL The required dependency $@ was not found.
}
NDEP=${#DEPENDENCIES[@]}
find_program_fun()
{
for ((i=0; i<$NDEP; i++)); do
if [[ ${DEPENDENCIES[$i]} == "$1" ]]
then
progr=${PROGEXEC[$i]}
envvar=${PROGEVAR[$i]}
fi
done
# Check if the program is in the environment
[[ -n $envvar ]] && [[ -f ${!envvar} ]] && echo ${!envvar} && return 0
# Check if the program is in the directory of this script
[[ -f $SDIR/$progr ]] && echo $SDIR/$progr && return 0
# Check if the program is in the PATH
which $progr 2>/dev/null && return 0 || return 1
}
## 1. GROMACS ##
# Check and set the gromacs related stuff
GMXRC=$(find_program_fun gmxrc)
echo Gromacs RC file: $GMXRC
# Source the gromacs RC file if one was found
# Otherwise the script will rely on the active gromacs commands
[[ $GMXRC ]] && source $GMXRC
# Find out which Gromacs version this is
GMXVERSION=$(mdrun -h 2>&1 | sed -n '/^.*VERSION \([^ ]*\).*$/{s//\1/p;q;}')
# From version 5.0.x on, the commands are gathered in one 'gmx' program
# The original commands are aliased, but there is no guarantee they will always remain
[[ -z $GMXVERSION ]] && GMXVERSION=$(gmx -h 2>&1 | sed -n '/^.*VERSION \([^ ]*\).*$/{s//\1/p;q;}')
ifs=$IFS; IFS="."; GMXVERSION=($GMXVERSION); IFS=$ifs
# Set the directory for binaries
[[ $GMXVERSION -gt 4 ]] && GMXBIN=$(which gmx) || GMXBIN=$(which mdrun)
# Extract the directory
GMXBIN=${GMXBIN%/*}
# Set the directory to SCRIPTDIR if GMXBIN is empty
GMXBIN=${GMXBIN:-$SCRIPTDIR}
# Make binaries executable if they are not
# (This may be required for Grid processing)
[[ -f $GMXBIN/grompp && ! -x $GMXBIN/grompp ]] && chmod +x $GMXBIN/grompp
[[ -f $GMXBIN/mdrun && ! -x $GMXBIN/mdrun ]] && chmod +x $GMXBIN/mdrun
[[ -f $GMXBIN/gmx && ! -x $GMXBIN/gmx ]] && chmod +x $GMXBIN/gmx
# Set the command prefix
[[ $GMXVERSION -gt 4 ]] && GMX="$GMXBIN/gmx " || GMX=$GMXBIN/
# Set the GMXLIB variable to point to the force field data and such
# In some cases, 'gromacs' is part of $GMXDATA
export GMXLIB=${GMXDATA}/gromacs/top
[[ -d $GMXLIB ]] || export GMXLIB=${GMXDATA%/gromacs*}/gromacs/top
echo Gromacs data directory: $GMXLIB
# Now finally, test a command and see if it works
# otherwise raise a fatal error.
${GMX}grompp -h >/dev/null 2>&1 || executable_not_found_error "GROMACS (GMXRC)"
## 2. DSSP ##
# Search the DSSP binary, from environment, from path, or guess
# Only required if we have an input file
echo -n 'Checking DSSP binary (for martinizing proteins)... '
DSSP=$(find_program_fun dssp)
if [[ $? == 1 ]]
then
warn="DSSP binary not found - Will martinize without secondary structure :S"
store_warning_fun "$warn"
else
echo "$DSSP"
MARTINIZE+=(-dssp=$DSSP)
fi
## 3. PATH ##
# Add the script location to the PATH
export PATH="${PATH}:${SDIR}"
## 4. Echo mdp options specified on the command line
# These options are formatted like --mdp-param=value
# This will add 'param = value' to the MDP file for
# all runs following energy minimization.
# *NOTE*: Options specified on the command line take
# precedence over internal parameters and over those
# read from an mdp file, provided as value to option
# -mdp
if [[ -n $MDPOPTS ]]
then
echo 'Simulation parameters specified on command line (note how flexible!):'
for ((i=0; i<${#MDPOPTS[@]}; i++)); do echo ${MDPOPTS[$i]}; done
echo ===
fi
## 5. Locate insane if STEP lies before SOLVENT and STOP lies after.
SOLSTEP=$(get_step_fun SOLVENT)
if [[ $STEP -le $SOLSTEP && $STOP -ge $SOLSTEP ]]
then
INSA=$(find_program_fun insane)
if [[ $? != 0 ]]
then
FATAL "Dependency (insane) required for building solvent/membrane, but not found."
fi
fi
## 5. Set the correct sed version for multi-platform use
# Also try to avoid GNU specific sed statements for the
# poor bastards that are stuck with one of those Mac things
SED=$(which gsed || which sed)
#--------------------------------------------------------------------
#---TIMING (GRID STUFF)
#--------------------------------------------------------------------
# If UNTIL is not set, then we run until all work is done, or until we crash
UNTIL=
# If we have a proxy, then we adhere to it, assuming to be running on the GRID
# The allowed runtime is set slightly lower to allow the script to finish
which voms-proxy-info && LEFT=$(( $(voms-proxy-info -timeleft &> /dev/null) - 300 )) || LEFT=
# If LEFT is set, MAXH may not be set negative
[[ $LEFT ]] && (( MAXH < 0 )) && MAXH=48
# Maximum time in seconds
if [[ $MAXH =~ ":" ]]
then
# Format HH:MM:SS
ifs=$IFS; IFS=":"; MAXS=($MAXH); IFS=$ifs
MAXS=$((3600*MAXS[0] + 60*MAXS[1] + MAXS[2]))
else
# Format x.y HH
# BASH floating point arithmetics
int=${MAXH%.*}
frac=${MAXH#$int}
frac=${frac/./}
MAXS=$(( ${MAXH/./} * 3600 / (10**${#frac}) ))
fi
[[ -n $LEFT ]] && (( MAXS > LEFT )) && MAXS=$LEFT
if (( MAXS > 0 ))
then
UNTIL=$(( $(date +%s) + MAXS ))
echo "# $PROGRAM will run until $(date --date=@$UNTIL), or until run has finished"
else
echo "# No maximum runtime set. Will run until finished or until crash."
fi
# This variable will be reset to the time needed for the last run run
# A following run will usually take longer.
LASTRUN=0
#--------------------------------------------------------------------
#---WARMING UP VARIABLE GYMNASTICS
#--------------------------------------------------------------------
## 1. Format for printing numbers to index files
fmt=" %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d"
## 2. WORKING DIRECTORY AND SOURCE DIRECTORY ##
SRCDIR=$(pwd)
[[ ! -d $DIR ]] && mkdir -p $DIR; pushd $DIR >/dev/null
## 3. START/STOP FLOW CONTROL ##
for ((i=0; i<${#STEPS[@]}; i++)); do [[ ${STEPS[$i]} == ${STEP}* ]] && STEP=$i && break; done
for ((i=0; i<${#STEPS[@]}; i++)); do [[ ${STEPS[$i]} == ${STOP}* ]] && STOP=$i && break; done
NOW=$STEP
echo Will run from step ${STEPS[$STEP]} until ${STEPS[$STOP]}
# Macro to do stuff only if the step is to be executed
DO() { [[ $STEP == $NOW ]] && echo "$@" && $@; }
# Sed wrapper - echo the command line before running it
SED() { echo sed "$@" 1>&2; sed "$@"; }
# Sequence generation; seq might not be available
SEQ() { for ((i=$1; i<=$2; i++)); do echo $i; done; }
## 4. SET THE SOLVENT ##
# Select the solvent to use
# Default solvent is martini water
if [[ -z $SOL ]]
then
if [[ $MARTINI == *p ]]
then
SOL=polarizable
fi
fi
SID=; for ((i=0; i<${#SOLVENTS[@]}; i++)); do [[ ${SOLVENTS[$i]} == ${SOL}* ]] && SID=$i; done
# Override if option -dry is given... Serving Dry Martini
[[ -n $DRY ]] && SID=0
# Check whether we found a matching solvent model
[[ -z $SID ]] && echo Unknown solvent model \"$SOL\" specified. && exit
# Check whether the solvent type is polarizable
[[ ${SOLTYPE[$SID]} == polarizable ]] && POLARIZABLE=true || POLARIZABLE=false
## 5. FORCE FIELD ##
# a. COARSE GRAINED: MARTINI/ELNEDYN
# Set a pointer to the correct forcefield generating script
# (of the form: martini_2.1.py or martini_2.1_P.py)
FFMARTINIPY=$SDIR/${MARTINI}${SOLVFF[$SID]}.py
if [[ ! -f $FFMARTINIPY ]]
then
if [[ -f $SDIR/${MARTINI}.py ]]
then
# If martini22p was specified in stead of martini22 with PW,
# then we end up here, setting the script to martini22p.py
FFMARTINIPY=$SDIR/${MARTINI}.py
else
# Unclear dependency, but shipped with the scripts...
FATAL Forcefield script $FFMARTINIPY does not exist, nor does $SDIR/${MARTINI}.py
fi
fi
# b. ATOMISTIC
# Set pointers to ffnonbonded.itp and ffbonded.itp if we do multiscaling
$M && ffnb=$GMXLIB/$ForceField.ff/ffnonbonded.itp || ffnb=
$M && ffbn=$GMXLIB/$ForceField.ff/ffbonded.itp || ffbn=
# c. GENERATE martini.itp FOR COARSE GRAINED, MULTISCALE or DRY
if [[ -n $DRY ]]
then
$FFMARTINIPY "$DRY" > martini.itp
else
$FFMARTINIPY $ffnb $ffbn > martini.itp
fi
# d. UPDATE martini.itp FOR DUMMIES
# Replace the #include statement for ff_dum.itp for atomistic force fields by the contents of it
$M && sed -i -e "/#include \"ff_dum.itp\"/r$GMXLIB/$ForceField.ff/ff_dum.itp" -e "/#include \"ff_dum.itp\"/d" martini.itp
## 6. ELECTROSTATICS AND TABLES ##
EPSR_CG=${EPSR_CG[$SID]}
EPSR_AA=${EPSR:-${EPSR_AA[$SID]}}
$M && TABLES=-tables || TABLES=
#--------------------------------------------------------------------
#---INPUT CHECKING, SPLITTING, TRIMMING, GROOMING
#--------------------------------------------------------------------
if [[ -n $PDB ]]
then
# If the input file is not found, check whether it was given without extension.
# If that is not the case, then fetch the file from the PDB repository.
if [[ ! -f $PDB ]]
then
if [[ ! -f $PDB.pdb ]]
then
echo Input file $PDB not found... Trying server
# Try fetching it from the PDB
pdb=$(tr [A-Z] [a-z] <<< ${PDB%.pdb})
RCSB="http://files.rcsb.org/download/${pdb%%.*}.pdb.gz"
echo "# Input file not found, but will try fetching it from the PDB ($RCSB)"
# Use wget or curl; one of them should work
wget $RCSB 2>/dev/null || curl -O "$RCSB"
gunzip $pdb.pdb.gz
[[ -n $SCRATCH ]] && cp $pdb.pdb $DIR
PDB=$pdb
fi
PDB=$PDB.pdb
fi
# If the input file is missing now, raise an errorr
if [[ ! -f $PDB ]]
then
echo Input file $PDB not found and fetching from PDB server failed.
exit 1
fi
# Check whether the input file is here or in another directory.
# In the latter case, copy it here
[[ $PDB == ${PDB##*/} || $PDB == ./${PDB##*/} ]] || cp $PDB .
pdb=${PDB##*/} # Filename
base=${pdb%.*} # Basename
ext=${pdb##*.} # Extension
dirn=${PDB%$pdb} # Directory
[[ $dirn ]] || dirn="."
dirn=`cd $dirn && pwd` # Full path to input file directory
if [ $dirn != `pwd` ]
then
NOTE "The run is performed here (`pwd`), while the input file is elsewhere ($dirn)."
fi
if [[ -z $TOP && $ext == "pdb" ]]
then
if $NOHETATM -a $(grep -q HETATM $PDB)
then
NOTE Removing HETATM entries from PDB file
sed -i '' -e /^HETATM/d $PDB
fi
# Extract a list of chains from PDB file
CHAINS=( $(grep '^\(ATOM\|HETATM\)' $PDB | cut -b 22 | uniq) )
# Unpack lists of chains to multiscale separated by commas
MULTI=( $(for i in ${MULTI[@]}; do echo ${i//,/ }; done) )
# Residues defined in martinize.py
AA=(ALA CYS ASP GLU PHE GLU HIS ILE LYS LEU MET ASN PRO GLN ARG SER THR VAL TRP TYR)
# Sed query for residues (separated by \|):
SED_AA=$(sed 's/ \+/\\\|/g' <<< ${AA[@]})
# ATOM selection (martinizable residues)
ATOM='/^\(ATOM \|HETATM\)/{/.\{17\} *'$SED_AA' */p;}'
# HETATM selection (non-martinizable residues)
HETATM='/^\(ATOM \|HETATM\)/{/.\{17\} *'$SED_AA' */!p;}'
# Split the pdb file in stuff that can be processed with pdb2gmx
# and stuff that cannot be processed with it
# Extract the names of building blocks defined in the rtp file
# of the force field used. These blocks are defined as '[ ALA ]',
# so we match a name in square brackets at the start of a line.
# The name is appended to the hold space.
RTPENTRIES='/^\[ *\(...\).*\].*/{s//\1/;H;}'
# At the end of the list, the building block names are reformatted
# to make a regular expression string matching each word. First,
# the hold space is swapped with the pattern space, the first bit is
# removed and then all embedded newlines are replaced by '\|'
FORMAT='${x;s/\n...\n//;s/\n/\\\|/g;p;}'
# Finally sed is called processing all rtp files of the force field
DEF=$(sed -n -e "$RTPENTRIES" -e "$FORMAT" $GMXLIB/$ForceField.ff/*.rtp)
# Now we can split the input PDB file into a processable and a non-processable part
echo $DEF
#sed -e '/^\(TER\|MODEL\|ENDMDL\)/p' -e '/^\(ATOM \|HETATM\)/{/.\{17\} *\('$DEF'\) */p;}' $dirn/$base.pdb > $base-def.pdb
#sed -e '/^\(TER\|MODEL\|ENDMDL\)/p' -e '/^\(ATOM \|HETATM\)/{/.\{17\} *\('$DEF'\) */!p;}' $dirn/$base.pdb > $base-ndef.pdb
fi
else
base=
fi
if [[ $PBC == retain && -n $PDB ]]
then
PBC="-pbc keep"
else
PBC="-pbc $PBC"
fi
echo Done checking
SED() { echo sed "$@" 1>&2; sed "$@"; }
## SED stuff
# Extract the moleculetype name
SED_MOLECULETYPE='/moleculetype/{
:a
n
/^;/ba
s/\s\+.*$//p
q
}
'
echo Done gymnastics
#--------------------------------------------------------------------
#---SIMULATION PARAMETERS--
#--------------------------------------------------------------------
## OT N ## For every parameter not defined the default is used
## NOTE ## This is probably fine for equilibration, but check the defaults to be sure
## E OT ## The list as is was set up for gromacs 4.5
# This function lists the mdp options requested based on a preceding tag
mdp_options ()
{
echo MDP tags: $@ 1>&2
for tag in $@
do
# Find variables declared with specified tag
for opt in `set | grep ^__mdp_${tag}__`
do
var=${opt%%=*}
val=${opt#*=}
# Replace the tag and redeclare in local space
# If the variable was already declared it will
# be overridden.
local ${var/mdp_$tag/mdp}=$val
done
done
# Find all variables starting with __mdp__ and echo them
set | sed -n '/^__mdp__/{s/__mdp__//;s/,/ /g;p;}'
}
#--------------------------------------------------------------------
# Global parameters
__mdp_cg__nstlist=10
if [[ -n $DELT ]]
then
__mdp_cg__dt=$DELT
elif $ALL -o [[ -n $MULTI ]]
then
if $VSITE
then
__mdp_cg__dt=0.004
__mdp_cg__nstlist=4
else
__mdp_cg__dt=0.002
fi
else
__mdp_cg__dt=0.020
fi
# Output parameters
TIME=$(python -c "print int(1000*$TIME/$__mdp_cg__dt + 0.5 )")
AT=$(python -c "print int(1000*$AT/$__mdp_cg__dt + 0.5)")
__mdp_cg__nsteps=$TIME
__mdp_cg__nstxout=$AT
__mdp_cg__nstvout=0
__mdp_cg__nstfout=0
__mdp_cg__nstlog=$AT
__mdp_cg__nstenergy=$AT
[[ $GMXVERSION -gt 4 ]] && __mdp_cg__nstxout_compressed=$AT || __mdp_cg__nstxtcout=$AT
# Nonbonded interactions
if [[ $GMXVERSION -gt 4 ]]
then
# GMX 5 parameters from De Jong, Baoukina and Marrink
__mdp_cg__cutoff_scheme=Verlet
__mdp_cg__coulombtype=Cut-off
__mdp_cg__coulomb_modifier=Potential-shift
__mdp_cg__rcoulomb=1.1
__mdp_cg__epsilon_r=$EPSR_CG
__mdp_cg__vdw_type=Cut-off
__mdp_cg__vdw_modifier=Potential-shift
__mdp_cg__rvdw=1.1
__mdp_cg__dispcorr=No
__mdp_cg__nstlist=20
else
__mdp_cg__coulombtype=Shift
__mdp_cg__rcoulomb=1.2
__mdp_cg__rcoulomb_switch=0.0
__mdp_cg__epsilon_r=$EPSR_CG
__mdp_cg__rlist=1.2
__mdp_cg__vdw_type=Shift
__mdp_cg__rvdw=1.2
__mdp_cg__rvdw_switch=0.9
__mdp_cg__dispcorr=No
fi
# Coupling - depending on presence of protein/membrane
# Pressure coupling semiisotropic for membranes,
# set to isotropic if no membrane is present
__mdp_cg__tcoupl=v-rescale
__mdp_cg__nsttcouple=$__mdp_cg__nstlist
__mdp_cg__pcoupl=no # Overridden at step NpT
__mdp_cg__nstpcouple=$__mdp_cg__nstlist
__mdp_cg__pcoupltype=Isotropic
__mdp_cg__compressibility=3e-4
__mdp_cg__tau_p=3.0
__mdp_cg__ref_p=$Pressure
__mdp_mem__pcoupltype=Semiisotropic
__mdp_mem__compressibility=3e-4,3e-4
__mdp_mem__tau_p=3.0,3.0 # Overridden at step NpT with GMX5
__mdp_mem__ref_p=$Pressure,$Pressure
# Gromacs can handle empty groups, so this is fine
# These are set based on groups in the index file
#__mdp_cg__tc_grps=Solute,Membrane,Solvent
#__mdp_cg__tau_t=1.0,1.0,1.0
#__mdp_cg__ref_t=$Temperature,$Temperature,$Temperature
# Other
__mdp_cg__constraints=none
__mdp_cg__energygrps=Solute,Membrane,Solvent
__mdp_cg__comm_mode=Linear
__mdp_cg__comm_grps=System
__mdp_cg__nstcomm=$__mdp_cg__nstlist
#--------------------------------------------------------------------
# Multiscale
__mdp_ms__rlist=$RC
__mdp_ms__coulombtype=user
__mdp_ms__rcoulomb=$RC
__mdp_ms__vdw_type=user
__mdp_ms__rvdw=$RC
__mdp_ms__energygrps=AA,CG,VZ
__mdp_ms__epsilon_r=1
if $POLARIZABLE
then
__mdp_ms__energygrp_table=AA,AA,AA,CG
__mdp_ms__energygrp_excl=AA,VZ,VZ,VZ
else
__mdp_ms__energygrp_table=AA,AA
__mdp_ms__energygrp_excl=AA,VZ,AA,CG,VZ,VZ
fi
#--------------------------------------------------------------------
# Energy minimization
__mdp_em__integrator=steep
__mdp_em__nsteps=$EMSTEPS
__mdp_em__emstep=0.001
__mdp_em__lincs_order=6
__mdp_em__lincs_iter=8
__mdp_em__lincs_warnangle=90
__mdp_em__define=-DFLEXIBLE
#--------------------------------------------------------------------
# Equilibration runs: position restraints, NVT, NPT
# Position restraints are relieved at step 8
__mdp_equil__define=-DPOSRES
__mdp_equil__dt=0.002
__mdp_equil__nsteps=5000
__mdp_equil__nstlist=1
__mdp_equil__nstlog=8
__mdp_equil__nstenergy=8
[[ $GMXVERSION -gt 4 ]] && __mdp_cg__nstxout_compressed= || __mdp_cg__nstxtcout=0
__mdp_equil__tcoupl=v-rescale
__mdp_equil__lincs_order=6
__mdp_equil__lincs_iter=8
__mdp_equil__lincs_warnangle=90
__mdp_equil__tau_p=10
#--------------------------------------------------------------------
# User specified parameters
if [[ -n $MDP ]]
then
# Check if the MDP file specified exists and exit if not
[[ ! -f $MDP ]] && echo "MDP file $MDP specified, but not found" && exit
# Gather options
# 1. Delete empty lines
# 2. Delete comment lines
# 3. Remove whitespace on either side of the equality sign
# 4. Remove trailing whitespace
# 5. Replace spaces with commas
USER_MDP=( $( sed '/^ *$/d;/^ *;/d;s/\s*=\s*/=/;s/\s*$//;s/ /,/g;' $MDP ) )
for i in ${USER_MDP[@]}
do
opt=${i%%=*}
val=${i#$opt}
eval "__mdp_usr__${opt//-/_}$val"
done
fi
if [[ -n $MDPOPTS ]]
then
for i in ${MDPOPTS[@]}
do
# --mdp-energygrps=bla,bla,bla
opt=${i%%=*}
val=${i#$opt}
eval "__mdp_usr__${opt//-/_}$val"
done
fi
#--------------------------------------------------------------------
#--------------------------------------------------------------------
#---SUBROUTINES--
#--------------------------------------------------------------------
ERROR=0
archive ()
{
if [[ -n $ARCHIVE ]]
then
tar cfz $ARCHIVE.tmp.tgz `ls --ignore=$ARCHIVE`
mv $ARCHIVE.tmp.tgz $ARCHIVE
fi
}
trap "archive" 2 9 15
exit_clean()
{
[[ -f RUNNING ]] && rm -f RUNNING
touch DONE
if ! $KEEP
then
echo Deleting redundant files:
printf "%-25s %-25s %-25s %-25s %-25s\n" ${JUNK[@]} \#*\#
for i in ${JUNK[@]} \#*\#; do [[ -f $i ]] && rm $i; done
fi