Skip to content

Commit

Permalink
MotionCorr drift plot now shows individual frame shifts
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-riggs committed Oct 20, 2023
1 parent e311558 commit 179ba33
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 20 deletions.
12 changes: 1 addition & 11 deletions src/relion/zocalo/motioncorr.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ class MotionCorr(CommonService):
# Values to extract for ISPyB
x_shift_list = []
y_shift_list = []
each_total_motion = []

def initializing(self):
"""Subscribe to a queue. Received messages must be acknowledged."""
Expand All @@ -122,9 +121,6 @@ def parse_mc_output(self, mc_stdout: str):
line_split = line.split()
self.x_shift_list.append(float(line_split[-2]))
self.y_shift_list.append(float(line_split[-1]))
self.each_total_motion.append(
hypot(float(line_split[-2]), float(line_split[-1]))
)

# Alternative frame reading for MotionCorr 1.6.3
if not line:
Expand All @@ -133,9 +129,6 @@ def parse_mc_output(self, mc_stdout: str):
line_split = line.split()
self.x_shift_list.append(float(line_split[1]))
self.y_shift_list.append(float(line_split[2]))
self.each_total_motion.append(
hypot(float(line_split[1]), float(line_split[2]))
)
if "x Shift" in line:
frames_line = True

Expand Down Expand Up @@ -306,9 +299,7 @@ def dummy(self, *args, **kwargs):
average_motion_per_frame = total_motion / len(self.x_shift_list)

# Extract results for ispyb
drift_plot_x = [range(0, len(self.x_shift_list))]
drift_plot_y = self.each_total_motion
fig = px.scatter(x=drift_plot_x, y=drift_plot_y)
fig = px.scatter(x=self.x_shift_list, y=self.y_shift_list)
drift_plot_name = str(Path(mc_params.movie).stem) + "_drift_plot.json"
plot_path = Path(mc_params.mrc_out).parent / drift_plot_name
snapshot_path = Path(mc_params.mrc_out).with_suffix(".jpeg")
Expand Down Expand Up @@ -541,4 +532,3 @@ def dummy(self, *args, **kwargs):
rw.transport.ack(header)
self.x_shift_list = []
self.y_shift_list = []
self.each_total_motion = []
9 changes: 1 addition & 8 deletions src/relion/zocalo/motioncorr_wilson.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import subprocess
import time
from collections import ChainMap
from math import hypot
from pathlib import Path

import yaml
Expand Down Expand Up @@ -83,9 +82,6 @@ def parse_mc_output(self, mc_output_file):
line_split = line.split()
self.x_shift_list.append(float(line_split[-2]))
self.y_shift_list.append(float(line_split[-1]))
self.each_total_motion.append(
hypot(float(line_split[-2]), float(line_split[-1]))
)

# Alternative frame reading for MotionCorr 1.6.3
if not line:
Expand All @@ -94,9 +90,6 @@ def parse_mc_output(self, mc_output_file):
line_split = line.split()
self.x_shift_list.append(float(line_split[1]))
self.y_shift_list.append(float(line_split[2]))
self.each_total_motion.append(
hypot(float(line_split[1]), float(line_split[2]))
)
if "x Shift" in line:
frames_line = True

Expand Down Expand Up @@ -238,7 +231,7 @@ def motioncor2(self, command: list, mrc_out: Path):
stderr = f"Reading MotionCor output file {mc_output_file} failed"
slurm_job_state = "FAILED"

if self.x_shift_list and self.y_shift_list and self.each_total_motion:
if self.x_shift_list and self.y_shift_list:
Path(mc_output_file).unlink()
Path(mc_error_file).unlink()
Path(submission_file).unlink()
Expand Down
1 change: 0 additions & 1 deletion tests/zocalo/test_motioncorr_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,4 +485,3 @@ def test_parse_motioncorr_output(mock_environment, offline_transport):
)
assert service.x_shift_list == [-3.0, 3.0]
assert service.y_shift_list == [4.0, -4.0]
assert service.each_total_motion == [5.0, 5.0]

0 comments on commit 179ba33

Please sign in to comment.