def setBeamBlank(self, bb):
     if bb == "off":
         ToTEM.SetBeamBlank(0)
     elif bb == "on":
         ToTEM.SetBeamBlank(1)
     else:
         raise ValueError
	def setImageShift(self, vector, relative = "absolute"):
		shift = self.getImageShift()
		
		if relative == "relative":
			try:
				vector["x"] += shift["x"]
				vector["y"] += shift["y"]
			except KeyError:
				pass
		elif relative == "absolute":
			pass
		else:
			raise ValueError

		try:
			shift['x'] = vector['x']
		except KeyError:
			pass
		try:
			shift['y'] = vector['y']
		except KeyError:
			pass
			
		if self.theMagMode == self.LowMAG:
			x_shift = int(round(shift['x'] / self.IMAGESHIFT_FACTOR_X_LowMAG))
			y_shift = int(round(shift['y'] / self.IMAGESHIFT_FACTOR_Y_LowMAG))
			ToTEM.SetImageShift2(x_shift + self.IMAGESHIFT_ORIGIN_X, y_shift + self.IMAGESHIFT_ORIGIN_Y)
			
		else:
			x_shift = int(round(shift['x'] / self.IMAGESHIFT_FACTOR_X))
			y_shift = int(round(shift['y'] / self.IMAGESHIFT_FACTOR_Y))
			ToTEM.SetImageShift1(x_shift + self.IMAGESHIFT_ORIGIN_X, y_shift + self.IMAGESHIFT_ORIGIN_Y)
		
		print "set image shift (leginon): ", shift['x'], shift['y']
		print "set image shift (jeol): ", x_shift, y_shift
 def setLowDose(self, ld):
     if ld == "off":
         ToTEM.EndMDSMode()
     elif ld == "on":
         ToTEM.SetMDSMode(1)
     else:
         raise ValueError
 def getBeamBlank(self):
     if ToTEM.GetBeamBlank() == 0:
         return "off"
     elif ToTEM.GetBeamBlank() == 1:
         return "on"
     else:
         raise SystemError
 def getLowDoseMode(self):
     if ToTEM.GetMDSMode() == 3:
         return "exposure"
     elif ToTEM.GetMDSMode() == 2:
         return "focus1"
     elif ToTEM.GetMDSMode() == 1:
         return "search"
     else:
         return "unknown"
    def setDiffractionMode(self, mode):
        if mode == "imaging":
            ToTEM.SelectFunctionMode(0)
        elif mode == "diffraction":
            ToTEM.SelectFunctionMode(4)
        else:
            raise ValueError

        return 0
    def setMainScreenPosition(self, pos):
        self.theScreenPos = pos
        if (pos == 'up'):
            ToTEM.SetScreen(1)
        elif (pos == 'down'):
            ToTEM.SetScreen(0)
        else:
            raise KeyError

        return 0
    def initializeJeol(self):
        # 1. checking the communication to microscope
        if ToTEM.GetCheckMicroscope() != 0:
            print 'Communication Error: Jeol 3100 is not ready to serve.'
            return

        # 2.1 setting the mag mode LowMag and defining low mag focus for the future defocus
        ToTEM.SelectFunctionMode(self.LowMAG)
        ToTEM.SetOM(self.theObjectMini)
        self.theFocusLowMAG = self.theObjectMini

        # 2.2 setting the mag mode LMAG and defining focus for the future defocus
        ToTEM.SelectFunctionMode(self.MAG1)

        # 3. defining focus plane for the future defocus length
        ToTEM.SetOLFine(self.theObjectLensFine)
        ToTEM.SetOLCoarse(self.theObjectLensCoarse)
        self.theFocusMAG1 = self.theObjectLensFine + (
            self.theObjectLensCoarse * 32)

        print 'Jeol is MAG1 mode and focus is defined for the future defocus.'

        # 4. initializing screen position as 'up'
        ToTEM.SetScreen(1)
        self.theScreenPos = 'up'

        # 5. MDS photo mode is set for film recording
        if ToTEM.GetMDSMode() != 3:
            ToTEM.SetMDSMode(3)

        return
    def preFilmExposure(self, value):
        if not value:
            return

        if ToTEM.GetUnused() < 1:
            raise RuntimeError('No film to take exposure')

        ToTEM.LoadFilm()
        time.sleep(6)

        return
 def setLowDoseMode(self, mode):
     if mode == "exposure":
         ToTEM.SetMDSMode(3)
     elif mode == "focus1":
         ToTEM.SetMDSMode(2)
     elif mode == "focus2":
         ToTEM.SetMDSMode(2)
     elif mode == "search":
         ToTEM.SetMDSMode(1)
     else:
         raise ValueError
 def getDefocus(self):
     if self.theMagMode == self.LowMAG:
         focus_mini = ToTEM.GetOM()
         defocus_steps = focus_mini - self.theFocusLowMAG
         return defocus_steps * 0.00000001
     elif self.theMagMode == self.MAG1:
         focus_fine = ToTEM.GetOLFine()
         focus_coarse = ToTEM.GetOLCoarse()
         focus = focus_fine + (focus_coarse * 32)
         defocus_steps = focus - self.theFocusMAG1
         return defocus_steps * 0.0000000058
     else:
         return 0.0
    def resetDefocus(self, value):
        if not value:
            return 1

        if self.theMagMode == self.LowMAG:
            self.theFocusLowMAG = ToTEM.GetOM()
        elif self.theMagMode == self.MAG1:
            focus_fine = ToTEM.GetOLFine()
            focus_coarse = ToTEM.GetOLCoarse()
            self.theFocusMAG1 = focus_fine + (focus_coarse * 32)
            return 0
        else:
            return 1
    def postFilmExposure(self, value):
        if not value:
            return

        ToTEM.EjectFilm()

        return
    def setMagnificationIndex(index):
        key = self.theScreenPos

        for mag in self.magTable:
            if mag['index'] == index + 1:
                self.theMagMode = ToTEM.SetMagnification(mag['down'])
                return 0
        return 1
    def setMagnification(self, mag_value):
        key = self.theScreenPos

        for mag in self.magTable:
            if mag[key] == mag_value:
                self.theMagMode = ToTEM.SetMagnification(mag['down'])
                return 0
        return 1
Esempio n. 16
0
	def getImageShift(self):
		if self.theMagMode == self.LowMAG:
			shift = ToTEM.GetImageShift2()
			
			shift_x = shift[0] - self.IMAGESHIFT_ORIGIN_X
			shift_y = shift[1] - self.IMAGESHIFT_ORIGIN_Y
			#print "get image shift (jeol): ", shift_x, shift_y;
			
			return {"x" : self.IMAGESHIFT_FACTOR_X_LowMAG * shift_x, "y" : self.IMAGESHIFT_FACTOR_Y_LowMAG * shift_y}
		else:
			shift = ToTEM.GetImageShift1()
			
			shift_x = shift[0] - self.IMAGESHIFT_ORIGIN_X
			shift_y = shift[1] - self.IMAGESHIFT_ORIGIN_Y
			#print "get image shift (jeol): ", shift_x, shift_y;
			
			return {"x" : self.IMAGESHIFT_FACTOR_X * shift_x, "y" : self.IMAGESHIFT_FACTOR_Y * shift_y}
Esempio n. 17
0
	def getStagePosition(self):
		stagePosition = ToTEM.GetStagePosition()
		position = {"x" : stagePosition[0]/1000000000,
					"y" : stagePosition[1]/1000000000,
					"z" : stagePosition[2]/1000000000,
					"a" : stagePosition[3],
					"b" : stagePosition[4]}
		return position
    def getBeamTilt(self):
        tilt = ToTEM.GetBeamTilt()

        tilt_x = (tilt[0] - self.BEAMTILT_ORIGIN_X)
        tilt_y = (tilt[1] - self.BEAMTILT_ORIGIN_Y)
        return {
            "x": tilt_x * self.BEAMTILT_FACTOR_X,
            "y": tilt_y * self.BEAMTILT_FACTOR_Y
        }
Esempio n. 19
0
	def getBeamShift(self):
		shift = ToTEM.GetBeamShift()
		shift_x = shift[0] - self.BEAMSHIFT_ORIGIN_X
		shift_y = shift[1] - self.BEAMSHIFT_ORIGIN_Y
		
		if self.theMagMode == self.LowMAG:
			return {"x" : shift_x * self.BEAMSHIFT_FACTOR_X_LowMAG, "y" : shift_y * self.BEAMSHIFT_FACTOR_Y_LowMAG}
		elif self.theMagMode == self.MAG1:
			return {"x" : shift_x * self.BEAMSHIFT_FACTOR_X, "y" : shift_y * self.BEAMSHIFT_FACTOR_Y}
    def setSpotSize(self, ss, relative="absolute"):
        if relative == "relative":
            ss += self.getSpotSize()
        elif relative == "absolute":
            pass
        else:
            raise ValueError

        ToTEM.SetSpotSize(ss)
    def setIntensity(self, intensity, relative="absolute"):
        if relative == "relative":
            intensity += self.getIntensity()
        elif relative == "absolute":
            pass
        else:
            raise ValueError

        ToTEM.SetBrightness(int(round(intensity * self.MAX)))
        return 0
 def getDiffractionMode(self):
     mode = ToTEM.GetFunctionMode()
     if mode == 0:
         return "imaging"
     elif mode == 1:
         return "imaging"
     elif mode == 4:
         return "diffraction"
     else:
         raise SystemError
    def getMagnification(self):
        key = self.theScreenPos

        mag_value = ToTEM.GetMagnification()

        print mag_value

        for mag in self.magTable:
            if mag['down'] == mag_value:
                return mag[key]
    def setStigmator(self, stigs, relative="absolute"):
        for key in stigs.keys():
            stigmators = self.getStigmator()
            if key == "condenser":
                stigmator = stigmators["condenser"]
            elif key == "objective":
                stigmator = stigmators["objective"]
            elif key == "diffraction":
                stigmator = stigmators["diffraction"]
            else:
                raise ValueError

            if relative == "relative":
                try:
                    stigs[key]["x"] += stigmator["x"]
                    stigs[key]["y"] += stigmator["y"]
                except KeyError:
                    pass
            elif relative == "absolute":
                pass
            else:
                raise ValueError

            try:
                stigmator["x"] = stigs[key]["x"]
                stigmator["y"] = stigs[key]["y"]
            except KeyError:
                pass

            if key == "condenser":
                ToTEM.SetCondenserStigmator(self.toJeol(stigmator["x"]),
                                            self.toJeol(stigmator["y"]))
            elif key == "objective":
                ToTEM.SetObjectiveStigmator(self.toJeol(stigmator["x"]),
                                            self.toJeol(stigmator["y"]))
            elif key == "diffraction":
                ToTEM.SetIntermediateStigmator(self.toJeol(stigmator["x"]),
                                               self.toJeol(stigmator["y"]))
            else:
                raise ValueError
 def getStigmator(self):
     stigs = ToTEM.GetStigmator()
     return {
         "condenser": {
             "x": self.toLeginon(stigs[0]),
             "y": self.toLeginon(stigs[1])
         },
         "objective": {
             "x": self.toLeginon(stigs[2]),
             "y": self.toLeginon(stigs[3])
         },
         "diffraction": {
             "x": self.toLeginon(stigs[4]),
             "y": self.toLeginon(stigs[5])
         }
     }
Esempio n. 26
0
	def setGunShift(self, vector, relative = "absolute"):
		currentShift = self.getGunShift()
		if relative == "relative":
			try:
				vector["x"] += currentShift[0]
				vector["y"] += currentShift[1]
			except KeyError:
				pass
		elif relative == "absolute":
			pass
		else:
			raise ValueError

		try:
			ToTEM.SetGunShift(self.toJeol(vector["x"]), self.toJeol(vector["y"]))
		except KeyError:
			pass

		return 0
Esempio n. 27
0
	def setBeamTilt(self, vector, relative = "absolute"):
		if relative == "relative":
			tilt = self.getBeamTilt()
			try:
				vector["x"] += tilt["x"]
	 			vector["y"] += tilt["y"]
	 		except KeyError:
	 			pass
		elif relative == "absolute":
			pass
		else:
			raise ValueError
	
		tilt_x = int(round(vector['x'] / self.BEAMTILT_FACTOR_X)) + self.BEAMTILT_ORIGIN_X
		tilt_y = int(round(vector['y'] / self.BEAMTILT_FACTOR_Y)) + self.BEAMTILT_ORIGIN_Y
		
		print ">>>>>>>>>>>>>>>>> Set Beam Tilt : (", tilt_x, tilt_y, ")"
		
		try:
			ToTEM.SetBeamTilt(tilt_x, tilt_y)
		except KeyError:
			pass
    def setBeamShift(self, vector, relative="absolute"):
        shift = self.getBeamShift()
        if relative == "relative":
            try:
                vector["x"] += shift["x"]
                vector["y"] += shift["y"]
            except KeyError:
                pass
        elif relative == "absolute":
            pass
        else:
            raise ValueError

        try:
            shift['x'] = vector['x']
        except KeyError:
            pass
        try:
            shift['y'] = vector['y']
        except KeyError:
            pass

        if self.theMagMode == self.LowMAG:
            x_shift = int(round(shift["x"] / self.BEAMSHIFT_FACTOR_X_LowMAG))
            y_shift = int(round(shift["y"] / self.BEAMSHIFT_FACTOR_Y_LowMAG))
        elif self.theMagMode == self.MAG1:
            x_shift = int(round(shift["x"] / self.BEAMSHIFT_FACTOR_X))
            y_shift = int(round(shift["y"] / self.BEAMSHIFT_FACTOR_Y))

        print "beam shift", x_shift, y_shift

        try:
            ToTEM.SetBeamShift(x_shift + self.BEAMSHIFT_ORIGIN_X,
                               y_shift + self.BEAMSHIFT_ORIGIN_Y)
        except KeyError:
            pass
    def setDefocus(self, defocus, relative="absolute"):
        if defocus == 0.0:
            if self.theMagMode == self.LowMAG:
                ToTEM.SetOM(self.theFocusLowMAG)
            elif self.theMagMode == self.MAG1:
                focus = self.theFocusMAG1
                focus_coarse = int(focus / 32)
                focus_fine = focus - (focus_coarse * 32)
                print 'focus coarse:', focus_coarse, 'fine:', focus_fine
                ToTEM.SetOLCoarse(focus_coarse)
                ToTEM.SetOLFine(focus_fine)
            else:
                pass
            return 0

        if relative == 'relative':
            defocus += self.getDefocus()
        elif relative == 'absolute':
            pass

        print self.theMagMode

        if self.theMagMode == self.LowMAG:
            defocus_steps = int(round(defocus / 0.00000001))
            ToTEM.SetOM(self.theFocusLowMAG + defocus_steps)
        elif self.theMagMode == self.MAG1:
            defocus_steps = int(round(defocus / 0.0000000058))
            focus = self.theFocusMAG1 + defocus_steps
            focus_coarse = int(focus / 32)
            focus_fine = focus - (focus_coarse * 32)
            print 'focus coarse:', focus_coarse, 'fine:', focus_fine
            ToTEM.SetOLCoarse(focus_coarse)
            ToTEM.SetOLFine(focus_fine)
        else:
            return 1
        return 0
 def getLowDose(self):
     ld = ToTEM.GetMDSMode()
     if (ld == 0):
         return "off"
     else:
         return "on"