mxcubecore.queuelib

queuelib: the queue client library.

Builds and serializes the queue tree into format documented in JSON_FORMAT.md (in this package).

class mxcubecore.queuelib.CharacterisationNodeModel(*, type: str = '', queueID: int = -1, checked: bool = False, state: int = 0, label: str = '', sampleID: str, sampleQueueID: int | None = None, taskIndex: int | None = None, diffractionPlan: list[DataCollectionNodeModel] | None = None, diffractionPlanID: int | None = None, isDiffractionPlan: bool = False, name: str | None = None, parameters: CharacterisationParameters)[source]

Bases: TaskNodeModel

Parameters:
model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class mxcubecore.queuelib.CharacterisationParameters(*, shape: str | int = '', directory: str = '', process_directory: str = '', xds_dir: str = '', base_prefix: str = '', mad_prefix: str = '', reference_image_prefix: str = '', wedge_prefix: str = '', run_number: int = 0, suffix: str = '', precision: int = 0, start_num: int = 0, num_files: int = 0, compression: bool = False, path: str = '', prefix: str = '', fileName: str | None = '', fullPath: str | None = '', subdir: str = '')[source]

Bases: DataCollectionParameters

Parameters:
  • shape (str | int)

  • directory (str)

  • process_directory (str)

  • xds_dir (str)

  • base_prefix (str)

  • mad_prefix (str)

  • reference_image_prefix (str)

  • wedge_prefix (str)

  • run_number (int)

  • suffix (str)

  • precision (int)

  • start_num (int)

  • num_files (int)

  • compression (bool)

  • path (str)

  • prefix (str)

  • fileName (str | None)

  • fullPath (str | None)

  • subdir (str)

model_config: ClassVar[ConfigDict] = {'extra': 'ignore', 'str_strip_whitespace': True, 'use_enum_values': True, 'validate_assignment': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class mxcubecore.queuelib.DataCollectionNodeModel(*, type: str = '', queueID: int = -1, checked: bool = False, state: int = 0, label: str = '', sampleID: str, sampleQueueID: int | None = None, taskIndex: int | None = None, diffractionPlan: list[DataCollectionNodeModel] | None = None, diffractionPlanID: int | None = None, isDiffractionPlan: bool = False, name: str | None = None, parameters: DataCollectionParameters)[source]

Bases: TaskNodeModel

Parameters:
model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class mxcubecore.queuelib.DataCollectionParameters(*, shape: str | int = '', directory: str = '', process_directory: str = '', xds_dir: str = '', base_prefix: str = '', mad_prefix: str = '', reference_image_prefix: str = '', wedge_prefix: str = '', run_number: int = 0, suffix: str = '', precision: int = 0, start_num: int = 0, num_files: int = 0, compression: bool = False, path: str = '', prefix: str = '', fileName: str | None = '', fullPath: str | None = '', subdir: str = '')[source]

Bases: TaskDataPathModel

Parameters:
  • shape (str | int)

  • directory (str)

  • process_directory (str)

  • xds_dir (str)

  • base_prefix (str)

  • mad_prefix (str)

  • reference_image_prefix (str)

  • wedge_prefix (str)

  • run_number (int)

  • suffix (str)

  • precision (int)

  • start_num (int)

  • num_files (int)

  • compression (bool)

  • path (str)

  • prefix (str)

  • fileName (str | None)

  • fullPath (str | None)

  • subdir (str)

model_config: ClassVar[ConfigDict] = {'extra': 'ignore', 'str_strip_whitespace': True, 'use_enum_values': True, 'validate_assignment': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class mxcubecore.queuelib.EnergyScanNodeModel(*, type: str = '', queueID: int = -1, checked: bool = False, state: int = 0, label: str = '', sampleID: str, sampleQueueID: int | None = None, taskIndex: int | None = None, diffractionPlan: list[DataCollectionNodeModel] | None = None, diffractionPlanID: int | None = None, isDiffractionPlan: bool = False, name: str | None = None, parameters: EnergyScanParameters)[source]

Bases: TaskNodeModel

Parameters:
model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class mxcubecore.queuelib.EnergyScanParameters(*, shape: str | int = '', directory: str = '', process_directory: str = '', xds_dir: str = '', base_prefix: str = '', mad_prefix: str = '', reference_image_prefix: str = '', wedge_prefix: str = '', run_number: int = 0, suffix: str = '', precision: int = 0, start_num: int = 0, num_files: int = 0, compression: bool = False, path: str = '', prefix: str = '', fileName: str | None = '', fullPath: str | None = '', subdir: str = '', element: str = '', edge: str = '')[source]

Bases: TaskDataPathModel

Parameters:
  • shape (str | int)

  • directory (str)

  • process_directory (str)

  • xds_dir (str)

  • base_prefix (str)

  • mad_prefix (str)

  • reference_image_prefix (str)

  • wedge_prefix (str)

  • run_number (int)

  • suffix (str)

  • precision (int)

  • start_num (int)

  • num_files (int)

  • compression (bool)

  • path (str)

  • prefix (str)

  • fileName (str | None)

  • fullPath (str | None)

  • subdir (str)

  • element (str)

  • edge (str)

model_config: ClassVar[ConfigDict] = {'extra': 'ignore', 'str_strip_whitespace': True, 'use_enum_values': True, 'validate_assignment': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class mxcubecore.queuelib.GenericTaskNodeModel(*, type: str = '', queueID: int = -1, checked: bool = False, state: int = 0, label: str = '', sampleID: str, sampleQueueID: int | None = None, taskIndex: int | None = None, diffractionPlan: list[DataCollectionNodeModel] | None = None, diffractionPlanID: int | None = None, isDiffractionPlan: bool = False, name: str | None = None, parameters: GenericTaskParameters)[source]

Bases: TaskNodeModel

Parameters:
model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class mxcubecore.queuelib.GenericTaskParameters(*, shape: str | int = '', directory: str = '', process_directory: str = '', xds_dir: str = '', base_prefix: str = '', mad_prefix: str = '', reference_image_prefix: str = '', wedge_prefix: str = '', run_number: int = 0, suffix: str = '', precision: int = 0, start_num: int = 0, num_files: int = 0, compression: bool = False, path: str = '', prefix: str = '', fileName: str | None = '', fullPath: str | None = '', subdir: str = '', first_image: int = 0, num_images: int = 0, osc_start: float = 0, osc_range: float = 0, osc_total_range: float = 0, offset: float = 0, kappa: float | None = 0, kappa_phi: float | None = 0, exp_time: float = 0, num_lines: int = 1, energy: float = 0, resolution: float = 0, detector_distance: float = 0, transmission: float = 100, shutterless: bool = True, take_snapshots: int = 0, detector_binning_mode: str | None = None, detector_roi_mode: int = 0, mesh_range: dict[str, float] = {}, num_triggers: int = 0, num_images_per_trigger: int = 0, cell_counting: str | None = None, mesh_center: str | None = None, cell_spacing: tuple[float, float] | None = None, sub_wedge_size: int = 10, disable_processing: bool = False, inverse_beam: bool = False, space_group: str = '', cellA: float = 0, cellB: float = 0, cellC: float = 0, cellAlpha: float = 0, cellBeta: float = 0, cellGamma: float = 0, helical: bool = False, mesh: bool = False, taskIndexList: list[int] | None = None, wedges: list[DataCollectionNodeModel] = [], swNumImages: int = 0, **extra_data: Any)[source]

Bases: DataCollectionParameters

Parameters of tasks defined by a queue entry DATA_MODEL, for instance the SSX collections. The fields that are not defined here are kept, they are validated by the DATA_MODEL of the queue entry.

Parameters:
model_config: ClassVar[ConfigDict] = {'extra': 'allow', 'str_strip_whitespace': True, 'use_enum_values': True, 'validate_assignment': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class mxcubecore.queuelib.QueueBuilder[source]

Bases: object

Creates queue models the creation of queue entries are handled in queue_model_child_added event handler

add_characterisation(node_id: int, task: dict) → int[source]

Add a data characterisation task to the sample with id: <id>.

Parameters:
  • node_id (int) – id of the sample to which the task belongs

  • task (dict) – Task data (parameters)

Returns:

The queue id of the Data collection

Return type:

int

add_data_collection(node_id: int, task: dict) → int[source]

Add a data collection task to the sample with id: <id>.

Parameters:
  • node_id (int) – id of the sample to which the task belongs

  • task (dict) – task data

Returns:

The queue id of the data collection

Return type:

int

add_energy_scan(node_id: int, task: dict) → int[source]

Add a energy scan task to the sample with id: <id>.

Parameters:
  • node_id (int) – id of the sample to which the task belongs

  • task (dict) – task data

Returns:

The queue id of the data collection

Return type:

int

add_interleaved(node_id: int, task: dict) → int[source]

Add a interleaved data collection task to the sample with id: <id>.

Parameters:
  • node_id (int) – id of the sample to which the task belongs

  • task (dict) – task data

Returns:

The queue id of the data collection

Return type:

int

add_queue_entry(node_id: int, task: dict, task_name: str)[source]

Add a queue entry to the sample with id <node_id>.

Parameters:
  • node_id (int) – id of the sample to which the task belongs

  • task (dict) – task data

  • task_name (str) – The task name

add_sample(sample_id: str, item)[source]

Add a sample with sample id <sample_id> the queue.

Parameters:

sample_id (str) – Sample id (often sample changer location)

Returns:

SampleQueueEntry

add_workflow(node_id: int, task: dict) → int[source]

Add a worklfow task to the parent node with id: <id>.

For adding GPhL Auto workflow, call with node_id==parent_node_id and all required parameters in task[“parameters”]

Parameters:
  • node_id (int) – id of the parent node to which the task belongs

  • task (dict) – task data

Returns:

The queue id of the data collection

Return type:

int

add_xrf_scan(node_id: int, task: dict) → int[source]

Add a XRF Scan task to the sample with id: <id>.

Parameters:
  • node_id (int) – id of the sample to which the task belongs

  • task (dict) – task data

Returns:

The queue id of the data collection

Return type:

int

get_default_prefix(sample_data, generic_name=False)[source]

Thin pass-through to HWR.beamline.session.get_default_prefix.

Kept as its own method (rather than called inline) so apply_template can call it as self.get_default_prefix(…).

get_default_subdir(sample_data)[source]

Thin pass-through to HWR.beamline.session.get_default_subdir.

get_folder_tag(params, task_type='')[source]

Return the tag used in the run directory name, run_XX_<tag>

Parameters:
  • params – task parameters

  • task_type – type of the task, e.g. “Characterisation”. Not part of the validated task parameters, so it’s passed separately.

set_char_params(model: Characterisation, entry: BaseQueueEntry, task_data: dict, sample_model)[source]

Helper method that sets the characterisation parameters.

Helper method that sets the characterisation parameters for a Characterisation.

Parameters:
set_dc_params(model: DataCollection, entry: BaseQueueEntry, task_data: dict, sample_model)[source]

Helper method that sets the data collection parameters for a DataCollection.

Parameters:
  • model (DataCollection) – The model to set parameters of

  • entry (BaseQueueEntry) – The queue entry of the model

  • task_data (dict) – Dictionary with new parameters

set_energy_scan_params(model: EnergyScan, entry: BaseQueueEntry, task_data: dict, sample_model)[source]

Helper method that sets the xrf scan parameters for a XRF spectrum Scan.

Parameters:
  • model (EnergyScan) – The model to set parameters of

  • entry (BaseQueueEntry) – The queue entry of the model

  • task_data (dict) – Dictionary with new parameters

set_gphl_wf_params(model: GphlWorkflow, entry: BaseQueueEntry, task_data: dict, sample_model)[source]

Helper method that sets the parameters for a GPhL workflow task.

Parameters:
  • model (GphlWorkflow) – The model to set parameters of

  • entry (BaseQueueEntry) – The queue entry of the model

  • task_data (dict) – Dictionary with new parameters

  • sample_model – The Sample queueModelObject

set_wf_params(model: Workflow, entry: BaseQueueEntry, task_data: dict, sample_model)[source]

Helper method that sets the parameters for a workflow task.

Parameters:
  • model (Workflow) – The model to set parameters of

  • entry (BaseQueueEntry) – The queue entry of the model

  • task_data (dict) – Dictionary with new parameters

set_xrf_params(model: XRFSpectrum, entry: BaseQueueEntry, task_data: dict, sample_model)[source]

Helper method that sets the xrf scan parameters for a XRF spectrum Scan.

Parameters:
  • model (XRFSpectrum) – The model to set parameters of

  • entry (BaseQueueEntry) – The queue entry of the model

  • task_data (dict) – Dictionary with new parameters

strip_prefix(pt, prefix)[source]

Strip the reference, wedge and mad prefix from a given prefix.

For example, remove ref- from the beginning and _w[n] and -pk, -ip, -ipp from the end.

Parameters:
  • pt (PathTemplate) – path template used to create the prefix

  • prefix (str) – prefix from the client

Returns:

stripped prefix

class mxcubecore.queuelib.QueueNodeModel(*, type: str = '', queueID: int = -1, checked: bool = False, state: int = 0)[source]

Bases: BaseModel

Parameters:
model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class mxcubecore.queuelib.QueueSerializer(builder)[source]

Bases: object

Serializes the queue. Depends only on mxcubecore (HWR.beamline.*) and its sibling QueueBuilder - no self.app reference.

add_task(parent: int | str, item: dict) → int[source]

Add a single task to an already-queued sample.

Unlike queue_add_item (which validates and adds a whole batch of samples/tasks at once), this adds exactly one task to a sample that must already be in the queue - it never creates a Sample node.

Parameters:
  • parent (int | str) – the sample’s queueID, or its sampleID/loc_str

  • item (dict) – task dict, e.g. {“type”: “DataCollection”, “parameters”: {…}}

Returns:

the new task’s queue id

Return type:

int

node_to_dict(node) → dict[source]

Return a dict representing <node> itself

Return type:

dict

pretty_print_queue(msg: str | None = None) → None[source]

Pretty print current queue state for debugging.

Parameters:

msg (str | None)

Return type:

None

queue_add_item(item_list)[source]

Add queue items to the queue.

Add the queue items in item_list to the queue. The items in the list can be either samples and or tasks. Samples are only added if they are not already in the queue and tasks are appended to the end of an (already existing) sample. A task is ignored if the sample is not already in the queue.

The items in item_list are dictionaries with the following structure:

{ “type”: “Sample | DataCollection | Characterisation”, “sampleID”: sid … task or sample specific data }

Each item (dictionary) describes either a sample or a task.

Validation (malformed input) is all-or-nothing: if any item fails schema validation, nothing is mutated and ValidationError propagates - the request never touched the queue. Once past validation, adding is best-effort per top-level item (see JSON_FORMAT.md known issue #8): items can depend on an earlier one in the same call (e.g. a task nested under a sample added earlier in the same list), so a failed item can’t simply roll back everything after it without also undoing work later items may already depend on. The returned dict’s “add_results” key reports which top-level items (by sampleID) succeeded or failed, so a client doesn’t have to guess from an all-or-nothing HTTP status and risk re-submitting (duplicating) items that already succeeded.

queue_to_dict() → dict[source]

Return the whole queue: a dict keyed by sample ID, plus “sample_order” and “format_version” - see JSON_FORMAT.md.

Return type:

dict

class mxcubecore.queuelib.SampleNode(*, type: str = '', queueID: int = -1, checked: bool = False, state: int | None = None, sampleID: str, limsID: int | None = None, code: str | None = None, location: str, cell_no: int = 0, puck_no: int = 1, sampleName: str, proteinAcronym: str | None = '', defaultPrefix: str | None = '', defaultSubDir: str | None = '', tasks: list[DataCollectionNodeModel | CharacterisationNodeModel | XRFNodeModel | EnergyScanNodeModel | WorkflowNodeModel | GenericTaskNodeModel], crystalUUID: str | None = None, image_url: str = '', image_x: str | None = None, image_y: str | None = None, loadable: bool = True, puck_barcode: str | None = None, puck_type: str | None = None, sample_barcode: str = '', sc_state: str = '', containerCode: str | None = None, crystalSpaceGroup: str | None = None, cellA: float | None = None, cellB: float | None = None, cellC: float | None = None, cellAlpha: float | None = None, cellBeta: float | None = None, cellGamma: float | None = None)[source]

Bases: QueueNodeModel

Parameters:
model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class mxcubecore.queuelib.TaskDataPathModel(*, shape: str | int = '', directory: str = '', process_directory: str = '', xds_dir: str = '', base_prefix: str = '', mad_prefix: str = '', reference_image_prefix: str = '', wedge_prefix: str = '', run_number: int = 0, suffix: str = '', precision: int = 0, start_num: int = 0, num_files: int = 0, compression: bool = False, path: str = '', prefix: str = '', fileName: str | None = '', fullPath: str | None = '', subdir: str = '')[source]

Bases: BaseModel

Parameters:
  • shape (str | int)

  • directory (str)

  • process_directory (str)

  • xds_dir (str)

  • base_prefix (str)

  • mad_prefix (str)

  • reference_image_prefix (str)

  • wedge_prefix (str)

  • run_number (int)

  • suffix (str)

  • precision (int)

  • start_num (int)

  • num_files (int)

  • compression (bool)

  • path (str)

  • prefix (str)

  • fileName (str | None)

  • fullPath (str | None)

  • subdir (str)

model_config: ClassVar[ConfigDict] = {'extra': 'ignore', 'str_strip_whitespace': True, 'use_enum_values': True, 'validate_assignment': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class mxcubecore.queuelib.TaskNodeModel(*, type: str = '', queueID: int = -1, checked: bool = False, state: int = 0)[source]

Bases: QueueNodeModel

Parameters:
model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class mxcubecore.queuelib.WorkflowNodeModel(*, type: str = '', queueID: int = -1, checked: bool = False, state: int = 0, label: str = '', sampleID: str, sampleQueueID: int | None = None, taskIndex: int | None = None, diffractionPlan: list[DataCollectionNodeModel] | None = None, diffractionPlanID: int | None = None, isDiffractionPlan: bool = False, name: str | None = None, parameters: WorkflowParameters)[source]

Bases: TaskNodeModel

Parameters:
model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class mxcubecore.queuelib.WorkflowParameters(*, shape: str | int = '', directory: str = '', process_directory: str = '', xds_dir: str = '', base_prefix: str = '', mad_prefix: str = '', reference_image_prefix: str = '', wedge_prefix: str = '', run_number: int = 0, suffix: str = '', precision: int = 0, start_num: int = 0, num_files: int = 0, compression: bool = False, path: str = '', prefix: str = '', fileName: str | None = '', fullPath: str | None = '', subdir: str = '', beam_size: str | None = None, cell_count: int | None = None, doc: str = '', label: str = '', name: str | None = None, numCols: int = 0, numRows: int = 0, requires: list[str] = [], type: str = '', wfname: str = '', wfpath: str = '')[source]

Bases: TaskDataPathModel

Parameters:
  • shape (str | int)

  • directory (str)

  • process_directory (str)

  • xds_dir (str)

  • base_prefix (str)

  • mad_prefix (str)

  • reference_image_prefix (str)

  • wedge_prefix (str)

  • run_number (int)

  • suffix (str)

  • precision (int)

  • start_num (int)

  • num_files (int)

  • compression (bool)

  • path (str)

  • prefix (str)

  • fileName (str | None)

  • fullPath (str | None)

  • subdir (str)

  • beam_size (str | None)

  • cell_count (int | None)

  • doc (str)

  • label (str)

  • name (str | None)

  • numCols (int)

  • numRows (int)

  • requires (list[str])

  • type (str)

  • wfname (str)

  • wfpath (str)

model_config: ClassVar[ConfigDict] = {'extra': 'ignore', 'str_strip_whitespace': True, 'use_enum_values': True, 'validate_assignment': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class mxcubecore.queuelib.XRFNodeModel(*, type: str = '', queueID: int = -1, checked: bool = False, state: int = 0, label: str = '', sampleID: str, sampleQueueID: int | None = None, taskIndex: int | None = None, diffractionPlan: list[DataCollectionNodeModel] | None = None, diffractionPlanID: int | None = None, isDiffractionPlan: bool = False, name: str | None = None, parameters: XRFParameters)[source]

Bases: TaskNodeModel

Parameters:
model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class mxcubecore.queuelib.XRFParameters(*, shape: str | int = '', directory: str = '', process_directory: str = '', xds_dir: str = '', base_prefix: str = '', mad_prefix: str = '', reference_image_prefix: str = '', wedge_prefix: str = '', run_number: int = 0, suffix: str = '', precision: int = 0, start_num: int = 0, num_files: int = 0, compression: bool = False, path: str = '', prefix: str = '', fileName: str | None = '', fullPath: str | None = '', subdir: str = '', countTime: float = 0, exp_time: float = 0)[source]

Bases: TaskDataPathModel

Parameters:
  • shape (str | int)

  • directory (str)

  • process_directory (str)

  • xds_dir (str)

  • base_prefix (str)

  • mad_prefix (str)

  • reference_image_prefix (str)

  • wedge_prefix (str)

  • run_number (int)

  • suffix (str)

  • precision (int)

  • start_num (int)

  • num_files (int)

  • compression (bool)

  • path (str)

  • prefix (str)

  • fileName (str | None)

  • fullPath (str | None)

  • subdir (str)

  • countTime (float)

  • exp_time (float)

model_config: ClassVar[ConfigDict] = {'extra': 'ignore', 'str_strip_whitespace': True, 'use_enum_values': True, 'validate_assignment': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

mxcubecore.queuelib.get_json_schema() → dict[source]

Return the JSON Schema for queue_to_dict()’s root (“get the whole queue”) response.

Returns:

a JSON Schema (draft 2020-12) dict.

Return type:

dict

mxcubecore.queuelib.validate_model_tolerant(model_cls, data)[source]

Validate <data> against <model_cls>, tolerating unknown fields.

Unknown/extra fields (model_config extra=”forbid”) are logged as a warning and dropped rather than failing the request; any other validation error (missing or invalid field) is re-raised as-is.

Modules

builder

QueueBuilder: constructs queue model nodes (and, indirectly, their matching QueueEntry objects - see QueueModel.queue_model_child_added) from client task data.

constants

Constants for the queue client JSON format.

json_schema

Generates the JSON Schema for the queue JSON format.

models

Pydantic models for the queue client wire format.

regenerate_queue_schema

Regenerate the checked-in queue JSON schema snapshot.

serializer

QueueSerializer: turns the queue tree into the client JSON format, and turns client JSON back into calls on QueueBuilder.