Mercurial > repos > muon-spectroscopy-computational-project > larch_select_paths
annotate larch_select_paths.py @ 0:2e827836f0ad draft
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
author | muon-spectroscopy-computational-project |
---|---|
date | Tue, 14 Nov 2023 15:35:52 +0000 (17 months ago) |
parents | |
children | 7fdca938d90c |
rev | line source |
---|---|
0
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
1 import csv |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
2 import json |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
3 import os |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
4 import re |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
5 import sys |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
6 from zipfile import ZIP_DEFLATED, ZipFile |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
7 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
8 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
9 class GDSWriter: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
10 def __init__(self, default_variables: "dict[str, dict]"): |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
11 self.default_properties = { |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
12 "s02": {"name": "s02"}, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
13 "e0": {"name": "e0"}, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
14 "deltar": {"name": "alpha*reff"}, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
15 "sigma2": {"name": "sigma2"}, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
16 } |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
17 self.rows = [ |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
18 f"{'id':>4s}, {'name':>24s}, {'value':>5s}, {'expr':>4s}, " |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
19 f"{'vary':>4s}\n" |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
20 ] |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
21 self.names = set() |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
22 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
23 for property in self.default_properties: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
24 name = self.default_properties[property]["name"] |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
25 value = default_variables[property]["value"] |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
26 vary = default_variables[property]["vary"] |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
27 is_common = default_variables[property]["is_common"] |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
28 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
29 self.default_properties[property]["value"] = value |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
30 self.default_properties[property]["vary"] = vary |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
31 self.default_properties[property]["is_common"] = is_common |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
32 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
33 if is_common: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
34 self.append_gds(name=name, value=value, vary=vary) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
35 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
36 def append_gds( |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
37 self, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
38 name: str, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
39 value: float = 0., |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
40 expr: str = None, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
41 vary: bool = True, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
42 label: str = "", |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
43 ): |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
44 """Append a single GDS variable to the list of rows, later to be |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
45 written to file. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
46 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
47 Args: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
48 name (str): Name of the GDS variable. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
49 value (float, optional): Starting value for variable. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
50 Defaults to 0. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
51 expr (str, optional): Expression for setting the variable. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
52 Defaults to None. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
53 vary (bool, optional): Whether the variable is optimised during the |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
54 fit. Defaults to True. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
55 label (str, optional): Label to keep variables for different FEFF |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
56 directories distinct. Defaults to "". |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
57 """ |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
58 formatted_name = name if (label is None) else label + name |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
59 formatted_name = formatted_name.replace("*reff", "") |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
60 if not expr: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
61 expr = " " |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
62 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
63 if formatted_name in self.names: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
64 raise ValueError(f"{formatted_name} already used as variable name") |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
65 self.names.add(formatted_name) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
66 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
67 self.rows.append( |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
68 f"{len(self.rows):4d}, {formatted_name:>24s}, {str(value):>5s}, " |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
69 f"{expr:>4s}, {str(vary):>4s}\n" |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
70 ) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
71 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
72 def parse_gds( |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
73 self, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
74 property_name: str, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
75 variable_name: str = None, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
76 path_variable: dict = None, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
77 directory_label: str = None, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
78 path_label: str = None, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
79 ) -> str: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
80 """Parse and append a row defining a GDS variable for a particular |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
81 path. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
82 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
83 Args: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
84 property_name (str): The property to which the variable |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
85 corresponds. Should be a key in `self.default_properties`. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
86 variable_name (str, optional): Custom name for this variable. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
87 Defaults to None. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
88 path_variable (dict, optional): Dictionary defining the GDS |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
89 settings for this path's variable. Defaults to None. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
90 directory_label (str, optional): Label to indicate paths from a |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
91 separate directory. Defaults to None. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
92 path_label (str, optional): Label indicating the atoms involved in |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
93 this path. Defaults to None. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
94 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
95 Returns: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
96 str: Either `variable_name`, the name used as a default globally |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
97 for this `property_name`, or an automatically generated unique |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
98 name. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
99 """ |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
100 if variable_name: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
101 self.append_gds( |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
102 name=variable_name, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
103 value=path_variable["value"], |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
104 expr=path_variable["expr"], |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
105 vary=path_variable["vary"], |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
106 ) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
107 return variable_name |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
108 elif self.default_properties[property_name]["is_common"]: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
109 return self.default_properties[property_name]["name"] |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
110 else: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
111 auto_name = self.default_properties[property_name]["name"] |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
112 if directory_label: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
113 auto_name += f"_{directory_label}" |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
114 if path_label: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
115 auto_name += f"_{path_label.lower().replace('.', '')}" |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
116 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
117 self.append_gds( |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
118 name=auto_name, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
119 value=self.default_properties[property_name]["value"], |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
120 vary=self.default_properties[property_name]["vary"], |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
121 ) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
122 return auto_name |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
123 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
124 def write(self): |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
125 """Write GDS rows to file. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
126 """ |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
127 with open("gds.csv", "w") as out: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
128 out.writelines(self.rows) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
129 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
130 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
131 class PathsWriter: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
132 def __init__(self, default_variables: "dict[str, dict]"): |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
133 self.rows = [ |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
134 f"{'id':>4s}, {'filename':>24s}, {'label':>24s}, {'s02':>3s}, " |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
135 f"{'e0':>4s}, {'sigma2':>24s}, {'deltar':>10s}\n" |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
136 ] |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
137 self.gds_writer = GDSWriter(default_variables=default_variables) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
138 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
139 def parse_feff_output( |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
140 self, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
141 paths_file: str, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
142 selection: "dict[str, str|list]", |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
143 directory_label: str = "", |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
144 ): |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
145 """Parse selected paths from CSV summary and define GDS variables. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
146 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
147 Args: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
148 paths_file (str): CSV summary filename. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
149 selection (dict[str, str|list]): Dictionary indicating which paths |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
150 to select, and how to define their variables. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
151 directory_label (str, optional): Label to indicate paths from a |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
152 separate directory. Defaults to "". |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
153 """ |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
154 paths = selection["paths"] |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
155 path_values_ids = [path_value["id"] for path_value in paths] |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
156 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
157 with open(paths_file) as file: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
158 reader = csv.reader(file) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
159 for row in reader: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
160 id_match = re.search(r"\d+", row[0]) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
161 if id_match: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
162 path_id = int(id_match.group()) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
163 filename = row[0].strip() |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
164 path_label = row[-2].strip() |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
165 variables = {} |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
166 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
167 if path_id in path_values_ids: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
168 path_value = paths[path_values_ids.index(path_id)] |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
169 for property in self.gds_writer.default_properties: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
170 variables[property] = self.gds_writer.parse_gds( |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
171 property_name=property, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
172 variable_name=path_value[property]["name"], |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
173 path_variable=path_value[property], |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
174 directory_label=directory_label, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
175 path_label=path_label, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
176 ) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
177 self.parse_selected_path( |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
178 filename=filename, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
179 path_label=path_label, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
180 directory_label=directory_label, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
181 **variables, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
182 ) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
183 elif selection["selection"] == "all" or int(row[-1]): |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
184 path_value = None |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
185 for property in self.gds_writer.default_properties: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
186 variables[property] = self.gds_writer.parse_gds( |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
187 property_name=property, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
188 directory_label=directory_label, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
189 path_label=path_label, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
190 ) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
191 self.parse_selected_path( |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
192 filename=filename, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
193 path_label=path_label, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
194 directory_label=directory_label, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
195 **variables, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
196 ) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
197 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
198 def parse_selected_path( |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
199 self, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
200 filename: str, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
201 path_label: str, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
202 directory_label: str = "", |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
203 s02: str = "s02", |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
204 e0: str = "e0", |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
205 sigma2: str = "sigma2", |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
206 deltar: str = "alpha*reff", |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
207 ): |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
208 """Format and append row representing a selected FEFF path. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
209 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
210 Args: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
211 filename (str): Name of the underlying FEFF path file, without |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
212 parent directory. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
213 path_label (str): Label indicating the atoms involved in this path. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
214 directory_label (str, optional): Label to indicate paths from a |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
215 separate directory. Defaults to "". |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
216 s02 (str, optional): Electron screening factor variable name. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
217 Defaults to "s02". |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
218 e0 (str, optional): Energy shift variable name. Defaults to "e0". |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
219 sigma2 (str, optional): Mean squared displacement variable name. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
220 Defaults to "sigma2". |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
221 deltar (str, optional): Change in path length variable. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
222 Defaults to "alpha*reff". |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
223 """ |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
224 if directory_label: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
225 filename = os.path.join(directory_label, filename) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
226 label = f"{directory_label}.{path_label}" |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
227 else: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
228 filename = os.path.join("feff", filename) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
229 label = path_label |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
230 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
231 self.rows.append( |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
232 f"{len(self.rows):>4d}, {filename:>24s}, {label:>24s}, " |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
233 f"{s02:>3s}, {e0:>4s}, {sigma2:>24s}, {deltar:>10s}\n" |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
234 ) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
235 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
236 def write(self): |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
237 """Write selected path and GDS rows to file. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
238 """ |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
239 self.gds_writer.write() |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
240 with open("sp.csv", "w") as out: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
241 out.writelines(self.rows) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
242 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
243 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
244 def main(input_values: dict): |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
245 """Select paths and define GDS parameters. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
246 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
247 Args: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
248 input_values (dict): All input values from the Galaxy tool UI. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
249 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
250 Raises: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
251 ValueError: If a FEFF label is not unique. |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
252 """ |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
253 default_variables = input_values["variables"] |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
254 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
255 writer = PathsWriter(default_variables=default_variables) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
256 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
257 if len(input_values["feff_outputs"]) == 1: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
258 feff_output = input_values["feff_outputs"][0] |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
259 writer.parse_feff_output( |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
260 paths_file=feff_output["paths_file"], |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
261 selection=feff_output["selection"], |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
262 ) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
263 else: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
264 zfill_length = len(str(len(input_values["feff_outputs"]))) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
265 labels = set() |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
266 with ZipFile("merged.zip", "x", ZIP_DEFLATED) as zipfile_out: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
267 for i, feff_output in enumerate(input_values["feff_outputs"]): |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
268 label = feff_output.pop("label") or str(i + 1).zfill( |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
269 zfill_length |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
270 ) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
271 if label in labels: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
272 raise ValueError(f"Label '{label}' is not unique") |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
273 labels.add(label) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
274 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
275 writer.parse_feff_output( |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
276 directory_label=label, |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
277 paths_file=feff_output["paths_file"], |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
278 selection=feff_output["selection"], |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
279 ) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
280 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
281 with ZipFile(feff_output["paths_zip"]) as z: |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
282 for zipinfo in z.infolist(): |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
283 if zipinfo.filename != "feff/": |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
284 zipinfo.filename = zipinfo.filename[5:] |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
285 z.extract(member=zipinfo, path=label) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
286 zipfile_out.write( |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
287 os.path.join(label, zipinfo.filename) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
288 ) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
289 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
290 writer.write() |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
291 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
292 |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
293 if __name__ == "__main__": |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
294 input_values = json.load(open(sys.argv[1], "r", encoding="utf-8")) |
2e827836f0ad
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff
changeset
|
295 main(input_values) |