#! /bin/tcsh -f # # Use Wedger Elves to index the most recent images and import this # strategy into BLU-ICE # # set cwd = `pwd` set homedir = `cd ; pwd` if ("$cwd" == "$homedir") then # try not to clutter up the root directory mkdir -p index >& /dev/null cd index endif # farm this out to an un-busy host? set pwd = `pwd` set host = `hostname -s` set sshopts = "+x -t -o BatchMode=yes" if(0 && "$host" != "graphics3" ) then rsh graphics3 "source .cshrc ; source .login ; setenv STAY ; cd $pwd ; $0 $*" exit $status endif set tempfile = /tmp/${USER}/tempfile_index$$ rm -f strategy.txt >& /dev/null onintr break # find the last image collected #set lastimage = `tac /data/log/watchdog.log | awk '/image_ready/{print $NF;exit}'` #set dist = `awk 'BEGIN{RS="\f"} {print;exit}' $lastimage | awk -F "[=]" '/^DIST/{print $2+0}'` #set energy = `awk 'BEGIN{RS="\f"} {print;exit}' $lastimage | awk -F "[=]" '/^WAVE/ && $2+0>0{print 12398.42/$2}'` #set twotheta = `awk 'BEGIN{RS="\f"} {print;exit}' $lastimage | awk -F "[=]" '/^TWOTH/{print $2+0}'` # look for the oldest image with these same camera settings tac /data/log/watchdog.log |\ egrep "image_ready|shutter|sample" |\ awk '/image_ready/{++frames;image=$NF;prefix=image;\ while(prefix!~/_$/){prefix=substr(prefix,1,length(prefix)-1)}\ RS="\f"; status = getline header < image;\ if(status<0){header=""}\ gsub("[=;]", " ", header);\ print header;\ close(image);RS="\n";\ print "collected",prefix,image}\ /completed sample/{print "moved sample"}\ /door open/{print "opened door"} /door open/ && frames>3{exit}' |\ awk '/^WAVE/{energy=12398.42/$2}\ /^DIST/{dist=$2}\ /^TWOTH/{twotheta=$2}\ /^collected/{print $1,$2,energy,dist,twotheta,$3;next} /door/ || /sample/{print}' |\ awk '/^opened door/{print "break",$0}\ /^moved sample/{print "break",$0}\ /^collected/ && sqrt(($3-dist)^2)>2{print "break";$0}\ /^collected/ && sqrt(($4-twotheta)^2)>2{print "break",$0}\ /^collected/ && sqrt(($5-energy)^2)>2{print "break",$0}\ /^collected/ && $2!=prefix {print "break",$0}\ /^collected/{prefix=$2;dist=$3;twotheta=$4;energy=$5;print $1,$NF}' |\ awk '/^collected/{++frames;print $NF} /^break / && frames{exit}' |\ cat >! ${tempfile} set lastimage = `head -1 ${tempfile}` set firstimage = `tail -1 ${tempfile}` rm -f ${tempfile} >& /dev/null if(! -r "$lastimage") then set lastimage = `awk '{print $2}' $XFORMSTATUSFILE` endif if(! -r "$firstimage") then set firstimage = "$lastimage" endif #spotfinder.com $lastimage >&! spotfinder.log & # allow user to overide first-image selection set test = `echo " $* " | awk 'BEGIN{RS=" "} {print}' | awk '/.(img|cbf)$/'` if("$test" != "") set firstimage = "" onintr afterwedger Wedger -new -index -strategy -norun $firstimage $* set normal_exit afterwedger: if(! -e strategy.txt || ! $?normal_exit) then exit 9 endif goto postcalc break: onintr exit 9 postcalc: # estimate the size of the ASU (assume Vm=2.4) set CELL = `awk '/^CELL/{$1="";print}' strategy.com` set SG = `awk '/^SYMM/{$1="";print}' strategy.com` set Vm = 2.4 set ASU_per_CELL = `awk -v SG=$SG '$4 == toupper(SG) {print $2}' $CLIBD/symop.lib |& head -1` if("$ASU_per_CELL" == "") set ASU_per_CELL = 1 # calculate the volume of the cell echo $CELL |\ awk 'NF==6{s=3.1415926535897899419/180; A=cos(s*$4); B=cos(s*$5); G=cos(s*$6); \ skew = 1 + 2*A*B*G - A*A - B*B - G*G ; if(skew < 0) skew = -skew;\ printf "%.3f\n", $1*$2*$3*sqrt(skew)}' |\ cat >! ${tempfile}volume set CELLvolume = `cat ${tempfile}volume` rm -f ${tempfile}volume >> /dev/null set ASU = `echo "$CELLvolume $ASU_per_CELL $Vm" | awk '$2+0>0 && $3+0>0{printf "%.1f", ($1/$2) / $3 / 1000}'` # ASU is the estimated protein size in kDa # get the exposure time used set actual_exposure = `awk 'BEGIN{RS="\f"} {print;exit}' $lastimage | awk -F "[=;]" '/^TIME/{print $2}'` set dosestored = `dcsmotor.com doseStoredCounts |& awk '{print $NF}'` set doselast = `dcsmotor.com doseLastCounts |& awk '{print $NF}'` set doseratio = `echo $dosestored $doselast | awk '$2+0<=0{print 1;exit} {print $1/$2}'` # this is what was entered in BLU-ICE set specified_exposure = `echo $actual_exposure $doseratio | awk '{printf "%.1f", $1/$2}'` set exposure = $specified_exposure # guess at the element set Ee = Se set electrons = 4 # get the energy used set energy = `awk 'BEGIN{RS="\f"} {print;exit}' $lastimage | awk -F "[=;]" '/^WAVE/{print 12398.42/$2}'` set nearest_edge = `echo $energy | elements` if("$nearest_edge" != "") then set nearedge = `echo $nearest_edge $energy | awk '{print (sqrt(($NF - $4)^2) < 20 && sqrt(($NF - 11111)^2) > 2 && sqrt(($NF - 12398)^2) > 2 && sqrt(($NF - 11000)^2) > 2)}'` if($nearedge) then set Ee = $nearest_edge[2] set electrons = $nearest_edge[6] endif endif # now have a look at the strategy set runs = `tail -n +2 strategy.txt | wc -l` set range = unknown if($runs > 0) then set start = `tail -n +2 strategy.txt | head -1 | awk '{print $1}'` set osc = `tail -n +2 strategy.txt | sort -n --key=2 | awk '{print $2}' | head -1` set range = `tail -n -1 strategy.txt | awk '{print $5}'` set wedges = 1 if("$exposure" == "") then set exposure = `runinfo.com | awk '$2=="run0"{print $14}'` endif # assume a 3 minute damage limit? set max_exposure = `echo 180 $range $osc $wedges | awk '{print $1/($2/$3*$4)}'` # require that the exposure be less than the damage limit set exposure = `echo $exposure $max_exposure | awk '$1>$2{$1=$2} {print $1}'` # go for redundancy if exposure time is really long set long_exposure = 15 set test = `echo $exposure $long_exposure | awk '{print ($1>$2)}'` if($test) then # set range = `echo $range $exposure $long_exposure | awk '{print $1*$2/$3}'` # set exposure = $long_exposure endif # we have a Pilatus now set exposure = 0.04 # do not suggest stupid strategies set test = `echo $osc 0.02 | awk '{print ($1<$2)}'` if ($test) then echo "required oscillation width is too small" tput smso echo "cannot collect complete data from this crystal! " tput rmso echo "you must either back off the detector" echo "or bend the pin to avoid overlaping spots" exit 9 endif echo "copying run info into BLU-ICE" echo "start $start" echo "osc $osc" echo "range $range" echo "time $exposure" run1.com -norun phi=$start osc=$osc range=$range exposure=$exposure -nodosemode num=1 >& /dev/null endif