From 6d962de236dd0a85f7494b143f044431153981a6 Mon Sep 17 00:00:00 2001 From: Eu Pin Tien Date: Wed, 12 Mar 2025 15:29:11 +0000 Subject: [PATCH 1/4] Added values used by Murfey's email notification workflow to the message sent back from cryolo --- src/cryoemservices/services/cryolo.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cryoemservices/services/cryolo.py b/src/cryoemservices/services/cryolo.py index 25ac308f..8392b947 100644 --- a/src/cryoemservices/services/cryolo.py +++ b/src/cryoemservices/services/cryolo.py @@ -439,7 +439,7 @@ def cryolo(self, rw, header: dict, message: dict): rw.send_to("images", images_parameters) # Gather results needed for particle extraction - extraction_params = { + extraction_params: dict[str, Any] = { "ctf_values": cryolo_params.ctf_values, "micrographs_file": cryolo_params.input_path, "coord_list_file": cryolo_params.output_path, @@ -454,6 +454,8 @@ def cryolo(self, rw, header: dict, message: dict): ) / (Path(cryolo_params.input_path).stem + "_extract.star") ) + # Load the CTF values returned by the CTFFind service + ctf_values: dict[str, Any] = extraction_params["ctf_values"] # Forward results to murfey self.log.info("Sending to Murfey for particle extraction") @@ -464,6 +466,10 @@ def cryolo(self, rw, header: dict, message: dict): "motion_correction_id": cryolo_params.mc_uuid, "micrograph": cryolo_params.input_path, "particle_diameters": list(cryolo_particle_sizes), + "particle_count": len(cryolo_particle_sizes), + "resolution": ctf_values["CtfMaxResolution"], + "astigmatism": ctf_values["DefocusAngle"], + "defocus": ((ctf_values["DefocusU"]) + (ctf_values["DefocusV"])) / 2, "extraction_parameters": extraction_params, }, ) From a3c35241691cb8c91dd119ce773d60d0034fbd5d Mon Sep 17 00:00:00 2001 From: Eu Pin Tien Date: Wed, 12 Mar 2025 15:51:04 +0000 Subject: [PATCH 2/4] Fixed astigmatism and defocus calculations --- src/cryoemservices/services/cryolo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cryoemservices/services/cryolo.py b/src/cryoemservices/services/cryolo.py index 8392b947..fc17d863 100644 --- a/src/cryoemservices/services/cryolo.py +++ b/src/cryoemservices/services/cryolo.py @@ -468,8 +468,8 @@ def cryolo(self, rw, header: dict, message: dict): "particle_diameters": list(cryolo_particle_sizes), "particle_count": len(cryolo_particle_sizes), "resolution": ctf_values["CtfMaxResolution"], - "astigmatism": ctf_values["DefocusAngle"], - "defocus": ((ctf_values["DefocusU"]) + (ctf_values["DefocusV"])) / 2, + "astigmatism": ctf_values["DefocusV"] - ctf_values["DefocusU"], + "defocus": (ctf_values["DefocusU"] + ctf_values["DefocusV"]) / 2, "extraction_parameters": extraction_params, }, ) From b1c71bef0a4588ea7309e688037be84db9e0943f Mon Sep 17 00:00:00 2001 From: Eu Pin Tien Date: Wed, 12 Mar 2025 15:59:02 +0000 Subject: [PATCH 3/4] Updated test for Cryolo service --- tests/services/test_cryolo_service.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/services/test_cryolo_service.py b/tests/services/test_cryolo_service.py index e6004e90..ec146cdb 100644 --- a/tests/services/test_cryolo_service.py +++ b/tests/services/test_cryolo_service.py @@ -39,6 +39,11 @@ def test_cryolo_service_spa(mock_subprocess, offline_transport, tmp_path): output_path = tmp_path / "AutoPick/job007/STAR/sample.star" cbox_path = tmp_path / "AutoPick/job007/CBOX/sample.cbox" + ctf_test_values = { + "CtfMaxResolution": 0.00001, + "DefocusU": 0.05, + "DefocusV": 0.08, + } cryolo_test_message = { "pixel_size": 0.1, "input_path": "MotionCorr/job002/sample.mrc", @@ -52,7 +57,7 @@ def test_cryolo_service_spa(mock_subprocess, offline_transport, tmp_path): "mc_uuid": 0, "picker_uuid": 0, "particle_diameter": 1.1, - "ctf_values": {"dummy": "dummy"}, + "ctf_values": ctf_test_values, "cryolo_command": "cryolo_predict.py", "relion_options": {"batch_size": 20000, "downscale": True}, } @@ -161,6 +166,10 @@ def test_cryolo_service_spa(mock_subprocess, offline_transport, tmp_path): "motion_correction_id": cryolo_test_message["mc_uuid"], "micrograph": cryolo_test_message["input_path"], "particle_diameters": [10.0, 20.0], + "particle_count": 2, + "resolution": ctf_test_values["CtfMaxResolution"], + "astigmatism": ctf_test_values["DefocusV"] - ctf_test_values["DefocusU"], + "defocus": (ctf_test_values["DefocusU"] + ctf_test_values["DefocusV"]) / 2, "extraction_parameters": extraction_params, }, ) From 56dfc10da5e5384548fe4dd5aea8345ec646025a Mon Sep 17 00:00:00 2001 From: Eu Pin Tien Date: Wed, 12 Mar 2025 16:01:49 +0000 Subject: [PATCH 4/4] Use variables directly instead of re-defining --- src/cryoemservices/services/cryolo.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/cryoemservices/services/cryolo.py b/src/cryoemservices/services/cryolo.py index fc17d863..2da897b6 100644 --- a/src/cryoemservices/services/cryolo.py +++ b/src/cryoemservices/services/cryolo.py @@ -454,8 +454,6 @@ def cryolo(self, rw, header: dict, message: dict): ) / (Path(cryolo_params.input_path).stem + "_extract.star") ) - # Load the CTF values returned by the CTFFind service - ctf_values: dict[str, Any] = extraction_params["ctf_values"] # Forward results to murfey self.log.info("Sending to Murfey for particle extraction") @@ -467,9 +465,14 @@ def cryolo(self, rw, header: dict, message: dict): "micrograph": cryolo_params.input_path, "particle_diameters": list(cryolo_particle_sizes), "particle_count": len(cryolo_particle_sizes), - "resolution": ctf_values["CtfMaxResolution"], - "astigmatism": ctf_values["DefocusV"] - ctf_values["DefocusU"], - "defocus": (ctf_values["DefocusU"] + ctf_values["DefocusV"]) / 2, + "resolution": cryolo_params.ctf_values["CtfMaxResolution"], + "astigmatism": cryolo_params.ctf_values["DefocusV"] + - cryolo_params.ctf_values["DefocusU"], + "defocus": ( + cryolo_params.ctf_values["DefocusU"] + + cryolo_params.ctf_values["DefocusV"] + ) + / 2, "extraction_parameters": extraction_params, }, )