Exemple #1
0
def mount_sample_clean_up(sample):
    from mxcube3.routes import signals

    sc = blcontrol.beamline.sample_changer

    res = None

    try:
        msg = "[SC] mounting %s" % sample["location"]
        logging.getLogger("MX3.HWR").info(msg)

        signals.sc_load(sample["location"])

        sid = get_current_sample().get("sampleID", False)
        current_queue = qutils.queue_to_dict()

        set_sample_to_be_mounted(sample["sampleID"])

        if sample["location"] != "Manual":
            if not sc.get_loaded_sample():
                res = sc.load(sample["sampleID"], wait=True)
            elif sc.get_loaded_sample().get_address() != sample["location"]:
                res = sc.load(sample["sampleID"], wait=True)

            if res is None:
                res = True

            if (res and mxcube.CENTRING_METHOD == CENTRING_METHOD.LOOP
                    and blcontrol.beamline.diffractometer.in_kappa_mode()):
                msg = "Starting autoloop centring ..."
                logging.getLogger("MX3.HWR").info(msg)
                C3D_MODE = blcontrol.beamline.diffractometer.C3D_MODE
                blcontrol.beamline.diffractometer.start_centring_method(
                    C3D_MODE)
            elif not sc.get_loaded_sample():
                set_current_sample(None)
        else:
            set_current_sample(sample["sampleID"])
            res = True

    except Exception as ex:
        logging.getLogger("MX3.HWR").exception(
            "[SC] sample could not be mounted")

        raise RuntimeError(str(ex))
    else:
        # Clean up if the new sample was mounted or the current sample was
        # unmounted and the new one, for some reason, failed to mount
        if res or (not res and not sc.get_loaded_sample()):
            blcontrol.beamline.sample_view.clear_all()

            # We remove the current sample from the queue, if we are moving
            # from one sample to another and the current sample is in the queue
            if sid and current_queue[sid]:
                node_id = current_queue[sid]["queueID"]
                qutils.set_enabled_entry(node_id, False)
    finally:
        signals.sc_load_ready(sample["location"])

    return res
Exemple #2
0
def set_current_sample(sample_id):
    mxcube.CURRENTLY_MOUNTED_SAMPLE = sample_id
    msg = "[SC] Setting currenly mounted sample to %s" % sample_id
    logging.getLogger("MX3.HWR").info(msg)

    from mxcube3.routes.signals import set_current_sample

    set_current_sample(sample_id)
Exemple #3
0
def set_current_sample(sample_id):
    mxcube.CURRENTLY_MOUNTED_SAMPLE = sample_id
    msg = "[SC] Setting currenly mounted sample to %s" % sample_id
    logging.getLogger("MX3.HWR").info(msg)

    from mxcube3.routes.signals import set_current_sample

    set_current_sample(sample_id)
Exemple #4
0
def get_sample_list():
    samples_list = blcontrol.beamline.sample_changer.get_sample_list()
    samples = {}
    samplesByCoords = {}
    order = []
    current_sample = {}

    for s in samples_list:
        if not s.is_present():
            continue
        if s.is_loaded():
            state = qutils.SAMPLE_MOUNTED
        elif s.has_been_loaded():
            state = qutils.COLLECTED
        else:
            state = qutils.UNCOLLECTED
        sample_dm = s.get_id() or ""
        coords = s.get_coords()
        sample_data = {
            "sampleID": s.get_address(),
            "location": s.get_address(),
            "sampleName": "Sample-%s" % s.get_address(),
            "code": sample_dm,
            "loadable": True,
            "state": state,
            "tasks": [],
            "type": "Sample",
        }
        order.append(coords)
        samplesByCoords[coords] = sample_data["sampleID"]

        sample_data["defaultPrefix"] = limsutils.get_default_prefix(
            sample_data, False)
        sample_data["defaultSubDir"] = limsutils.get_default_subdir(
            sample_data)

        samples[s.get_address()] = sample_data
        sc_contents_add(sample_data)

        loaded_sample = blcontrol.beamline.sample_changer.get_loaded_sample()

        if loaded_sample and sample_data[
                "location"] == loaded_sample.get_address():
            current_sample = sample_data
            qutils.queue_add_item([current_sample])

    # sort by location, using coords tuple
    order.sort()
    sample_list = {
        "sampleList": samples,
        "sampleOrder": [samplesByCoords[coords] for coords in order],
    }

    limsutils.sample_list_set(sample_list)

    if current_sample:
        set_current_sample(current_sample["sampleID"])
Exemple #5
0
def mount_sample_clean_up(sample):
    from mxcube3.routes import signals

    sc = blcontrol.sample_changer

    res = None

    try:
        msg = "[SC] mounting %s" % sample["location"]
        logging.getLogger("MX3.HWR").info(msg)

        signals.sc_load(sample["location"])

        sid = get_current_sample().get("sampleID", False)
        current_queue = qutils.queue_to_dict()

        set_sample_to_be_mounted(sample["sampleID"])

        if sample["location"] != "Manual":
            if not sc.getLoadedSample():
                res = sc.load(sample["sampleID"], wait=True)
            elif sc.getLoadedSample().getAddress() != sample["location"]:
                res = sc.load(sample["sampleID"], wait=True)
            if res is None:
                res = True
            if res and mxcube.CENTRING_METHOD == CENTRING_METHOD.LOOP:
                msg = "Starting autoloop centring ..."
                logging.getLogger("MX3.HWR").info(msg)
                C3D_MODE = blcontrol.diffractometer.C3D_MODE
                blcontrol.diffractometer.startCentringMethod(C3D_MODE)
            elif not sc.getLoadedSample():
                set_current_sample(None)
        else:
            set_current_sample(sample["sampleID"])
            res = True

    except Exception as ex:
        logging.getLogger("MX3.HWR").exception("[SC] sample could not be mounted")

        raise RuntimeError(str(ex))
    else:
        # Clean up if the new sample was mounted or the current sample was
        # unmounted and the new one, for some reason, failed to mount
        if res or (not res and not sc.getLoadedSample()):
            blcontrol.shapes.clear_all()

            # We remove the current sample from the queue, if we are moving
            # from one sample to another and the current sample is in the queue
            if sid and current_queue[sid]:
                node_id = current_queue[sid]["queueID"]
                qutils.set_enabled_entry(node_id, False)
    finally:
        signals.sc_load_ready(sample["location"])

    return res
Exemple #6
0
def get_sample_list():
    samples_list = blcontrol.sample_changer.getSampleList()
    samples = {}
    samplesByCoords = {}
    order = []
    current_sample = {}

    for s in samples_list:
        if not s.isPresent():
            continue
        if s.isLoaded():
            state = qutils.SAMPLE_MOUNTED
        elif s.hasBeenLoaded():
            state = qutils.COLLECTED
        else:
            state = qutils.UNCOLLECTED
        sample_dm = s.getID() or ""
        coords = s.getCoords()
        sample_data = {
            "sampleID": s.getAddress(),
            "location": s.getAddress(),
            "sampleName": "Sample-%s" % s.getAddress(),
            "code": sample_dm,
            "loadable": True,
            "state": state,
            "tasks": [],
            "type": "Sample",
        }
        order.append(coords)
        samplesByCoords[coords] = sample_data["sampleID"]

        sample_data["defaultPrefix"] = limsutils.get_default_prefix(sample_data, False)
        sample_data["defaultSubDir"] = limsutils.get_default_subdir(sample_data)

        samples[s.getAddress()] = sample_data
        sc_contents_add(sample_data)

        if sample_data["state"] == qutils.SAMPLE_MOUNTED:
            current_sample = sample_data
            qutils.queue_add_item([current_sample])

    # sort by location, using coords tuple
    order.sort()
    sample_list = {
        "sampleList": samples,
        "sampleOrder": [samplesByCoords[coords] for coords in order],
    }

    limsutils.sample_list_set(sample_list)

    if current_sample:
        set_current_sample(current_sample["sampleID"])
Exemple #7
0
def unmount_sample_clean_up(sample):
    from mxcube3.routes import signals

    try:
        signals.sc_unload(sample["location"])

        if not sample["location"] == "Manual":
            blcontrol.beamline.sample_changer.unload(sample["location"],
                                                     wait=False)
        else:
            set_current_sample(None)
            signals.sc_load_ready(sample["location"])

        msg = "[SC] unmounted %s" % sample["location"]
        logging.getLogger("MX3.HWR").info(msg)
    except Exception:
        msg = "[SC] sample could not be mounted"
        logging.getLogger("MX3.HWR").exception(msg)
        raise
    else:
        blcontrol.beamline.queue_model.mounted_sample = ""
        blcontrol.beamline.sample_view.clear_all()
Exemple #8
0
def unmount_sample_clean_up(sample):
    from mxcube3.routes import signals

    try:
        signals.sc_unload(sample["location"])

        if not sample["location"] == "Manual":
            blcontrol.sample_changer.unload(sample["sampleID"], wait=False)
        else:
            set_current_sample(None)

        msg = "[SC] unmounted %s" % sample["location"]
        logging.getLogger("MX3.HWR").info(msg)
    except Exception:
        msg = "[SC] sample could not be mounted"
        logging.getLogger("MX3.HWR").exception(msg)
        raise
    else:
        blcontrol.queue.mounted_sample = ""
        set_current_sample(None)
        blcontrol.shapes.clear_all()
    finally:
        signals.sc_load_ready(sample["location"])
Exemple #9
0
def unmount_current():
    blcontrol.beamline.sample_changer.unload(None, wait=True)
    set_current_sample(None)

    return get_sc_contents()
Exemple #10
0
def unmount_current():
    blcontrol.sample_changer.unload(None, wait=True)
    set_current_sample(None)

    return get_sc_contents()