RATapi 0.0.0.dev16__cp315-cp315-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ratapi/__init__.py +42 -0
- ratapi/classlist.py +620 -0
- ratapi/controls.py +258 -0
- ratapi/eventManager.dll +0 -0
- ratapi/events.py +88 -0
- ratapi/examples/__init__.py +25 -0
- ratapi/examples/absorption/__init__.py +1 -0
- ratapi/examples/absorption/absorption.py +172 -0
- ratapi/examples/absorption/volume_thiol_bilayer.py +144 -0
- ratapi/examples/convert_rascal_project/Model_IIb.py +90 -0
- ratapi/examples/convert_rascal_project/__init__.py +1 -0
- ratapi/examples/convert_rascal_project/convert_rascal.py +49 -0
- ratapi/examples/data/D2O_spin_down.dat +100 -0
- ratapi/examples/data/D2O_spin_up.dat +101 -0
- ratapi/examples/data/DSPC_D2O.dat +82 -0
- ratapi/examples/data/DSPC_SMW.dat +82 -0
- ratapi/examples/data/H2O_spin_down.dat +102 -0
- ratapi/examples/data/H2O_spin_up.dat +102 -0
- ratapi/examples/data/__init__.py +1 -0
- ratapi/examples/data/c_PLP0016596.dat +146 -0
- ratapi/examples/data/c_PLP0016601.dat +97 -0
- ratapi/examples/data/c_PLP0016607.dat +104 -0
- ratapi/examples/data/d2o_background_data.dat +82 -0
- ratapi/examples/domains/__init__.py +1 -0
- ratapi/examples/domains/alloy_domains.py +34 -0
- ratapi/examples/domains/domains_XY_model.py +75 -0
- ratapi/examples/domains/domains_custom_XY.py +86 -0
- ratapi/examples/domains/domains_custom_layers.py +60 -0
- ratapi/examples/domains/domains_standard_layers.py +92 -0
- ratapi/examples/languages/__init__.py +1 -0
- ratapi/examples/languages/custom_bilayer.py +72 -0
- ratapi/examples/languages/run_custom_file_languages.py +41 -0
- ratapi/examples/languages/setup_problem.py +130 -0
- ratapi/examples/normal_reflectivity/DSPC_custom_XY.py +149 -0
- ratapi/examples/normal_reflectivity/DSPC_custom_layers.py +130 -0
- ratapi/examples/normal_reflectivity/DSPC_data_background.py +220 -0
- ratapi/examples/normal_reflectivity/DSPC_function_background.py +219 -0
- ratapi/examples/normal_reflectivity/DSPC_standard_layers.py +210 -0
- ratapi/examples/normal_reflectivity/__init__.py +1 -0
- ratapi/examples/normal_reflectivity/background_function.py +16 -0
- ratapi/examples/normal_reflectivity/custom_XY_DSPC.py +141 -0
- ratapi/examples/normal_reflectivity/custom_bilayer_DSPC.py +89 -0
- ratapi/inputs.py +603 -0
- ratapi/models.py +717 -0
- ratapi/outputs.py +821 -0
- ratapi/project.py +1091 -0
- ratapi/rat_core.cp315-win_amd64.pyd +0 -0
- ratapi/run.py +142 -0
- ratapi/utils/__init__.py +1 -0
- ratapi/utils/convert.py +597 -0
- ratapi/utils/custom_errors.py +40 -0
- ratapi/utils/enums.py +203 -0
- ratapi/utils/matlab.py +254 -0
- ratapi/utils/orso.py +247 -0
- ratapi/utils/plotting.py +1316 -0
- ratapi/wrappers.py +147 -0
- ratapi-0.0.0.dev16.dist-info/DELVEWHEEL +2 -0
- ratapi-0.0.0.dev16.dist-info/METADATA +61 -0
- ratapi-0.0.0.dev16.dist-info/RECORD +63 -0
- ratapi-0.0.0.dev16.dist-info/WHEEL +5 -0
- ratapi-0.0.0.dev16.dist-info/top_level.txt +1 -0
- ratapi.libs/msvcp140-a4c2229bdc2a2a630acdc095b4d86008.dll +0 -0
- ratapi.libs/vcomp140-f96f3a14d88d8846f31f3ab38a490304.dll +0 -0
|
Binary file
|
ratapi/run.py
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"""The function used to run a RAT algorithm for a given project and controls."""
|
|
2
|
+
|
|
3
|
+
import time
|
|
4
|
+
|
|
5
|
+
from tqdm.auto import tqdm
|
|
6
|
+
|
|
7
|
+
import ratapi.rat_core
|
|
8
|
+
from ratapi.inputs import make_input
|
|
9
|
+
from ratapi.outputs import make_results
|
|
10
|
+
from ratapi.utils.enums import Display
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ProgressBar:
|
|
14
|
+
"""Create a progress bar that gets updates from the progress event during a calculation.
|
|
15
|
+
|
|
16
|
+
Parameters
|
|
17
|
+
----------
|
|
18
|
+
display : bool, default True
|
|
19
|
+
Indicates if displaying is allowed
|
|
20
|
+
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
def __init__(self, display=True):
|
|
24
|
+
self.pbar = None
|
|
25
|
+
self.display = display
|
|
26
|
+
self.tqdm_kwargs = {"total": 100, "desc": "", "bar_format": "{l_bar}{bar}", "disable": not self.display}
|
|
27
|
+
# Determine if the auto tqdm is standard or notebook
|
|
28
|
+
from tqdm.asyncio import tqdm as asyncio_tqdm
|
|
29
|
+
|
|
30
|
+
if tqdm == asyncio_tqdm:
|
|
31
|
+
self.tqdm_kwargs.update({"ncols": 90})
|
|
32
|
+
|
|
33
|
+
def __enter__(self):
|
|
34
|
+
if self.display:
|
|
35
|
+
ratapi.events.register(ratapi.events.EventTypes.Progress, self.updateProgress)
|
|
36
|
+
|
|
37
|
+
return self
|
|
38
|
+
|
|
39
|
+
def updateProgress(self, event):
|
|
40
|
+
"""Update the progress bar with progress event data.
|
|
41
|
+
|
|
42
|
+
Parameters
|
|
43
|
+
----------
|
|
44
|
+
event: ProgressEventData
|
|
45
|
+
The progress event data.
|
|
46
|
+
|
|
47
|
+
"""
|
|
48
|
+
if self.pbar is None:
|
|
49
|
+
self.pbar = tqdm(**self.tqdm_kwargs)
|
|
50
|
+
value = event.percent * 100
|
|
51
|
+
self.pbar.desc = event.message
|
|
52
|
+
self.pbar.update(value - self.pbar.n)
|
|
53
|
+
|
|
54
|
+
def __exit__(self, _exc_type, _exc_val, _traceback):
|
|
55
|
+
if self.pbar is not None:
|
|
56
|
+
self.pbar.close()
|
|
57
|
+
print("") # Print new line after bar
|
|
58
|
+
|
|
59
|
+
if self.display:
|
|
60
|
+
ratapi.events.clear(ratapi.events.EventTypes.Progress, self.updateProgress)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class TextOutput:
|
|
64
|
+
"""Context manager to pipe message events to stdout.
|
|
65
|
+
|
|
66
|
+
Parameters
|
|
67
|
+
----------
|
|
68
|
+
display : bool, default: True
|
|
69
|
+
Indicates if displaying is allowed
|
|
70
|
+
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
def __init__(self, display=True):
|
|
74
|
+
self.display = display
|
|
75
|
+
|
|
76
|
+
def __enter__(self):
|
|
77
|
+
if self.display:
|
|
78
|
+
ratapi.events.register(ratapi.events.EventTypes.Message, self.printMessage)
|
|
79
|
+
|
|
80
|
+
return self
|
|
81
|
+
|
|
82
|
+
def printMessage(self, msg):
|
|
83
|
+
"""Print an event message.
|
|
84
|
+
|
|
85
|
+
Parameters
|
|
86
|
+
----------
|
|
87
|
+
msg: str
|
|
88
|
+
The event message.
|
|
89
|
+
|
|
90
|
+
"""
|
|
91
|
+
print(msg, end="")
|
|
92
|
+
|
|
93
|
+
def __exit__(self, _exc_type, _exc_val, _traceback):
|
|
94
|
+
if self.display:
|
|
95
|
+
ratapi.events.clear(ratapi.events.EventTypes.Message, self.printMessage)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def run(project, controls):
|
|
99
|
+
"""Run RAT for the given project and controls inputs."""
|
|
100
|
+
parameter_field = {
|
|
101
|
+
"parameters": "params",
|
|
102
|
+
"bulk_in": "bulkIns",
|
|
103
|
+
"bulk_out": "bulkOuts",
|
|
104
|
+
"scalefactors": "scalefactors",
|
|
105
|
+
"domain_ratios": "domainRatios",
|
|
106
|
+
"background_parameters": "backgroundParams",
|
|
107
|
+
"resolution_parameters": "resolutionParams",
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
horizontal_line = "\u2500" * 107 + "\n"
|
|
111
|
+
display_on = controls.display != Display.Off
|
|
112
|
+
problem_definition, cpp_controls = make_input(project, controls)
|
|
113
|
+
|
|
114
|
+
if display_on:
|
|
115
|
+
print("Starting RAT " + horizontal_line)
|
|
116
|
+
|
|
117
|
+
start = time.time()
|
|
118
|
+
with ProgressBar(display=display_on), TextOutput(display=display_on):
|
|
119
|
+
problem_definition, output_results, bayes_results = ratapi.rat_core.RATMain(
|
|
120
|
+
problem_definition,
|
|
121
|
+
cpp_controls,
|
|
122
|
+
)
|
|
123
|
+
end = time.time()
|
|
124
|
+
|
|
125
|
+
if display_on:
|
|
126
|
+
print(f"Elapsed time is {end - start:.3f} seconds\n")
|
|
127
|
+
|
|
128
|
+
results = make_results(controls.procedure, output_results, bayes_results)
|
|
129
|
+
|
|
130
|
+
# Update parameter values in project
|
|
131
|
+
for class_list in ratapi.project.parameter_class_lists:
|
|
132
|
+
for index, value in enumerate(getattr(problem_definition, parameter_field[class_list])):
|
|
133
|
+
param = getattr(project, class_list)[index]
|
|
134
|
+
param.fit = bool(getattr(problem_definition.checks, parameter_field[class_list])[index])
|
|
135
|
+
param.value = value
|
|
136
|
+
|
|
137
|
+
controls.delete_IPC()
|
|
138
|
+
|
|
139
|
+
if display_on:
|
|
140
|
+
print("Finished RAT " + horizontal_line)
|
|
141
|
+
|
|
142
|
+
return project, results
|
ratapi/utils/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Additional utilities for ratapi."""
|