RATapi 0.0.0.dev0__cp310-cp310-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 +8 -0
- RATapi/classlist.py +387 -0
- RATapi/controls.py +143 -0
- RATapi/eventManager.dll +0 -0
- RATapi/events.py +70 -0
- RATapi/examples/__init__.py +0 -0
- RATapi/examples/absorption/__init__.py +0 -0
- RATapi/examples/absorption/absorption.py +148 -0
- RATapi/examples/absorption/volume_thiol_bilayer.py +138 -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 +0 -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/domains/__init__.py +0 -0
- RATapi/examples/domains/alloy_domains.py +26 -0
- RATapi/examples/domains/domains_XY_model.py +70 -0
- RATapi/examples/domains/domains_custom_XY.py +69 -0
- RATapi/examples/domains/domains_custom_layers.py +46 -0
- RATapi/examples/domains/domains_standard_layers.py +75 -0
- RATapi/examples/languages/__init__.py +0 -0
- RATapi/examples/languages/custom_bilayer.py +66 -0
- RATapi/examples/languages/run_custom_file_languages.py +41 -0
- RATapi/examples/languages/setup_problem.py +130 -0
- RATapi/examples/non_polarised/DSPC_custom_XY.py +140 -0
- RATapi/examples/non_polarised/DSPC_custom_layers.py +121 -0
- RATapi/examples/non_polarised/DSPC_standard_layers.py +358 -0
- RATapi/examples/non_polarised/__init__.py +0 -0
- RATapi/examples/non_polarised/custom_XY_DSPC.py +137 -0
- RATapi/examples/non_polarised/custom_bilayer_DSPC.py +85 -0
- RATapi/inputs.py +471 -0
- RATapi/models.py +288 -0
- RATapi/outputs.py +218 -0
- RATapi/project.py +659 -0
- RATapi/rat_core.cp310-win_amd64.pyd +0 -0
- RATapi/run.py +35 -0
- RATapi/utils/__init__.py +0 -0
- RATapi/utils/custom_errors.py +42 -0
- RATapi/utils/enums.py +101 -0
- RATapi/utils/plotting.py +211 -0
- RATapi/wrappers.py +115 -0
- RATapi-0.0.0.dev0.dist-info/METADATA +57 -0
- RATapi-0.0.0.dev0.dist-info/RECORD +64 -0
- RATapi-0.0.0.dev0.dist-info/WHEEL +5 -0
- RATapi-0.0.0.dev0.dist-info/top_level.txt +2 -0
- tests/__init__.py +0 -0
- tests/conftest.py +4728 -0
- tests/test_classlist.py +882 -0
- tests/test_controls.py +863 -0
- tests/test_custom_errors.py +49 -0
- tests/test_events.py +61 -0
- tests/test_inputs.py +908 -0
- tests/test_models.py +308 -0
- tests/test_outputs.py +31 -0
- tests/test_plotting.py +167 -0
- tests/test_project.py +1387 -0
- tests/test_run.py +570 -0
- tests/test_wrappers.py +57 -0
- tests/utils.py +171 -0
RATapi/run.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import RATapi.rat_core
|
|
2
|
+
from RATapi.inputs import make_input
|
|
3
|
+
from RATapi.outputs import make_results
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def run(project, controls):
|
|
7
|
+
"""Run RAT for the given project and controls inputs."""
|
|
8
|
+
parameter_field = {
|
|
9
|
+
"parameters": "params",
|
|
10
|
+
"bulk_in": "bulkIn",
|
|
11
|
+
"bulk_out": "bulkOut",
|
|
12
|
+
"scalefactors": "scalefactors",
|
|
13
|
+
"domain_ratios": "domainRatio",
|
|
14
|
+
"background_parameters": "backgroundParams",
|
|
15
|
+
"resolution_parameters": "resolutionParams",
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
problem_definition, cells, limits, priors, cpp_controls = make_input(project, controls)
|
|
19
|
+
|
|
20
|
+
problem_definition, output_results, bayes_results = RATapi.rat_core.RATMain(
|
|
21
|
+
problem_definition,
|
|
22
|
+
cells,
|
|
23
|
+
limits,
|
|
24
|
+
cpp_controls,
|
|
25
|
+
priors,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
results = make_results(controls.procedure, output_results, bayes_results)
|
|
29
|
+
|
|
30
|
+
# Update parameter values in project
|
|
31
|
+
for class_list in RATapi.project.parameter_class_lists:
|
|
32
|
+
for index, value in enumerate(getattr(problem_definition, parameter_field[class_list])):
|
|
33
|
+
getattr(project, class_list)[index].value = value
|
|
34
|
+
|
|
35
|
+
return project, results
|
RATapi/utils/__init__.py
ADDED
|
File without changes
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Defines routines for custom error handling in RAT."""
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
import pydantic_core
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def custom_pydantic_validation_error(
|
|
9
|
+
error_list: list[pydantic_core.ErrorDetails],
|
|
10
|
+
custom_error_msgs: Optional[dict[str, str]] = None,
|
|
11
|
+
) -> list[pydantic_core.ErrorDetails]:
|
|
12
|
+
"""Run through the list of errors generated from a pydantic ValidationError, substituting the standard error for a
|
|
13
|
+
PydanticCustomError for a given set of error types.
|
|
14
|
+
|
|
15
|
+
For errors that do not have a custom error message defined, we redefine them using a PydanticCustomError to remove
|
|
16
|
+
the url from the error message.
|
|
17
|
+
|
|
18
|
+
Parameters
|
|
19
|
+
----------
|
|
20
|
+
error_list : list[pydantic_core.ErrorDetails]
|
|
21
|
+
A list of errors produced by pydantic.ValidationError.errors().
|
|
22
|
+
custom_error_msgs: dict[str, str], optional
|
|
23
|
+
A dict of custom error messages for given error types.
|
|
24
|
+
|
|
25
|
+
Returns
|
|
26
|
+
-------
|
|
27
|
+
new_error : list[pydantic_core.ErrorDetails]
|
|
28
|
+
A list of errors including PydanticCustomErrors in place of the error types in custom_errors.
|
|
29
|
+
|
|
30
|
+
"""
|
|
31
|
+
if custom_error_msgs is None:
|
|
32
|
+
custom_error_msgs = {}
|
|
33
|
+
custom_error_list = []
|
|
34
|
+
for error in error_list:
|
|
35
|
+
if error["type"] in custom_error_msgs:
|
|
36
|
+
custom_error = pydantic_core.PydanticCustomError(error["type"], custom_error_msgs[error["type"]])
|
|
37
|
+
else:
|
|
38
|
+
custom_error = pydantic_core.PydanticCustomError(error["type"], error["msg"])
|
|
39
|
+
error["type"] = custom_error
|
|
40
|
+
custom_error_list.append(error)
|
|
41
|
+
|
|
42
|
+
return custom_error_list
|
RATapi/utils/enums.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
try:
|
|
4
|
+
from enum import StrEnum
|
|
5
|
+
except ImportError:
|
|
6
|
+
from strenum import StrEnum
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# Controls
|
|
10
|
+
class Parallel(StrEnum):
|
|
11
|
+
"""Defines the available options for parallelization"""
|
|
12
|
+
|
|
13
|
+
Single = "single"
|
|
14
|
+
Points = "points"
|
|
15
|
+
Contrasts = "contrasts"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class Procedures(StrEnum):
|
|
19
|
+
"""Defines the available options for procedures"""
|
|
20
|
+
|
|
21
|
+
Calculate = "calculate"
|
|
22
|
+
Simplex = "simplex"
|
|
23
|
+
DE = "de"
|
|
24
|
+
NS = "ns"
|
|
25
|
+
Dream = "dream"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class Display(StrEnum):
|
|
29
|
+
"""Defines the available options for display"""
|
|
30
|
+
|
|
31
|
+
Off = "off"
|
|
32
|
+
Iter = "iter"
|
|
33
|
+
Notify = "notify"
|
|
34
|
+
Final = "final"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class BoundHandling(StrEnum):
|
|
38
|
+
"""Defines the available options for bound handling"""
|
|
39
|
+
|
|
40
|
+
Off = "off"
|
|
41
|
+
Reflect = "reflect"
|
|
42
|
+
Bound = "bound"
|
|
43
|
+
Fold = "fold"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class Strategies(Enum):
|
|
47
|
+
"""Defines the available options for strategies"""
|
|
48
|
+
|
|
49
|
+
Random = 1
|
|
50
|
+
LocalToBest = 2
|
|
51
|
+
BestWithJitter = 3
|
|
52
|
+
RandomWithPerVectorDither = 4
|
|
53
|
+
RandomWithPerGenerationDither = 5
|
|
54
|
+
RandomEitherOrAlgorithm = 6
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
# Models
|
|
58
|
+
class Hydration(StrEnum):
|
|
59
|
+
None_ = "none"
|
|
60
|
+
BulkIn = "bulk in"
|
|
61
|
+
BulkOut = "bulk out"
|
|
62
|
+
Oil = "oil"
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class Languages(StrEnum):
|
|
66
|
+
Cpp = "cpp"
|
|
67
|
+
Python = "python"
|
|
68
|
+
Matlab = "matlab"
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class Priors(StrEnum):
|
|
72
|
+
Uniform = "uniform"
|
|
73
|
+
Gaussian = "gaussian"
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class TypeOptions(StrEnum):
|
|
77
|
+
Constant = "constant"
|
|
78
|
+
Data = "data"
|
|
79
|
+
Function = "function"
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class BackgroundActions(StrEnum):
|
|
83
|
+
Add = "add"
|
|
84
|
+
Subtract = "subtract"
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
# Project
|
|
88
|
+
class Calculations(StrEnum):
|
|
89
|
+
NonPolarised = "non polarised"
|
|
90
|
+
Domains = "domains"
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class Geometries(StrEnum):
|
|
94
|
+
AirSubstrate = "air/substrate"
|
|
95
|
+
SubstrateLiquid = "substrate/liquid"
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class LayerModels(StrEnum):
|
|
99
|
+
CustomLayers = "custom layers"
|
|
100
|
+
CustomXY = "custom xy"
|
|
101
|
+
StandardLayers = "standard layers"
|
RATapi/utils/plotting.py
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"""Plots using the matplotlib library"""
|
|
2
|
+
|
|
3
|
+
from typing import Optional, Union
|
|
4
|
+
|
|
5
|
+
import matplotlib.pyplot as plt
|
|
6
|
+
import numpy as np
|
|
7
|
+
from matplotlib.axes._axes import Axes
|
|
8
|
+
|
|
9
|
+
import RATapi
|
|
10
|
+
import RATapi.inputs
|
|
11
|
+
import RATapi.outputs
|
|
12
|
+
from RATapi.rat_core import PlotEventData, makeSLDProfileXY
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Figure:
|
|
16
|
+
"""Creates a plotting figure."""
|
|
17
|
+
|
|
18
|
+
def __init__(self, row: int = 1, col: int = 1):
|
|
19
|
+
"""Initializes the figure and the subplots.
|
|
20
|
+
|
|
21
|
+
Parameters
|
|
22
|
+
----------
|
|
23
|
+
row : int, default: 1
|
|
24
|
+
The number of rows in subplot
|
|
25
|
+
col : int, default: 1
|
|
26
|
+
The number of columns in subplot
|
|
27
|
+
|
|
28
|
+
"""
|
|
29
|
+
self._fig, self._ax = plt.subplots(row, col, num="Reflectivity Algorithms Toolbox (RAT)")
|
|
30
|
+
plt.show(block=False)
|
|
31
|
+
self._esc_pressed = False
|
|
32
|
+
self._close_clicked = False
|
|
33
|
+
self._fig.canvas.mpl_connect("key_press_event", self._process_button_press)
|
|
34
|
+
self._fig.canvas.mpl_connect("close_event", self._close)
|
|
35
|
+
|
|
36
|
+
def wait_for_close(self):
|
|
37
|
+
"""Waits for the user to close the figure
|
|
38
|
+
using the esc key.
|
|
39
|
+
"""
|
|
40
|
+
while not (self._esc_pressed or self._close_clicked):
|
|
41
|
+
plt.waitforbuttonpress(timeout=0.005)
|
|
42
|
+
plt.close(self._fig)
|
|
43
|
+
|
|
44
|
+
def _process_button_press(self, event):
|
|
45
|
+
"""Process the key_press_event."""
|
|
46
|
+
if event.key == "escape":
|
|
47
|
+
self._esc_pressed = True
|
|
48
|
+
|
|
49
|
+
def _close(self, _):
|
|
50
|
+
"""Process the close_event."""
|
|
51
|
+
self._close_clicked = True
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def plot_errorbars(ax: Axes, x: np.ndarray, y: np.ndarray, err: np.ndarray, one_sided: bool, color: str):
|
|
55
|
+
"""Plots the error bars.
|
|
56
|
+
|
|
57
|
+
Parameters
|
|
58
|
+
----------
|
|
59
|
+
ax : matplotlib.axes._axes.Axes
|
|
60
|
+
The axis on which to draw errorbars
|
|
61
|
+
x : np.ndarray
|
|
62
|
+
The shifted data x axis data
|
|
63
|
+
y : np.ndarray
|
|
64
|
+
The shifted data y axis data
|
|
65
|
+
err : np.ndarray
|
|
66
|
+
The shifted data e data
|
|
67
|
+
one_sided : bool
|
|
68
|
+
A boolean to indicate whether to draw one sided errorbars
|
|
69
|
+
color : str
|
|
70
|
+
The hex representing the color of the errorbars
|
|
71
|
+
|
|
72
|
+
"""
|
|
73
|
+
y_error = [[0] * len(err), err] if one_sided else err
|
|
74
|
+
ax.errorbar(x=x, y=y, yerr=y_error, fmt="none", ecolor=color, elinewidth=1, capsize=0)
|
|
75
|
+
ax.scatter(x=x, y=y, s=3, marker="o", color=color)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def plot_ref_sld_helper(data: PlotEventData, fig: Optional[Figure] = None, delay: bool = True):
|
|
79
|
+
"""Clears the previous plots and updates the ref and SLD plots.
|
|
80
|
+
|
|
81
|
+
Parameters
|
|
82
|
+
----------
|
|
83
|
+
data : PlotEventData
|
|
84
|
+
The plot event data that contains all the information
|
|
85
|
+
to generate the ref and sld plots
|
|
86
|
+
fig : Figure, optional
|
|
87
|
+
The figure class that has two subplots
|
|
88
|
+
delay : bool, default: True
|
|
89
|
+
Controls whether to delay 0.005s after plot is created
|
|
90
|
+
|
|
91
|
+
Returns
|
|
92
|
+
-------
|
|
93
|
+
fig : Figure
|
|
94
|
+
The figure class that has two subplots
|
|
95
|
+
|
|
96
|
+
"""
|
|
97
|
+
if fig is None:
|
|
98
|
+
fig = Figure(1, 2)
|
|
99
|
+
elif fig._ax.shape != (2,):
|
|
100
|
+
fig._fig.clf()
|
|
101
|
+
fig._ax = fig._fig.subplots(1, 2)
|
|
102
|
+
|
|
103
|
+
ref_plot = fig._ax[0]
|
|
104
|
+
sld_plot = fig._ax[1]
|
|
105
|
+
|
|
106
|
+
# Clears the previous plots
|
|
107
|
+
ref_plot.cla()
|
|
108
|
+
sld_plot.cla()
|
|
109
|
+
|
|
110
|
+
for i, (r, sd, sld, layer) in enumerate(
|
|
111
|
+
zip(data.reflectivity, data.shiftedData, data.sldProfiles, data.resampledLayers),
|
|
112
|
+
):
|
|
113
|
+
# Calculate the divisor
|
|
114
|
+
div = 1 if i == 0 else 2 ** (4 * (i + 1))
|
|
115
|
+
|
|
116
|
+
# Plot the reflectivity on plot (1,1)
|
|
117
|
+
ref_plot.plot(r[:, 0], r[:, 1] / div, label=f"ref {i+1}", linewidth=2)
|
|
118
|
+
color = ref_plot.get_lines()[-1].get_color()
|
|
119
|
+
|
|
120
|
+
if data.dataPresent[i]:
|
|
121
|
+
sd_x = sd[:, 0]
|
|
122
|
+
sd_y, sd_e = map(lambda x: x / div, (sd[:, 1], sd[:, 2]))
|
|
123
|
+
|
|
124
|
+
# Plot the errorbars
|
|
125
|
+
indices_removed = np.flip(np.nonzero(sd_y - sd_e < 0)[0])
|
|
126
|
+
sd_x_r, sd_y_r, sd_e_r = map(lambda x: np.delete(x, indices_removed), (sd_x, sd_y, sd_e))
|
|
127
|
+
plot_errorbars(ref_plot, sd_x_r, sd_y_r, sd_e_r, False, color)
|
|
128
|
+
|
|
129
|
+
# Plot one sided errorbars
|
|
130
|
+
indices_selected = [x for x in indices_removed if x not in np.nonzero(sd_y < 0)[0]]
|
|
131
|
+
sd_x_s, sd_y_s, sd_e_s = map(lambda x: [x[i] for i in indices_selected], (sd_x, sd_y, sd_e))
|
|
132
|
+
plot_errorbars(ref_plot, sd_x_s, sd_y_s, sd_e_s, True, color)
|
|
133
|
+
|
|
134
|
+
# Plot the slds on plot (1,2)
|
|
135
|
+
for j in range(len(sld)):
|
|
136
|
+
sld_plot.plot(sld[j][:, 0], sld[j][:, 1], label=f"sld {i+1}", linewidth=1)
|
|
137
|
+
|
|
138
|
+
if data.resample[i] == 1 or data.modelType == "custom xy":
|
|
139
|
+
layers = data.resampledLayers[i][0]
|
|
140
|
+
for j in range(len(data.resampledLayers[i])):
|
|
141
|
+
layer = data.resampledLayers[i][j]
|
|
142
|
+
if layers.shape[1] == 4:
|
|
143
|
+
layer = np.delete(layer, 2, 1)
|
|
144
|
+
new_profile = makeSLDProfileXY(
|
|
145
|
+
layers[0, 1], # Bulk In
|
|
146
|
+
layers[-1, 1], # Bulk Out
|
|
147
|
+
data.subRoughs[i], # roughness
|
|
148
|
+
layer,
|
|
149
|
+
len(layer),
|
|
150
|
+
1.0,
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
sld_plot.plot(
|
|
154
|
+
[row[0] - 49 for row in new_profile],
|
|
155
|
+
[row[1] for row in new_profile],
|
|
156
|
+
color=color,
|
|
157
|
+
linewidth=1,
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
# Format the axis
|
|
161
|
+
ref_plot.set_yscale("log")
|
|
162
|
+
ref_plot.set_xscale("log")
|
|
163
|
+
ref_plot.set_xlabel("Qz")
|
|
164
|
+
ref_plot.set_ylabel("Ref")
|
|
165
|
+
ref_plot.legend()
|
|
166
|
+
ref_plot.grid()
|
|
167
|
+
|
|
168
|
+
sld_plot.set_xlabel("Z")
|
|
169
|
+
sld_plot.set_ylabel("SLD")
|
|
170
|
+
sld_plot.legend()
|
|
171
|
+
sld_plot.grid()
|
|
172
|
+
|
|
173
|
+
if delay:
|
|
174
|
+
plt.pause(0.005)
|
|
175
|
+
|
|
176
|
+
return fig
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def plot_ref_sld(
|
|
180
|
+
project: RATapi.Project,
|
|
181
|
+
results: Union[RATapi.outputs.Results, RATapi.outputs.BayesResults],
|
|
182
|
+
block: bool = False,
|
|
183
|
+
):
|
|
184
|
+
"""Plots the reflectivity and SLD profiles.
|
|
185
|
+
|
|
186
|
+
Parameters
|
|
187
|
+
----------
|
|
188
|
+
project : Project
|
|
189
|
+
An instance of the Project class
|
|
190
|
+
results : Union[Results, BayesResults]
|
|
191
|
+
The result from the calculation
|
|
192
|
+
block : bool, default: False
|
|
193
|
+
Indicates the plot should block until it is closed
|
|
194
|
+
|
|
195
|
+
"""
|
|
196
|
+
data = PlotEventData()
|
|
197
|
+
|
|
198
|
+
data.modelType = project.model
|
|
199
|
+
data.reflectivity = results.reflectivity
|
|
200
|
+
data.shiftedData = results.shiftedData
|
|
201
|
+
data.sldProfiles = results.sldProfiles
|
|
202
|
+
data.resampledLayers = results.resampledLayers
|
|
203
|
+
data.dataPresent = RATapi.inputs.make_data_present(project)
|
|
204
|
+
data.subRoughs = results.contrastParams.subRoughs
|
|
205
|
+
data.resample = RATapi.inputs.make_resample(project)
|
|
206
|
+
|
|
207
|
+
figure = Figure(1, 2)
|
|
208
|
+
|
|
209
|
+
plot_ref_sld_helper(data, figure)
|
|
210
|
+
if block:
|
|
211
|
+
figure.wait_for_close()
|
RATapi/wrappers.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import pathlib
|
|
2
|
+
from contextlib import suppress
|
|
3
|
+
from typing import Callable, Tuple
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
from numpy.typing import ArrayLike
|
|
7
|
+
|
|
8
|
+
import RATapi.rat_core
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def start_matlab():
|
|
12
|
+
"""Starts MATLAB asynchronously and returns a future to retrieve the engine later
|
|
13
|
+
|
|
14
|
+
Returns
|
|
15
|
+
-------
|
|
16
|
+
future : matlab.engine.futureresult.FutureResult
|
|
17
|
+
A future used to get the actual matlab engine
|
|
18
|
+
|
|
19
|
+
"""
|
|
20
|
+
future = None
|
|
21
|
+
with suppress(ImportError):
|
|
22
|
+
import matlab.engine
|
|
23
|
+
|
|
24
|
+
future = matlab.engine.start_matlab(background=True)
|
|
25
|
+
|
|
26
|
+
return future
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class MatlabWrapper:
|
|
30
|
+
"""Creates a python callback for a MATLAB function.
|
|
31
|
+
|
|
32
|
+
Parameters
|
|
33
|
+
----------
|
|
34
|
+
filename : string
|
|
35
|
+
The path of the file containing MATLAB function
|
|
36
|
+
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
loader = start_matlab()
|
|
40
|
+
|
|
41
|
+
def __init__(self, filename: str) -> None:
|
|
42
|
+
if self.loader is None:
|
|
43
|
+
raise ImportError("matlabengine is required to use MatlabWrapper") from None
|
|
44
|
+
|
|
45
|
+
self.engine = self.loader.result()
|
|
46
|
+
path = pathlib.Path(filename)
|
|
47
|
+
self.engine.cd(str(path.parent), nargout=0)
|
|
48
|
+
self.function_name = path.stem
|
|
49
|
+
|
|
50
|
+
def getHandle(self) -> Callable[[ArrayLike, ArrayLike, ArrayLike, int, int], Tuple[ArrayLike, float]]:
|
|
51
|
+
"""Returns a wrapper for the custom MATLAB function
|
|
52
|
+
|
|
53
|
+
Returns
|
|
54
|
+
-------
|
|
55
|
+
wrapper : Callable[[ArrayLike, ArrayLike, ArrayLike, int, int], Tuple[ArrayLike, float]]
|
|
56
|
+
The wrapper function for the MATLAB callback
|
|
57
|
+
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
def handle(params, bulk_in, bulk_out, contrast, domain=-1):
|
|
61
|
+
if domain == -1:
|
|
62
|
+
output, sub_rough = getattr(self.engine, self.function_name)(
|
|
63
|
+
np.array(params, "float"),
|
|
64
|
+
np.array(bulk_in, "float"),
|
|
65
|
+
np.array(bulk_out, "float"),
|
|
66
|
+
float(contrast + 1),
|
|
67
|
+
nargout=2,
|
|
68
|
+
)
|
|
69
|
+
else:
|
|
70
|
+
output, sub_rough = getattr(self.engine, self.function_name)(
|
|
71
|
+
np.array(params, "float"),
|
|
72
|
+
np.array(bulk_in, "float"),
|
|
73
|
+
np.array(bulk_out, "float"),
|
|
74
|
+
float(contrast + 1),
|
|
75
|
+
float(domain + 1),
|
|
76
|
+
nargout=2,
|
|
77
|
+
)
|
|
78
|
+
return output, sub_rough
|
|
79
|
+
|
|
80
|
+
return handle
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class DylibWrapper:
|
|
84
|
+
"""Creates a python callback for a function in dynamic library.
|
|
85
|
+
|
|
86
|
+
Parameters
|
|
87
|
+
----------
|
|
88
|
+
filename : str
|
|
89
|
+
The path of the dynamic library
|
|
90
|
+
function_name : str
|
|
91
|
+
The name of the function to call
|
|
92
|
+
|
|
93
|
+
"""
|
|
94
|
+
|
|
95
|
+
def __init__(self, filename, function_name) -> None:
|
|
96
|
+
self.engine = RATapi.rat_core.DylibEngine(filename, function_name)
|
|
97
|
+
|
|
98
|
+
def getHandle(self) -> Callable[[ArrayLike, ArrayLike, ArrayLike, int, int], Tuple[ArrayLike, float]]:
|
|
99
|
+
"""Returns a wrapper for the custom dynamic library function
|
|
100
|
+
|
|
101
|
+
Returns
|
|
102
|
+
-------
|
|
103
|
+
wrapper : Callable[[ArrayLike, ArrayLike, ArrayLike, int, int], Tuple[ArrayLike, float]]
|
|
104
|
+
The wrapper function for the dynamic library callback
|
|
105
|
+
|
|
106
|
+
"""
|
|
107
|
+
|
|
108
|
+
def handle(params, bulk_in, bulk_out, contrast, domain=-1):
|
|
109
|
+
if domain == -1:
|
|
110
|
+
output, sub_rough = self.engine.invoke(params, bulk_in, bulk_out, contrast)
|
|
111
|
+
else:
|
|
112
|
+
output, sub_rough = self.engine.invoke(params, bulk_in, bulk_out, contrast, domain)
|
|
113
|
+
return output, sub_rough
|
|
114
|
+
|
|
115
|
+
return handle
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: RATapi
|
|
3
|
+
Version: 0.0.0.dev0
|
|
4
|
+
Summary: Python extension for the Reflectivity Analysis Toolbox (RAT)
|
|
5
|
+
Home-page: https://github.com/RascalSoftware/python-RAT
|
|
6
|
+
Author:
|
|
7
|
+
Author-email:
|
|
8
|
+
Requires-Python: >=3.9
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
Requires-Dist: numpy >=1.20
|
|
11
|
+
Requires-Dist: prettytable >=3.9.0
|
|
12
|
+
Requires-Dist: pydantic >=2.7.2
|
|
13
|
+
Requires-Dist: matplotlib >=3.8.3
|
|
14
|
+
Requires-Dist: StrEnum >=0.4.15 ; python_version < "3.11"
|
|
15
|
+
Provides-Extra: dev
|
|
16
|
+
Requires-Dist: pytest >=7.4.0 ; extra == 'dev'
|
|
17
|
+
Requires-Dist: pytest-cov >=4.1.0 ; extra == 'dev'
|
|
18
|
+
Requires-Dist: ruff >=0.4.10 ; extra == 'dev'
|
|
19
|
+
Provides-Extra: matlab_2021a
|
|
20
|
+
Requires-Dist: matlabengine ==9.10.3 ; extra == 'matlab_2021a'
|
|
21
|
+
Provides-Extra: matlab_2021b
|
|
22
|
+
Requires-Dist: matlabengine ==9.11.21 ; extra == 'matlab_2021b'
|
|
23
|
+
Provides-Extra: matlab_2022a
|
|
24
|
+
Requires-Dist: matlabengine ==9.12.19 ; extra == 'matlab_2022a'
|
|
25
|
+
Provides-Extra: matlab_2022b
|
|
26
|
+
Requires-Dist: matlabengine ==9.13.9 ; extra == 'matlab_2022b'
|
|
27
|
+
Provides-Extra: matlab_2023a
|
|
28
|
+
Requires-Dist: matlabengine ==9.14.3 ; extra == 'matlab_2023a'
|
|
29
|
+
Provides-Extra: matlab_2023b
|
|
30
|
+
Requires-Dist: matlabengine ==23.2.1 ; extra == 'matlab_2023b'
|
|
31
|
+
Provides-Extra: matlab_latest
|
|
32
|
+
Requires-Dist: matlabengine ; extra == 'matlab_latest'
|
|
33
|
+
|
|
34
|
+
python-RAT
|
|
35
|
+
==========
|
|
36
|
+
Python-RAT is the Python interface for the [Reflectivity Algorithm Toolbox](https://github.com/RascalSoftware/RAT) (RAT).
|
|
37
|
+
|
|
38
|
+
Install
|
|
39
|
+
=======
|
|
40
|
+
To install in local directory:
|
|
41
|
+
|
|
42
|
+
git clone --recurse-submodules https://github.com/RascalSoftware/python-RAT.git
|
|
43
|
+
cd python-RAT
|
|
44
|
+
pip install -e .
|
|
45
|
+
|
|
46
|
+
matlabengine is an optional dependency only required for Matlab custom functions. The version of matlabengine should match the version of Matlab installed on the machine. This can be installed as shown below:
|
|
47
|
+
|
|
48
|
+
pip install -e .[Matlab-2023a]
|
|
49
|
+
|
|
50
|
+
Development dependencies can be installed as shown below
|
|
51
|
+
|
|
52
|
+
pip install -e .[Dev]
|
|
53
|
+
|
|
54
|
+
To build wheel:
|
|
55
|
+
|
|
56
|
+
pip install build
|
|
57
|
+
python -m build --wheel
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
RATapi/__init__.py,sha256=PtRzofWFEkpm8-qc475GtsG7wA5mCyoCGj1VsED3vc0,301
|
|
2
|
+
RATapi/classlist.py,sha256=fNOqpC3UCakzsBjk4oBQxDtQP45hhBE9MuINre2CcEk,16739
|
|
3
|
+
RATapi/controls.py,sha256=UalU1uv2qGuSwf7Tw53meGu1ToAp_9fUME2u5-TG-2k,6032
|
|
4
|
+
RATapi/eventManager.dll,sha256=ElnVjkYjm6HFaH_IY_3xBVUpXbwI3ZkP3ian_FM32h4,18432
|
|
5
|
+
RATapi/events.py,sha256=-lBcL6m8NejTc5D4Yf63Y1s3Hrih-EubfQLYYuyt4ns,2272
|
|
6
|
+
RATapi/inputs.py,sha256=bHKO-CmvvOMNaC9X3fyuHWGDtHSuU1xw7W3y373RZe0,18555
|
|
7
|
+
RATapi/models.py,sha256=snzlBhutdNnEpp1xUhmTYhcVdhvz7SJr1eE21TsMmrI,11445
|
|
8
|
+
RATapi/outputs.py,sha256=w8J9e1DCEj2idftSL7Pd1LpfnuztAO72suQsOaf7MIw,7225
|
|
9
|
+
RATapi/project.py,sha256=nqVvMecyEnrtLEjhmh80uKGGlxcN2IqtcNJCZXbNzY4,27152
|
|
10
|
+
RATapi/rat_core.cp310-win_amd64.pyd,sha256=vF5RNz14TqndzV5735LcRPujlF6EnsyCdAkekH7qQVs,1102336
|
|
11
|
+
RATapi/run.py,sha256=ti2C7hk5YwuXa_J5Vkz1XWgfS3qQ2UoAciwLXmEs8RE,1181
|
|
12
|
+
RATapi/wrappers.py,sha256=3IlkqT4f9gHkHHspJEF1nbyEkI4syzOFe5CLhmFHtYc,3601
|
|
13
|
+
RATapi/examples/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
|
+
RATapi/examples/absorption/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
|
+
RATapi/examples/absorption/absorption.py,sha256=Mkh6g9hS84TiTUTLeE_xVVHaaZWZLiUG6-kx27uoGKQ,6141
|
|
16
|
+
RATapi/examples/absorption/volume_thiol_bilayer.py,sha256=Q0zfxKIqgBJH_CtABbDkNbW-9iMpE6SMoCCj7asxpBk,4716
|
|
17
|
+
RATapi/examples/data/D2O_spin_down.dat,sha256=drdy9BhxbwBd8K6WOqgmb9hFa7JyZ84djVBRP7hcEaQ,4995
|
|
18
|
+
RATapi/examples/data/D2O_spin_up.dat,sha256=BNf9GnYbfSI_N-jBkYOUCTLYyaVnOFk_QllNtAlcvsk,5027
|
|
19
|
+
RATapi/examples/data/DSPC_D2O.dat,sha256=asZY6C-9pkkyVuwwllNwTgUGgISIkq4_-tTJYWiyeF4,2529
|
|
20
|
+
RATapi/examples/data/DSPC_SMW.dat,sha256=nQ2Y7F8rLhffB6Wds_isJcS2DUB4awig8TjqOepFtCE,2556
|
|
21
|
+
RATapi/examples/data/H2O_spin_down.dat,sha256=tp0yBZRUmr2xS4c27jPwHeVF9bQ3nR_3UBiniOYOK80,5110
|
|
22
|
+
RATapi/examples/data/H2O_spin_up.dat,sha256=5xastIRtR-D91l8oov0VhWQDCOKqv0ZKDuurdYHXKhg,5078
|
|
23
|
+
RATapi/examples/data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
24
|
+
RATapi/examples/data/c_PLP0016596.dat,sha256=Zbdoyu4Z5EU9-m32wOP-D33ESYtqOQu1zEAceM3URng,5796
|
|
25
|
+
RATapi/examples/data/c_PLP0016601.dat,sha256=i69TFgZJq2fgEmbrvqbIyHekCj3Fd2lysJ_5KLY8eLw,3980
|
|
26
|
+
RATapi/examples/data/c_PLP0016607.dat,sha256=yZ4Zo34h2m0qQwKt-e1aQGtzoTmfgwYu8zqAN21lGpY,4226
|
|
27
|
+
RATapi/examples/domains/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
28
|
+
RATapi/examples/domains/alloy_domains.py,sha256=wUzjqotlPFoM_SSmB_8-HYApAU-rxm8o9grZrB1sVs4,817
|
|
29
|
+
RATapi/examples/domains/domains_XY_model.py,sha256=BAdfTQPlhLQDd6eBeMdcuEbxHtextWGATSOKTydabxY,2147
|
|
30
|
+
RATapi/examples/domains/domains_custom_XY.py,sha256=bhner7QtU7mbbXfhiXlfml_wuXSqM1Yvc5Bp20gif1I,2202
|
|
31
|
+
RATapi/examples/domains/domains_custom_layers.py,sha256=LrvAOBS7FkIjeArEReG83vh0xzT0u96yRMO1J54XJyE,1682
|
|
32
|
+
RATapi/examples/domains/domains_standard_layers.py,sha256=4ddWNxVobQEBuPWar8lV99YeUCI-xYsGb4JUJ3-Ezps,2771
|
|
33
|
+
RATapi/examples/languages/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
34
|
+
RATapi/examples/languages/custom_bilayer.py,sha256=KPKV21TgrFJ8q0pbTh7XlP4G6OeHQk1Dv3qLhRAgukI,2045
|
|
35
|
+
RATapi/examples/languages/run_custom_file_languages.py,sha256=rvgRhE5teEWlsFrR2ZPhwyDNW6FKM4xY7nIO7-X_qaY,996
|
|
36
|
+
RATapi/examples/languages/setup_problem.py,sha256=LINpINzHvNaFacMoZsNLXl1JJ31jEEE7HpvN5PUWOwI,5087
|
|
37
|
+
RATapi/examples/non_polarised/DSPC_custom_XY.py,sha256=jjsoWvJozRjr186EyXGUHYtYxh62wsZEFUPrGC0s10M,6068
|
|
38
|
+
RATapi/examples/non_polarised/DSPC_custom_layers.py,sha256=INlMsX8m50i7sSnZ50FgYi7zUn37fgWlZJYwwsUqZ04,4926
|
|
39
|
+
RATapi/examples/non_polarised/DSPC_standard_layers.py,sha256=J_B-wyt891YF-uQ_oKmPOnpy9u9-Ceqhlu95U8TuSzE,7872
|
|
40
|
+
RATapi/examples/non_polarised/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
41
|
+
RATapi/examples/non_polarised/custom_XY_DSPC.py,sha256=kqEz9E-V4XnaaXomBUiTOJfuFlpQsK7_njD9n5UbVFQ,4733
|
|
42
|
+
RATapi/examples/non_polarised/custom_bilayer_DSPC.py,sha256=WI4f8DQz3fKyakg0vpgXvFbyp7gQgzPXfROmey1nQJs,2887
|
|
43
|
+
RATapi/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
44
|
+
RATapi/utils/custom_errors.py,sha256=PJE1xDNOxrRUmx1kb3d_gqDei47WvCXgOCJBJ6GneyI,1604
|
|
45
|
+
RATapi/utils/enums.py,sha256=8ioLHdIzEBlnprWpn9rALy2IS2OScYS-VixsNcnj18k,1932
|
|
46
|
+
RATapi/utils/plotting.py,sha256=yfzz8H-lDvUq2KDacYLZh-K82xI_f1azKpxRDWDGY18,6897
|
|
47
|
+
tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
48
|
+
tests/conftest.py,sha256=0las5Fzr3x573Z1HCGzsi8GTzfN9zTYz0ZzjrFQegPA,173717
|
|
49
|
+
tests/test_classlist.py,sha256=pFSvMl15Soqb7zWpP7URXTTO8pFhYrJ5kAjQnLgh4bI,32617
|
|
50
|
+
tests/test_controls.py,sha256=UCNF3ZxV50VvjA2cZuPHrgdDF7WjUFsxNwtWNQSBumc,34305
|
|
51
|
+
tests/test_custom_errors.py,sha256=1Ir6N8A1tcOisK-oalzPnxIqFSg9XkGs1ZiHS60E25U,2008
|
|
52
|
+
tests/test_events.py,sha256=5sxjPHUc7WnopuhehDCtKPPb4ngWM58IYB9vsNlP2Gk,2448
|
|
53
|
+
tests/test_inputs.py,sha256=bfub0GDXzri51PiFxD_L4fnqjl3jmxdamtHKgF62Kww,31711
|
|
54
|
+
tests/test_models.py,sha256=y4AJGuiYFqcTEJrER3erdz8aLRGa98mXsdgpXSWqHXw,10906
|
|
55
|
+
tests/test_outputs.py,sha256=EABRzY7KlxvnlIN-OMgQG8m--OEM5CLGUbXeLriGA84,1280
|
|
56
|
+
tests/test_plotting.py,sha256=rfsMmx1SIN06hn1KJIq2IlCaWss3qtDPLa58IwTC7Mk,6129
|
|
57
|
+
tests/test_project.py,sha256=yb53vaquHSTaDXPUkiTjzCyGO2UkZL5kV56wd3pc2uo,58631
|
|
58
|
+
tests/test_run.py,sha256=52GR4IrjMQVgBqkf4TDQOyxlze3GCvTQCn9IfVL0dyA,16278
|
|
59
|
+
tests/test_wrappers.py,sha256=wCc0tMnzUxAieER0zFKu6R2fZMalQzl48bVwF-9_zQo,2207
|
|
60
|
+
tests/utils.py,sha256=Ksf6A_udxROaYJVjDi0XDC8zNE2CXUOX1iZT3fY69Ig,6499
|
|
61
|
+
RATapi-0.0.0.dev0.dist-info/METADATA,sha256=TmL8zb8v00nHwwliiHZmHJuk6i2jvX-Q7Zke2CZuBjg,2035
|
|
62
|
+
RATapi-0.0.0.dev0.dist-info/WHEEL,sha256=fDXqnFpBBnqSxsDqGs4iGbeTQND-IiCQk4XZQ3lG1HU,101
|
|
63
|
+
RATapi-0.0.0.dev0.dist-info/top_level.txt,sha256=dB2AEUTcUC1Ekmkkt1_bbMnug_vwWYyzzPM1FCtojIk,13
|
|
64
|
+
RATapi-0.0.0.dev0.dist-info/RECORD,,
|
tests/__init__.py
ADDED
|
File without changes
|