2222
2323 from typing_extensions import Self
2424
25+ from pymatgen .alchemy .filters import AbstractStructureFilter
26+
2527__author__ = "Shyue Ping Ong, Will Richards"
2628__copyright__ = "Copyright 2012, The Materials Project"
2729__version__ = "0.1"
@@ -40,7 +42,7 @@ class StandardTransmuter:
4042
4143 def __init__ (
4244 self ,
43- transformed_structures ,
45+ transformed_structures : list [ TransformedStructure ] ,
4446 transformations = None ,
4547 extend_collection : int = 0 ,
4648 ncores : int | None = None ,
@@ -130,8 +132,8 @@ def append_transformation(self, transformation, extend_collection=False, clear_r
130132 for x in self .transformed_structures :
131133 new = x .append_transformation (transformation , extend_collection , clear_redo = clear_redo )
132134 if new is not None :
133- new_structures . extend ( new )
134- self .transformed_structures . extend ( new_structures )
135+ new_structures += new
136+ self .transformed_structures += new_structures
135137
136138 def extend_transformations (self , transformations ):
137139 """Extend a sequence of transformations to the TransformedStructure.
@@ -142,18 +144,16 @@ def extend_transformations(self, transformations):
142144 for trafo in transformations :
143145 self .append_transformation (trafo )
144146
145- def apply_filter (self , structure_filter ):
147+ def apply_filter (self , structure_filter : AbstractStructureFilter ):
146148 """Apply a structure_filter to the list of TransformedStructures
147149 in the transmuter.
148150
149151 Args:
150152 structure_filter: StructureFilter to apply.
151153 """
152-
153- def test_transformed_structure (ts ):
154- return structure_filter .test (ts .final_structure )
155-
156- self .transformed_structures = list (filter (test_transformed_structure , self .transformed_structures ))
154+ self .transformed_structures = list (
155+ filter (lambda ts : structure_filter .test (ts .final_structure ), self .transformed_structures )
156+ )
157157 for ts in self .transformed_structures :
158158 ts .append_filter (structure_filter )
159159
@@ -174,8 +174,8 @@ def set_parameter(self, key, value):
174174 key: The key for the parameter.
175175 value: The value for the parameter.
176176 """
177- for x in self .transformed_structures :
178- x .other_parameters [key ] = value
177+ for struct in self .transformed_structures :
178+ struct .other_parameters [key ] = value
179179
180180 def add_tags (self , tags ):
181181 """Add tags for the structures generated by the transmuter.
@@ -196,11 +196,11 @@ def append_transformed_structures(self, trafo_structs_or_transmuter):
196196 transmuter.
197197 """
198198 if isinstance (trafo_structs_or_transmuter , self .__class__ ):
199- self .transformed_structures . extend ( trafo_structs_or_transmuter .transformed_structures )
199+ self .transformed_structures += trafo_structs_or_transmuter .transformed_structures
200200 else :
201201 for ts in trafo_structs_or_transmuter :
202202 assert isinstance (ts , TransformedStructure )
203- self .transformed_structures . extend ( trafo_structs_or_transmuter )
203+ self .transformed_structures += trafo_structs_or_transmuter
204204
205205 @classmethod
206206 def from_structures (cls , structures , transformations = None , extend_collection = 0 ) -> Self :
@@ -219,8 +219,8 @@ def from_structures(cls, structures, transformations=None, extend_collection=0)
219219 Returns:
220220 StandardTransmuter
221221 """
222- trafo_struct = [TransformedStructure (s , []) for s in structures ]
223- return cls (trafo_struct , transformations , extend_collection )
222+ t_struct = [TransformedStructure (s , []) for s in structures ]
223+ return cls (t_struct , transformations , extend_collection )
224224
225225
226226class CifTransmuter (StandardTransmuter ):
@@ -253,8 +253,8 @@ def __init__(self, cif_string, transformations=None, primitive=True, extend_coll
253253 if read_data :
254254 structure_data [- 1 ].append (line )
255255 for data in structure_data :
256- trafo_struct = TransformedStructure .from_cif_str ("\n " .join (data ), [], primitive )
257- transformed_structures .append (trafo_struct )
256+ t_struct = TransformedStructure .from_cif_str ("\n " .join (data ), [], primitive )
257+ transformed_structures .append (t_struct )
258258 super ().__init__ (transformed_structures , transformations , extend_collection )
259259
260260 @classmethod
@@ -293,8 +293,8 @@ def __init__(self, poscar_string, transformations=None, extend_collection=False)
293293 extend_collection: Whether to use more than one output structure
294294 from one-to-many transformations.
295295 """
296- trafo_struct = TransformedStructure .from_poscar_str (poscar_string , [])
297- super ().__init__ ([trafo_struct ], transformations , extend_collection = extend_collection )
296+ t_struct = TransformedStructure .from_poscar_str (poscar_string , [])
297+ super ().__init__ ([t_struct ], transformations , extend_collection = extend_collection )
298298
299299 @classmethod
300300 def from_filenames (cls , poscar_filenames , transformations = None , extend_collection = False ) -> StandardTransmuter :
@@ -373,7 +373,7 @@ def _apply_transformation(inputs):
373373 """
374374 ts , transformation , extend_collection , clear_redo = inputs
375375 new = ts .append_transformation (transformation , extend_collection , clear_redo = clear_redo )
376- o = [ts ]
376+ out = [ts ]
377377 if new :
378- o . extend ( new )
379- return o
378+ out += new
379+ return out
0 commit comments