22
22
23
23
from typing_extensions import Self
24
24
25
+ from pymatgen .alchemy .filters import AbstractStructureFilter
26
+
25
27
__author__ = "Shyue Ping Ong, Will Richards"
26
28
__copyright__ = "Copyright 2012, The Materials Project"
27
29
__version__ = "0.1"
@@ -40,7 +42,7 @@ class StandardTransmuter:
40
42
41
43
def __init__ (
42
44
self ,
43
- transformed_structures ,
45
+ transformed_structures : list [ TransformedStructure ] ,
44
46
transformations = None ,
45
47
extend_collection : int = 0 ,
46
48
ncores : int | None = None ,
@@ -130,8 +132,8 @@ def append_transformation(self, transformation, extend_collection=False, clear_r
130
132
for x in self .transformed_structures :
131
133
new = x .append_transformation (transformation , extend_collection , clear_redo = clear_redo )
132
134
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
135
137
136
138
def extend_transformations (self , transformations ):
137
139
"""Extend a sequence of transformations to the TransformedStructure.
@@ -142,18 +144,16 @@ def extend_transformations(self, transformations):
142
144
for trafo in transformations :
143
145
self .append_transformation (trafo )
144
146
145
- def apply_filter (self , structure_filter ):
147
+ def apply_filter (self , structure_filter : AbstractStructureFilter ):
146
148
"""Apply a structure_filter to the list of TransformedStructures
147
149
in the transmuter.
148
150
149
151
Args:
150
152
structure_filter: StructureFilter to apply.
151
153
"""
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
+ )
157
157
for ts in self .transformed_structures :
158
158
ts .append_filter (structure_filter )
159
159
@@ -174,8 +174,8 @@ def set_parameter(self, key, value):
174
174
key: The key for the parameter.
175
175
value: The value for the parameter.
176
176
"""
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
179
179
180
180
def add_tags (self , tags ):
181
181
"""Add tags for the structures generated by the transmuter.
@@ -196,11 +196,11 @@ def append_transformed_structures(self, trafo_structs_or_transmuter):
196
196
transmuter.
197
197
"""
198
198
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
200
200
else :
201
201
for ts in trafo_structs_or_transmuter :
202
202
assert isinstance (ts , TransformedStructure )
203
- self .transformed_structures . extend ( trafo_structs_or_transmuter )
203
+ self .transformed_structures += trafo_structs_or_transmuter
204
204
205
205
@classmethod
206
206
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)
219
219
Returns:
220
220
StandardTransmuter
221
221
"""
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 )
224
224
225
225
226
226
class CifTransmuter (StandardTransmuter ):
@@ -253,8 +253,8 @@ def __init__(self, cif_string, transformations=None, primitive=True, extend_coll
253
253
if read_data :
254
254
structure_data [- 1 ].append (line )
255
255
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 )
258
258
super ().__init__ (transformed_structures , transformations , extend_collection )
259
259
260
260
@classmethod
@@ -293,8 +293,8 @@ def __init__(self, poscar_string, transformations=None, extend_collection=False)
293
293
extend_collection: Whether to use more than one output structure
294
294
from one-to-many transformations.
295
295
"""
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 )
298
298
299
299
@classmethod
300
300
def from_filenames (cls , poscar_filenames , transformations = None , extend_collection = False ) -> StandardTransmuter :
@@ -373,7 +373,7 @@ def _apply_transformation(inputs):
373
373
"""
374
374
ts , transformation , extend_collection , clear_redo = inputs
375
375
new = ts .append_transformation (transformation , extend_collection , clear_redo = clear_redo )
376
- o = [ts ]
376
+ out = [ts ]
377
377
if new :
378
- o . extend ( new )
379
- return o
378
+ out += new
379
+ return out
0 commit comments