Using Falcon Hack

Chen Xu

$BrandeisEM: ~/emdoc/articles-xml/Flacon-Hack/article.xml 1 2014-03-10 01:38:24 xuchen Exp$

Now, Falcon II fast readout (Falcon Hack) is in place and running happily, we need a brief document describing how to use this new system.

Using the system includes a few parts. 1) How to start and stop the capturing. 2) How to monitor captured file being generated. 3) How to view the newly captured MRC stack files. 4) How to align the stacks at background, automatically. 5) for tomography users, how to stack the aligned mrc output according to the order in SerialEM's mdoc file. I will try to cover these.

You can also get pdf version of this document here.

Table of Contents
1 Start and Stop Falcon Frame Capturing
2 How to Monitor Capturing Process
3 Align the Stacks at Background
4 View Flacon Stack File
5 Restacking Aligned Falcon Frames for Tomography

1 Start and Stop Falcon Frame Capturing

  1. From Tecnai F30 computer, login to as capture using a SSH client. On Tf30, you can use "putty".

  2. Start capturing program with a Suffix.

[capture@localhost ~]$ start_capture XC-Sample1
    User account: [capture] capture
    Saving data to directory /mnt/SSD_RAID/captured/2014-03-10_capture_XC-Sample1
    capture: no process killed
    24147: old priority 0, new priority -20 

    This command will kill any exsiting capture job and start a new one. It also creates a new direcotry /mnt/SSD_RAID/captured/2014-03-10_capture_XC-Sample1 for your captured frames from now on.

2 How to Monitor Capturing Process

(1) To monitor the capturing process, you can see from a log file:

[capture@localhost ~]$ cd /mnt/SSD_RAID/captured/2014-03-10_capture_XC-Sample1
[capture@localhost 2014-03-10_capture_XC-Sample1]$ ls -l
total 65544
-rw-r--r--. 1 root root     1616 Mar 10 11:32 capture_10_03_2014-11_28_04.log
-rw-r--r--. 1 root root 67109888 Mar 10 11:28 gain_2014_03_10-11_28_05.mrc
[capture@localhost 2014-03-10_capture_XC-Sample1]$ tail -f capture_10_03_2014-11_28_04.log
THREAD id 1 ->vis_n 1 
>>>>>>>>>>>>>>>> SET FILTERS 0 
>>>>>>>>>>>>>>>> SET FILTERS 1 
Unknown event 
Unknown event 
Unknown event 
11_29_06:Idle     :330, 0:330, 73446:: 0 0 0: Range 10000 0 
11_30_06:Idle     :329, 0:329, 73446:: 0 0 0: Range 10000 0 
11_31_06:Idle     :330, 0:330, 73446:: 0 0 0: Range 10000 0 
11_32_06:Idle     :330, 0:329, 73446:: 0 0 0: Range 10000 0 
11_33_06:Idle     :330, 0:330, 73446:: 0 0 0: Range 10000 0 

If an expsoure happens, you will see activities from this log file.

Note: Currently, Capture program will save all the stack larger than 1GB (about 1 second exposure). Smaller than that won't be saved to hard drive. This prevents littering. Therefore, we should set all the parameters in camera setup to less than 1 seconds, except R.

(2) To monitor stack files being generated, we can simply user unix grogram "watch".

[capture@localhost 2014-03-10_capture_XC-Sample1]$ watch -n 20 "ls -lt | head -10"

This will list the latest 10 files generated, every 20 second.

3 Align the Stacks at Background

The capturing Linux box is a relatively powerful computer. Except capturing job, there is no other things running. Therefore, I thought it would be very efficient if we can align the stacks at the background as soon as the stack file is mature. If the alignment is good, tomography users can simply get the aligned output. You can always get the raw stack files in case you want to realign or do whatever you like to do with them.

Currently, I tried to use IMOD aligning programs. Other program might also work well here. Following Greg's idea to copy files over to storage computer, I run a cron jon every 20 seconds to find the captured Falcon frames and run a bash shell script on it. Here is an example how I run it.

Example 1., to be run every 30 seconds from system cron.


# First avoid running the script if it is already running


if [ -d /tmp/$lockfile ]; then
  echo Lockfile exited, exit...

mkdir /tmp/$lockfile
if [ $? -ne 0 ]; then
   echo "Failed to make temp directory"

## assume destincation is mounted. 

cd -- "$source" &&
find . -type f -name "*.mrcs" -mmin +10 | \
    while read file; do sh /root/com/ $file; done

if [ -d /tmp/$lockfile ]; then
  rmdir /tmp/$lockfile 

Here is the content of I first check if the file has been processed already. If not, I genarated a IMOD python command script (.pcm) and run it.

Example 2.

# sh script to generate IMOD command file *.pcm
  echo    Usage: sh $0 "stack.mrc"

if [ $# == 0 ]; then usage; exit 0; fi

# if processed, i.e. have .mrcs_aligned.mrc, don't do

dirname=$(dirname "$file")
filename=$(basename "$file")

if [ -f $dirname/$basename.$ext_processed ]; then 
	echo $dirname/$basename.mrcs is already processed, exit ...
	exit 1

#grep Path ${mdoc} | cut -f3 -d'\' | sed s'/mrc/mrc",/' | sed s'/^/\>"/' > tmp
#echo ${file}
echo ${mrcf}

if [ -f ${pcmf} ]; then rm -f ${pcmf}; fi


echo '>files = [' >> ${pcmf}
echo \>\"${mrcf}\", >> ${pcmf}
echo \>']' >> ${pcmf}
cat << EOF >> ${pcmf}
>iter = ${iter}
>filter = ${filter}
>corrbin = ${corrbin}
>radius2 = ${radius2}
>sigma2 = ${sigma2}
>scaling = ${scaling}
>countsPerElec = ${countsPerElec}
>shrink = ${shrink}
>avgstr = ''
>for mrcf in files:
>  avgfile = mrcf + '.avg'
>  xffile = mrcf + '.xf'
>  xgfile = mrcf + '.xg'
>  tmpfile = mrcf + '.tmp'
>  truncfile = mrcf + '.trnc'
>  avgstr += ' ' + avgfile
$  tiltxcorr -Stan
InputFile %mrcf
OutputFile %xffile
RotationAngle 0
FirstTiltAngle 0
TiltIncrement 0
FilterRadius2 %radius2
FilterSigma1 0.01
FilterSigma2 %sigma2
ShiftLimitsXandY 30,30
BinningToApply %corrbin
Iterate %iter
#AntialiasFilter %filter

$  xftoxg -n 0 %xffile %xgfile
#$  newstack -bin %shrink -mul %scaling,0 -anti 6 -mode 1 -xf %xgfile %mrcf tmp.ali
$  newstack -bin %shrink -anti 6 -mode 1 -xf %xgfile %mrcf %tmpfile
$  avgstack
#$  newstack -mode 1 -mul %scaling,0 %avgstr ${mrcf}
$  newstack -mode 1 %avgstr ${mrcf}_aligned.mrc

if [ -f ${pcmf} ]; then 
  echo  ${pcmf} has been created...
  echo  % submfg ${pcmf}
  #subm ${pcmf}
  /usr/local/IMOD/bin/submfg ${pcmf}

# clean up
rm -f *.avg *.avg~
rm -f *.tmp *.tmp~
rm -f *.xf *.xf~ *.xg *.xg~

4 View Flacon Stack File

For each Falcon stack captured, there is also a sum mrc file. The sum mrc has only 64MB, which is easy to be viewed from F30 computer. I planned to have another higher end computer (e.g. 64-bit for SerialEM in F20 room) for this purpose, but I haven't done it yet.

5 Restacking Aligned Falcon Frames for Tomography

Captured frame stack has date and time stamp in the filename, such as Falcon_2014_03_01-22_20_46_0.mrcs, but it doesn't have any tilting angle information like in extended header of SerialEM stacks. Recent implement of bi-directional way of collecting a tilting series in SerialEM makes this order even more complicated. We need a way to assemble all the aligned outputs from each captured Falcon stack into a tilting stack with the same correct order as mdoc file. Considering there could be time difference between capturing Linux computer and Tf30 computer on which mdoc file is generated, I have found that it is not a very easy job to me. I finally come up a script to do it. I hope that , there is a much better and easy way.

Basically, I extract DateTime info from the mdoc file and compare it with the timestamp in Falcon frame filenames. If it is less then a threshold value, I conclude it is THAT tilt. I made it into a fileinput and stack them using newstack.

Example 3.


# find correspondent Falcon*.mrc file belong to which
# section (tilts) and stack them together. 

usage (){
	echo usage: $0 "mdoc-file"

if [ $# -ne 1 ]; then

grep -n $var $mdoc > tmp
no=`grep -c $var $mdoc`
echo $no > fileinlist
while read line; do
#Z=`echo $line | cut -d":" -f2 | grep -oP '\[\K[^\]]+'`
      Z=`echo $line | cut -d":" -f2`
      line=`echo $line | cut -d":" -f1` 
      tiltline=`expr $line + 1`
      tilt=`sed -n ${tiltline}p $mdoc | cut -d"=" -f2 | tr '\n' ' '`
      line=`expr $line + 18`
      datetime=`sed -n ${line}p $mdoc | cut -d"=" -f2 | tr '\n' ' '`
      sec_mdoc=`date --date "$datetime" +%s`
      for file in Falcon*.mrc; do
            year=`basename $file .mrc | cut -d"-" -f1 | cut -d"_" -f2`
            month=`basename $file .mrc | cut -d"-" -f1 | cut -d"_" -f3`
            mon=`date --date $month +%b`
            date=`basename $file .mrc | cut -d"-" -f1 | cut -d"_" -f4`
            hour=`basename $file .mrc | cut -d"-" -f2 | cut -d"_" -f1`
            min=`basename $file .mrc | cut -d"-" -f2 | cut -d"_" -f2`
            sec=`basename $file .mrc | cut -d"-" -f2 | cut -d"_" -f3`
            str_datetime="$date-$mon-$year $hour:$min:$sec"
            second=`date --date "$str_datetime" +%s`
            diff=`expr $sec_mdoc - $second`
            abs=`echo ${diff#-}`
            if [ "$abs" -le "${offset}" ]; then
              echo ""
              echo "      $datetime"
              echo $file "--" "$Z"
              echo "      Tilt angle =$tilt"			
              echo $file >> fileinlist			
              echo 0 >> fileinlist
            #  echo too different
done < tmp
#rm -f tmp

# make the stack file
newstack --fileinlist fileinlist Falcon-`echo $mdoc | cut -d"." -f1`.st