1515 RelionServiceOptions ,
1616 update_relion_options ,
1717)
18- from cryoemservices .util .tomo_output_files import _get_tilt_name_v5_12
18+ from cryoemservices .util .tomo_output_files import (
19+ _get_tilt_name_v5_12 ,
20+ _get_tilt_number_v5_12 ,
21+ )
1922
2023
2124class ExtractSubTomoParameters (BaseModel ):
@@ -25,6 +28,7 @@ class ExtractSubTomoParameters(BaseModel):
2528 output_star : str = Field (..., min_length = 1 )
2629 scaled_tomogram_shape : list [int ] | str
2730 pixel_size : float
31+ dose_per_tilt : float
2832 particle_diameter : float = 0
2933 boxsize : int = 256
3034 small_boxsize : int = 64
@@ -194,19 +198,28 @@ def extract_subtomo(self, rw, header: dict, message: dict):
194198 # Read in tilt images
195199 self .log .info ("Reading tilt images" )
196200 tilt_images = []
201+ tilt_numbers = []
197202 with open (extract_subtomo_params .newstack_file ) as ns_file :
198203 while True :
199204 line = ns_file .readline ()
200205 if not line :
201206 break
202207 elif line .startswith ("/" ):
203208 tilt_name = line .strip ()
209+ tilt_numbers .append (_get_tilt_number_v5_12 (Path (tilt_name )))
204210 with mrcfile .open (tilt_name ) as mrc :
205211 tilt_images .append (mrc .data )
206212
213+ frames = np .zeros ((len (particles_x ), tilt_count ), dtype = int )
207214 for particle in range (len (particles_x )):
208215 output_mrc_stack = np .array ([])
209216 for tilt in range (tilt_count ):
217+ if (
218+ extract_subtomo_params .dose_per_tilt * tilt_numbers [tilt ]
219+ < extract_subtomo_params .maximum_dose
220+ ):
221+ continue
222+
210223 # Extract the particle image and pad the edges if it is not square
211224 x_left_pad = 0
212225 x_right_pad = 0
@@ -307,6 +320,7 @@ def extract_subtomo(self, rw, header: dict, message: dict):
307320 )
308321 else :
309322 output_mrc_stack = np .array ([particle_subimage ], dtype = np .float32 )
323+ frames [particle , tilt ] = 1
310324
311325 if not len (output_mrc_stack ):
312326 self .log .warning (f"Could not extract particle { particle } " )
@@ -333,22 +347,32 @@ def extract_subtomo(self, rw, header: dict, message: dict):
333347 extracted_parts_loop = extracted_parts_block .init_loop (
334348 "_rln" ,
335349 [
336- "CenteredCoordinateXAngst" ,
337- "CenteredCoordinateYAngst" ,
338- "CenteredCoordinateZAngst" ,
350+ "TomoName" ,
339351 "OpticsGroup" ,
340352 "TomoParticleName" ,
341353 "TomoVisibleFrames" ,
342354 "ImageName" ,
343355 "OriginXAngst" ,
344356 "OriginYAngst" ,
345357 "OriginZAngst" ,
358+ "CenteredCoordinateXAngst" ,
359+ "CenteredCoordinateYAngst" ,
360+ "CenteredCoordinateZAngst" ,
346361 ],
347362 )
348- frames = "?????"
349363 for particle in range (len (particles_x )):
350364 extracted_parts_loop .add_row (
351365 [
366+ _get_tilt_name_v5_12 (
367+ Path (extract_subtomo_params .tilt_alignment_file )
368+ ),
369+ "1" ,
370+ f"{ _get_tilt_name_v5_12 (Path (extract_subtomo_params .tilt_alignment_file ))} /{ particle } " ,
371+ f"[{ frames [particle ]} ]" ,
372+ f"{ Path (extract_subtomo_params .output_star ).parent } /{ particle } _stack2d.mrcs" ,
373+ "0.0" ,
374+ "0.0" ,
375+ "0.0" ,
352376 str (
353377 float (particles_x [particle ])
354378 - float (extract_subtomo_params .scaled_tomogram_shape [2 ])
@@ -367,13 +391,6 @@ def extract_subtomo(self, rw, header: dict, message: dict):
367391 / 2
368392 * extract_subtomo_params .tomogram_binning
369393 ),
370- "1" ,
371- f"{ _get_tilt_name_v5_12 (Path (extract_subtomo_params .tilt_alignment_file ))} /{ particle } " ,
372- f"[{ frames } ]" ,
373- f"{ Path (extract_subtomo_params .output_star ).parent } /{ particle } _stack2d.mrcs" ,
374- "0.0" ,
375- "0.0" ,
376- "0.0" ,
377394 ]
378395 )
379396 extracted_parts_doc .write_file (
0 commit comments