annotate larch_select_paths.py @ 1:7fdca938d90c draft

planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
author muon-spectroscopy-computational-project
date Wed, 06 Dec 2023 13:04:15 +0000 (16 months ago)
parents 2e827836f0ad
children 204c4afe2f1e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
1
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
6 from itertools import combinations
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
7 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
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
1
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
10 class CriteriaSelector:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
11 def __init__(self, criteria: "dict[str, int|float]"):
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
12 self.max_number = criteria["max_number"]
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
13 self.max_path_length = criteria["max_path_length"]
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
14 self.min_amp_ratio = criteria["min_amplitude_ratio"]
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
15 self.max_degeneracy = criteria["max_degeneracy"]
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
16 self.path_count = 0
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
17
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
18 def evaluate(self, path_id: int, row: "list[str]") -> (bool, None):
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
19 if self.max_number and self.path_count >= self.max_number:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
20 print(f"Reject path: {self.max_number} paths already reached")
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
21 return (False, None)
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
22
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
23 r_effective = float(row[5].strip())
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
24 if self.max_path_length and r_effective > self.max_path_length:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
25 print(f"Reject path: {r_effective} > {self.max_path_length}")
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
26 return (False, None)
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
27
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
28 amplitude_ratio = float(row[2].strip())
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
29 if self.min_amp_ratio and (amplitude_ratio < self.min_amp_ratio):
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
30 print(f"Reject path: {amplitude_ratio} < {self.min_amp_ratio}")
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
31 return (False, None)
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
32
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
33 degeneracy = float(row[3].strip())
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
34 if self.max_degeneracy and degeneracy > self.max_degeneracy:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
35 print(f"Reject path: {degeneracy} > {self.max_degeneracy}")
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
36 return (False, None)
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
37
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
38 self.path_count += 1
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
39 return (True, None)
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
40
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
41
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
42 class ManualSelector:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
43 def __init__(self, selection: dict):
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
44 self.select_all = selection["selection"] == "all"
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
45 self.paths = selection["paths"]
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
46 self.path_values_ids = [path_value["id"] for path_value in self.paths]
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
47
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
48 def evaluate(self, path_id: int, row: "list[str]") -> (bool, "None|dict"):
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
49 if path_id in self.path_values_ids:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
50 return (True, self.paths[self.path_values_ids.index(path_id)])
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
51
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
52 if self.select_all or int(row[-1]):
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
53 return (True, None)
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
54
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
55 return (False, None)
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
56
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
57
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
58 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
59 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
60 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
61 "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
62 "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
63 "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
64 "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
65 }
2e827836f0ad 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 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
67 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
68 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
69 ]
2e827836f0ad 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 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
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 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
73 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
74 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
75 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
76 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
77
2e827836f0ad 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 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
79 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
80 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
81
2e827836f0ad 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 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
83 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
84
2e827836f0ad 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 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
86 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
87 name: str,
1
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
88 value: float = 0.0,
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
89 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
90 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
91 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
92 ):
2e827836f0ad 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 """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
94 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
95
2e827836f0ad 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 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
97 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
98 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
99 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
100 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
101 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
102 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
103 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
104 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
105 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
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 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
108 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
109 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
110 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
111
2e827836f0ad 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 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
113 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
114 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
115
2e827836f0ad 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 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
117 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
118 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
119 )
2e827836f0ad 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
2e827836f0ad 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 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
122 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
123 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
124 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
125 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
126 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
127 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
128 ) -> 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
129 """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
130 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
131
2e827836f0ad 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 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
133 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
134 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
135 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
136 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
137 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
138 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
139 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
140 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
141 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
142 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
143
2e827836f0ad 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 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
145 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
146 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
147 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
148 """
2e827836f0ad 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 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
150 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
151 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
152 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
153 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
154 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
155 )
2e827836f0ad 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 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
157 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
158 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
159 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
160 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
161 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
162 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
163 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
164 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
165
2e827836f0ad 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 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
167 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
168 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
169 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
170 )
2e827836f0ad 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 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
172
2e827836f0ad 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 def write(self):
1
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
174 """Write GDS rows to file."""
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
175 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
176 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
177
2e827836f0ad 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
2e827836f0ad 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 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
180 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
181 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
182 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
183 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
184 ]
2e827836f0ad 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 self.gds_writer = GDSWriter(default_variables=default_variables)
1
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
186 self.all_combinations = [[0]] # 0 corresponds to the header 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
187
2e827836f0ad 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 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
189 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
190 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
191 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
192 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
193 ):
2e827836f0ad 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 """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
195
2e827836f0ad 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 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
197 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
198 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
199 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
200 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
201 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
202 """
1
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
203 combinations_list = []
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
204 if selection["selection"] in {"criteria", "combinations"}:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
205 selector = CriteriaSelector(selection)
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
206 else:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
207 selector = ManualSelector(selection)
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
208
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
209 selected_ids = self.select_rows(paths_file, directory_label, selector)
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
210
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
211 if selection["selection"] == "combinations":
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
212 min_number = selection["min_combination_size"]
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
213 min_number = min(min_number, len(selected_ids))
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
214 max_number = selection["max_combination_size"]
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
215 if not max_number or max_number > len(selected_ids):
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
216 max_number = len(selected_ids)
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
217
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
218 for number_of_paths in range(min_number, max_number + 1):
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
219 for combination in combinations(selected_ids, number_of_paths):
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
220 combinations_list.append(combination)
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
221
1
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
222 new_combinations = len(combinations_list)
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
223 print(
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
224 f"{new_combinations} combinations for {directory_label}:\n"
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
225 f"{combinations_list}"
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
226 )
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
227 old_combinations_len = len(self.all_combinations)
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
228 self.all_combinations *= new_combinations
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
229 for i, combination in enumerate(self.all_combinations):
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
230 new_combinations = combinations_list[i // old_combinations_len]
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
231 self.all_combinations[i] = combination + list(new_combinations)
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
232 else:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
233 for combination in self.all_combinations:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
234 combination.extend(selected_ids)
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
235
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
236 def select_rows(
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
237 self,
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
238 paths_file: str,
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
239 directory_label: str,
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
240 selector: "CriteriaSelector|ManualSelector",
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
241 ) -> "list[int]":
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
242 """Evaluate each row in turn to decide whether or not it should be
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
243 included in the final output. Does not account for combinations.
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
244
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
245 Args:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
246 paths_file (str): CSV summary filename.
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
247 directory_label (str): Label to indicate paths from a separate
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
248 directory.
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
249 selector (CriteriaSelector|ManualSelector): Object to evaluate
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
250 whether to select each path or not.
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
251
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
252 Returns:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
253 list[int]: The ids of the selected rows.
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
254 """
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
255 row_ids = []
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
256 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
257 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
258 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
259 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
260 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
261 path_id = int(id_match.group())
1
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
262 selected, path_value = selector.evaluate(
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
263 path_id=path_id,
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
264 row=row,
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
265 )
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
266 if selected:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
267 filename = row[0].strip()
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
268 path_label = row[-2].strip()
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
269 row_id = self.parse_row(
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
270 directory_label, filename, path_label, path_value
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
271 )
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
272 row_ids.append(row_id)
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
273
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
274 return row_ids
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
275
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
276 def parse_row(
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
277 self,
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
278 directory_label: str,
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
279 filename: str,
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
280 path_label: str,
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
281 path_value: "None|dict",
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
282 ) -> int:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
283 """Parse row for GDS and path information.
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
284
1
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
285 Args:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
286 directory_label (str): Label to indicate paths from a separate
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
287 directory.
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
288 filename (str): Filename for the FEFF path, extracted from row.
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
289 path_label (str): Label for the FEFF path, extracted from row.
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
290 path_value (None|dict): The values associated with the selected
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
291 FEFF path. May be None in which case defaults are used.
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
292
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
293 Returns:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
294 int: The id of the added row.
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
295 """
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
296 variables = {}
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
297 if path_value is not None:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
298 for property in self.gds_writer.default_properties:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
299 variables[property] = self.gds_writer.parse_gds(
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
300 property_name=property,
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
301 variable_name=path_value[property]["name"],
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
302 path_variable=path_value[property],
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
303 directory_label=directory_label,
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
304 path_label=path_label,
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
305 )
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
306 else:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
307 for property in self.gds_writer.default_properties:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
308 variables[property] = self.gds_writer.parse_gds(
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
309 property_name=property,
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
310 directory_label=directory_label,
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
311 path_label=path_label,
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
312 )
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
313
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
314 return self.parse_selected_path(
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
315 filename=filename,
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
316 path_label=path_label,
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
317 directory_label=directory_label,
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
318 **variables,
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
319 )
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
320
2e827836f0ad planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
321 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
322 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
323 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
324 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
325 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
326 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
327 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
328 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
329 deltar: str = "alpha*reff",
1
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
330 ) -> int:
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
331 """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
332
2e827836f0ad planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
333 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
334 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
335 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
336 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
337 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
338 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
339 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
340 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
341 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
342 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
343 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
344 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
345 Defaults to "alpha*reff".
1
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
346
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
347 Returns:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
348 int: The id of the added 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
349 """
2e827836f0ad planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
350 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
351 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
352 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
353 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
354 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
355 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
356
1
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
357 row_id = len(self.rows)
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
358 self.rows.append(
1
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
359 f"{row_id:>4d}, {filename:>24s}, {label:>24s}, "
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
360 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
361 )
2e827836f0ad planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
362
1
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
363 return row_id
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
364
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
365 def write(self):
1
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
366 """Write selected path and GDS rows to file."""
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
367 self.gds_writer.write()
1
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
368
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
369 if len(self.all_combinations) == 1:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
370 with open("sp.csv", "w") as out:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
371 out.writelines(self.rows)
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
372 else:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
373 for combination in self.all_combinations:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
374 filename = "_".join([str(c) for c in combination[1:]])
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
375 print(f"Writing combination {filename}")
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
376 with open(f"sp/{filename}.csv", "w") as out:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
377 for row_id, row in enumerate(self.rows):
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
378 if row_id in combination:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
379 out.write(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
380
2e827836f0ad planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
381
2e827836f0ad planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
382 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
383 """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
384
2e827836f0ad planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
385 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
386 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
387
2e827836f0ad planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
388 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
389 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
390 """
2e827836f0ad planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
391 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
392
2e827836f0ad planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
393 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
394
2e827836f0ad planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
395 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
396 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
397 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
398 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
399 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
400 )
2e827836f0ad planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
401 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
402 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
403 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
404 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
405 for i, feff_output in enumerate(input_values["feff_outputs"]):
1
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
406 label = feff_output["label"]
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
407 if not label:
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
408 label = str(i + 1).zfill(zfill_length)
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
409 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
410 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
411 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
412
2e827836f0ad planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
413 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
414 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
415 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
416 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
417 )
2e827836f0ad planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
418
2e827836f0ad planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
419 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
420 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
421 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
422 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
423 z.extract(member=zipinfo, path=label)
1
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
424 filename = os.path.join(label, zipinfo.filename)
7fdca938d90c planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
muon-spectroscopy-computational-project
parents: 0
diff changeset
425 zipfile_out.write(filename)
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
426
2e827836f0ad planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
427 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
428
2e827836f0ad planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
429
2e827836f0ad planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_select_paths commit 5be486890442dedfb327289d597e1c8110240735
muon-spectroscopy-computational-project
parents:
diff changeset
430 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
431 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
432 main(input_values)