Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 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
8 changes: 1 addition & 7 deletions mxcubecore/HardwareObjects/ANSTO/Diffractometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,8 @@ def start_automatic_centring(
try:
sample_centering = MX3SyncPrefectClient(
name=settings.SAMPLE_CENTERING_PREFECT_DEPLOYMENT_NAME,
parameters={
"sample_id": "test",
"beam_position": [self.beam_position[0], self.beam_position[1]],
"use_top_camera": settings.USE_TOP_CAMERA,
"calibrated_alignment_z": settings.CALIBRATED_ALIGNMENT_Z,
},
parameters={},
)
# NOTE: using asyncio.run() does not seem to work consistently

sample_centering.trigger_flow(wait=True)
logging.getLogger("HWR").debug("Optical centering finished")
Expand Down
20 changes: 19 additions & 1 deletion mxcubecore/HardwareObjects/ANSTO/PrefectWorkflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import redis
import yaml
from gevent.event import Event
from mx3_beamline_library.devices.motors import md3

from mxcubecore import HardwareRepository as HWR
from mxcubecore.BaseHardwareObjects import HardwareObject
Expand All @@ -22,6 +21,7 @@
from .prefect_flows.full_dataset_collection_flow import FullDatasetFlow
from .prefect_flows.grid_scan_flow import GridScanFlow
from .prefect_flows.one_shot_flow import OneShotFlow
from .prefect_flows.partial_udc import PartialUDCFlow
from .prefect_flows.schemas.prefect_workflow import PrefectFlows
from .prefect_flows.screening_flow import ScreeningFlow
from .redis_utils import get_redis_connection
Expand Down Expand Up @@ -494,6 +494,24 @@ def start_prefect_workflow(self, sample_id: int | None) -> None:
self.state.value = "ON"
raise QueueExecutionException("dialog_box_parameters is empty", self)

elif self.workflow_name == PrefectFlows.partial_udc:
logging.getLogger("HWR").info(f"Starting workflow: {self.workflow_name}")

self.partial_udc_flow = PartialUDCFlow(
state=self._state,
resolution=self.resolution,
sample_id=sample_id,
)
dialog_box_parameters = self.open_dialog(self.partial_udc_flow.dialog_box())
if dialog_box_parameters:
logging.getLogger("HWR").info(
f"Dialog box parameters: {dialog_box_parameters}"
)
self.partial_udc_flow.run(dialog_box_parameters=dialog_box_parameters)
else:
self.state.value = "ON"
raise QueueExecutionException("dialog_box_parameters is empty", self)

else:
logging.getLogger("HWR").error(
f"Workflow {self.workflow_name} not supported"
Expand Down
20 changes: 17 additions & 3 deletions mxcubecore/HardwareObjects/ANSTO/prefect_flows/abstract_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from .schemas.full_dataset import FullDatasetDialogBox
from .schemas.grid_scan import GridScanDialogBox
from .schemas.one_shot import OneShotDialogBox
from .schemas.prefect_workflow import PrefectFlows
from .schemas.screening import ScreeningDialogBox


Expand Down Expand Up @@ -299,6 +300,7 @@ def _save_dialog_box_params_to_redis(
| GridScanDialogBox
| OneShotDialogBox
),
collection_type: str | None = None,
) -> None:
"""
Save the last set parameters from the dialog box to Redis.
Expand All @@ -308,6 +310,10 @@ def _save_dialog_box_params_to_redis(
dialog_box : ScreeningDialogBox | FullDatasetDialogBox | GridScanDialogBox | OneShotDialogBox
A dialog box pydantic model
"""
if collection_type is not None:
type = collection_type
else:
type = self._collection_type
with get_redis_connection() as redis_connection:
for key, value in dialog_box.model_dump(exclude_none=True).items():
if isinstance(value, bool):
Expand All @@ -316,7 +322,7 @@ def _save_dialog_box_params_to_redis(
if key in ["lab_name", "project_name", "auto_create_well"]:
redis_connection.set(f"mxcube_common_params:{key}", value)
else:
redis_connection.set(f"{self._collection_type}:{key}", value)
redis_connection.set(f"{type}:{key}", value)

def _get_dialog_box_param(
self,
Expand All @@ -334,13 +340,14 @@ def _get_dialog_box_param(
"lab_name",
"project_name",
],
collection_type: str | None = None,
) -> str | int | float | None:
"""
Retrieve a parameter value from Redis.

Parameters
----------
Literal[
parameter : Literal[
"exposure_time",
"omega_range",
"number_of_frames",
Expand All @@ -355,17 +362,24 @@ def _get_dialog_box_param(
"project_name",
]
A parameter saved in redis
collection_type : str | None
The collection type. If None, use the current collection type

Returns
-------
str | int | float
The last value set in redis for a given parameter
"""
if collection_type is not None:
type = collection_type
else:
type = self._collection_type

with get_redis_connection() as redis_connection:
if parameter in ["lab_name", "project_name", "auto_create_well"]:
value = redis_connection.get(f"mxcube_common_params:{parameter}")
else:
value = redis_connection.get(f"{self._collection_type}:{parameter}")
value = redis_connection.get(f"{type}:{parameter}")

if parameter == "auto_create_well":
if value is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ grid_scan:
resolution: 1.5 # Ångström (16M)
transmission: 1.0 # Percentage
detector_roi_mode: "4M" # 4M or disabled
grid_step: "20x20"

one_shot:
exposure_time: 0.5 # Total exposure time, seconds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from ..Resolution import Resolution
from .abstract_flow import AbstractPrefectWorkflow
from .schemas.dialog_boxes.full_dataset import get_full_dataset_schema
from .schemas.full_dataset import (
FullDatasetDialogBox,
FullDatasetParams,
Expand Down Expand Up @@ -125,72 +126,8 @@ def dialog_box(self) -> dict:
"""
resolution_limits = self.resolution.get_limits()

properties = {
"exposure_time": {
"title": "Total Exposure Time [s]",
"type": "number",
"exclusiveMinimum": 0,
"default": float(self._get_dialog_box_param("exposure_time")),
"widget": "textarea",
},
"omega_range": {
"title": "Omega Range [degrees]",
"type": "number",
"exclusiveMinimum": 0,
"default": float(self._get_dialog_box_param("omega_range")),
"widget": "textarea",
},
"number_of_frames": {
"title": "Number of Frames",
"type": "integer",
"minimum": 1,
"default": int(self._get_dialog_box_param("number_of_frames")),
"widget": "textarea",
},
"resolution": {
"title": "Resolution [Å]",
"type": "number",
"minimum": resolution_limits[0],
"maximum": resolution_limits[1],
"default": float(self._get_dialog_box_param("resolution")),
"widget": "textarea",
},
"transmission": {
"title": "Transmission [%]",
"type": "number",
"minimum": 0,
"maximum": 100,
"default": float(self._get_dialog_box_param("transmission")),
"widget": "textarea",
},
"processing_pipeline": {
"title": "Data Processing Pipeline",
"type": "string",
"enum": [
"dials",
"fast_dp",
"dials_and_fast_dp",
"fast_dp_and_xia2",
"xia2",
],
"default": self._get_dialog_box_param("processing_pipeline"),
},
"crystal_counter": {
"title": "Crystal ID",
"type": "integer",
"minimum": 0,
"default": int(self._get_dialog_box_param("crystal_counter")),
"widget": "textarea",
},
}
properties = get_full_dataset_schema(resolution_limits)

if settings.ADD_DUMMY_PIN_TO_DB:
properties["sample_id"] = {
"title": "Database sample id (dev only)",
"type": "integer",
"default": 1,
"widget": "textarea",
}
tray_conditional: dict | None = None
if self.get_head_type() == "Plate":
tray_properties, tray_conditional = self.build_tray_dialog_schema()
Expand Down
27 changes: 2 additions & 25 deletions mxcubecore/HardwareObjects/ANSTO/prefect_flows/grid_scan_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from ..Resolution import Resolution
from .abstract_flow import AbstractPrefectWorkflow
from .schemas.dialog_boxes.grid_scan import get_grid_scan_schema
from .schemas.grid_scan import (
GridScanDialogBox,
GridScanParams,
Expand Down Expand Up @@ -334,31 +335,7 @@ def dialog_box(self) -> dict:
dialog : dict
A dictionary following the JSON schema.
"""
properties = {
"md3_alignment_y_speed": {
"title": "Alignment Y Speed [mm/s]",
"type": "number",
"minimum": 0.1,
"maximum": 14.8,
"default": float(self._get_dialog_box_param("md3_alignment_y_speed")),
"widget": "textarea",
},
"transmission": {
"title": "Transmission [%]",
"type": "number",
"minimum": 0,
"maximum": 100,
"default": float(self._get_dialog_box_param("transmission")),
"widget": "textarea",
},
"detector_roi_mode": {
"title": "Detector ROI Mode",
"type": "string",
"enum": ["4M", "disabled"],
"default": str(self._get_dialog_box_param("detector_roi_mode")),
"widget": "select",
},
}
properties = get_grid_scan_schema(partial_udc=False)
tray_conditional: dict | None = None
if self.get_head_type() == "Plate":
tray_properties, tray_conditional = self.build_tray_dialog_schema()
Expand Down
43 changes: 2 additions & 41 deletions mxcubecore/HardwareObjects/ANSTO/prefect_flows/one_shot_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from ..Resolution import Resolution
from .abstract_flow import AbstractPrefectWorkflow
from .schemas.dialog_boxes.one_shot import get_one_shot_schema
from .schemas.one_shot import (
OneShotDialogBox,
OneShotParams,
Expand Down Expand Up @@ -110,47 +111,7 @@ def dialog_box(self) -> dict:
A dictionary following the JSON schema.
"""
resolution_limits = self.resolution.get_limits()

properties = {
"exposure_time": {
"title": "Total Exposure Time [s]",
"type": "number",
"exclusiveMinimum": 0,
"default": float(self._get_dialog_box_param("exposure_time")),
"widget": "textarea",
},
"omega_range": {
"title": "Omega Range [degrees]",
"type": "number",
"exclusiveMinimum": 0,
"default": float(self._get_dialog_box_param("omega_range")),
"widget": "textarea",
},
"resolution": {
"title": "Resolution [Å]",
"type": "number",
"minimum": resolution_limits[0],
"maximum": resolution_limits[1],
"default": float(self._get_dialog_box_param("resolution")),
"widget": "textarea",
},
"transmission": {
"title": "Transmission [%]",
"type": "number",
"minimum": 0, # TODO: get limits from PV?
"maximum": 100,
"default": float(self._get_dialog_box_param("transmission")),
"widget": "textarea",
},
}

if settings.ADD_DUMMY_PIN_TO_DB:
properties["sample_id"] = {
"title": "Database sample id (dev only)",
"type": "integer",
"default": 1,
"widget": "textarea",
}
properties = get_one_shot_schema(resolution_limits)

tray_conditional: dict | None = None
if self.get_head_type() == "Plate":
Expand Down
Loading
Loading