Skip to content

Commit bdb954f

Browse files
committed
Apply clipping to user initial model if not a cube
1 parent 24d6628 commit bdb954f

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/murfey/server/feedback.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,34 @@ def _resize_intial_model(
11511151
executables: Dict[str, str],
11521152
env: Dict[str, str],
11531153
) -> None:
1154+
with mrcfile.open(input_path) as input_mrc:
1155+
input_size_x = input_mrc.nx
1156+
input_size_y = input_mrc.ny
1157+
input_size_z = input_mrc.nz
1158+
if executables.get("clip") and not input_size_x == input_size_y == input_size_z:
1159+
# If the initial model is not a cube, do some padding
1160+
clip_proc = subprocess.run(
1161+
[
1162+
f"{executables['clip']}",
1163+
"resize",
1164+
"-ox",
1165+
str(max(input_size_x, input_size_y, input_size_z)),
1166+
"-oy",
1167+
str(max(input_size_x, input_size_y, input_size_z)),
1168+
"-oz",
1169+
str(max(input_size_x, input_size_y, input_size_z)),
1170+
str(input_path),
1171+
str(input_path.with_suffix("_cube.mrc")),
1172+
],
1173+
capture_output=True,
1174+
text=True,
1175+
env=env,
1176+
)
1177+
input_path = input_path.with_suffix("_cube.mrc")
1178+
if clip_proc.returncode:
1179+
logger.error(
1180+
f"Clipping initial model {input_path} failed \n {clip_proc.stdout}"
1181+
)
11541182
if executables.get("relion_image_handler"):
11551183
comp_proc = subprocess.run(
11561184
[
@@ -1168,6 +1196,9 @@ def _resize_intial_model(
11681196
text=True,
11691197
env=env,
11701198
)
1199+
logger.info(
1200+
f"Initial model rescaling finished with code {comp_proc.returncode}"
1201+
)
11711202
with mrcfile.open(output_path) as rescaled_mrc:
11721203
rescaled_mrc.header.cella = (
11731204
downscaled_pixel_size,
@@ -1223,7 +1254,7 @@ def _register_3d_batch(message: dict, _db, demo: bool = False):
12231254
if not rescaled_initial_model_path.is_file():
12241255
_resize_intial_model(
12251256
*_downscaled_box_size(
1226-
message["particle_diameter"],
1257+
relion_options["particle_diameter"],
12271258
relion_options["angpix"],
12281259
),
12291260
provided_initial_model,

0 commit comments

Comments
 (0)