From d227a3ec7a12525c6909ef83aa79404ac44f5320 Mon Sep 17 00:00:00 2001 From: yxd92326 Date: Fri, 27 Jun 2025 10:16:01 +0100 Subject: [PATCH 1/4] Insert tomogram search map locations into ispyb --- recipes/em-tomo-align.json | 5 ++++- src/cryoemservices/util/ispyb_commands.py | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/recipes/em-tomo-align.json b/recipes/em-tomo-align.json index 3886bf31..073206c9 100644 --- a/recipes/em-tomo-align.json +++ b/recipes/em-tomo-align.json @@ -5,7 +5,10 @@ "dcid": "{dcid}", "ispyb_command": "insert_tomogram", "program_id": "{appid}", - "store_result": "ispyb_tomogram_id" + "store_result": "ispyb_tomogram_id", + "x_location": "{x_location}", + "y_location": "{y_location}", + "grid_square_id": "{search_map_id}" }, "queue": "ispyb_connector", "service": "EMISPyB" diff --git a/src/cryoemservices/util/ispyb_commands.py b/src/cryoemservices/util/ispyb_commands.py index fd9a43ab..f2335ab9 100644 --- a/src/cryoemservices/util/ispyb_commands.py +++ b/src/cryoemservices/util/ispyb_commands.py @@ -616,6 +616,9 @@ def full_parameters(param): projXY=full_parameters("proj_xy"), projXZ=full_parameters("proj_xz"), globalAlignmentQuality=full_parameters("alignment_quality"), + gridSquareId=full_parameters("grid_square_id"), + pixelLocationX=full_parameters("pixel_location_x"), + pixelLocationY=full_parameters("pixel_location_y"), ) tomogram_row = ( session.query(models.Tomogram) From d076d62a834779f071765bb272ce6bd0b491282c Mon Sep 17 00:00:00 2001 From: yxd92326 Date: Thu, 3 Jul 2025 13:38:19 +0100 Subject: [PATCH 2/4] Update tests --- recipes/em-tomo-align.json | 4 +-- tests/util/test_ispyb_commands.py | 46 +++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/recipes/em-tomo-align.json b/recipes/em-tomo-align.json index 073206c9..d413ef34 100644 --- a/recipes/em-tomo-align.json +++ b/recipes/em-tomo-align.json @@ -6,8 +6,8 @@ "ispyb_command": "insert_tomogram", "program_id": "{appid}", "store_result": "ispyb_tomogram_id", - "x_location": "{x_location}", - "y_location": "{y_location}", + "pixel_location_x": "{x_location}", + "pixel_location_y": "{y_location}", "grid_square_id": "{search_map_id}" }, "queue": "ispyb_connector", diff --git a/tests/util/test_ispyb_commands.py b/tests/util/test_ispyb_commands.py index 6a8a5820..170df43f 100644 --- a/tests/util/test_ispyb_commands.py +++ b/tests/util/test_ispyb_commands.py @@ -51,6 +51,10 @@ def ispyb_parameters(p): assert ispyb_commands.buffer(commands, ispyb_parameters, mock.MagicMock()) is False +def raise_sql_error(mock_call): + raise SQLAlchemyError("Mock error") + + @mock.patch("cryoemservices.util.ispyb_commands.models") def test_insert_movie_id_notime(mock_models): def mock_movie_parameters(p): @@ -744,6 +748,9 @@ def mock_tomogram_parameters(p): "proj_xy": "/path/to/xy", "proj_xz": "/path/to/xz", "alignment_quality": 0.2, + "grid_square_id": 12345, + "pixel_location_x": 200, + "pixel_location_y": 400, } return tomogram_parameters[p] @@ -783,6 +790,9 @@ def mock_tomogram_parameters(p): projXY="/path/to/xy", projXZ="/path/to/xz", globalAlignmentQuality=0.2, + gridSquareId=12345, + pixelLocationX=200, + pixelLocationY=400, ) mock_session.add.assert_called() mock_session.commit.assert_called() @@ -812,6 +822,9 @@ def mock_tomogram_parameters(p): "proj_xy": "/path/to/xy", "proj_xz": "/path/to/xz", "alignment_quality": 0.2, + "grid_square_id": 12345, + "pixel_location_x": 200, + "pixel_location_y": 400, } return tomogram_parameters[p] @@ -852,12 +865,30 @@ def mock_tomogram_parameters(p): "projXY": "/path/to/xy", "projXZ": "/path/to/xz", "globalAlignmentQuality": 0.2, + "gridSquareId": 12345, + "pixelLocationX": 200, + "pixelLocationY": 400, } ) mock_session.add.assert_not_called() mock_session.commit.assert_called() +def test_insert_tomogram_failure(): + def mock_tomogram_parameters(p): + return None + + # Mock which returns an existing object + mock_session = mock.MagicMock() + mock_session.add.side_effect = raise_sql_error + + return_value = ispyb_commands.insert_tomogram( + {}, mock_tomogram_parameters, mock_session + ) + assert return_value is False + mock_session.add.assert_called() + + @mock.patch("cryoemservices.util.ispyb_commands.models") def test_insert_processed_tomogram(mock_models): def mock_tomogram_parameters(p): @@ -884,6 +915,21 @@ def mock_tomogram_parameters(p): mock_session.commit.assert_called() +def test_insert_processed_tomogram_failure(): + def mock_tomogram_parameters(p): + return None + + # Mock which returns an existing object + mock_session = mock.MagicMock() + mock_session.add.side_effect = raise_sql_error + + return_value = ispyb_commands.insert_processed_tomogram( + {}, mock_tomogram_parameters, mock_session + ) + assert return_value is False + mock_session.add.assert_called() + + @mock.patch("cryoemservices.util.ispyb_commands.models") def test_insert_tilts_has_movie(mock_models): def mock_tilt_parameters(p): From ae5d1ab7b2822398382eba4efb31b03ca2396b6d Mon Sep 17 00:00:00 2001 From: yxd92326 Date: Thu, 17 Jul 2025 14:54:44 +0100 Subject: [PATCH 3/4] Update ispyb version --- pyproject.toml | 2 +- tests/util/test_ispyb_commands.py | 34 ------------------------------- 2 files changed, 1 insertion(+), 35 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 169939d5..4d4c3799 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,7 +34,7 @@ dependencies = [ "graypy", "healpy", "icebreaker-em", - "ispyb>=11.0.3", + "ispyb>=11.0.5", "mrcfile", "numpy<2", "pillow", diff --git a/tests/util/test_ispyb_commands.py b/tests/util/test_ispyb_commands.py index 170df43f..50789a64 100644 --- a/tests/util/test_ispyb_commands.py +++ b/tests/util/test_ispyb_commands.py @@ -51,10 +51,6 @@ def ispyb_parameters(p): assert ispyb_commands.buffer(commands, ispyb_parameters, mock.MagicMock()) is False -def raise_sql_error(mock_call): - raise SQLAlchemyError("Mock error") - - @mock.patch("cryoemservices.util.ispyb_commands.models") def test_insert_movie_id_notime(mock_models): def mock_movie_parameters(p): @@ -874,21 +870,6 @@ def mock_tomogram_parameters(p): mock_session.commit.assert_called() -def test_insert_tomogram_failure(): - def mock_tomogram_parameters(p): - return None - - # Mock which returns an existing object - mock_session = mock.MagicMock() - mock_session.add.side_effect = raise_sql_error - - return_value = ispyb_commands.insert_tomogram( - {}, mock_tomogram_parameters, mock_session - ) - assert return_value is False - mock_session.add.assert_called() - - @mock.patch("cryoemservices.util.ispyb_commands.models") def test_insert_processed_tomogram(mock_models): def mock_tomogram_parameters(p): @@ -915,21 +896,6 @@ def mock_tomogram_parameters(p): mock_session.commit.assert_called() -def test_insert_processed_tomogram_failure(): - def mock_tomogram_parameters(p): - return None - - # Mock which returns an existing object - mock_session = mock.MagicMock() - mock_session.add.side_effect = raise_sql_error - - return_value = ispyb_commands.insert_processed_tomogram( - {}, mock_tomogram_parameters, mock_session - ) - assert return_value is False - mock_session.add.assert_called() - - @mock.patch("cryoemservices.util.ispyb_commands.models") def test_insert_tilts_has_movie(mock_models): def mock_tilt_parameters(p): From eb40cfb1a4f978c2df8579539029e1c371bd2fc5 Mon Sep 17 00:00:00 2001 From: yxd92326 Date: Thu, 17 Jul 2025 15:17:12 +0100 Subject: [PATCH 4/4] Fix ispyb test --- tests/recipes/test_recipes.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/recipes/test_recipes.py b/tests/recipes/test_recipes.py index 13f04427..0ffe4351 100644 --- a/tests/recipes/test_recipes.py +++ b/tests/recipes/test_recipes.py @@ -46,6 +46,9 @@ class ISPyBParameters(BaseModel): status: str store_result: str tomogram_id: int + grid_square_id: int + pixel_location_x: float + pixel_location_y: float class MurfeyParameters(BaseModel):