Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
86ed2c6
Workflow for picked tomos
stephen-riggs Oct 9, 2025
32ecc10
Generate extract pj
stephen-riggs Oct 13, 2025
7bd8c2a
Tomo class bits for db
stephen-riggs Oct 13, 2025
d8afdac
Tomo picking feedback workflow
stephen-riggs Oct 14, 2025
2bfd0ff
Renamed table and fix rebase
stephen-riggs Oct 14, 2025
fe43c02
Change params available for tomo class2d
stephen-riggs Oct 14, 2025
500089e
Rename workflow
stephen-riggs Oct 15, 2025
eac3702
Test for tomo picking feedback
stephen-riggs Oct 15, 2025
0ab6102
Improve tests
stephen-riggs Oct 15, 2025
5e22677
Mis-named item
stephen-riggs Oct 15, 2025
8478ec3
Needs to keep adding
stephen-riggs Oct 15, 2025
1afadc3
Fix session id
stephen-riggs Oct 15, 2025
9ab0fdd
Tomo params depend on dcg_id
stephen-riggs Oct 15, 2025
6749386
Function got renamed
stephen-riggs Oct 15, 2025
e485575
wrong dcgid
stephen-riggs Oct 15, 2025
2fc4428
Fix murfey id counts and autoproc id in test
stephen-riggs Oct 15, 2025
7208088
Only 5 classes
stephen-riggs Oct 15, 2025
7ed3fb7
Add feedback params for tomo
stephen-riggs Oct 20, 2025
7469abd
Test the route without diameter supplied
stephen-riggs Oct 20, 2025
27c50c7
Test pjids
stephen-riggs Oct 20, 2025
fad7f2a
Fix error in test
stephen-riggs Oct 20, 2025
2a902a1
Change primary key in tomogram picks
stephen-riggs Oct 20, 2025
f6e7d02
Skip expunging?
stephen-riggs Oct 20, 2025
17d4759
Ids are bigger
stephen-riggs Oct 20, 2025
15df9a7
Ids are not that
stephen-riggs Oct 20, 2025
569c670
Try mocking out the count for faster tests
stephen-riggs Oct 20, 2025
d679771
Mocked wrong thing
stephen-riggs Oct 20, 2025
9b29882
Mocking count didn't work
stephen-riggs Oct 20, 2025
8cb5830
Name things consistently
stephen-riggs Oct 20, 2025
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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ GitHub = "https://github.com/DiamondLightSource/python-murfey"
"clem.register_preprocessing_result" = "murfey.workflows.clem.register_preprocessing_results:run"
"pato" = "murfey.workflows.notifications:notification_setup"
"picked_particles" = "murfey.workflows.spa.picking:particles_picked"
"picked_tomogram" = "murfey.workflows.tomo.picking:picked_tomogram"
"spa.flush_spa_preprocess" = "murfey.workflows.spa.flush_spa_preprocess:flush_spa_preprocess"

[tool.setuptools]
Expand Down
6 changes: 3 additions & 3 deletions src/murfey/cli/inject_spa_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
from murfey.util.config import get_machine_config, get_microscope, get_security_config
from murfey.util.db import (
AutoProcProgram,
ClassificationFeedbackParameters,
ClientEnvironment,
DataCollection,
DataCollectionGroup,
Movie,
ProcessingJob,
SPAFeedbackParameters,
SPARelionParameters,
)
from murfey.util.processing_params import default_spa_parameters
Expand Down Expand Up @@ -137,9 +137,9 @@ def run():
.where(ProcessingJob.recipe == "em-spa-preprocess")
).one()
params = murfey_db.exec(
select(SPARelionParameters, SPAFeedbackParameters)
select(SPARelionParameters, ClassificationFeedbackParameters)
.where(SPARelionParameters.pj_id == collected_ids[2].id)
.where(SPAFeedbackParameters.pj_id == SPARelionParameters.pj_id)
.where(ClassificationFeedbackParameters.pj_id == SPARelionParameters.pj_id)
).one()
proc_params: dict | None = dict(params[0])
feedback_params = params[1]
Expand Down
2 changes: 1 addition & 1 deletion src/murfey/cli/spa_ispyb_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def run():
small_boxsize=metadata["small_boxsize"],
mask_diameter=metadata["mask_diameter"],
)
feedback_params = db.SPAFeedbackParameters(
feedback_params = db.ClassificationFeedbackParameters(
pj_id=collected_ids[2].id,
estimate_particle_diameter=not bool(metadata["particle_diameter"]),
hold_class2d=False,
Expand Down
8 changes: 7 additions & 1 deletion src/murfey/client/contexts/tomo.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,13 @@ def register_tomography_data_collections(
data=dc_data,
)

for recipe in ("em-tomo-preprocess", "em-tomo-align"):
recipes_to_assign_pjids = [
"em-tomo-preprocess",
"em-tomo-align",
]
if not self._tilt_series_with_pjids:
recipes_to_assign_pjids.append("em-tomo-class2d")
for recipe in recipes_to_assign_pjids:
capture_post(
base_url=str(environment.url.geturl()),
router_name="workflow.router",
Expand Down
8 changes: 4 additions & 4 deletions src/murfey/server/api/session_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from murfey.util import sanitise
from murfey.util.config import MachineConfig, get_machine_config
from murfey.util.db import (
ClassificationFeedbackParameters,
ClientEnvironment,
DataCollection,
DataCollectionGroup,
Expand All @@ -41,7 +42,6 @@
RsyncInstance,
Session,
SessionProcessingParameters,
SPAFeedbackParameters,
SPARelionParameters,
Tilt,
TiltSeries,
Expand Down Expand Up @@ -280,7 +280,7 @@ class ProcessingDetails(BaseModel):
data_collections: List[DataCollection]
processing_jobs: List[ProcessingJob]
relion_params: SPARelionParameters
feedback_params: SPAFeedbackParameters
feedback_params: ClassificationFeedbackParameters


@spa_router.get("/sessions/{session_id}/spa_processing_parameters")
Expand All @@ -293,13 +293,13 @@ def get_spa_proc_param_details(
DataCollection,
ProcessingJob,
SPARelionParameters,
SPAFeedbackParameters,
ClassificationFeedbackParameters,
)
.where(DataCollectionGroup.session_id == session_id)
.where(DataCollectionGroup.id == DataCollection.dcg_id)
.where(DataCollection.id == ProcessingJob.dc_id)
.where(SPARelionParameters.pj_id == ProcessingJob.id)
.where(SPAFeedbackParameters.pj_id == ProcessingJob.id)
.where(ClassificationFeedbackParameters.pj_id == ProcessingJob.id)
).all()
if not params:
return None
Expand Down
6 changes: 3 additions & 3 deletions src/murfey/server/api/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from murfey.util.config import get_machine_config
from murfey.util.db import (
AutoProcProgram,
ClassificationFeedbackParameters,
DataCollection,
DataCollectionGroup,
FoilHole,
Expand All @@ -54,7 +55,6 @@
SearchMap,
Session,
SessionProcessingParameters,
SPAFeedbackParameters,
SPARelionParameters,
Tilt,
TiltSeries,
Expand Down Expand Up @@ -409,9 +409,9 @@ async def request_spa_preprocessing(
.where(ProcessingJob.recipe == "em-spa-preprocess")
).one()
params = db.exec(
select(SPARelionParameters, SPAFeedbackParameters)
select(SPARelionParameters, ClassificationFeedbackParameters)
.where(SPARelionParameters.pj_id == collected_ids[2].id)
.where(SPAFeedbackParameters.pj_id == SPARelionParameters.pj_id)
.where(ClassificationFeedbackParameters.pj_id == SPARelionParameters.pj_id)
).one()
proc_params: Optional[dict] = dict(params[0])
feedback_params = params[1]
Expand Down
12 changes: 6 additions & 6 deletions src/murfey/server/demo_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
)
from murfey.util.db import (
AutoProcProgram,
ClassificationFeedbackParameters,
ClientEnvironment,
DataCollection,
DataCollectionGroup,
Expand All @@ -60,7 +61,6 @@
ProcessingJob,
RsyncInstance,
Session,
SPAFeedbackParameters,
SPARelionParameters,
Tilt,
TiltSeries,
Expand Down Expand Up @@ -244,7 +244,7 @@ class ProcessingDetails(BaseModel):
data_collections: List[DataCollection]
processing_jobs: List[ProcessingJob]
relion_params: SPARelionParameters
feedback_params: SPAFeedbackParameters
feedback_params: ClassificationFeedbackParameters


@router.get("/sessions/{session_id}/spa_processing_parameters")
Expand All @@ -257,13 +257,13 @@ def get_spa_proc_param_details(
DataCollection,
ProcessingJob,
SPARelionParameters,
SPAFeedbackParameters,
ClassificationFeedbackParameters,
)
.where(DataCollectionGroup.session_id == session_id)
.where(DataCollectionGroup.id == DataCollection.dcg_id)
.where(DataCollection.id == ProcessingJob.dc_id)
.where(SPARelionParameters.pj_id == ProcessingJob.id)
.where(SPAFeedbackParameters.pj_id == ProcessingJob.id)
.where(ClassificationFeedbackParameters.pj_id == ProcessingJob.id)
).all()
if not params:
return None
Expand Down Expand Up @@ -560,9 +560,9 @@ def flush_spa_processing(
.where(ProcessingJob.recipe == "em-spa-preprocess")
).one()
params = db.exec(
select(SPARelionParameters, SPAFeedbackParameters)
select(SPARelionParameters, ClassificationFeedbackParameters)
.where(SPARelionParameters.pj_id == collected_ids[2].id)
.where(SPAFeedbackParameters.pj_id == SPARelionParameters.pj_id)
.where(ClassificationFeedbackParameters.pj_id == SPARelionParameters.pj_id)
).one()
proc_params = dict(params[0])
feedback_params = params[1]
Expand Down
85 changes: 57 additions & 28 deletions src/murfey/server/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,15 @@ def _pj_id(app_id: int, _db, recipe: str = "") -> int:

def _get_spa_params(
app_id: int, _db
) -> Tuple[db.SPARelionParameters, db.SPAFeedbackParameters]:
) -> Tuple[db.SPARelionParameters, db.ClassificationFeedbackParameters]:
pj_id = _pj_id(app_id, _db, recipe="em-spa-preprocess")
relion_params = _db.exec(
select(db.SPARelionParameters).where(db.SPARelionParameters.pj_id == pj_id)
).one()
feedback_params = _db.exec(
select(db.SPAFeedbackParameters).where(db.SPAFeedbackParameters.pj_id == pj_id)
select(db.ClassificationFeedbackParameters).where(
db.ClassificationFeedbackParameters.pj_id == pj_id
)
).one()
_db.expunge(relion_params)
_db.expunge(feedback_params)
Expand Down Expand Up @@ -412,8 +414,8 @@ def _release_3d_hold(message: dict, _db):
)
).one()
feedback_params = _db.exec(
select(db.SPAFeedbackParameters).where(
db.SPAFeedbackParameters.pj_id == pj_id_params
select(db.ClassificationFeedbackParameters).where(
db.ClassificationFeedbackParameters.pj_id == pj_id_params
)
).one()
class3d_params = _db.exec(
Expand Down Expand Up @@ -490,8 +492,8 @@ def _release_refine_hold(message: dict, _db):
)
).one()
feedback_params = _db.exec(
select(db.SPAFeedbackParameters).where(
db.SPAFeedbackParameters.pj_id == pj_id_params
select(db.ClassificationFeedbackParameters).where(
db.ClassificationFeedbackParameters.pj_id == pj_id_params
)
).one()
refine_params = _db.exec(
Expand Down Expand Up @@ -582,8 +584,8 @@ def _register_incomplete_2d_batch(message: dict, _db, demo: bool = False):
)
).one()
feedback_params = _db.exec(
select(db.SPAFeedbackParameters).where(
db.SPAFeedbackParameters.pj_id == pj_id_params
select(db.ClassificationFeedbackParameters).where(
db.ClassificationFeedbackParameters.pj_id == pj_id_params
)
).one()
if feedback_params.hold_class2d:
Expand Down Expand Up @@ -623,7 +625,9 @@ def _register_incomplete_2d_batch(message: dict, _db, demo: bool = False):
)
_db.add(class2d_params)
_db.commit()
murfey_ids = _murfey_id(message["program_id"], _db, number=50)
murfey_ids = _murfey_id(
message["program_id"], _db, number=default_spa_parameters.nr_classes_2d
)
_murfey_class2ds(
murfey_ids, class2d_message["particles_file"], message["program_id"], _db
)
Expand Down Expand Up @@ -706,8 +710,8 @@ def _register_complete_2d_batch(message: dict, _db, demo: bool = False):
)
).one()
feedback_params = _db.exec(
select(db.SPAFeedbackParameters).where(
db.SPAFeedbackParameters.pj_id == pj_id_params
select(db.ClassificationFeedbackParameters).where(
db.ClassificationFeedbackParameters.pj_id == pj_id_params
)
).one()
_db.expunge(relion_params)
Expand Down Expand Up @@ -747,7 +751,9 @@ def _register_complete_2d_batch(message: dict, _db, demo: bool = False):
_db.add(class2d_params)
_db.commit()
_db.close()
murfey_ids = _murfey_id(_app_id(pj_id, _db), _db, number=50)
murfey_ids = _murfey_id(
_app_id(pj_id, _db), _db, number=default_spa_parameters.nr_classes_2d
)
_murfey_class2ds(
murfey_ids, class2d_message["particles_file"], _app_id(pj_id, _db), _db
)
Expand Down Expand Up @@ -796,7 +802,13 @@ def _register_complete_2d_batch(message: dict, _db, demo: bool = False):
else:
class_uuids = {
str(i + 1): m
for i, m in enumerate(_murfey_id(_app_id(pj_id, _db), _db, number=50))
for i, m in enumerate(
_murfey_id(
_app_id(pj_id, _db),
_db,
number=default_spa_parameters.nr_classes_2d,
)
)
}
class2d_grp_uuid = _murfey_id(_app_id(pj_id, _db), _db)[0]
zocalo_message: dict = {
Expand Down Expand Up @@ -865,7 +877,13 @@ def _register_complete_2d_batch(message: dict, _db, demo: bool = False):
else:
class_uuids = {
str(i + 1): m
for i, m in enumerate(_murfey_id(_app_id(pj_id, _db), _db, number=50))
for i, m in enumerate(
_murfey_id(
_app_id(pj_id, _db),
_db,
number=default_spa_parameters.nr_classes_2d,
)
)
}
class2d_grp_uuid = _murfey_id(_app_id(pj_id, _db), _db)[0]
zocalo_message = {
Expand Down Expand Up @@ -913,7 +931,7 @@ def _flush_class2d(
app_id: int,
_db,
relion_params: db.SPARelionParameters | None = None,
feedback_params: db.SPAFeedbackParameters | None = None,
feedback_params: db.ClassificationFeedbackParameters | None = None,
):
instrument_name = (
_db.exec(select(db.Session).where(db.Session.id == session_id))
Expand All @@ -934,8 +952,8 @@ def _flush_class2d(
_db.expunge(relion_params)
if not feedback_params:
feedback_params = _db.exec(
select(db.SPAFeedbackParameters).where(
db.SPAFeedbackParameters.pj_id == pj_id_params
select(db.ClassificationFeedbackParameters).where(
db.ClassificationFeedbackParameters.pj_id == pj_id_params
)
).one()
_db.expunge(feedback_params)
Expand Down Expand Up @@ -1012,8 +1030,8 @@ def _register_class_selection(message: dict, _db, demo: bool = False):
).all()
# Add the class selection score to the database
feedback_params = _db.exec(
select(db.SPAFeedbackParameters).where(
db.SPAFeedbackParameters.pj_id == pj_id_params
select(db.ClassificationFeedbackParameters).where(
db.ClassificationFeedbackParameters.pj_id == pj_id_params
)
).one()
_db.expunge(feedback_params)
Expand Down Expand Up @@ -1233,8 +1251,8 @@ def _register_3d_batch(message: dict, _db, demo: bool = False):
).one()
relion_options = dict(relion_params)
feedback_params = _db.exec(
select(db.SPAFeedbackParameters).where(
db.SPAFeedbackParameters.pj_id == pj_id_params
select(db.ClassificationFeedbackParameters).where(
db.ClassificationFeedbackParameters.pj_id == pj_id_params
)
).one()
other_options = dict(feedback_params)
Expand Down Expand Up @@ -1411,8 +1429,8 @@ def _register_initial_model(message: dict, _db, demo: bool = False):
pj_id_params = _pj_id(message["program_id"], _db, recipe="em-spa-preprocess")
# Add the initial model file to the database
feedback_params = _db.exec(
select(db.SPAFeedbackParameters).where(
db.SPAFeedbackParameters.pj_id == pj_id_params
select(db.ClassificationFeedbackParameters).where(
db.ClassificationFeedbackParameters.pj_id == pj_id_params
)
).one()
feedback_params.initial_model = message.get("initial_model")
Expand Down Expand Up @@ -1578,8 +1596,8 @@ def _register_refinement(message: dict, _db, demo: bool = False):
).one()
relion_options = dict(relion_params)
feedback_params = _db.exec(
select(db.SPAFeedbackParameters).where(
db.SPAFeedbackParameters.pj_id == pj_id_params
select(db.ClassificationFeedbackParameters).where(
db.ClassificationFeedbackParameters.pj_id == pj_id_params
)
).one()
other_options = dict(feedback_params)
Expand Down Expand Up @@ -1726,8 +1744,8 @@ def _register_bfactors(message: dict, _db, demo: bool = False):
).one()
relion_options = dict(relion_params)
feedback_params = _db.exec(
select(db.SPAFeedbackParameters).where(
db.SPAFeedbackParameters.pj_id == pj_id_params
select(db.ClassificationFeedbackParameters).where(
db.ClassificationFeedbackParameters.pj_id == pj_id_params
)
).one()

Expand Down Expand Up @@ -2289,7 +2307,7 @@ def feedback_callback(header: dict, message: dict, _db=murfey_db) -> None:
eer_fractionation_file=message["eer_fractionation_file"],
symmetry=message["symmetry"],
)
feedback_params = db.SPAFeedbackParameters(
feedback_params = db.ClassificationFeedbackParameters(
pj_id=collected_ids[2].id,
estimate_particle_diameter=True,
hold_class2d=False,
Expand Down Expand Up @@ -2346,7 +2364,18 @@ def feedback_callback(header: dict, message: dict, _db=murfey_db) -> None:
gain_ref=message["gain_ref"],
eer_fractionation_file=message["eer_fractionation_file"],
)
feedback_params = db.ClassificationFeedbackParameters(
pj_id=collected_ids[2].id,
estimate_particle_diameter=True,
hold_class2d=False,
hold_class3d=False,
class_selection_score=0,
star_combination_job=0,
initial_model="",
next_job=0,
)
_db.add(params)
_db.add(feedback_params)
_db.commit()
_db.close()
if murfey.server._transport_object:
Expand Down
Loading