Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Added MXLIMS v. 0.3.0 exporter code #1114

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mxcubecore/HardwareObjects/Beamline.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ def get_default_acquisition_parameters(self, acquisition_type="default"):
acq_parameters.detector_binning_mode = ""

try:
acq_parameters.detector_roi_mode = self.detector.get_roi_mode()
acq_parameters.detector_roi_mode = self.detector.get_roi_mode_name()
except Exception:
logging.getLogger("HWR").warning(
"get_default_acquisition_parameters: "
Expand Down
17 changes: 16 additions & 1 deletion mxcubecore/HardwareObjects/Gphl/GphlQueueEntry.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
from mxcubecore import HardwareRepository as HWR
from mxcubecore.queue_entry.base_queue_entry import BaseQueueEntry

from mxlims.pydantic import mxmodel
from mxcubecore.utils import mxlims as mxutils

__credits__ = ["MXCuBE collaboration"]
__license__ = "LGPLv3+"
__category__ = "queue"
Expand Down Expand Up @@ -54,7 +57,7 @@ def pre_execute(self):

def post_execute(self):
BaseQueueEntry.post_execute(self)
msg = "Finishing GΦL workflow (%s)" % (self.get_data_model().strategy_name)
msg = "Finishing GΦL workflow (%s)" % self.get_data_model().strategy_name
logging.getLogger("user_level_log").info(msg)
HWR.beamline.gphl_workflow.post_execute()

Expand All @@ -63,3 +66,15 @@ def stop(self):
BaseQueueEntry.stop(self)
logging.getLogger("HWR").info("MXCuBE aborting current GΦL workflow")
self.get_view().setText(1, "Stopped")

def init_mxlims(self):
"""Initialise MXLIMS MxExperimentMessage if it is not already set"""

mxexperiment: mxmodel.MxExperimentMessage = self.get_mxlims_record()
if mxexperiment is None:
data_model = self.get_data_model()
self._mxlims_record = mxutils.create_mxrecord(
sample=data_model.get_sample_node(),
tracking_data=data_model.tracking_data,
measured_flux = HWR.beamline.flux.get_value()
)
104 changes: 70 additions & 34 deletions mxcubecore/HardwareObjects/Gphl/GphlWorkflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
import socket
import subprocess
import time
import uuid
from collections import OrderedDict
from uuid import uuid1

import f90nml
import gevent
Expand Down Expand Up @@ -77,7 +77,6 @@ class GphlWorkflowStates(enum.Enum):
COMPLETED = 4
UNKNOWN = 5


__copyright__ = """ Copyright © 2016 - 2019 by Global Phasing Ltd. """
__license__ = "LGPLv3+"
__author__ = "Rasmus H Fogh"
Expand Down Expand Up @@ -260,6 +259,7 @@ def init(self):
"WorkflowAborted": self.workflow_aborted,
"WorkflowCompleted": self.workflow_completed,
"WorkflowFailed": self.workflow_failed,
"StartEnactment": self.start_enactment,
}

# Set standard configurable file paths
Expand Down Expand Up @@ -729,7 +729,6 @@ def query_pre_strategy_params(self, choose_lattice=None):
dispatcher.connect(
self.receive_pre_strategy_data,
self.PARAMETER_RETURN_SIGNAL,
dispatcher.Any,
)
responses = dispatcher.send(
self.PARAMETERS_NEEDED,
Expand All @@ -752,7 +751,6 @@ def query_pre_strategy_params(self, choose_lattice=None):
dispatcher.disconnect(
self.receive_pre_strategy_data,
self.PARAMETER_RETURN_SIGNAL,
dispatcher.Any,
)
self._return_parameters = None

Expand Down Expand Up @@ -851,6 +849,34 @@ def pre_execute(self, queue_entry):

self._workflow_queue = gevent.queue.Queue()

def start_enactment(self, enactment_id:str, correlation_id:str):
"""Set enactment_id and initialise MXLIMS MxExperimentMessage"""
data_model = self._queue_entry.get_data_model()
tracking_data = data_model.tracking_data
workflow_parameters = data_model.workflow_parameters
tracking_data.uuid = enactment_id
tracking_data.workflow_uid = (
workflow_parameters.get("workflow_uid") or enactment_id
)
# NB it is not set it will be overwritten later
tracking_data.workflow_name = workflow_parameters.get("workflow_name")
tracking_data.workflow_type = (
workflow_parameters.get("workflow_type")
or data_model.strategy_type
)
tracking_data.location_id = (
workflow_parameters.get("workflow_position_id")
or str(uuid1())
)
# NB first orientation only:
tracking_data.orientation_id = workflow_parameters.get(
"workflow_kappa_settings_id"
)
tracking_data.characterisation_id = workflow_parameters.get(
"characterisation_id"
)
self._queue_entry.init_mxlims()

def execute(self):

if self._workflow_queue is None:
Expand Down Expand Up @@ -1261,10 +1287,9 @@ def query_collection_strategy(self, geometric_strategy):
raise ValueError(
"invalid default recentring mode '%s' " % default_recentring_mode
)
use_modes = ["sweep"]
use_modes = ["sweep", "none"]
if len(orientations) > 1:
use_modes.append("start")
use_modes.append("none")
if is_interleaved:
use_modes.append("scan")
for indx in range(len(modes) - 1, -1, -1):
Expand Down Expand Up @@ -1378,7 +1403,6 @@ def query_collection_strategy(self, geometric_strategy):
dispatcher.connect(
self.receive_pre_collection_data,
self.PARAMETER_RETURN_SIGNAL,
dispatcher.Any,
)
responses = dispatcher.send(
self.PARAMETERS_NEEDED,
Expand All @@ -1398,7 +1422,6 @@ def query_collection_strategy(self, geometric_strategy):
dispatcher.disconnect(
self.receive_pre_collection_data,
self.PARAMETER_RETURN_SIGNAL,
dispatcher.Any,
)
self._return_parameters = None

Expand Down Expand Up @@ -1949,6 +1972,7 @@ def collect_data(self, payload, correlation_id):
last_orientation = ()
maxdev = -1
snapshotted_rotation_ids = set()
characterisation_id = None
scan_numbers = {}
for scan in scans:
sweep = scan.sweep
Expand Down Expand Up @@ -2043,31 +2067,48 @@ def collect_data(self, payload, correlation_id):

# Handle orientations and (re) centring
goniostatRotation = sweep.goniostatSweepSetting
rotation_id = orientation_id = goniostatRotation.id_

model_workflow_parameters = gphl_workflow_model.workflow_parameters
if not model_workflow_parameters.get("workflow_name"):
model_workflow_parameters["workflow_name"] = gphl_workflow_model.wfname
if not model_workflow_parameters.get("workflow_type"):
model_workflow_parameters["workflow_type"] = gphl_workflow_model.wftype
if not model_workflow_parameters.get("workflow_uid"):
model_workflow_parameters["workflow_uid"] = str(
HWR.beamline.gphl_connection._enactment_id
)
if not model_workflow_parameters.get("workflow_position_id"):
# As of 20240911 all workflows use a single position,
model_workflow_parameters["workflow_position_id"] = str(uuid.uuid1())
rotation_id = goniostatRotation.id_


# handle mxlims
# handle workflow parameters
new_workflow_parameters = gphl_workflow_model.workflow_parameters.copy()
wf_tracking_data = gphl_workflow_model.tracking_data
data_collection = queue_model_objects.DataCollection([acq], crystal)
# Workflow parameters for ICAT / external workflow
# The 'if' statement is to allow this to work in multiple versions
data_collection.workflow_parameters = new_workflow_parameters
tracking_data = data_collection.tracking_data
tracking_data.uuid = str(scan.id_)
tracking_data.workflow_name = wf_tracking_data.workflow_name
tracking_data.workflow_type = wf_tracking_data.workflow_type
tracking_data.workflow_uid = wf_tracking_data.uuid
tracking_data.location_id = wf_tracking_data.location_id
tracking_data.orientation_id = rotation_id
if (
gphl_workflow_model.wftype == "acquisition"
and not gphl_workflow_model.characterisation_done
and not model_workflow_parameters.get("workflow_characterisation_id")
):
model_workflow_parameters["workflow_characterisation_id"] = str(
sweep.id_
)
model_workflow_parameters["workflow_kappa_settings_id"] = str(
orientation_id
)
if characterisation_id is None:
# NB this is a hack - forces tharacterisation to be a single sweep
characterisation_id = str(sweep.id_)
tracking_data.characterisation_id = characterisation_id
wf_tracking_data.characterisation_id = characterisation_id
tracking_data.role = "Characterisation"
tracking_data.sweep_id = characterisation_id
else:
tracking_data.characterisation_id = wf_tracking_data.characterisation_id#
tracking_data.role = "Result"
tracking_data.sweep_id = str(sweep.id_)
tracking_data.scan_number = gphl_workflow_model.next_scan_number
gphl_workflow_model.next_scan_number += 1

new_workflow_parameters["workflow_name"] = tracking_data.workflow_name
new_workflow_parameters["workflow_type"] = tracking_data.workflow_type
new_workflow_parameters["workflow_uid"] = tracking_data.workflow_uid
new_workflow_parameters["workflow_position_id"] = tracking_data.location_id
new_workflow_parameters["characterisation_id"] = tracking_data.characterisation_id
new_workflow_parameters["workflow_kappa_settings_id"] = tracking_data.orientation_id

initial_settings = sweep.get_initial_settings()
orientation = (
Expand Down Expand Up @@ -2129,11 +2170,6 @@ def collect_data(self, payload, correlation_id):
acq_parameters.num_images_per_trigger * acq_parameters.osc_range
- sweep_offset
)
data_collection = queue_model_objects.DataCollection([acq], crystal)
# Workflow parameters for ICAT / external workflow
# The 'if' statement is to allow this to work in multiple versions
if hasattr(data_collection, "workflow_parameters"):
data_collection.workflow_parameters.update(model_workflow_parameters)
data_collections.append(data_collection)
data_collection.set_enabled(True)
data_collection.ispyb_group_data_collections = True
Expand Down
11 changes: 11 additions & 0 deletions mxcubecore/HardwareObjects/Gphl/GphlWorkflowConnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,17 @@ def processMessage(self, py4j_message):
"GΦL - response=%s jobId=%s messageId=%s"
% (result.__class__.__name__, enactment_id, correlation_id)
)
if message_type == "ObtainPriorInformation":
# At this point we have the enactment_id and can set the workflow_id
self.workflow_queue.put_nowait(
(
"StartEnactment",
self._enactment_id,
None,
None,
)
)

return self._response_to_server(result, correlation_id)

elif message_type in ("WorkflowAborted", "WorkflowCompleted", "WorkflowFailed"):
Expand Down
4 changes: 2 additions & 2 deletions mxcubecore/configuration/mockup/gphl/gphl-setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,6 @@ software_properties:

# OPTIONAL. simcal *binary* For Mock collection emulation only. Not used by workflow
co.gphl.wf.simcal.bin:
/alt/rhfogh/Software/GPhL/nightly_20240611/Files_workflow_TRUNK_alpha-bdg/autoPROC/bin/linux64/simcal
/alt/rhfogh/Software/GPhL/nightly_20241108/Files_workflow_TRUNK_alpha-bdg/autoPROC/bin/linux64/simcal
co.gphl.wf.simcal.bdg_licence_dir:
/alt/rhfogh/Software/GPhL/nightly_20240611/Files_workflow_TRUNK_alpha-bdg
/alt/rhfogh/Software/GPhL/nightly_20241108/Files_workflow_TRUNK_alpha-bdg
5 changes: 4 additions & 1 deletion mxcubecore/configuration/mockup/gphl/gphl-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
default_beam_energy_tag: Main

# NB Temporary developer option. Defaults to 1
allow_duplicate_orientations: 0
# allow_duplicate_orientations: 0

Check warning on line 45 in mxcubecore/configuration/mockup/gphl/gphl-workflow.yml

View workflow job for this annotation

GitHub Actions / pre-commit

45:1 [comments-indentation] comment not indented like content

# Suppress log output of programs called from GPhL workflow
# Default to False
Expand Down Expand Up @@ -240,6 +240,7 @@

- title: Phasing (SAD)
strategy_type: phasing
short_name: SAD
wf_selection: mxexpt
variants:
- full
Expand All @@ -261,6 +262,7 @@

- title: Two-wavelength MAD
strategy_type: phasing
short_name: "2wvlMAD"
wf_selection: mxexpt
variants:
- quick
Expand Down Expand Up @@ -291,6 +293,7 @@

- title: Three-wavelength MAD
strategy_type: phasing
short_name: "3wvlMAD"
wf_selection: mxexpt
variants:
- quick
Expand Down
Loading
Loading