ScriptName AutoSP SuppressReports ErrorsToLog #OnStopCallFunc CloseTheBastaFunct TiltTo 0 RecordFlag = 0 ReportNavItem NavInd = $ReportedValue1 NavX = $ReportedValue2 NavY = $ReportedValue3 NavZ = $ReportedValue4 NavItemType = $ReportedValue5 NavLabel = $navIntLabel navNoteString = $NavNote If $NavLabel == 0 # Nvigate to the point and skip to tne next nav item ItemType @= Skip Point WhatToDo = 0 Elseif $NavLabel == -1 # Do Auto Focus WhatToDo = 1 ItemType @= Focus Point ElseIf $NavLabel == -2 # Calibrate stage postion WhatToDo = 2 ItemType @= Fiducial Point echo **** Not implimented yet Else # Record WhatToDo = 10 ItemType @= Record Point #echo **** Not implimented yet EndIf echo **** Starting data collection on point# $NavInd - $ItemType If $SevereCrashFlag == 1 # *** *** *** *** Crash Test *** *** *** *** *** SetColumnOrGunValve 0 GoToLowDoseArea R 0 SetLowDoseMode 1 #pause Severe Crash was Invoked continue run only if you understand the results !!! echo !!! Severe Crash was invoked due to unexpected micrscope/detector behavior !!! echo !!! Restrat run and continue only if you understand the results !!! echo !!! To clear the flag issue the command SevereCrashFlag := 0 echo !!! Altenatively reset all counters and flags by calling the script: ResetSP #send e-mail to the user Ext = Crashing * the * navigator EndIf If $StopRunFlag == 1 # *** *** *** *** Stop Run Test *** *** *** *** *** StopRunFlag := 0 SetColumnOrGunValve 0 GoToLowDoseArea R 0 SetLowDoseMode 1 echo !!! Stop Run call was invoked by the user!!! #send e-mail to the user Stop Run call was invoked by the user !!! Ext = Crashing * the * navigator EndIf # *** Starting data collection sequence *** # ResetClock # Starting to count time for current nav item data collection # *** Locking on the postion of the nav item *** Out = 0 CallFunction Functs::LockOnTarget $NumTargetingLoops $PosErr_TH $Out SatgeErrST = {StageErrX_nm StageErrY_nm AbsErr_nm} SatgeErr = $Out GoToLowDoseArea R 0 ReportClock TimeAtStageMove # Recoridng the time from last stage movement (will be used for settling) # *** Housekeeping #LongOperation DarkRefrence $DarkRefIntervalHr BufferCycle $BufferCycleIntervalHr # *** Determining if AutoFocus is required ReportStageXYZ CurrentX CurrentY CurrentZ echo $CurrentX $CurrentY $CurrentZ DX = $CurrentX - $LastFocX DY = $CurrentY - $LastFocY Abs_DZ = ABS ( $CurrentZ - $LastFocZ ) DistFromLastAutoFoc = SQRT (( $DX * $DX ) + ( $DY * $DY )) # Auto focus If one of these conditions is true: # a) Last autofocus was done at a distance larger than a pre-set TH (DoAutoFocusLateralMoveTH) # b) Last autofocus was done at stage Z which is furhter than a pre-set TH (DoAutoFocusZMoveTH) # c) Last autofocus was done more than pre-set (DoAutoFocusEvery) data points ago # d) Previous autofocus attempt was unsuccessful ( $AutoFocusFailedCounter > 0 ) # e) Current nav item point is a Focus Point ( $WhatToDo == 1 ) echo If ( $DistFromLastAutoFoc > $DoAutoFocusLateralMoveTH ) OR ( $Abs_DZ > $DoAutoFocusZMoveTH ) OR ( $CountUpFromFocus >= $DoAutoFocusEvery ) OR ( $AutoFocusFailedCounter > 0 ) OR ( $WhatToDo == 1 ) If ( $DistFromLastAutoFoc > $DoAutoFocusLateralMoveTH ) OR ( $Abs_DZ > $DoAutoFocusZMoveTH ) OR ( $CountUpFromFocus >= $DoAutoFocusEvery ) OR ( $AutoFocusFailedCounter > 0 ) OR ( $WhatToDo == 1 ) DoAutoFocusFlag = 1 Else # Autofocus is NOT required DoAutoFocusFlag = 0 CountUpFromFocus := $CountUpFromFocus + 1 EndIf If ( $DoAutoFocusFlag == 1 ) AND ( $FocusBeforRecord == 1 ) # i.e. if Autofocus is needed at this nav item and autofocus is done BEFORE exposure CallFunction GotToZeroDefocus EndIf #*** Setting the Defocus value for the current micrograph RandInd = 1000 * ( RAND ) RandInd = 1 + ( MODULO $RandInd $sz_DefocusList ) # Selecting a random index of the defocus list CurrentTargetDefocus = $DefocusList[$RandInd] NominalDeFocus = $CurrentTargetDefocus + $NominalZeroDefocus GoToLowDoseArea R 0 SetDefocus $NominalDeFocus # Setting the selected defocus for the curent Record echo *** Setting target defocus to: $CurrentTargetDefocus um => Nominal defocus of: $NominalDeFocus um NormalizeLenses 5 # Normalize the projector and condesor but NOT the ojective ReportClock TimeAtLensChange # Recoridng the time from last lens change (will be used for settling) If $DeferredSumIsWatingFlg == 1 ReportLastFrameFile FrameSumFileName GetDeferredSum OpenFrameSumFile _sum.mrc Save #AddToAutodoc NavItem $PrevNavItem #AddToAutodoc AccelerationVoltage_kV 300 #AddToAutodoc StageErrorXY_nm $PrevStageErrorX $PrevStageErrorY #AddToAutodoc NumberOfNavItemsSinceLastAutoFocus $PrevCountUpFromFocus #AddToAutodoc STDevOfLastAutoFocus_um $PrevSTDDefocus #AddToAutodoc TargetDefocus_um $prevDeFocusForMicrograph #AddToAutodoc EstiamtedZeroDefocus_um $PrevZeroDeFocus #AddToAutodoc LensesSettlingTime_sec $MeasuredLensesSettlingTime #AddToAutodoc StageSettlingTime_sec $TimeUpToRecored #AddToAutodoc TotalDataAcquisitionTime_sec $PrevTotalDataCollectionTime #WriteAutodoc echo *!* Info_for $FrameSumFileName echo *!* NavItem $PrevNavItem echo *!* AccelerationVoltage_kV 300 echo *!* StageError_nm $PrevStageError echo *!* NumberOfNavItemsSinceLastAutoFocus $PrevCountUpFromFocus #echo *!* STDevOfLastAutoFocus_um $PrevSTDDefocus echo *!* TargetDefocus_um $PrevTargetDefocus echo *!* NominalZeroDeFocus_um $PrevNominalZeroDeFocus echo *!* NominalDefocus_um $PrevNominalDefocus echo *!* LensesSettlingTime_sec $PervLensesSettlingTime echo *!* StageSettlingTime_sec $PervStageSettlingTime echo *!* TotalDataAcquisitionTime_sec $PrevTotalDataCollectionTime CloseFile DeferredSumIsWatingFlg := 0 EndIf # *** *** *** *** Micrograph acquisition sequence *** *** *** *** # *** Pre acquisition settling StageSettlingEnds = $TimeAtStageMove + $PreRecordStageSettling LensSettlingEnds = $TimeAtLensChange + $PreRecordLensSettling If $StageSettlingEnds >= $LensSettlingEnds WaitUntil = $StageSettlingEnds Else WaitUntil = $LensSettlingEnds Endif ReportClock CurrentTime SettlingTime_sec = $WaitUntil - $CurrentTime echo Settling for $SettlingTime_sec sec from $CurrentTime until $WaitUntil #SettlingSequence: CallFunction Functs::DelayUntil $WaitUntil $Out KeyBreakFlag = $Out CallFunction ProcessKeyBreak $KeyBreakFlag $Out KeyBreakFlag = $Out ReportClock CurrentTime LensSettlingTime = $CurrentTime - $TimeAtLensChange StageSettlingTime = $CurrentTime - $TimeAtStageMove #If ($CurrentTime <= $WaitUntil) AND ($KeyBreakFlag != -1) # SkipTo SettlingSequence #EndIf # *** Recording micrograph or skipping if SkipFlag is up If ( $WhatToDo == 10 ) AND ( $SkipFlag != 1 ) echo *** Starting Record *** FlashDisplay 3 .2 ReportClock TimeUpToRecored EarlyReturnNextShot 0 1 Record # <========== Recording Micrograph DeferredSumIsWatingFlg := 1 echo *** Record Done *** ReportClock CurrentTime # Transferring information for the autodoc file that will be saved with the alligned sum micrograph (at next nav item) PrevNavItem := $NavInd PrevStageError := $SatgeErr PrevCountUpFromFocus := $CountUpFromFocus #PrevSTDDefocus := $STDDefocus PrevTargetDefocus := $CurrentTargetDefocus PrevNominalZeroDeFocus := $NominalZeroDefocus PrevNominalDefocus := $NominalDeFocus PervLensesSettlingTime := $LensSettlingTime PervStageSettlingTime := $StageSettlingTime PrevTotalDataCollectionTime := $CurrentTime Else SkipFlag := 0 echo !!! Skipped current data point !!! ReportClock CurrentTime = $ReportedValue1 EndIf If ( $DoAutoFocusFlag == 1 ) AND ( $FocusBeforRecord == 0 ) # i.e. if Autofocus is needed at this nav item and autofocus is done AFTER exposure CallFunction GotToZeroDefocus EndIf # *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** Function GotToZeroDefocus 0 0 # This subrutine calls AutoFocusToZero based with $AutoFocusLoopRepeat $PreFocusSettling (time in sec) as parameters # The rutine anlyze the output and udates the nominal defocus values and flags as needed (or handels errors in autofocus runs) Out = 0 ReportDefocus NominalZeroDefocusStart CallFunction Functs::AutoFocusToZero $AutoFocusLoopRepeat $PreFocusSettling $Out AutoFocusDat := $Out echo If ($AutoFocusDat[4] == 0) AND ($AutoFocusDat[2] <= $STDDefocusTH ) # Checking that outofocus was successful i.e. No Errors AND acceptable STD(defocus) If ($AutoFocusDat[4] == 0) AND ($AutoFocusDat[2] <= $STDDefocusTH ) # Checking that outofocus was successful i.e. No Errors AND acceptable STD(defocus) ReportDefocus NominalZeroDefocus := $ReportedValue1 CountUpFromFocus := 0 AutoFocusFailedCounter := 0 Else AutoFocusFailedCounter := $AutoFocusFailedCounter + 1 CountUpFromFocus := $CountUpFromFocus + 1 SetDefocus $NominalZeroDefocusStart EndIf If $AutoFocusFaieldCount >= $AllowedConscutiveBadAF SevereCrashFlag := 1 echo Autofocus failed $AutoFocusFaieldCount Times - Crashing the navigator run # send e-mail Ext = Crashing * the * navigator * Autofocus * Problem EndIf EndFunction # *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** Function ProcessKeyBreak 2 0 # Take care of user invoked KeyBreakes # Input 1: KeyBreakFlag => Positve Integer - A KeyBreak or -1 # Out : Changes to KeyBreakFlag KeyBreakFlag = $ArgVal1 If $KeyBreakFlag == -1 # Nothing to do ElseIf KeyBreakFlag == 0 # *** *** *** *** *** *** *** *** Killing the navigator run !!! StopRunFlag := 0 SetColumnOrGunValve 0 GoToLowDoseArea R 0 SetLowDoseMode 1 Out = -1 echo Stop Run call was invoked by the user!!! #send e-mail to the user Stop Run call was invoked by the user!!! Ext = Stop * the * navigator * run ElseIf KeyBreakFlag == 9 # *** *** *** *** *** *** *** *** Skipping next data collection point echo User invoked - skipping of next data point!! SkipFlag := 1 Out = -1 ElseIf KeyBreakFlag == 2# *** *** *** *** *** *** *** *** Change early return policy EnterDefaultedNumber -1 0 Early return policy: Set the number of frames to sum for screen desplay upon data acquisition -1 => all | 1 => Only the 1st frame | or any other number of does-frac frames larger than zero NumberOfFramesToReturn := $ReportedValue1 If $NumberOfFramesToReturn == 0 NumberOfFramesToReturn := 1 EndIf ElseIf KeyBreakFlag == 1# *** *** *** *** *** *** *** *** Skip Settling echo User invoked - skipping of Settling Out = -2 Else echo Unexpecteded user BreakKey - Continue as usual Out = 10 EndIf EndFunction # *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ** Function CloseTheBastaFunct 0 0 echo Close the basta was invoked If $DeferredSumIsWatingFlg == 1 ReportLastFrameFile fr GetDeferredSum OpenFrameSumFile _sum.mrc Save #AddToAutodoc NavItem $PrevNavItem #AddToAutodoc AccelerationVoltage_kV 300 #AddToAutodoc StageErrorXY_nm $PrevStageErrorX $PrevStageErrorY #AddToAutodoc NumberOfNavItemsSinceLastAutoFocus $PrevCountUpFromFocus #AddToAutodoc STDevOfLastAutoFocus_um $PrevSTDDefocus #AddToAutodoc TargetDefocus_um $prevDeFocusForMicrograph #AddToAutodoc EstiamtedZeroDefocus_um $PrevZeroDeFocus #AddToAutodoc LensesSettlingTime_sec $MeasuredLensesSettlingTime #AddToAutodoc StageSettlingTime_sec $TimeUpToRecored #AddToAutodoc TotalDataAcquisitionTime_sec $PrevTotalDataCollectionTime #WriteAutodoc echo *!* Info_for $FrameSumFileName echo *!* NavItem $PrevNavItem echo *!* AccelerationVoltage_kV 300 echo *!* StageErrorXY_nm $PrevStageErrorX $PrevStageErrorY echo *!* NumberOfNavItemsSinceLastAutoFocus $PrevCountUpFromFocus #echo *!* STDevOfLastAutoFocus_um $PrevSTDDefocus echo *!* TargetDefocus_um $prevDeFocusForMicrograph echo *!* EstiamtedZeroDefocus_um $PrevZeroDeFocus echo *!* LensesSettlingTime_sec $MeasuredLensesSettlingTime echo *!* StageSettlingTime_sec $TimeUpToRecored echo *!* TotalDataAcquisitionTime_sec $PrevTotalDataCollectionTime CloseFile DeferredSumIsWatingFlg := 0 EndIf GoToLowDoseArea R 0 EndFunction