Skip to content

Commit

Permalink
[Queue] - Removed queue_mount_sample
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-oscarsson committed Oct 17, 2024
1 parent a020dd5 commit c9eba4a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 183 deletions.
4 changes: 0 additions & 4 deletions mxcubeweb/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,6 @@ class MXCUBEApplication:
# Sample location of sample that are in process of being mounted
SAMPLE_TO_BE_MOUNTED = ""

# Method used for sample centring
CENTRING_METHOD = queue_entry.CENTRING_METHOD.LOOP

# Look up table for finding the limsID for a corresponding queueID (QueueNode)
NODE_ID_TO_LIMS_ID = {}

Expand Down Expand Up @@ -512,7 +509,6 @@ def save_settings():
"QUEUE": queue,
"CURRENTLY_MOUNTED_SAMPLE": MXCUBEApplication.CURRENTLY_MOUNTED_SAMPLE,
"SAMPLE_TO_BE_MOUNTED": MXCUBEApplication.SAMPLE_TO_BE_MOUNTED,
"CENTRING_METHOD": MXCUBEApplication.CENTRING_METHOD,
"NODE_ID_TO_LIMS_ID": MXCUBEApplication.NODE_ID_TO_LIMS_ID,
"INITIAL_FILE_LIST": MXCUBEApplication.INITIAL_FILE_LIST,
"SC_CONTENTS": MXCUBEApplication.SC_CONTENTS,
Expand Down
2 changes: 1 addition & 1 deletion mxcubeweb/core/components/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ def get_queue_state(self):
for setting_name in [
"NUM_SNAPSHOTS",
"REMEMBER_PARAMETERS_BETWEEN_SAMPLES",
"CENTRING_METHOD",
"AUTO_ADD_DIFFPLAN",
]:
settings[str_to_camel(setting_name)] = getattr(self.app, setting_name)
Expand All @@ -280,6 +279,7 @@ def get_queue_state(self):
"queue": sample_order,
"sampleList": self.app.lims.sample_list_get(current_queue=queue),
"queueStatus": self.queue_exec_state(),
"CENTRING_METHOD": HWR.beamline.queue_manager.centring_method,
}

res.update(settings)
Expand Down
178 changes: 2 additions & 176 deletions mxcubeweb/core/components/samplechanger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
import logging
import time
import gevent

from mxcubecore import queue_entry
Expand All @@ -15,7 +14,6 @@
class SampleChanger(ComponentBase):
def __init__(self, app, config):
super().__init__(app, config)
patch_queue_entry_mount_sample()

def init_signals(self):
from mxcubeweb.routes import signals
Expand Down Expand Up @@ -217,7 +215,8 @@ def mount_sample_clean_up(self, sample, center_sample=True):
if (
res is not False
and center_sample
and self.app.CENTRING_METHOD == queue_entry.CENTRING_METHOD.LOOP
and HWR.beamline.queue_manager.centring_method
== queue_entry.CENTRING_METHOD.LOOP
and not HWR.beamline.diffractometer.in_plate_mode()
and not self.app.harvester.mount_from_harvester()
):
Expand Down Expand Up @@ -407,176 +406,3 @@ def _gripper_changed(self):
self.app.server.emit(
"queue", {"Signal": "update", "message": "all"}, namespace="/hwr"
)


# Disabling C901 function is too complex (19)
def queue_mount_sample(view, data_model, centring_done_cb, async_result): # noqa: C901
from mxcubeweb.routes import signals
from mxcubeweb.app import MXCUBEApplication as mxcube

HWR.beamline.sample_view.clear_all()
logging.getLogger("user_level_log").info("Loading sample ...")
log = logging.getLogger("user_level_log")

loc = data_model.location
data_model.holder_length

robot_action_dict = {
"actionType": "LOAD",
"containerLocation": loc[1],
"dewarLocation": loc[0],
"sampleBarcode": data_model.code,
"sampleId": data_model.lims_id,
"sessionId": HWR.beamline.session.session_id,
"startTime": time.strftime("%Y-%m-%d %H:%M:%S"),
}

# devices that can move sample on beam
# (sample changer, plate holder)
sample_mount_device = HWR.beamline.sample_changer
mount_from_harvester = mxcube.harvester.mount_from_harvester()

if (
sample_mount_device.get_loaded_sample()
and sample_mount_device.get_loaded_sample().get_address() == data_model.loc_str
):
return

if hasattr(sample_mount_device, "__TYPE__"):
if sample_mount_device.__TYPE__ in ["Marvin", "CATS"]:
element = "%d:%02d" % loc
sample = {"location": element, "sampleID": element}
mxcube.sample_changer.mount_sample_clean_up(sample, center_sample=False)
else:
sample = {
"location": data_model.loc_str,
"sampleID": data_model.loc_str,
}

# in this case the sample changer takes the sample from an Harvester
# We Harvest the sample and make it ready to load
if mount_from_harvester:
mxcube.harvester.queue_harvest_sample(data_model)

try:
res = mxcube.sample_changer.mount_sample_clean_up(
sample, center_sample=False
)
except RuntimeError:
res = False
logging.getLogger("user_level_log").info(
"Sample loading res: %s" % str(res)
)

if not res:
raise queue_entry.QueueSkippEntryException(
"Sample changer could not load sample", ""
)

# Harvest Next sample while loading current
if mount_from_harvester and not HWR.beamline.harvester.get_room_temperature_mode():
mxcube.harvester.queue_harvest_next_sample(data_model)

robot_action_dict["endTime"] = time.strftime("%Y-%m-%d %H:%M:%S")
if sample_mount_device.has_loaded_sample():
robot_action_dict["status"] = "SUCCESS"
else:
robot_action_dict["message"] = "Sample was not loaded"
robot_action_dict["status"] = "ERROR"

HWR.beamline.lims.store_robot_action(robot_action_dict)

if not sample_mount_device.has_loaded_sample():
# Disables all related collections
logging.getLogger("user_level_log").info("Sample not loaded")
raise queue_entry.QueueSkipEntryException("Sample not loaded", "")
else:
signals.loaded_sample_changed(sample_mount_device.get_loaded_sample())
logging.getLogger("user_level_log").info("Sample loaded")
dm = HWR.beamline.diffractometer

if mount_from_harvester:
try:
logging.getLogger("user_level_log").info(
"Start Auto Harvesting Centring"
)

computed_offset = (
HWR.beamline.harvester.get_offsets_for_sample_centering()
)
dm.start_harvester_centring(computed_offset)

except Exception:
logging.getLogger("user_level_log").exception(
"Could not center sample, skipping"
)
raise queue_entry.QueueSkipEntryException(
"Could not center sample, skipping", ""
)

else:
use_custom_centring_routine = dm.get_property(
"use_custom_centring_script", False
)

if not use_custom_centring_routine:
if dm is not None:
try:
dm.connect("centringAccepted", centring_done_cb)
centring_method = mxcube.CENTRING_METHOD

if centring_method == queue_entry.CENTRING_METHOD.MANUAL:
msg = (
"Manual centring used, waiting for"
+ " user to center sample"
)
log.warning(msg)
dm.start_centring_method(dm.MANUAL3CLICK_MODE)
elif centring_method in [
queue_entry.CENTRING_METHOD.LOOP,
queue_entry.CENTRING_METHOD.FULLY_AUTOMATIC,
]:
if not dm.current_centring_procedure:
dm.start_centring_method(dm.C3D_MODE)

# NBNB BUG . self and app are not available here
if mxcube.AUTO_MOUNT_SAMPLE:
msg = (
"Going to save centring automatically, please wait"
)
else:
msg = (
"Centring in progress. Please save"
+ " the suggested centring or re-center"
)

log.warning(msg)
else:
dm.start_centring_method(dm.MANUAL3CLICK_MODE)

logging.getLogger("user_level_log").info("Centring ...")
centring_result = async_result.get()
if centring_result["valid"]:
logging.getLogger("user_level_log").info("Centring done !")
else:
if (
centring_method
== queue_entry.CENTRING_METHOD.FULLY_AUTOMATIC
):
raise queue_entry.QueueSkipEntryException(
"Could not center sample, skipping",
"",
)
else:
raise RuntimeError("Could not center sample")
except Exception:
log.exception("centring did not pass")
finally:
dm.disconnect("centringAccepted", centring_done_cb)
else:
dm.disconnect("centringAccepted", centring_done_cb)


def patch_queue_entry_mount_sample():
# Important, patch queue_entry.mount_sample with the mount_sample defined above
queue_entry.base_queue_entry.mount_sample = queue_mount_sample
4 changes: 2 additions & 2 deletions mxcubeweb/core/components/sampleview.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,9 @@ def move_to_beam(self, x, y):
def set_centring_method(self, method):
if method == CENTRING_METHOD.LOOP:
msg = "Using automatic loop centring when mounting samples"
self.app.CENTRING_METHOD = CENTRING_METHOD.LOOP
HWR.beamline.queue_manager.centring_method = CENTRING_METHOD.LOOP
else:
msg = "Using click centring when mounting samples"
self.app.CENTRING_METHOD = CENTRING_METHOD.MANUAL
HWR.beamline.queue_manager.centring_method = CENTRING_METHOD.MANUAL

logging.getLogger("user_level_log").info(msg)

0 comments on commit c9eba4a

Please sign in to comment.