forked from azazellochg/SerialEM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
montage2.txt
154 lines (138 loc) · 4.98 KB
/
montage2.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
MacroName Montage neg.stain
LongName Montage neg.stain
# Grigory Sharov, MRC-LMB 19/01/2018
# Preparation:
# 1) Check eucentricity, switch on Administrator mode in Calibration menu. Calibrate Image Shift and Autofocus
# (set focus range to 10um). Calibrations -> Save.
# 2) In Montage Control Panel tick "Show Overview at End", "Align pieces".
# 3) Check Record & Trial (for drift estimation) params.
# 4) Check that SetMontageParams command uses correct camera size (e.g. 2048 or 4096px) and overlap
# 5) Run one montage manually to figure out max image shift for the current magnification.
# 6) Start macro at the top left corner of the grid square (1/2 shift away from the edges!).
###################################
# Edit the following parameters:
SetDirectory \\EM-SUPPORT3\Spirit\Grigory\Folder
x = 5 # montage X by Y patches: X-axis points downwards, Y-axis - rightwards
y = 5
Xsteps = 8 # Number of stage shift steps in X direction
Ysteps = 8 # Number of stage shift steps in Y direction
shift = 4 # X um shift between montage areas (adjust to 2x [max image shift])
delay = 5 # X sec delay after stage shift
drift = 5 # X A/s max drift
autofocus = 5 # autofocus every X-th image
defLow = -1.0 # defocus min, in microns
defHigh = -2.5 # defocus max
defStep = 0.2 # defocus step
indexImg = 1 # change this index for every gridsquare (new file will be montage_$index.mrc)
###################################
Verbose 0
FocusChangeLimits -5 5 # If focus changes too much, abort and use original
YesNoBox Do you want to check the number of steps for stage shift (the stage will shift along the borders of the square)?
If $reportedValue1 == 1
TestShiftX = $shift * $Xsteps
TestShiftY = $shift * $Ysteps
ScreenDown
MoveStage 0 $TestShiftY
Delay 2 sec
MoveStage $TestShiftX 0
Delay 2 sec
MoveStage 0 -$TestShiftY
YesNoBox Was the stage always ON a gridsquare? If not, click No and change X/Y-steps parameters in the script!
MoveStage -$TestShiftX 0
If $reportedValue1 == 1
Delay $delay sec
Else
Exit
Endif
Endif
# The following will acquire montage maps in a snake-like manner
# from top left to bottom right corner of grid square
SetTargetDefocus $defLow
ChangeFocus -0.5
Autofocus
Loop $Ysteps row
Loop $Xsteps
ResetClock
SetBeamBlank 1
OpenNewMontage $x $y montage_$indexImg.mrc
SetMontageParams 0 204 204 2048 2048 1 # No stage move, overlap x=y=206, frame size x=y=2048, skip correlations
Delay $delay sec
CallFunction CycleTargetDefocus $defLow $defHigh $defStep
checkAutofocus = modulo $indexImg $autofocus
If $checkAutofocus == 0
Echo ---> Autofocusing (every $autofocus images)...
ImageShiftByMicrons -$shift 0 1 # go to off-target area for focusing
ChangeFocus -0.5 # SerialEM mistakes when too close to focus
Autofocus
CallFunction Drift $drift # wait for drift below threshold
ImageShiftByMicrons $shift 0 1
Endif
Montage
CloseFile
ReportClock
Echo ---> Acquired montage # $indexImg in $reportedValue1 seconds!
Echo ---------------------------------------
If modulo $row 2 == 0 # even row numbers --> shift in the opposite direction
MoveStage 0 -$shift
Else
MoveStage 0 $shift
Endif
indexImg = $indexImg + 1
EndLoop
MoveStage $shift 0 # goes to next Y-row
EndLoop
####################################
Function CycleTargetDefocus 3 0
## three variables, not string
TD_low = $argVal1
TD_high = $argVal2
step = $argVal3
Echo --> Selecting defocus from range: $TD_low um to $TD_high um with $step um step.
delta = -1 * $step
# if the current TargetDefocus is outside of range, make it as TD_low.
# Otherwise, increase a step of $delta
SuppressReports
ReportTargetDefocus
If $reportedValue1 > $TD_low OR $reportedValue1 < $TD_high
SetTargetDefocus $TD_low
Else
IncTargetDefocus $delta
Endif
ReportTargetDefocus
TargetDefocus = $repVal1
Echo TargetDefocus = $repVal1 um
EndFunction
######################################
Function Drift 1 0
# A function to measure drift rate, if good, skip to the end of loop.
# Otherwise, exit execution -- i.e. skip the point.
Echo ---> Measuring Drift ($argVal1 A/s max allowed)...
crit = $argVal1
shot = T
interval = 3
times = 10
period = $interval + 1
$shot
Delay $interval
Loop $times index
$shot
AlignTo B
ReportAlignShift
ClearAlignment
dx = $reportedValue3
dy = $reportedValue4
dist = sqrt $dx * $dx + $dy * $dy
rate = $dist / $period * 10
echo Estimated drift = $rate A/sec
If $rate < $crit
echo Drift is below $crit after $index trials, continuing...
break
Elseif $index < $times
Delay $interval
Else
echo Drift has never got below $crit: Skipping ...
Exit
Endif
EndLoop
EndFunction
######################################