comparison larch_select_paths.py @ 4:204c4afe2f1e draft default tip

planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 4814f53888643f1d3667789050914675fffb7d59
author muon-spectroscopy-computational-project
date Fri, 23 Aug 2024 14:10:59 +0000
parents 7fdca938d90c
children
comparison
equal deleted inserted replaced
3:1d08395c1a9f 4:204c4afe2f1e
56 56
57 57
58 class GDSWriter: 58 class GDSWriter:
59 def __init__(self, default_variables: "dict[str, dict]"): 59 def __init__(self, default_variables: "dict[str, dict]"):
60 self.default_properties = { 60 self.default_properties = {
61 "degen": {"name": "degen"},
61 "s02": {"name": "s02"}, 62 "s02": {"name": "s02"},
62 "e0": {"name": "e0"}, 63 "e0": {"name": "e0"},
63 "deltar": {"name": "alpha*reff"}, 64 "deltar": {"name": "alpha"},
64 "sigma2": {"name": "sigma2"}, 65 "sigma2": {"name": "sigma2"},
65 } 66 }
66 self.rows = [ 67 self.rows = [
67 f"{'id':>4s}, {'name':>24s}, {'value':>5s}, {'expr':>4s}, " 68 f"{'id':>4s}, {'name':>24s}, {'value':>5s}, {'expr':>4s}, "
68 f"{'vary':>4s}\n" 69 f"{'vary':>4s}\n"
111 112
112 if formatted_name in self.names: 113 if formatted_name in self.names:
113 raise ValueError(f"{formatted_name} already used as variable name") 114 raise ValueError(f"{formatted_name} already used as variable name")
114 self.names.add(formatted_name) 115 self.names.add(formatted_name)
115 116
117 if value is not None:
118 formatted_value = str(value)
119 else:
120 formatted_value = ""
121
116 self.rows.append( 122 self.rows.append(
117 f"{len(self.rows):4d}, {formatted_name:>24s}, {str(value):>5s}, " 123 f"{len(self.rows):4d}, {formatted_name:>24s}, "
118 f"{expr:>4s}, {str(vary):>4s}\n" 124 f"{formatted_value:>5s}, {expr:>4s}, {str(vary):>4s}\n"
119 ) 125 )
120 126
121 def parse_gds( 127 def parse_gds(
122 self, 128 self,
123 property_name: str, 129 property_name: str,
177 183
178 184
179 class PathsWriter: 185 class PathsWriter:
180 def __init__(self, default_variables: "dict[str, dict]"): 186 def __init__(self, default_variables: "dict[str, dict]"):
181 self.rows = [ 187 self.rows = [
182 f"{'id':>4s}, {'filename':>24s}, {'label':>24s}, {'s02':>3s}, " 188 f"{'id':>4s}, {'filename':>24s}, {'label':>24s}, {'degen':>5s}, "
183 f"{'e0':>4s}, {'sigma2':>24s}, {'deltar':>10s}\n" 189 f"{'s02':>3s}, {'e0':>4s}, {'sigma2':>24s}, {'deltar':>10s}\n"
184 ] 190 ]
185 self.gds_writer = GDSWriter(default_variables=default_variables) 191 self.gds_writer = GDSWriter(default_variables=default_variables)
186 self.all_combinations = [[0]] # 0 corresponds to the header row 192 self.all_combinations = [[0]] # 0 corresponds to the header row
187 193
188 def parse_feff_output( 194 def parse_feff_output(
321 def parse_selected_path( 327 def parse_selected_path(
322 self, 328 self,
323 filename: str, 329 filename: str,
324 path_label: str, 330 path_label: str,
325 directory_label: str = "", 331 directory_label: str = "",
332 degen: str = "degen",
326 s02: str = "s02", 333 s02: str = "s02",
327 e0: str = "e0", 334 e0: str = "e0",
328 sigma2: str = "sigma2", 335 sigma2: str = "sigma2",
329 deltar: str = "alpha*reff", 336 deltar: str = "alpha",
330 ) -> int: 337 ) -> int:
331 """Format and append row representing a selected FEFF path. 338 """Format and append row representing a selected FEFF path.
332 339
333 Args: 340 Args:
334 filename (str): Name of the underlying FEFF path file, without 341 filename (str): Name of the underlying FEFF path file, without
335 parent directory. 342 parent directory.
336 path_label (str): Label indicating the atoms involved in this path. 343 path_label (str): Label indicating the atoms involved in this path.
337 directory_label (str, optional): Label to indicate paths from a 344 directory_label (str, optional): Label to indicate paths from a
338 separate directory. Defaults to "". 345 separate directory. Defaults to "".
346 degen (str, optional): Path degeneracy variable name.
347 Defaults to "degen".
339 s02 (str, optional): Electron screening factor variable name. 348 s02 (str, optional): Electron screening factor variable name.
340 Defaults to "s02". 349 Defaults to "s02".
341 e0 (str, optional): Energy shift variable name. Defaults to "e0". 350 e0 (str, optional): Energy shift variable name. Defaults to "e0".
342 sigma2 (str, optional): Mean squared displacement variable name. 351 sigma2 (str, optional): Mean squared displacement variable name.
343 Defaults to "sigma2". 352 Defaults to "sigma2".
344 deltar (str, optional): Change in path length variable. 353 deltar (str, optional): Change in path length variable.
345 Defaults to "alpha*reff". 354 Defaults to "alpha".
346 355
347 Returns: 356 Returns:
348 int: The id of the added row. 357 int: The id of the added row.
349 """ 358 """
350 if directory_label: 359 if directory_label:
354 filename = os.path.join("feff", filename) 363 filename = os.path.join("feff", filename)
355 label = path_label 364 label = path_label
356 365
357 row_id = len(self.rows) 366 row_id = len(self.rows)
358 self.rows.append( 367 self.rows.append(
359 f"{row_id:>4d}, {filename:>24s}, {label:>24s}, " 368 f"{row_id:>4d}, {filename:>24s}, {label:>24s}, {degen:>5s}, "
360 f"{s02:>3s}, {e0:>4s}, {sigma2:>24s}, {deltar:>10s}\n" 369 f"{s02:>3s}, {e0:>4s}, {sigma2:>24s}, {deltar + '*reff':>10s}\n"
361 ) 370 )
362 371
363 return row_id 372 return row_id
364 373
365 def write(self): 374 def write(self):