@@ -290,31 +290,25 @@ def _from_dict(
290290 elif is_structure :
291291 props ["lattice" ] = [structure .lattice .matrix for structure in structures ]
292292
293- reordered_structs = [None ] * len (structures )
294- reordered_site_idxs = [None ] * len (structures )
295- order_changed = [None ] * len (structures )
296- for ion_step_idx , structure in enumerate (structures ):
297- (
298- reordered_structs [ion_step_idx ],
299- reordered_site_idxs [ion_step_idx ],
300- order_changed [ion_step_idx ],
301- ) = cls .reorder_sites (structure , props ["elements" ])
293+ reordered : list [tuple [Structure | Molecule , list [int ], bool ]] = [
294+ cls .reorder_sites (structure , props ["elements" ]) for structure in structures
295+ ]
302296
303297 # Ensure that coordinates and properties associated with sites have consistent ordering
304- props ["cart_coords" ] = [struct .cart_coords for struct in reordered_structs ]
298+ props ["cart_coords" ] = [entry [ 0 ] .cart_coords for entry in reordered ]
305299
306- if any (order_changed ):
300+ if any (entry [ 2 ] for entry in reordered ):
307301 for site_prop_key in {"magmoms" , "forces" }:
308302 if (site_prop_val := props .pop (site_prop_key , None )) or (
309303 site_prop_val := kwargs .pop (site_prop_key , None )
310304 ):
311305 props [site_prop_key ] = [
312306 (
313- [site_prop_val [ion_step_idx ][idx ] for idx in ordered_idxs ]
314- if order_changed [ ion_step_idx ]
307+ [site_prop_val [ion_step_idx ][idx ] for idx in entry [ 1 ] ]
308+ if entry [ 2 ]
315309 else site_prop_key [ion_step_idx ]
316310 )
317- for ion_step_idx , ordered_idxs in enumerate (reordered_site_idxs )
311+ for ion_step_idx , entry in enumerate (reordered )
318312 ]
319313
320314 if len (esteps := props .get ("electronic_steps" , [])) > 0 :
0 commit comments