@@ -123,17 +123,21 @@ def read_mslice(path: MSliceFile) -> AtomCell:
123123 return AtomCell (atoms , cell , frame = 'cell_frac' )
124124
125125
126- def write_mslice (cell : HasAtomCell , f : BinaryFileOrPath , template : t .Optional [MSliceFile ] = None , * ,
127- slice_thickness : t .Optional [float ] = None , # angstrom
128- scan_points : t .Optional [ArrayLike ] = None ,
129- scan_extent : t .Optional [ArrayLike ] = None ,
130- noise_sigma : t .Optional [float ] = None , # angstrom
131- conv_angle : t .Optional [float ] = None , # mrad
132- energy : t .Optional [float ] = None , # keV
133- defocus : t .Optional [float ] = None , # angstrom
134- tilt : t .Optional [t .Tuple [float , float ]] = None , # (mrad, mrad)
135- tds : t .Optional [bool ] = None ,
136- n_cells : t .Optional [ArrayLike ] = None ):
126+ def write_mslice (
127+ cell : HasAtomCell , f : BinaryFileOrPath , template : t .Optional [MSliceFile ] = None , * ,
128+ slice_thickness : t .Optional [float ] = None , # angstrom
129+ scan_points : t .Optional [ArrayLike ] = None ,
130+ scan_extent : t .Optional [ArrayLike ] = None ,
131+ noise_sigma : t .Optional [float ] = None , # angstrom
132+ conv_angle : t .Optional [float ] = None , # mrad
133+ energy : t .Optional [float ] = None , # keV
134+ defocus : t .Optional [float ] = None , # angstrom
135+ c3 : t .Optional [float ] = None , # mm
136+ source_size : t .Optional [float ] = None , # angstrom
137+ tilt : t .Optional [t .Tuple [float , float ]] = None , # (mrad, mrad)
138+ tds : t .Optional [bool ] = None ,
139+ n_cells : t .Optional [ArrayLike ] = None
140+ ):
137141 """
138142 Write a structure to an mslice file. The structure must be orthogonal and aligned
139143 with the local coordinate system. It should be periodic in X and Y.
@@ -232,6 +236,8 @@ def parse_xml_object(obj: Element) -> t.Dict[str, t.Any]:
232236 set_attr (params , 'slicethickness' , 'float' , f"{ float (slice_thickness ):.8g} " )
233237 if tds is not None :
234238 set_attr (params , 'includetds' , 'bool' , str (int (bool (tds ))))
239+ if source_size is not None :
240+ set_attr (params , 'sourceSize' , 'float' , f"{ float (source_size ):.8g} " ) # angstrom
235241 if conv_angle is not None :
236242 set_attr (microscope , 'aperture' , 'float' , f"{ float (conv_angle ):.8g} " )
237243 if energy is not None :
@@ -251,6 +257,16 @@ def parse_xml_object(obj: Element) -> t.Dict[str, t.Any]:
251257 else :
252258 raise ValueError ("Couldn't find defocus aberration to modify." )
253259
260+ if c3 is not None :
261+ for aberration in aberrations :
262+ obj = parse_xml_object (aberration )
263+ if obj ['n' ] == 3 and obj ['m' ] == 0 :
264+ set_attr (aberration , 'cnma' , 'float' , f"{ float (c3 ):.8g} " ) # mm
265+ set_attr (aberration , 'cnmb' , 'float' , "0.0" )
266+ break
267+ else :
268+ raise ValueError ("Couldn't find spherical aberration to modify." )
269+
254270 if scan_points is not None :
255271 (nx , ny ) = numpy .broadcast_to (scan_points , 2 ,).astype (int )
256272 if scan is not None :
0 commit comments