Skip to content

Commit

Permalink
[ESRF] - Fixes to ESRF specific HardwareObjects
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-oscarsson committed Jan 31, 2025
1 parent b908625 commit 3d1d29c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 21 deletions.
3 changes: 2 additions & 1 deletion mxcubecore/HardwareObjects/ESRF/ESRFSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __init__(self, name):

def init(self):
Session.Session.init(self)
self._use_acronym = self.get_property("use_acronym", True)

archive_base_directory = self["file_info"].get_property(
"archive_base_directory"
Expand Down Expand Up @@ -95,7 +96,7 @@ def get_default_subdir(self, sample_data: dict) -> str:
sample_name = sample_data.name
protein_acronym = sample_data.crystals[0].protein_acronym

if protein_acronym:
if self._use_acronym and protein_acronym:
subdir = "%s/%s-%s/" % (protein_acronym, protein_acronym, sample_name)
else:
subdir = "%s/" % sample_name
Expand Down
6 changes: 3 additions & 3 deletions mxcubecore/HardwareObjects/ESRF/ID231BeamCmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self, *args):
def init(self):
controller = self.get_object_by_role("controller")
detcover = self.get_object_by_role("detcover")
scintilator = self.get_object_by_role("scintilator")
scintillator = self.get_object_by_role("scintillator")
aperture = self.get_object_by_role("aperture")
hutchtrigger = self.get_object_by_role("hutchtrigger")
cryo = self.get_object_by_role("cryostream")
Expand All @@ -26,7 +26,7 @@ def init(self):
# self.anneal = ControllerCommand("Anneal", controller.anneal_procedure)

self.detcover = HWObjActuatorCommand("Detector cover", detcover)
self.scintilator = HWObjActuatorCommand("Scintillator", scintilator)
self.scintillator = HWObjActuatorCommand("Scintillator", scintillator)
self.aperture = HWObjActuatorCommand("Aperture", aperture)
self.hutchtrigger = HWObjActuatorCommand("Hutchtrigger", hutchtrigger)
self.cryo = HWObjActuatorCommand("Cryostream", cryo)
Expand All @@ -38,7 +38,7 @@ def get_commands(self):
self.quick_realign,
# self.anneal,
self.detcover,
self.scintilator,
self.scintillator,
self.aperture,
self.hutchtrigger,
self.cryo,
Expand Down
6 changes: 3 additions & 3 deletions mxcubecore/HardwareObjects/ESRF/ID29BeamCmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, *args):
def init(self):
controller = self.get_object_by_role("controller")
detcover = self.get_object_by_role("detcover")
scintilator = self.get_object_by_role("scintilator")
scintillator = self.get_object_by_role("scintillator")
aperture = self.get_object_by_role("aperture")
hutchtrigger = self.get_object_by_role("hutchtrigger")
cryo = self.get_object_by_role("cryo")
Expand All @@ -26,7 +26,7 @@ def init(self):
self.anneal = ControllerCommand("Anneal", controller.anneal_procedure)

self.detcover = HWObjActuatorCommand("Detector cover", detcover)
self.scintilator = HWObjActuatorCommand("Scintillator", scintilator)
self.scintillator = HWObjActuatorCommand("Scintillator", scintillator)
self.aperture = HWObjActuatorCommand("Aperture", aperture)
self.hutchtrigger = HWObjActuatorCommand("Hutchtrigger", hutchtrigger)
self.cryo = HWObjActuatorCommand("Cryo", cryo)
Expand All @@ -37,7 +37,7 @@ def get_commands(self):
self.quick_realign,
self.anneal,
self.detcover,
self.scintilator,
self.scintillator,
self.aperture,
self.hutchtrigger,
self.cryo,
Expand Down
2 changes: 1 addition & 1 deletion mxcubecore/HardwareObjects/MicrodiffActuator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
If private_state not specified, True will be send to set in and False for out.
Example xml file:
<object class="MicrodiffActuator">
<username>Scintilator</username>
<username>Scintillator</username>
<exporter_address>wid30bmd2s:9001</exporter_address>
<cmd_name>ScintillatorPosition</cmd_name>
<private_state>{"PARK":"out", "SCINTILLATOR":"in"}</private_state>
Expand Down
45 changes: 33 additions & 12 deletions mxcubecore/HardwareObjects/sample_centring.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,22 @@ def __getattr__(self, attr):


def prepare(centring_motors_dict):
logging.debug("Preparing for centring")
logging.getLogger("HWR").debug("Preparing for centring")

global SAVED_INITIAL_POSITIONS
global USER_CLICKED_EVENT
global READY_FOR_NEXT_POINT

if CURRENT_CENTRING and not CURRENT_CENTRING.ready():
logging.getLogger("HWR").debug("DEBUG: ENDING CURRENT CENTRING")
end()

global USER_CLICKED_EVENT
global READY_FOR_NEXT_POINT
if USER_CLICKED_EVENT and not USER_CLICKED_EVENT.ready():
logging.getLogger("HWR").debug("DEBUG: USER_CLICKED_EVENT: false")

# Clear ready flag incase it was stuck
USER_CLICKED_EVENT.set()

USER_CLICKED_EVENT = gevent.event.AsyncResult()
READY_FOR_NEXT_POINT = gevent.event.Event()

Expand Down Expand Up @@ -275,7 +282,7 @@ def centre_plate1Click(
READY_FOR_NEXT_POINT.set()
i += 1
except Exception:
logging.exception("Exception while centring")
logging.getLogger("HWR").exception("Exception while centring")
move_motors(SAVED_INITIAL_POSITIONS)
raise RuntimeError("Exception while centring")

Expand Down Expand Up @@ -327,11 +334,11 @@ def centre_plate(
READY_FOR_NEXT_POINT.set()
i += 1
except Exception:
logging.exception("Exception while centring")
logging.getLogger("HWR").exception("Exception while centring")
move_motors(SAVED_INITIAL_POSITIONS)
raise

# logging.info("X=%s,Y=%s", X, Y)
# logging.getLogger("HWR").info("X=%s,Y=%s", X, Y)
chi_angle = math.radians(chi_angle)
chiRotMatrix = numpy.matrix(
[
Expand Down Expand Up @@ -386,7 +393,10 @@ def centre_plate(


def ready(motor_list):
return all([m.is_ready() for m in motor_list])
logging.getLogger("HWR").info([m.actuator_name for m in motor_list])
rstate = [m._ready() for m in motor_list]
logging.getLogger("HWR").info(rstate)
return all(rstate)


def wait_ready(motor_positions_dict, timeout=None):
Expand All @@ -410,7 +420,9 @@ def move_motors(motor_positions_dict):
def user_click(x, y, wait=False):
READY_FOR_NEXT_POINT.clear()
USER_CLICKED_EVENT.set((x, y))
logging.getLogger("HWR").debug(f"Clicked registred at {x} {y}")
if wait:
logging.getLogger("HWR").debug(f"Waiting for rotation ...")
READY_FOR_NEXT_POINT.wait()


Expand All @@ -437,8 +449,12 @@ def center(
i = 0
while i < n_points:
try:
logging.getLogger("HWR").debug("Waiting for click")
x, y = USER_CLICKED_EVENT.get()
except Exception:
logging.getLogger("HWR").exception(
"Aborted while waiting for point selection"
)
raise RuntimeError("Aborted while waiting for point selection")
USER_CLICKED_EVENT = gevent.event.AsyncResult()
X.append(x / float(pixelsPerMm_Hor))
Expand All @@ -448,13 +464,14 @@ def center(
phi.set_value_relative(phi.direction * phi_angle, timeout=10)
READY_FOR_NEXT_POINT.set()
i += 1
# logging.getLogger("HWR").debug(f"Click at {x}, {y}")
except Exception:
logging.exception("Exception while centring")
logging.getLogger("HWR").exception("Exception while centring")
move_motors(SAVED_INITIAL_POSITIONS)
READY_FOR_NEXT_POINT.set()
raise RuntimeError("Exception while centring")

# logging.info("X=%s,Y=%s", X, Y)
# logging.getLogger("HWR").debug("X=%s,Y=%s", X, Y)
chi_angle = math.radians(chi_angle)
chiRotMatrix = numpy.matrix(
[
Expand Down Expand Up @@ -500,12 +517,13 @@ def center(

def end(centred_pos=None):
if centred_pos is None:
centred_pos = CURRENT_CENTRING.get()
centred_pos = CURRENT_CENTRING.get(timeout=1)
try:
move_motors(centred_pos)
except Exception:
READY_FOR_NEXT_POINT.set()
move_motors(SAVED_INITIAL_POSITIONS)
logging.getLogger("HWR").exception("")
raise RuntimeError("Centring aborted")


Expand Down Expand Up @@ -631,10 +649,10 @@ def auto_center(
x, y = find_loop(
sample_view, pixelsPerMm_Hor, chi_angle, msg_cb, new_point_cb
)
# logging.info("in autocentre, x=%f, y=%f",x,y)
logging.getLogger("HWR").info("Lucid found loop at, x=%f, y=%f", x, y)
if x < 0 or y < 0:
for i in range(1, 18):
# logging.info("loop not found - moving back %d" % i)
logging.getLogger("HWR").info("loop not found - moving back %d" % i)
phi.set_value_relative(5)
x, y = find_loop(
sample_view,
Expand All @@ -660,6 +678,9 @@ def auto_center(
break
if -1 in (x, y):
centring_greenlet.kill()
logging.getLogger("HWR").debug(
f"DEBUG: Incorrect position from auto loop centring {(x,y)}"
)
raise RuntimeError("Could not centre sample automatically.")
phi.set_value_relative(-i * 5)
else:
Expand Down
2 changes: 1 addition & 1 deletion mxcubecore/configuration/esrf_id29/udiff_scint.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<object class="InOut">
<username>Scintilator</username>
<username>Scintillator</username>
<specversion>lid292:exp</specversion>
<command type="spec" name="set_in">scinton</command>
<command type="spec" name="set_out">scintoff</command>
Expand Down

0 comments on commit 3d1d29c

Please sign in to comment.