#! /bin/csh -f # # Procedure for taking a direct beam shot # # if(! $?beamline) then # default to beamline this computer belongs to setenv beamline `beamline.com` if($status) then echo "ERROR: $beamline" exit 9 endif endif #if(! $?beamline) setenv beamline 831 set bin = 4 set tempfile = tempfile set FIT set divsetting = ( 0.01 0.01 ) foreach arg ( $* ) if ( "$arg" =~ *[0-9]mm ) then # see if the user specified a distance set temp = `echo $arg | awk '$1+0>70 && $1+0<=1000{print $1+0}'` if("$temp" != "") set goal_dist = $temp endif if ( "$arg" =~ *.img ) then # must have specified an image if ( ! -e "$arg" ) then echo "ERROR: $arg does not exits! " exit 9 endif set image = "$arg" goto extract endif if ( "$arg" =~ *[0-9]x[0-9]* ) then # see if the user specified a beam center set temp = `echo $arg | awk -F "x" 'NF==2 && $1+0<400 && $1+0>-100 && $2+0<400 && $2+0>-100{print $1+0,$2+0}'` if($#temp == 2) then set beam_center = ( $temp ) set image = "command line" set xsize = 3072 set xsize = 2048 set pixel = 0.1024 set db_pix = `echo $beam_center $xsize $pixel | awk '{print $3-$2/$NF, $1/$NF}'` goto manual_set else echo "ERROR: invalid beam center $arg" endif endif end # store current values so we can restore them #set dist = `distance.com | awk '{print $(NF-1)+0}' | tail -1` #set old_wave = `wave.com | awk '/^Wavelength:/{print $2}' | tail -1` set old_div = `divergence.com | tail -1 | awk '{print $(NF-1), $NF}'` set old_stage = `stage.com | awk '{print $5}'| tail -1` set old_sample = `sample.com | awk '{print $5,$6,$7}'` set info = `echo -n "" | xos3_exchange.tcl |& awk '/stog_configure_run run0 /{print; exit}'` if($#info < 20) then echo "ERROR: unable to access DCSS" exit 9 endif set oldname = $info[6] set directory = $info[7] set delta = $info[12] set expose = $info[14] set dist = $info[15] set oldenergy = $info[17] set energy = 11111.00 set dist = `echo $dist | awk '{print $1+0}'` if(! $?goal_dist) then set goal_dist = $dist endif if(! -w $directory) then set directory = /data/${USER}/ endif try_again: onintr finish attenuator.com Se in attenuator.com Al in attenuator.com Cu in divergence.com $divsetting & #stage.com -30 & #sample.com 0 0 -1 & #distance.com $goal_dist & echo "" wait #set directory = `echo -n "" | xos_exchange.tcl control 1 "over out" | awk '/configure_run_text/{print $NF}' | tail -1` set n = `ls -1 ${directory}/db_${dist}mm_0_???.img |& tail -1 | awk -F "_" '{print $NF%999+1}'` set num = `echo $n | awk '{printf "%03d", $1+0}'` set image = "${directory}/db_${goal_dist}mm_0_${num}.img" echo "collecting:" echo "$image" ################################################################### # reset the "zero" position to be out of the beam set stage_up = `dcsmotor.com stage_up | awk '{print $NF}'` dcsmotor.com stage_up `echo $stage_up | awk '{print $1-30}'` ( sleep 10 ; dcsmotor.com stage_up $stage_up ) & # now take the snapshot picture snapshot.com $image osc=1 time=0.1 dist=$goal_dist energy=$energy -nodose finish: onintr dcsmotor.com stage_up $stage_up attenuator.com Se out attenuator.com Al out attenuator.com Cu out divergence.com $old_div & wave.com $oldenergy & stage.com $old_stage & sample.com to $old_sample # kill %1 >& /dev/null extract: # retreive the coordinates set head = `od -cv $image | awk '{for(i=2;i<=NF;++i) print $i}' | awk '/\\n/{++n;c=0} {++c} c>1000{exit} END{print n}'` set header = `head -$head $image | awk 'BEGIN{FS="="} /^HEADER_BYTES/{print $2+0; exit}'` set xsize = `head -$head $image | awk 'BEGIN{FS="="} /^SIZE1/{print $2+0}' | tail -1` set ysize = `head -$head $image | awk 'BEGIN{FS="="} /^SIZE2/{print $2+0}' | tail -1` set pixel = `head -$head $image | awk 'BEGIN{FS="="} /^PIXEL/{print $2+0}' | tail -1` set xbeam = `head -$head $image | awk 'BEGIN{FS="="} /^BEAM_CENTER_X/{print $2+0}' | tail -1` set ybeam = `head -$head $image | awk 'BEGIN{FS="="} /^BEAM_CENTER_Y/{print $2+0}' | tail -1` set word = 2 set record = `echo "$word $ysize" | awk '{print $1*$2}'` # select a box around where the beam is supposed to be set boxedge = 100 set db_header = `echo $xbeam $ybeam $xsize $pixel | awk '{print $3-$2/$4,$1/$4}'` set X1 = `echo $db_header $boxedge | awk '{printf "%d", $1-$3/2}'` set X2 = `echo $db_header $boxedge | awk '{printf "%d", $1+$3/2}'` set Y1 = `echo $db_header $boxedge | awk '{printf "%d", $2-$3/2}'` set Y2 = `echo $db_header $boxedge | awk '{printf "%d", $2+$3/2}'` if ($?AGRESSIVE) then # look all the way up and down for the beam set X1 = 0 set X2 = $xsize endif # calculate starting point (in the frame file) of interesting pixels @ offset = ( $header + ($record * $X1) + ($Y1 * $word)) od -dv -j $offset $image |\ awk "BEGIN{record=$record/$word; xpixels=$X2-$X1; ypixels=$Y2-$Y1;}"' \ {# scan each "od" printout line \ for(i=2;i<=NF;++i){++pixels; ++y; \ # only print pixels within "y" limits \ if(y<=ypixels) print x+0,y-1,$i;\ # "record" boundary is now "x" boundary \ if(pixels%record==0){y=0; ++x};\ # detect end of desired image \ if(x>=xpixels) exit}}' |\ sort -nr +2 >! ${tempfile}.pixeldump set intensity = `awk '{printf "%d", $3; exit}' ${tempfile}.pixeldump` set overload = `echo $intensity | awk '{print ($1>65500); exit}'` set underload = `echo $intensity | awk '{print ($1<100); exit}'` if ($overload) then echo "ERROR: direct beam is too strong! " set area = `echo $divsetting | awk '{print $1*$2*1000000}'` if($area > 100) then set divsetting = `echo $divsetting | awk '{print $1*0.5,$2*0.5}'` goto try_again endif exit 9 endif if ($underload) then echo "ERROR: direct beam is too weak! " if ($?AGRESSIVE) exit 9 set AGRESSIVE echo "trying wider area..." goto extract endif set db_pix = `awk '{print $1,$2; exit}' ${tempfile}.pixeldump` if ($?FIT) then cp ${tempfile}.pixeldump plotme rm -f fit.log gnuplot << EOF |& awk -v X1=$X1 -v Y1=$Y1 -v pixel=$pixel -v xsize=$xsize '$4!="+/-"{next} /^x0 /{x0=$3} /^y0 /{y0=$3;print ((Y1+y0))*pixel,(xsize-(X1+x0))*pixel}' gauss(x,y)=(x**2<50 && y**2<50 ? exp(-log(2)*((x**2)+(y**2))) : 0) peak(x,y)=height*gauss((x-x0)/wx,(y-y0)/wy)+dc x0=$db_pix[1] y0=$db_pix[2] height=$intensity wx=2 wy=2 dc=40 set isosamples 30 plot peak(x0,x), 'plotme' using 2:( abs(\$1-x0)<0.5 ? \$3 : 1/0) fit peak(x0,x) 'plotme' using 2:( abs(\$1-x0)<0.5 ? \$3 : 1/0) via height,y0,wy plot peak(x0,x), 'plotme' using 2:( abs(\$1-x0)<0.5 ? \$3 : 1/0) fit peak(x,y0) 'plotme' using 1:( abs(\$2-y0)<0.5 ? \$3 : 1/0) via height,x0,wx plot peak(x,y0), 'plotme' using 1:( abs(\$2-y0)<0.5 ? \$3 : 1/0) plot peak(x,y0), 'plotme' using 1:3 splot 'plotme' using 1:2:(\$3>80 ? \$3 : 1/0), peak(x,y) fit peak(x,y) 'plotme' using 1:2:3:(1) via x0,y0 splot 'plotme' using 1:2:(\$3>80 ? \$3 : 1/0), peak(x,y) fit peak(x,y) 'plotme' using 1:2:3:(1) via wx splot 'plotme' using 1:2:(\$3>80 ? \$3 : 1/0), peak(x,y) fit peak(x,y) 'plotme' using 1:2:3:(1) via wy splot 'plotme' using 1:2:(\$3>80 ? \$3 : 1/0), peak(x,y) fit peak(x,y) 'plotme' using 1:2:3:(1) via wx,wy splot 'plotme' using 1:2:(\$3>80 ? \$3 : 1/0), peak(x,y) fit peak(x,y) 'plotme' using 1:2:3:(1) via height,x0,y0 splot 'plotme' using 1:2:(\$3>80 ? \$3 : 1/0), peak(x,y) fit peak(x,y) 'plotme' using 1:2:3:(1) via x0,y0,dc,wx,wy splot 'plotme' using 1:2:(\$3>80 ? \$3 : 1/0), peak(x,y) EOF set fitted_db_pix = `awk '$1=="x0" && $4=="+/-"{x=$3} $1=="y0" && $4=="+/-"{y=$3} END{print x,y}' fit.log` set test = `echo $db_pix $fitted_db_pix | awk '{printf "%d", sqrt(($1-$3)^2+($2-$4)^2)}'` if ($test < 2) then echo "using fitted position" set db_pix = ( $fitted_db_pix ) endif endif set db_pix = `echo $X1 $Y1 $db_pix | awk '{print $1+$3,$2+$4}'` manual_set: # appropriate for values in ADXV set db_mm = `echo $db_pix $xsize $pixel | awk '{print $2*$4,($3-$1)*$4}'` set denzo_beam = `echo $db_mm $xsize $pixel | awk '{print ($3*$4)-$2,$1}'` wait if (! -e "$image" && "$image" != "command line") then set BAD echo "ERROR: image file was not produced! " endif if ($?BAD) exit 9 echo "direct beam is ready in: $image" echo "" echo "direct beam is now at: $db_mm ( $db_pix[2] $db_pix[1] )" echo "mosflm/denzo beam is : $denzo_beam" echo "" exit cp ${tempfile}.pixeldump plotme set db_pix = `awk '{print $1,$2; exit}' ${tempfile}.pixeldump` rm -f fit.log gnuplot -persist << EOF gauss(x,y)=(x**2<50 && y**2<50 ? exp(-(x**2) -(y**2)) : 0) peak(x,y)=height*gauss((x-x0)/wx,(y-y0)/wy)+dc x0=$db_pix[1] y0=$db_pix[2] height=$intensity wx=2 wy=2 dc=40 set isosamples 30 fit peak(x0,x) 'plotme' using 2:( abs(\$1-x0)<0.5 ? \$3 : 1/0) via height,y0,wy plot peak(x0,x), 'plotme' using 2:( abs(\$1-x0)<0.5 ? \$3 : 1/0) fit peak(x,y0) 'plotme' using 1:( abs(\$2-y0)<0.5 ? $3 : 1/0) via height,x0,wx plot peak(x,y0), 'plotme' using 1:( abs(\$2-y0)<0.5 ? \$3 : 1/0) plot peak(x,y0), 'plotme' using 1:3 fit peak(x,y) 'plotme' using 1:2:3:(sqrt(\$3)) via x0,y0 splot 'plotme' using 1:2:(\$3>80 ? \$3 : 1/0), peak(x,y) fit peak(x,y) 'plotme' using 1:2:3:(sqrt(\$3)) via wx splot 'plotme' using 1:2:(\$3>80 ? \$3 : 1/0), peak(x,y) fit peak(x,y) 'plotme' using 1:2:3:(sqrt(\$3)) via wy splot 'plotme' using 1:2:(\$3>80 ? \$3 : 1/0), peak(x,y) fit peak(x,y) 'plotme' using 1:2:3:(sqrt(\$3)) via wx,wy splot 'plotme' using 1:2:(\$3>80 ? \$3 : 1/0), peak(x,y) fit peak(x,y) 'plotme' using 1:2:3:(sqrt(\$3)) via height,x0,y0 splot 'plotme' using 1:2:(\$3>80 ? \$3 : 1/0), peak(x,y) fit peak(x,y) 'plotme' using 1:2:3:(sqrt(\$3)) via x0,y0,dc,wx,wy splot 'plotme' using 1:2:(\$3>80 ? \$3 : 1/0), peak(x,y) EOF set db_pix = `awk '$1=="x0" && $4=="+/-"{x=$3} $1=="y0" && $4=="+/-"{y=$3} END{print x,y}' fit.log` exit 600 150.2 149.4 100 150.3 149.3 3-29-03 600 150.1 148.8 300 150.2 148.9 150 150.3 148.8 5-14-03 90mm 155.515 149.096 100mm 155.516 149.114 150mm 155.477 149.035 200mm 155.437 149.081 300mm 155.393 149.039 400mm 155.373 148.906 500mm 155.315 148.941 600mm 155.237 148.86 700mm 155.209 148.813 800mm 155.161 148.8 900mm 155.13 148.785 5-14-03 after 2theta adjust 100mm 155.537 149.149 200mm 155.478 149.137 300mm 155.435 149.138 400mm 155.402 149.132 500mm 155.349 149.126 600mm 155.286 149.112 700mm 155.242 149.141 800mm 155.179 149.135 900mm 155.155 149.155 #2p beam goal 149.134 0 148.77 60 148.314 -60 149.155 Chi2 beam 900mm 100mm goal 155.584 155.584 1.4400 154.544 1.4500 155.149 155.537 1.4510 155.159 1.4550 155.409 155.784 1.4570 155.508 1.4600 155.682