Introduce pysawsim in the README and add fit_force_histograms.py & friends.
[sawsim.git] / pysawsim / run_vel_dep
1 #!/bin/bash
2 #
3 # run_vel_dep
4 #
5 # run BN*N simulations each at a series of pulling speeds V
6 # (non-velocity parameters are copied from the run_vel_dep command
7 # line) for each speed, save all unfolding data data_$V, and generate
8 # a histogram of unfolding forces hist_$V also generate a file v_dep
9 # with the mean unfolding force vs velocity.
10 #
11 # usage: run_vel_dep OUTPUT_DIR VS SAWSIM PARAMS...
12 # e.g.   run_vel_dep v_dep-123xs \
13 #          1e-9,1e-8,1e-7,1e-6,1e-5 \
14 #          -s cantilever,hooke,0.05 -N1 \
15 #          -s folded,null -N8 \
16 #          -s 'unfolded,wlc,{0.39e-9,28e-9}' \
17 #          -k 'folded,unfolded,bell,{3.3e-4,0.25e-9}' \
18 #          -q folded
19
20 if [ $# -lt 3 ]; then
21   STAMP=`date +"%Y.%m.%d.%H.%M.%S"`
22   echo 'usage: run_vel_dep OUTPUT_DIR VS SAWSIM PARAMS...'
23   echo "e.g.   run_vel_dep v_dep-$STAMP \\"
24   echo '   1e-9,1e-8,1e-7,1e-6,1e-5 \'
25   echo '   -s cantilever,hooke,0.05 -N1 \'
26   echo '   -s folded,null -N8 \'
27   echo '   -s "unfolded,wlc,{0.39e-9,28e-9}" \'
28   echo '   -k "folded,unfolded,bell,{3.3e-4,0.25e-9}" \'
29   echo '   -q folded'
30   exit 1
31 fi
32
33 DIR="$1"
34 shift
35 Vs=`echo $1 | sed 's/,/ /g'`
36 shift
37 # Protect special chars from later shell expansion by quoting and
38 # escaping and " characters that may have been in $arg already.
39 Q='"'
40 EQ='\"'
41 SAWSIM_PARAMS=`for arg in $@; do echo -n "$Q${arg//$Q/$EQ}$Q "; done`
42
43
44 # We can't depend on the entire array in one shot, so
45 # batch executions into a single array instance
46 BN=20 # sawsim executions per array job instance
47 #N=8 # number of arrays
48 N=20 # number of arrays
49 SAFTEY_SLEEP=2 # seconds to sleep between spawning array job and depending on it
50                # otherwise dependencies don't catch
51
52 mkdir "$DIR" || exit 1
53 pushd "$DIR" > /dev/null
54 echo "Date "`date` > v_dep_notes
55 echo "Run$ sawsim $SAWSIM_PARAMS -v \$V" >> v_dep_notes
56 echo "for V in $Vs" >> v_dep_notes
57
58 Is=`seq 1 $N` # a list of allowed 'i's, since 'for' more compact than 'while'
59
60 vdone_condition="afterany"
61 VJOBIDS=""
62 for V in $Vs
63 do
64   # run N sawtooth simulations
65   idone_condition="afterany"
66   cmd="cd \$PBS_O_WORKDIR
67        for i in \`seq 1 $BN\`; do
68          ~/sawsim/sawsim $SAWSIM_PARAMS -v $V > run_$V-\$PBS_ARRAYID-\$i
69        done"
70   JOBID=`echo "$cmd" | qsub -h -t 1-$N -N "sawsim" -o run_$V.o -e run_$V.e` || exit 1
71   #  "3643.abax.physics.drexel.edu" --> "3643"
72   ARRAYID=`echo "$JOBID" | sed "s/\\([0-9]*\\)\\([.].*\\)/\\1/g"`
73   for i in $Is; do idone_condition="$idone_condition:$ARRAYID-$i"; done
74
75   sleep $SAFTEY_SLEEP
76   # once they're done, compile a list of all unfolding forces for each speed
77   JOBID=`echo "cd \\\$PBS_O_WORKDIR && cat run_$V-* | grep -v '#' | cut -f1 > data_$V" |\
78       qsub -h -W depend="$idone_condition" -N sawComp -o data_$V.o -e data_$V.e` \
79         || exit 1
80   vdone_condition="$vdone_condition:$JOBID"
81   VJOBIDS="$VJOBIDS $JOBID"
82   for i in $Is; do qrls "$ARRAYID-$i"; done
83 done
84
85 # once we have force lists for each velocity, make histograms and F(V) chart
86 JOBID=`echo "cd \\\$PBS_O_WORKDIR && $HOME/script/vel_dep_graph $Vs" | \
87     qsub -W depend="$vdone_condition" -N sawsimGraph` || exit 1
88 #  "3643.abax.physics.drexel.edu" --> "3643"
89 ARRAYID=`echo "$JOBID" | sed "s/\\([0-9]*\\)\\([.].*\\)/\\1/g"`
90 for job in $VJOBIDS; do qrls $job; done
91
92 popd > /dev/null
93
94 # wait until the final job exits
95 qwait $ARRAYID
96
97 exit 0