ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/owl/trunk/modelit/scripts/md_continue.sh
Revision: 1299
Committed: Tue Jan 11 17:38:33 2011 UTC (10 years, 5 months ago) by hstehr
File size: 5398 byte(s)
Log Message:
adding Model-It server files to repository
Line User Rev File contents
1 hstehr 1299 #!/bin/sh
2     # Script to continue an MD simulation given a gro file output of an earlier MD simulation.
3    
4     # CONSTANTS
5    
6     MDPDIR=/project/StruPPi/Software/gromacs-3.3.3/mdp_files
7     # MD simulation parameters
8     MDP_MD=$MDPDIR/md.mdp
9    
10     SOLVENTGROUP=12
11    
12     DEFAULT_NP=1
13    
14     # END CONSTANTS
15    
16     # command line parameters
17     inGro=""
18     outDir=""
19     np=$DEFAULT_NP
20     endT=""
21    
22     while getopts i:o:p:e: opt
23     do
24     case "$opt" in
25     i) inGro="$OPTARG";;
26     o) outDir="$OPTARG";;
27     p) np="$OPTARG";;
28     e) endT="$OPTARG";;
29     esac
30     done
31    
32     if [ -z "$inGro" ] || [ -z "$outDir" ] || [ -z "$endT" ]
33     then
34     echo ""
35     echo "Usage: $0 "
36     echo " -i <input gro file>"
37     echo " -o <out dir> "
38     echo " -e <end time (ns)>"
39     echo " [-p] <number of processes>"
40     echo "Use end time (ns) for the end time of the simulation, the start"
41     echo "time will be taken from the name of the input gro file "
42     echo "Use absolute paths to run on cluster!!"
43     echo ""
44     exit 1
45     fi
46    
47     # gromacs dir
48     arch=`uname -m`
49     gmxDir=/project/StruPPi/Software/gromacs-3.3.3/i686/bin
50     if [ "$arch" == "x86_64" ]
51     then
52     gmxDir=/project/StruPPi/Software/gromacs-3.3.3/x86_64/bin
53     fi
54    
55     # mdrun command (use mpi or not)
56     mdrunCmd="$gmxDir/mdrun"
57     if [ "$np" -gt "1" ]
58     then
59     mdrunCmd="mpirun -np $np $gmxDir/mdrun_mpi"
60     fi
61    
62     # mdp files
63    
64     mdpMD=$MDP_MD
65     if [ -e "$outDir/md.mdp" ]
66     then
67     mdpMD="md.mdp"
68     echo "Using $mdpMD in $outDir as parameter file for MD step"
69     fi
70    
71    
72     outLog=out.log
73     cmdLog=cmd.log
74    
75    
76     # FUNCTIONS
77    
78     # checkExitStatus, takes 2 parameters:
79     # exit value
80     # program name
81     checkExitStatus () {
82     exitVal="$1"
83     prog="$2"
84     if [ "$exitVal" -ne "0" ]
85     then
86     echo "$prog failed. Revise log file $outLog. Exiting"
87     exit 1
88     fi
89     }
90    
91     checkFilesExist () {
92     while [ ! -z "$1" ]
93     do
94     if [ ! -e "$1" ]
95     then
96     echo "File $1 does not exist in $outDir"
97     exit 1
98     fi
99     shift
100     done
101     }
102    
103     # runSimulation, takes 5 parameters:
104     # mdp file
105     # in gro file
106     # in top file
107     # suffix of the input gro file (without the .gro), e.g. for T0123.pr.gro the suffix is "pr"
108     # suffix of the output files, e.g. if input is T0123.pr.gro and we specify "md" as suffix output, we'd get output files like T0123.md.gro or T0123.md.xtc
109     runSimulation () {
110     if [ -z "$5" ]
111     then
112     echo "Not enough parameters were passed to runSimulation. This is a bug in this script... exiting"
113     exit 1
114     fi
115    
116     # globals: outLog, cmdLog, gmxDir, mdrunCmd, np
117    
118     # parameters
119     mdp="$1"
120     gro="$2"
121     top="$3"
122     suffixIn="$4"
123     suffixOut="$5"
124    
125     # locals: beware!! these cannot conflict with a name already in use elsewhere in the script
126     bn1=`basename $gro .gro`
127     bn2=`basename $bn1 .$suffixIn`
128     tpr=$bn2.$suffixOut.tpr
129     trr=$bn2.$suffixOut.trr
130     outGro=$bn2.$suffixOut.gro
131     edr=$bn2.$suffixOut.edr
132     xtc=$bn2.$suffixOut.xtc
133     log=$bn2.$suffixOut.log
134    
135     # grompp creates a mdout.mdp file by default, which is (I think) useless
136     # If there is already one in the outdir it will back it up giving the backed up file a version number.
137     # But gromacs won't backup up beyond version 128: because of that we remove the file here before running grompp
138     rm -f mdout.mdp
139    
140     echo -e "##########\n# preparing run with input $bn1.gro and output $outGro (grompp)\n##########" >> $outLog
141     echo "$gmxDir/grompp -f $mdp -c $gro -p $top -o $tpr -np $np" >> $cmdLog
142     $gmxDir/grompp -f $mdp -c $gro -p $top -o $tpr -np $np 1>> $outLog 2>&1
143    
144     echo -e "##########\n# mdrun with input $bn1.gro and output $outGro (mdrun)\n##########" >> $outLog
145     echo "$mdrunCmd -s $tpr -o $trr -c $outGro -e $edr -x $xtc -g $log -np $np" >> $cmdLog
146     $mdrunCmd -s $tpr -o $trr -c $outGro -e $edr -x $xtc -g $log -np $np 1>> $outLog 2>&1
147    
148     checkExitStatus $? mdrun
149     }
150    
151    
152    
153     # END FUNCTIONS
154    
155     # gromacs assumes that its output directory is the same as the current, a few things don't work well if that's not the case
156     # thus we change to the outDir before starting to run any commands,
157     # that means we use directly the file names without paths for all input/output files
158    
159    
160     cd $outDir
161     echo "" > $outLog
162     echo "" > $cmdLog
163    
164    
165    
166     inGro=`basename $inGro` # we strip the directory off inGro, it simply must be in outDir
167     # top file
168     basename1=`echo "$inGro" | perl -ne 'print $1 if /^(\w+)\./'`
169     topFile=$basename1.top
170    
171     # we check if files are in $outDir, if not we exit
172     checkFilesExist $inGro $topFile
173    
174    
175     begT=`echo $inGro | perl -ne 'print $1 if /^\w+\.(\d\d\d\d)ns.*\.gro/'`
176     if [ -z "$begT" ]
177     then
178     echo "Input gro file is not in the right format, it must contain the ns end point of the simulation and have the .gro extension, e.g. Txxxx.0001ns.md.gro"
179     exit 1
180     fi
181    
182     begT=`expr $begT + 1` # this strips off the leading 0s and sum 1
183    
184     # MD simulation
185     echo "Molecular dynamics simulation"
186     lastSuffix=""
187    
188     for et in `seq $begT $endT`
189     do
190     bt=`expr $et - 1`
191     btStr=`printf %04.0f $bt`ns
192     etStr=`printf %04.0f $et`ns
193     echo "Running simulation up to $etStr"
194    
195     runSimulation $mdpMD $basename1.$btStr.md.gro $topFile $btStr.md $etStr.md
196     lastSuffix="$etStr.md"
197     done
198    
199    
200    
201     # 8. converting the final md gro file to pdb
202     mdFile=$basename1.$lastSuffix.gro
203     tprMD=$basename1.$lastSuffix.tpr
204     # final pdb file
205     mdPdbFile=$basename1.$lastSuffix.pdb
206    
207    
208     echo "Converting $mdFile to $mdPdbFile"
209     echo -e "##########\n# converting gro to pdb (trjconv)\n##########" >> $outLog
210     echo "echo 1 | $gmxDir/trjconv -f $mdFile -o $mdPdbFile -s $tprMD" >> $cmdLog
211     echo 1 | $gmxDir/trjconv -f $mdFile -o $mdPdbFile -s $tprMD 1>> $outLog 2>&1
212     checkExitStatus $? trjconv

Properties

Name Value
svn:executable *