RATapi 0.0.0.dev10__cp313-cp313-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.
Files changed (59) hide show
  1. ratapi/__init__.py +29 -0
  2. ratapi/classlist.py +620 -0
  3. ratapi/controls.py +258 -0
  4. ratapi/eventManager.dll +0 -0
  5. ratapi/events.py +88 -0
  6. ratapi/examples/__init__.py +25 -0
  7. ratapi/examples/absorption/__init__.py +1 -0
  8. ratapi/examples/absorption/absorption.py +172 -0
  9. ratapi/examples/absorption/volume_thiol_bilayer.py +141 -0
  10. ratapi/examples/convert_rascal_project/Model_IIb.py +87 -0
  11. ratapi/examples/convert_rascal_project/__init__.py +1 -0
  12. ratapi/examples/convert_rascal_project/convert_rascal.py +49 -0
  13. ratapi/examples/data/D2O_spin_down.dat +100 -0
  14. ratapi/examples/data/D2O_spin_up.dat +101 -0
  15. ratapi/examples/data/DSPC_D2O.dat +82 -0
  16. ratapi/examples/data/DSPC_SMW.dat +82 -0
  17. ratapi/examples/data/H2O_spin_down.dat +102 -0
  18. ratapi/examples/data/H2O_spin_up.dat +102 -0
  19. ratapi/examples/data/__init__.py +1 -0
  20. ratapi/examples/data/c_PLP0016596.dat +146 -0
  21. ratapi/examples/data/c_PLP0016601.dat +97 -0
  22. ratapi/examples/data/c_PLP0016607.dat +104 -0
  23. ratapi/examples/data/d2o_background_data.dat +82 -0
  24. ratapi/examples/domains/__init__.py +1 -0
  25. ratapi/examples/domains/alloy_domains.py +31 -0
  26. ratapi/examples/domains/domains_XY_model.py +72 -0
  27. ratapi/examples/domains/domains_custom_XY.py +86 -0
  28. ratapi/examples/domains/domains_custom_layers.py +60 -0
  29. ratapi/examples/domains/domains_standard_layers.py +92 -0
  30. ratapi/examples/languages/__init__.py +1 -0
  31. ratapi/examples/languages/custom_bilayer.py +69 -0
  32. ratapi/examples/languages/run_custom_file_languages.py +41 -0
  33. ratapi/examples/languages/setup_problem.py +130 -0
  34. ratapi/examples/normal_reflectivity/DSPC_custom_XY.py +149 -0
  35. ratapi/examples/normal_reflectivity/DSPC_custom_layers.py +130 -0
  36. ratapi/examples/normal_reflectivity/DSPC_data_background.py +220 -0
  37. ratapi/examples/normal_reflectivity/DSPC_function_background.py +219 -0
  38. ratapi/examples/normal_reflectivity/DSPC_standard_layers.py +210 -0
  39. ratapi/examples/normal_reflectivity/__init__.py +1 -0
  40. ratapi/examples/normal_reflectivity/background_function.py +16 -0
  41. ratapi/examples/normal_reflectivity/custom_XY_DSPC.py +138 -0
  42. ratapi/examples/normal_reflectivity/custom_bilayer_DSPC.py +87 -0
  43. ratapi/inputs.py +588 -0
  44. ratapi/models.py +677 -0
  45. ratapi/outputs.py +821 -0
  46. ratapi/project.py +1074 -0
  47. ratapi/rat_core.cp313-win_amd64.pyd +0 -0
  48. ratapi/run.py +140 -0
  49. ratapi/utils/__init__.py +1 -0
  50. ratapi/utils/convert.py +564 -0
  51. ratapi/utils/custom_errors.py +40 -0
  52. ratapi/utils/enums.py +204 -0
  53. ratapi/utils/orso.py +247 -0
  54. ratapi/utils/plotting.py +1231 -0
  55. ratapi/wrappers.py +144 -0
  56. ratapi-0.0.0.dev10.dist-info/METADATA +61 -0
  57. ratapi-0.0.0.dev10.dist-info/RECORD +59 -0
  58. ratapi-0.0.0.dev10.dist-info/WHEEL +5 -0
  59. ratapi-0.0.0.dev10.dist-info/top_level.txt +1 -0
@@ -0,0 +1,130 @@
1
+ """Example of using custom layers to model a DSPC supported bilayer."""
2
+
3
+ import pathlib
4
+
5
+ import numpy as np
6
+
7
+ import ratapi as RAT
8
+
9
+
10
+ def DSPC_custom_layers():
11
+ """Calculate a Custom Layers example for a supported DSPC layer."""
12
+ problem = RAT.Project(name="Orso lipid example - custom layers", model="custom layers", geometry="substrate/liquid")
13
+
14
+ # First we need to set up a parameters group. We will be using a pre-prepared custom model file, so we need to add
15
+ # the relevant parameters we are going to need to define the model (note that Substrate Roughness always exists as
16
+ # parameter 1).
17
+ problem.parameters.append(name="Oxide Thickness", min=5.0, value=20.0, max=60.0, fit=True)
18
+ problem.parameters.append(name="Oxide Hydration", min=0.0, value=0.2, max=0.5, fit=True)
19
+ problem.parameters.append(name="Lipid APM", min=45.0, value=55.0, max=65.0, fit=True)
20
+ problem.parameters.append(name="Head Hydration", min=0.0, value=0.2, max=0.5, fit=True)
21
+ problem.parameters.append(name="Bilayer Hydration", min=0.0, value=0.1, max=0.2, fit=True)
22
+ problem.parameters.append(name="Bilayer Roughness", min=2.0, value=4.0, max=8.0, fit=True)
23
+ problem.parameters.append(name="Water Thickness", min=0.0, value=2.0, max=10.0, fit=True)
24
+
25
+ problem.parameters.set_fields(0, min=1.0, max=10.0)
26
+
27
+ # Need to add the relevant Bulk SLDs. Change the bulk in from air to silicon, and add two additional water
28
+ # contrasts:
29
+ problem.bulk_in.set_fields(0, name="Silicon", min=2.07e-6, value=2.073e-6, max=2.08e-6, fit=False)
30
+
31
+ problem.bulk_out.append(name="SLD SMW", min=1.0e-6, value=2.073e-6, max=3.0e-6, fit=True)
32
+ problem.bulk_out.append(name="SLD H2O", min=-0.6e-6, value=-0.56e-6, max=-0.3e-6, fit=True)
33
+
34
+ problem.bulk_out.set_fields(0, min=5.0e-6, fit=True)
35
+
36
+ # Now add the datafiles. We have three datasets we need to consider - the bilayer against D2O, Silicon Matched
37
+ # Water and H2O. Load these datafiles in and put them in the data block
38
+
39
+ # Read in the datafiles
40
+ data_path = pathlib.Path(__file__).parents[1] / "data"
41
+ D2O_data = np.loadtxt(data_path / "c_PLP0016596.dat", delimiter=",")
42
+ SMW_data = np.loadtxt(data_path / "c_PLP0016601.dat", delimiter=",")
43
+ H2O_data = np.loadtxt(data_path / "c_PLP0016607.dat", delimiter=",")
44
+
45
+ # Add the data to the project - note this data has a resolution 4th column
46
+ problem.data.append(name="Bilayer / D2O", data=D2O_data, data_range=[0.013, 0.37])
47
+ problem.data.append(name="Bilayer / SMW", data=SMW_data, data_range=[0.013, 0.32996])
48
+ problem.data.append(name="Bilayer / H2O", data=H2O_data, data_range=[0.013, 0.33048])
49
+
50
+ # Add the custom file to the project
51
+ problem.custom_files.append(
52
+ name="DSPC Model",
53
+ filename="custom_bilayer_DSPC.py",
54
+ language="python",
55
+ path=pathlib.Path(__file__).parent,
56
+ )
57
+
58
+ # Also, add the relevant background parameters - one each for each contrast:
59
+ problem.background_parameters.set_fields(
60
+ 0,
61
+ name="Background parameter D2O",
62
+ min=1.0e-10,
63
+ max=1.0e-5,
64
+ value=1.0e-07,
65
+ fit=True,
66
+ )
67
+
68
+ problem.background_parameters.append(
69
+ name="Background parameter SMW", min=1.0e-10, value=1.0e-7, max=1.0e-5, fit=True
70
+ )
71
+ problem.background_parameters.append(
72
+ name="Background parameter H2O", min=1.0e-10, value=1.0e-7, max=1.0e-5, fit=True
73
+ )
74
+
75
+ # And add the two new constant backgrounds
76
+ problem.backgrounds.append(name="Background SMW", type="constant", source="Background parameter SMW")
77
+ problem.backgrounds.append(name="Background H2O", type="constant", source="Background parameter H2O")
78
+
79
+ # And edit the other one
80
+ problem.backgrounds.set_fields(0, name="Background D2O", source="Background parameter D2O")
81
+
82
+ # Finally modify some of the other parameters to be more suitable values for a solid / liquid experiment
83
+ problem.scalefactors.set_fields(0, value=1.0, min=0.5, max=2.0, fit=True)
84
+
85
+ # Also, we are going to use the data resolution
86
+ problem.resolutions.append(name="Data Resolution", type="data")
87
+
88
+ # Now add the three contrasts
89
+ problem.contrasts.append(
90
+ name="Bilayer / D2O",
91
+ background="Background D2O",
92
+ resolution="Data Resolution",
93
+ scalefactor="Scalefactor 1",
94
+ bulk_out="SLD D2O",
95
+ bulk_in="Silicon",
96
+ data="Bilayer / D2O",
97
+ model=["DSPC Model"],
98
+ )
99
+
100
+ problem.contrasts.append(
101
+ name="Bilayer / SMW",
102
+ background="Background SMW",
103
+ resolution="Data Resolution",
104
+ scalefactor="Scalefactor 1",
105
+ bulk_out="SLD SMW",
106
+ bulk_in="Silicon",
107
+ data="Bilayer / SMW",
108
+ model=["DSPC Model"],
109
+ )
110
+
111
+ problem.contrasts.append(
112
+ name="Bilayer / H2O",
113
+ background="Background H2O",
114
+ resolution="Data Resolution",
115
+ scalefactor="Scalefactor 1",
116
+ bulk_out="SLD H2O",
117
+ bulk_in="Silicon",
118
+ data="Bilayer / H2O",
119
+ model=["DSPC Model"],
120
+ )
121
+
122
+ controls = RAT.Controls()
123
+ problem, results = RAT.run(problem, controls)
124
+
125
+ return problem, results
126
+
127
+
128
+ if __name__ == "__main__":
129
+ problem, results = DSPC_custom_layers()
130
+ RAT.plotting.plot_ref_sld(problem, results, True)
@@ -0,0 +1,220 @@
1
+ """A standard layers example with a data background."""
2
+
3
+ import pathlib
4
+
5
+ import numpy as np
6
+
7
+ import ratapi as RAT
8
+
9
+
10
+ def DSPC_data_background():
11
+ """Calculate a Standard Layers fit of a DSPC floating bilayer with a data background."""
12
+ problem = RAT.Project(name="original_dspc_bilayer", model="standard layers", geometry="substrate/liquid")
13
+
14
+ # Set up the relevant parameters
15
+ problem.parameters.append(name="Oxide Thickness", min=5.0, value=19.54, max=60.0, fit=True)
16
+ problem.parameters.append(name="Oxide SLD", min=3.39e-06, value=3.39e-06, max=3.41e-06, fit=False)
17
+ problem.parameters.append(name="SAM Tails Thickness", min=15.0, value=22.66, max=35.0, fit=True)
18
+ problem.parameters.append(name="SAM Tails SLD", min=-5e-07, value=-4.01e-07, max=-3e-07, fit=False)
19
+ problem.parameters.append(name="SAM Tails Hydration", min=1.0, value=5.252, max=50.0, fit=True)
20
+ problem.parameters.append(name="SAM Roughness", min=1.0, value=5.64, max=15.0, fit=True)
21
+ problem.parameters.append(name="CW Thickness", min=10.0, value=17.12, max=28.0, fit=True)
22
+ problem.parameters.append(name="CW SLD", min=0.0, value=0.0, max=1e-09, fit=False)
23
+
24
+ problem.parameters.append(
25
+ name="SAM Heads Thickness",
26
+ min=5.0,
27
+ value=8.56,
28
+ max=17.0,
29
+ fit=True,
30
+ prior_type="gaussian",
31
+ mu=10.0,
32
+ sigma=2.0,
33
+ )
34
+ problem.parameters.append(name="SAM Heads SLD", min=1.0e-07, value=1.75e-06, max=2.0e-06, fit=False)
35
+ problem.parameters.append(
36
+ name="SAM Heads Hydration",
37
+ min=10.0,
38
+ value=45.45,
39
+ max=50.0,
40
+ fit=True,
41
+ prior_type="gaussian",
42
+ mu=30.0,
43
+ sigma=3.0,
44
+ )
45
+ problem.parameters.append(
46
+ name="Bilayer Heads Thickness",
47
+ min=7.0,
48
+ value=10.7,
49
+ max=17.0,
50
+ fit=True,
51
+ prior_type="gaussian",
52
+ mu=10.0,
53
+ sigma=2.0,
54
+ )
55
+ problem.parameters.append(name="Bilayer Heads SLD", min=5.0e-07, value=1.47e-06, max=1.5e-06, fit=False)
56
+ problem.parameters.append(name="Bilayer Roughness", min=2.0, value=6.014, max=15.0, fit=True)
57
+ problem.parameters.append(name="Bilayer Tails Thickness", min=14.0, value=17.82, max=22.0, fit=True)
58
+ problem.parameters.append(name="Bilayer Tails SLD", min=-5.0e-07, value=-4.61e-07, max=0.0, fit=False)
59
+ problem.parameters.append(name="Bilayer Tails Hydration", min=10.0, value=17.64, max=50.0, fit=True)
60
+ problem.parameters.append(name="Bilayer Heads Hydration", min=10.0, value=36.15, max=50.0, fit=True)
61
+ problem.parameters.append(name="CW Hydration", min=99.9, value=100.0, max=100.0, fit=False)
62
+ problem.parameters.append(name="Oxide Hydration", min=0.0, value=23.61, max=60.0, fit=True)
63
+
64
+ problem.parameters.set_fields(0, max=10)
65
+
66
+ # Group these into layers
67
+ problem.layers.append(
68
+ name="Oxide",
69
+ thickness="Oxide Thickness",
70
+ SLD="Oxide SLD",
71
+ roughness="Substrate Roughness",
72
+ hydration="Oxide Hydration",
73
+ hydrate_with="bulk out",
74
+ )
75
+
76
+ problem.layers.append(
77
+ name="SAM Tails",
78
+ thickness="SAM Tails Thickness",
79
+ SLD="SAM Tails SLD",
80
+ roughness="SAM Roughness",
81
+ hydration="SAM Tails Hydration",
82
+ hydrate_with="bulk out",
83
+ )
84
+
85
+ problem.layers.append(
86
+ name="SAM Heads",
87
+ thickness="SAM Heads Thickness",
88
+ SLD="SAM Heads SLD",
89
+ roughness="SAM Roughness",
90
+ hydration="SAM Heads Hydration",
91
+ hydrate_with="bulk out",
92
+ )
93
+
94
+ problem.layers.append(
95
+ name="Central Water",
96
+ thickness="CW Thickness",
97
+ SLD="CW SLD",
98
+ roughness="Bilayer Roughness",
99
+ hydration="CW Hydration",
100
+ hydrate_with="bulk out",
101
+ )
102
+
103
+ problem.layers.append(
104
+ name="Bilayer Heads",
105
+ thickness="Bilayer Heads Thickness",
106
+ SLD="Bilayer Heads SLD",
107
+ roughness="Bilayer Roughness",
108
+ hydration="Bilayer Heads Hydration",
109
+ hydrate_with="bulk out",
110
+ )
111
+
112
+ problem.layers.append(
113
+ name="Bilayer Tails",
114
+ thickness="Bilayer Tails Thickness",
115
+ SLD="Bilayer Tails SLD",
116
+ roughness="Bilayer Roughness",
117
+ hydration="Bilayer Tails Hydration",
118
+ hydrate_with="bulk out",
119
+ )
120
+
121
+ # Make the bulk SLDs
122
+ del problem.bulk_in[0]
123
+ problem.bulk_in.append(name="Silicon", min=2.0e-06, value=2.073e-06, max=2.1e-06, fit=False)
124
+
125
+ del problem.bulk_out[0]
126
+ problem.bulk_out.append(name="D2O", min=5.50e-06, value=5.98e-06, max=6.4e-06, fit=True)
127
+ problem.bulk_out.append(name="SMW", min=1.0e-06, value=2.21e-06, max=4.99e-06, fit=True)
128
+
129
+ # Set the scalefactors - use one for each contrast
130
+ del problem.scalefactors[0]
131
+ problem.scalefactors.append(name="Scalefactor 1", min=0.05, value=0.10, max=0.2, fit=False)
132
+ problem.scalefactors.append(name="Scalefactor 2", min=0.05, value=0.15, max=0.2, fit=False)
133
+
134
+ # Now deal with the backgrounds
135
+ # SMW has a constant background
136
+ del problem.backgrounds[0]
137
+ del problem.background_parameters[0]
138
+ problem.background_parameters.append(
139
+ name="Background parameter SMW",
140
+ min=1.0e-10,
141
+ value=3.38e-06,
142
+ max=4.99e-06,
143
+ fit=True,
144
+ )
145
+ problem.backgrounds.append(name="SMW Background", type="constant", source="Background parameter SMW")
146
+
147
+ data_path = pathlib.Path(__file__).parents[1] / "data"
148
+
149
+ # load in background data for D2O
150
+ d2o_background = np.loadtxt(data_path / "d2o_background_data.dat")
151
+ problem.data.append(name="D2O Background Data", data=d2o_background)
152
+
153
+ # add background parameter for the offset
154
+ problem.background_parameters.append(
155
+ name="D2O Data Offset",
156
+ min=-1e-8,
157
+ value=0,
158
+ max=1e-8,
159
+ fit=True,
160
+ )
161
+
162
+ # add the background with data and offset
163
+ problem.backgrounds.append(
164
+ name="D2O Data Background",
165
+ type="data",
166
+ source="D2O Background Data",
167
+ value_1="D2O Data Offset",
168
+ )
169
+
170
+ # Now add the data
171
+ d2o_dat = np.loadtxt(data_path / "DSPC_D2O.dat", delimiter=",")
172
+ problem.data.append(name="dspc_bil_D2O", data=d2o_dat)
173
+
174
+ smw_dat = np.loadtxt(data_path / "DSPC_SMW.dat", delimiter=",")
175
+ problem.data.append(name="dspc_bil_smw", data=smw_dat)
176
+
177
+ # Set the model
178
+ stack = [
179
+ "Oxide",
180
+ "SAM Tails",
181
+ "SAM Heads",
182
+ "Central Water",
183
+ "Bilayer Heads",
184
+ "Bilayer Tails",
185
+ "Bilayer Tails",
186
+ "Bilayer Heads",
187
+ ]
188
+
189
+ # Then make the two contrasts
190
+ problem.contrasts.append(
191
+ name="D2O",
192
+ bulk_in="Silicon",
193
+ bulk_out="D2O",
194
+ background="D2O Data Background",
195
+ resolution="Resolution 1",
196
+ scalefactor="Scalefactor 1",
197
+ data="dspc_bil_D2O",
198
+ model=stack,
199
+ )
200
+
201
+ problem.contrasts.append(
202
+ name="SMW",
203
+ bulk_in="Silicon",
204
+ bulk_out="SMW",
205
+ background="SMW Background",
206
+ resolution="Resolution 1",
207
+ scalefactor="Scalefactor 2",
208
+ data="dspc_bil_smw",
209
+ model=stack,
210
+ )
211
+
212
+ controls = RAT.Controls()
213
+ problem, results = RAT.run(problem, controls)
214
+
215
+ return problem, results
216
+
217
+
218
+ if __name__ == "__main__":
219
+ problem, results = DSPC_data_background()
220
+ RAT.plotting.plot_ref_sld(problem, results, True)
@@ -0,0 +1,219 @@
1
+ """A standard layers example with a function background."""
2
+
3
+ import pathlib
4
+
5
+ import numpy as np
6
+
7
+ import ratapi as RAT
8
+
9
+
10
+ def DSPC_function_background():
11
+ """Calculate a standard Layers fit of a DSPC floating bilayer with a function background."""
12
+ problem = RAT.Project(name="original_dspc_bilayer", model="standard layers", geometry="substrate/liquid")
13
+
14
+ # Set up the relevant parameters
15
+ problem.parameters.append(name="Oxide Thickness", min=5.0, value=19.54, max=60.0, fit=True)
16
+ problem.parameters.append(name="Oxide SLD", min=3.39e-06, value=3.39e-06, max=3.41e-06, fit=False)
17
+ problem.parameters.append(name="SAM Tails Thickness", min=15.0, value=22.66, max=35.0, fit=True)
18
+ problem.parameters.append(name="SAM Tails SLD", min=-5e-07, value=-4.01e-07, max=-3e-07, fit=False)
19
+ problem.parameters.append(name="SAM Tails Hydration", min=1.0, value=5.252, max=50.0, fit=True)
20
+ problem.parameters.append(name="SAM Roughness", min=1.0, value=5.64, max=15.0, fit=True)
21
+ problem.parameters.append(name="CW Thickness", min=10.0, value=17.12, max=28.0, fit=True)
22
+ problem.parameters.append(name="CW SLD", min=0.0, value=0.0, max=1e-09, fit=False)
23
+
24
+ problem.parameters.append(
25
+ name="SAM Heads Thickness",
26
+ min=5.0,
27
+ value=8.56,
28
+ max=17.0,
29
+ fit=True,
30
+ prior_type="gaussian",
31
+ mu=10.0,
32
+ sigma=2.0,
33
+ )
34
+ problem.parameters.append(name="SAM Heads SLD", min=1.0e-07, value=1.75e-06, max=2.0e-06, fit=False)
35
+ problem.parameters.append(
36
+ name="SAM Heads Hydration",
37
+ min=10.0,
38
+ value=45.45,
39
+ max=50.0,
40
+ fit=True,
41
+ prior_type="gaussian",
42
+ mu=30.0,
43
+ sigma=3.0,
44
+ )
45
+ problem.parameters.append(
46
+ name="Bilayer Heads Thickness",
47
+ min=7.0,
48
+ value=10.7,
49
+ max=17.0,
50
+ fit=True,
51
+ prior_type="gaussian",
52
+ mu=10.0,
53
+ sigma=2.0,
54
+ )
55
+ problem.parameters.append(name="Bilayer Heads SLD", min=5.0e-07, value=1.47e-06, max=1.5e-06, fit=False)
56
+ problem.parameters.append(name="Bilayer Roughness", min=2.0, value=6.014, max=15.0, fit=True)
57
+ problem.parameters.append(name="Bilayer Tails Thickness", min=14.0, value=17.82, max=22.0, fit=True)
58
+ problem.parameters.append(name="Bilayer Tails SLD", min=-5.0e-07, value=-4.61e-07, max=0.0, fit=False)
59
+ problem.parameters.append(name="Bilayer Tails Hydration", min=10.0, value=17.64, max=50.0, fit=True)
60
+ problem.parameters.append(name="Bilayer Heads Hydration", min=10.0, value=36.15, max=50.0, fit=True)
61
+ problem.parameters.append(name="CW Hydration", min=99.9, value=100.0, max=100.0, fit=False)
62
+ problem.parameters.append(name="Oxide Hydration", min=0.0, value=23.61, max=60.0, fit=True)
63
+
64
+ problem.parameters.set_fields(0, max=10)
65
+
66
+ # Group these into layers
67
+ problem.layers.append(
68
+ name="Oxide",
69
+ thickness="Oxide Thickness",
70
+ SLD="Oxide SLD",
71
+ roughness="Substrate Roughness",
72
+ hydration="Oxide Hydration",
73
+ hydrate_with="bulk out",
74
+ )
75
+
76
+ problem.layers.append(
77
+ name="SAM Tails",
78
+ thickness="SAM Tails Thickness",
79
+ SLD="SAM Tails SLD",
80
+ roughness="SAM Roughness",
81
+ hydration="SAM Tails Hydration",
82
+ hydrate_with="bulk out",
83
+ )
84
+
85
+ problem.layers.append(
86
+ name="SAM Heads",
87
+ thickness="SAM Heads Thickness",
88
+ SLD="SAM Heads SLD",
89
+ roughness="SAM Roughness",
90
+ hydration="SAM Heads Hydration",
91
+ hydrate_with="bulk out",
92
+ )
93
+
94
+ problem.layers.append(
95
+ name="Central Water",
96
+ thickness="CW Thickness",
97
+ SLD="CW SLD",
98
+ roughness="Bilayer Roughness",
99
+ hydration="CW Hydration",
100
+ hydrate_with="bulk out",
101
+ )
102
+
103
+ problem.layers.append(
104
+ name="Bilayer Heads",
105
+ thickness="Bilayer Heads Thickness",
106
+ SLD="Bilayer Heads SLD",
107
+ roughness="Bilayer Roughness",
108
+ hydration="Bilayer Heads Hydration",
109
+ hydrate_with="bulk out",
110
+ )
111
+
112
+ problem.layers.append(
113
+ name="Bilayer Tails",
114
+ thickness="Bilayer Tails Thickness",
115
+ SLD="Bilayer Tails SLD",
116
+ roughness="Bilayer Roughness",
117
+ hydration="Bilayer Tails Hydration",
118
+ hydrate_with="bulk out",
119
+ )
120
+
121
+ # Make the bulk SLDs
122
+ del problem.bulk_in[0]
123
+ problem.bulk_in.append(name="Silicon", min=2.0e-06, value=2.073e-06, max=2.1e-06, fit=False)
124
+
125
+ del problem.bulk_out[0]
126
+ problem.bulk_out.append(name="D2O", min=5.50e-06, value=5.98e-06, max=6.4e-06, fit=True)
127
+ problem.bulk_out.append(name="SMW", min=1.0e-06, value=2.21e-06, max=4.99e-06, fit=True)
128
+
129
+ # Set the scalefactors - use one for each contrast
130
+ del problem.scalefactors[0]
131
+ problem.scalefactors.append(name="Scalefactor 1", min=0.05, value=0.10, max=0.2, fit=False)
132
+ problem.scalefactors.append(name="Scalefactor 2", min=0.05, value=0.15, max=0.2, fit=False)
133
+
134
+ # Now deal with the backgrounds
135
+ # SMW has a constant background
136
+ del problem.backgrounds[0]
137
+ del problem.background_parameters[0]
138
+ problem.background_parameters.append(
139
+ name="Background parameter SMW",
140
+ min=1.0e-10,
141
+ value=3.38e-06,
142
+ max=4.99e-06,
143
+ fit=True,
144
+ )
145
+ problem.backgrounds.append(name="SMW Background", type="constant", source="Background parameter SMW")
146
+
147
+ problem.custom_files.append(
148
+ name="D2O Background Function",
149
+ filename="background_function.py",
150
+ language="python",
151
+ path=pathlib.Path(__file__).parent,
152
+ )
153
+
154
+ problem.background_parameters.append(name="Fn Ao", min=5e-7, value=8e-6, max=5e-5)
155
+ problem.background_parameters.append(name="Fn k", min=40, value=70, max=90)
156
+ problem.background_parameters.append(name="Fn Const", min=1e-7, value=8e-6, max=1e-5)
157
+
158
+ problem.backgrounds.append(
159
+ name="D2O Function Background",
160
+ type="function",
161
+ source="D2O Background Function",
162
+ value_1="Fn Ao",
163
+ value_2="Fn k",
164
+ value_3="Fn Const",
165
+ )
166
+
167
+ # Now add the data
168
+ data_path = pathlib.Path(__file__).parents[1] / "data"
169
+
170
+ d2o_dat = np.loadtxt(data_path / "DSPC_D2O.dat", delimiter=",")
171
+ problem.data.append(name="dspc_bil_D2O", data=d2o_dat)
172
+
173
+ smw_dat = np.loadtxt(data_path / "DSPC_SMW.dat", delimiter=",")
174
+ problem.data.append(name="dspc_bil_smw", data=smw_dat)
175
+
176
+ # Set the model
177
+ stack = [
178
+ "Oxide",
179
+ "SAM Tails",
180
+ "SAM Heads",
181
+ "Central Water",
182
+ "Bilayer Heads",
183
+ "Bilayer Tails",
184
+ "Bilayer Tails",
185
+ "Bilayer Heads",
186
+ ]
187
+
188
+ # Then make the two contrasts
189
+ problem.contrasts.append(
190
+ name="D2O",
191
+ bulk_in="Silicon",
192
+ bulk_out="D2O",
193
+ background="D2O Function Background",
194
+ resolution="Resolution 1",
195
+ scalefactor="Scalefactor 1",
196
+ data="dspc_bil_D2O",
197
+ model=stack,
198
+ )
199
+
200
+ problem.contrasts.append(
201
+ name="SMW",
202
+ bulk_in="Silicon",
203
+ bulk_out="SMW",
204
+ background="SMW Background",
205
+ resolution="Resolution 1",
206
+ scalefactor="Scalefactor 2",
207
+ data="dspc_bil_smw",
208
+ model=stack,
209
+ )
210
+
211
+ controls = RAT.Controls()
212
+ problem, results = RAT.run(problem, controls)
213
+
214
+ return problem, results
215
+
216
+
217
+ if __name__ == "__main__":
218
+ problem, results = DSPC_function_background()
219
+ RAT.plotting.plot_ref_sld(problem, results, True)