2 Change Target Defocus using Macro

With SerialEM, the macro


Autofocus 
Autofocus

will bring scope to the target defocus value which was pre-defined from Focus → Set Target. Runnig the command autofocus twice is perhaps needed if you want to get to the target defocus fairly close.

Luckily, SerialEM provides two macro commands that are target defocus related. They are IncTargetDefocus # and ReportTargetDefocus. Therefore, if we can set TargetDefocus value using those two commands, we are all set. Here is an example.

Example 1. CycleTargetDefocus.txt


MacroName CycleTargetDefocus
#
# by Chen Xu, modified @ 1/25/2013
#
# change Target Defocus in the fly
#
#==========================================================
# define defocus up and down thresholds, and changing step
#==========================================================
TD_low = -1.6
TD_high = -2.6
delta = 0.1

#==== no editing below ======
bigstep = $TD_low  - $TD_high 

# now check current TargetDefocus, if still in the range, increase
# or reset to TD_low by a bigstep up

ReportTargetDefocus
TD = $reportedValue1

if $TD > $TD_low
   diff = $TD - $TD_low
   IncTargetDefocus -$diff
elseif $TD > $TD_high 
   IncTargetDefocus -$delta
else
   IncTargetDefocus $bigstep
endif

Running this macro will cycle target defocus value between -1.6 and -2.6 μm with 0.1 μm as step size.

Thus, we only need to call this macro before running autofocus command in our macro, as below.


# change target defocus 
Call CycleTargetDefocus

Autofocus 
Autofocus