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.
Files changed (64) hide show
  1. RATapi/__init__.py +8 -0
  2. RATapi/classlist.py +387 -0
  3. RATapi/controls.py +143 -0
  4. RATapi/eventManager.dll +0 -0
  5. RATapi/events.py +70 -0
  6. RATapi/examples/__init__.py +0 -0
  7. RATapi/examples/absorption/__init__.py +0 -0
  8. RATapi/examples/absorption/absorption.py +148 -0
  9. RATapi/examples/absorption/volume_thiol_bilayer.py +138 -0
  10. RATapi/examples/data/D2O_spin_down.dat +100 -0
  11. RATapi/examples/data/D2O_spin_up.dat +101 -0
  12. RATapi/examples/data/DSPC_D2O.dat +82 -0
  13. RATapi/examples/data/DSPC_SMW.dat +82 -0
  14. RATapi/examples/data/H2O_spin_down.dat +102 -0
  15. RATapi/examples/data/H2O_spin_up.dat +102 -0
  16. RATapi/examples/data/__init__.py +0 -0
  17. RATapi/examples/data/c_PLP0016596.dat +146 -0
  18. RATapi/examples/data/c_PLP0016601.dat +97 -0
  19. RATapi/examples/data/c_PLP0016607.dat +104 -0
  20. RATapi/examples/domains/__init__.py +0 -0
  21. RATapi/examples/domains/alloy_domains.py +26 -0
  22. RATapi/examples/domains/domains_XY_model.py +70 -0
  23. RATapi/examples/domains/domains_custom_XY.py +69 -0
  24. RATapi/examples/domains/domains_custom_layers.py +46 -0
  25. RATapi/examples/domains/domains_standard_layers.py +75 -0
  26. RATapi/examples/languages/__init__.py +0 -0
  27. RATapi/examples/languages/custom_bilayer.py +66 -0
  28. RATapi/examples/languages/run_custom_file_languages.py +41 -0
  29. RATapi/examples/languages/setup_problem.py +130 -0
  30. RATapi/examples/non_polarised/DSPC_custom_XY.py +140 -0
  31. RATapi/examples/non_polarised/DSPC_custom_layers.py +121 -0
  32. RATapi/examples/non_polarised/DSPC_standard_layers.py +358 -0
  33. RATapi/examples/non_polarised/__init__.py +0 -0
  34. RATapi/examples/non_polarised/custom_XY_DSPC.py +137 -0
  35. RATapi/examples/non_polarised/custom_bilayer_DSPC.py +85 -0
  36. RATapi/inputs.py +471 -0
  37. RATapi/models.py +288 -0
  38. RATapi/outputs.py +218 -0
  39. RATapi/project.py +659 -0
  40. RATapi/rat_core.cp310-win_amd64.pyd +0 -0
  41. RATapi/run.py +35 -0
  42. RATapi/utils/__init__.py +0 -0
  43. RATapi/utils/custom_errors.py +42 -0
  44. RATapi/utils/enums.py +101 -0
  45. RATapi/utils/plotting.py +211 -0
  46. RATapi/wrappers.py +115 -0
  47. RATapi-0.0.0.dev0.dist-info/METADATA +57 -0
  48. RATapi-0.0.0.dev0.dist-info/RECORD +64 -0
  49. RATapi-0.0.0.dev0.dist-info/WHEEL +5 -0
  50. RATapi-0.0.0.dev0.dist-info/top_level.txt +2 -0
  51. tests/__init__.py +0 -0
  52. tests/conftest.py +4728 -0
  53. tests/test_classlist.py +882 -0
  54. tests/test_controls.py +863 -0
  55. tests/test_custom_errors.py +49 -0
  56. tests/test_events.py +61 -0
  57. tests/test_inputs.py +908 -0
  58. tests/test_models.py +308 -0
  59. tests/test_outputs.py +31 -0
  60. tests/test_plotting.py +167 -0
  61. tests/test_project.py +1387 -0
  62. tests/test_run.py +570 -0
  63. tests/test_wrappers.py +57 -0
  64. tests/utils.py +171 -0
@@ -0,0 +1,121 @@
1
+ """Custom Layers example for Supported DSPC layer.
2
+
3
+ Example of using custom layers to model a DSPC supported bilayer.
4
+ """
5
+
6
+ import os
7
+ import pathlib
8
+
9
+ import numpy as np
10
+
11
+ import RATapi as RAT
12
+
13
+ problem = RAT.Project(name="Orso lipid example - custom layers", model="custom layers", geometry="substrate/liquid")
14
+
15
+ # First we need to set up a parameters group. We will be using a pre-prepared custom model file, so we need to add the
16
+ # relevant parameters we are going to need to define the model (note that Substrate Roughness always exists as
17
+ # parameter 1).
18
+ problem.parameters.append(name="Oxide Thickness", min=5.0, value=20.0, max=60.0, fit=True)
19
+ problem.parameters.append(name="Oxide Hydration", min=0.0, value=0.2, max=0.5, fit=True)
20
+ problem.parameters.append(name="Lipid APM", min=45.0, value=55.0, max=65.0, fit=True)
21
+ problem.parameters.append(name="Head Hydration", min=0.0, value=0.2, max=0.5, fit=True)
22
+ problem.parameters.append(name="Bilayer Hydration", min=0.0, value=0.1, max=0.2, fit=True)
23
+ problem.parameters.append(name="Bilayer Roughness", min=2.0, value=4.0, max=8.0, fit=True)
24
+ problem.parameters.append(name="Water Thickness", min=0.0, value=2.0, max=10.0, fit=True)
25
+
26
+ problem.parameters.set_fields(0, min=1.0, max=10.0)
27
+
28
+ # Need to add the relevant Bulk SLDs. Change the bulk in from air to silicon, and add two additional water 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 Water
37
+ # and H2O.Load these datafiles in and put them in the data block
38
+
39
+ # Read in the datafiles
40
+ data_path = os.path.join(pathlib.Path(__file__).parents[1].resolve(), "data")
41
+ D2O_data = np.loadtxt(os.path.join(data_path, "c_PLP0016596.dat"), delimiter=",")
42
+ SMW_data = np.loadtxt(os.path.join(data_path, "c_PLP0016601.dat"), delimiter=",")
43
+ H2O_data = np.loadtxt(os.path.join(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.resolve(),
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(name="Background parameter SMW", min=1.0e-10, value=1.0e-7, max=1.0e-5, fit=True)
69
+ problem.background_parameters.append(name="Background parameter H2O", min=1.0e-10, value=1.0e-7, max=1.0e-5, fit=True)
70
+
71
+ # And add the two new constant backgrounds
72
+ problem.backgrounds.append(name="Background SMW", type="constant", value_1="Background parameter SMW")
73
+ problem.backgrounds.append(name="Background H2O", type="constant", value_1="Background parameter H2O")
74
+
75
+ # And edit the other one
76
+ problem.backgrounds.set_fields(0, name="Background D2O", value_1="Background parameter D2O")
77
+
78
+ # Finally modify some of the other parameters to be more suitable values for a solid / liquid experiment
79
+ problem.scalefactors.set_fields(0, value=1.0, min=0.5, max=2.0, fit=True)
80
+
81
+ # Also, we are going to use the data resolution
82
+ problem.resolutions.append(name="Data Resolution", type="data")
83
+
84
+ # Now add the three contrasts
85
+ problem.contrasts.append(
86
+ name="Bilayer / D2O",
87
+ background="Background D2O",
88
+ resolution="Data Resolution",
89
+ scalefactor="Scalefactor 1",
90
+ bulk_out="SLD D2O",
91
+ bulk_in="Silicon",
92
+ data="Bilayer / D2O",
93
+ model=["DSPC Model"],
94
+ )
95
+
96
+ problem.contrasts.append(
97
+ name="Bilayer / SMW",
98
+ background="Background SMW",
99
+ resolution="Data Resolution",
100
+ scalefactor="Scalefactor 1",
101
+ bulk_out="SLD SMW",
102
+ bulk_in="Silicon",
103
+ data="Bilayer / SMW",
104
+ model=["DSPC Model"],
105
+ )
106
+
107
+ problem.contrasts.append(
108
+ name="Bilayer / H2O",
109
+ background="Background H2O",
110
+ resolution="Data Resolution",
111
+ scalefactor="Scalefactor 1",
112
+ bulk_out="SLD H2O",
113
+ bulk_in="Silicon",
114
+ data="Bilayer / H2O",
115
+ model=["DSPC Model"],
116
+ )
117
+
118
+ controls = RAT.Controls()
119
+
120
+ problem, results = RAT.run(problem, controls)
121
+ RAT.plotting.plot_ref_sld(problem, results, True)
@@ -0,0 +1,358 @@
1
+ """Standard Layers fit of a DSPC floating bilayer"""
2
+
3
+ import os
4
+ import pathlib
5
+
6
+ import numpy as np
7
+
8
+ import RATapi as RAT
9
+
10
+ problem = RAT.Project(
11
+ name="original_dspc_bilayer",
12
+ calculation="non polarised",
13
+ model="standard layers",
14
+ geometry="substrate/liquid",
15
+ absorption=False,
16
+ )
17
+
18
+ # Set up the relevant parameters
19
+ problem.parameters.append(
20
+ name="Oxide Thickness",
21
+ min=5.0,
22
+ value=19.54,
23
+ max=60.0,
24
+ fit=True,
25
+ prior_type="uniform",
26
+ mu=0.0,
27
+ sigma=np.inf,
28
+ )
29
+ problem.parameters.append(
30
+ name="Oxide SLD",
31
+ min=3.39e-06,
32
+ value=3.39e-06,
33
+ max=3.41e-06,
34
+ fit=False,
35
+ prior_type="uniform",
36
+ mu=0.0,
37
+ sigma=np.inf,
38
+ )
39
+ problem.parameters.append(
40
+ name="SAM Tails Thickness",
41
+ min=15.0,
42
+ value=22.66,
43
+ max=35.0,
44
+ fit=True,
45
+ prior_type="uniform",
46
+ mu=0.0,
47
+ sigma=np.inf,
48
+ )
49
+ problem.parameters.append(
50
+ name="SAM Tails SLD",
51
+ min=-5e-07,
52
+ value=-4.01e-07,
53
+ max=-3e-07,
54
+ fit=False,
55
+ prior_type="uniform",
56
+ mu=0.0,
57
+ sigma=np.inf,
58
+ )
59
+ problem.parameters.append(
60
+ name="SAM Tails Hydration",
61
+ min=1.0,
62
+ value=5.252,
63
+ max=50.0,
64
+ fit=True,
65
+ prior_type="uniform",
66
+ mu=0.0,
67
+ sigma=np.inf,
68
+ )
69
+ problem.parameters.append(
70
+ name="SAM Roughness",
71
+ min=1.0,
72
+ value=5.64,
73
+ max=15.0,
74
+ fit=True,
75
+ prior_type="uniform",
76
+ mu=0.0,
77
+ sigma=np.inf,
78
+ )
79
+ problem.parameters.append(
80
+ name="CW Thickness",
81
+ min=10.0,
82
+ value=17.12,
83
+ max=28.0,
84
+ fit=True,
85
+ prior_type="uniform",
86
+ mu=0.0,
87
+ sigma=np.inf,
88
+ )
89
+ problem.parameters.append(
90
+ name="CW SLD",
91
+ min=0.0,
92
+ value=0.0,
93
+ max=1e-09,
94
+ fit=False,
95
+ prior_type="uniform",
96
+ mu=0.0,
97
+ sigma=np.inf,
98
+ )
99
+ problem.parameters.append(
100
+ name="SAM Heads Thickness",
101
+ min=5.0,
102
+ value=8.56,
103
+ max=17.0,
104
+ fit=True,
105
+ prior_type="gaussian",
106
+ mu=10.0,
107
+ sigma=2.0,
108
+ )
109
+ problem.parameters.append(
110
+ name="SAM Heads SLD",
111
+ min=1.0e-07,
112
+ value=1.75e-06,
113
+ max=2.0e-06,
114
+ fit=False,
115
+ prior_type="uniform",
116
+ mu=0.0,
117
+ sigma=np.inf,
118
+ )
119
+ problem.parameters.append(
120
+ name="SAM Heads Hydration",
121
+ min=10.0,
122
+ value=45.45,
123
+ max=50.0,
124
+ fit=True,
125
+ prior_type="uniform",
126
+ mu=30.0,
127
+ sigma=3.0,
128
+ )
129
+ problem.parameters.append(
130
+ name="Bilayer Heads Thickness",
131
+ min=7.0,
132
+ value=10.7,
133
+ max=17.0,
134
+ fit=True,
135
+ prior_type="gaussian",
136
+ mu=10.0,
137
+ sigma=2.0,
138
+ )
139
+ problem.parameters.append(
140
+ name="Bilayer Heads SLD",
141
+ min=5.0e-07,
142
+ value=1.47e-06,
143
+ max=1.5e-06,
144
+ fit=False,
145
+ prior_type="uniform",
146
+ mu=0.0,
147
+ sigma=np.inf,
148
+ )
149
+ problem.parameters.append(
150
+ name="Bilayer Roughness",
151
+ min=2.0,
152
+ value=6.014,
153
+ max=15.0,
154
+ fit=True,
155
+ prior_type="uniform",
156
+ mu=0.0,
157
+ sigma=np.inf,
158
+ )
159
+ problem.parameters.append(
160
+ name="Bilayer Tails Thickness",
161
+ min=14.0,
162
+ value=17.82,
163
+ max=22.0,
164
+ fit=True,
165
+ prior_type="uniform",
166
+ mu=0.0,
167
+ sigma=np.inf,
168
+ )
169
+ problem.parameters.append(
170
+ name="Bilayer Tails SLD",
171
+ min=-5.0e-07,
172
+ value=-4.61e-07,
173
+ max=0.0,
174
+ fit=False,
175
+ prior_type="uniform",
176
+ mu=0.0,
177
+ sigma=np.inf,
178
+ )
179
+ problem.parameters.append(
180
+ name="Bilayer Tails Hydration",
181
+ min=10.0,
182
+ value=17.64,
183
+ max=50.0,
184
+ fit=True,
185
+ prior_type="uniform",
186
+ mu=0.0,
187
+ sigma=np.inf,
188
+ )
189
+ problem.parameters.append(
190
+ name="Bilayer Heads Hydration",
191
+ min=10.0,
192
+ value=36.15,
193
+ max=50.0,
194
+ fit=True,
195
+ prior_type="gaussian",
196
+ mu=30.0,
197
+ sigma=3.0,
198
+ )
199
+ problem.parameters.append(
200
+ name="CW Hydration",
201
+ min=99.9,
202
+ value=100.0,
203
+ max=100.0,
204
+ fit=False,
205
+ prior_type="uniform",
206
+ mu=0.0,
207
+ sigma=np.inf,
208
+ )
209
+ problem.parameters.append(
210
+ name="Oxide Hydration",
211
+ min=0.0,
212
+ value=23.61,
213
+ max=60.0,
214
+ fit=True,
215
+ prior_type="uniform",
216
+ mu=0.0,
217
+ sigma=np.inf,
218
+ )
219
+
220
+ problem.parameters.set_fields(0, max=10)
221
+
222
+ # Group these into layers
223
+ problem.layers.append(
224
+ name="Oxide",
225
+ thickness="Oxide Thickness",
226
+ SLD="Oxide SLD",
227
+ roughness="Substrate Roughness",
228
+ hydration="Oxide Hydration",
229
+ hydrate_with="bulk out",
230
+ )
231
+
232
+ problem.layers.append(
233
+ name="SAM Tails",
234
+ thickness="SAM Tails Thickness",
235
+ SLD="SAM Tails SLD",
236
+ roughness="SAM Roughness",
237
+ hydration="SAM Tails Hydration",
238
+ hydrate_with="bulk out",
239
+ )
240
+
241
+ problem.layers.append(
242
+ name="SAM Heads",
243
+ thickness="SAM Heads Thickness",
244
+ SLD="SAM Heads SLD",
245
+ roughness="SAM Roughness",
246
+ hydration="SAM Heads Hydration",
247
+ hydrate_with="bulk out",
248
+ )
249
+
250
+ problem.layers.append(
251
+ name="Central Water",
252
+ thickness="CW Thickness",
253
+ SLD="CW SLD",
254
+ roughness="Bilayer Roughness",
255
+ hydration="CW Hydration",
256
+ hydrate_with="bulk out",
257
+ )
258
+
259
+ problem.layers.append(
260
+ name="Bilayer Heads",
261
+ thickness="Bilayer Heads Thickness",
262
+ SLD="Bilayer Heads SLD",
263
+ roughness="Bilayer Roughness",
264
+ hydration="Bilayer Heads Hydration",
265
+ hydrate_with="bulk out",
266
+ )
267
+
268
+ problem.layers.append(
269
+ name="Bilayer Tails",
270
+ thickness="Bilayer Tails Thickness",
271
+ SLD="Bilayer Tails SLD",
272
+ roughness="Bilayer Roughness",
273
+ hydration="Bilayer Tails Hydration",
274
+ hydrate_with="bulk out",
275
+ )
276
+
277
+ # Make the bulk SLDs
278
+ del problem.bulk_in[0]
279
+ problem.bulk_in.append(name="Silicon", min=2.0e-06, value=2.073e-06, max=2.1e-06, fit=False)
280
+
281
+ del problem.bulk_out[0]
282
+ problem.bulk_out.append(name="D2O", min=5.50e-06, value=5.98e-06, max=6.4e-06, fit=True)
283
+ problem.bulk_out.append(name="SMW", min=1.0e-06, value=2.21e-06, max=4.99e-06, fit=True)
284
+
285
+ # Set the scalefactors - use one for each contrast
286
+ del problem.scalefactors[0]
287
+ problem.scalefactors.append(name="Scalefactor 1", min=0.05, value=0.10, max=0.2, fit=False)
288
+ problem.scalefactors.append(name="Scalefactor 2", min=0.05, value=0.15, max=0.2, fit=False)
289
+
290
+ # Now deal with the backgrounds
291
+ del problem.backgrounds[0]
292
+ del problem.background_parameters[0]
293
+ problem.background_parameters.append(
294
+ name="Background parameter D2O",
295
+ min=5.0e-10,
296
+ value=2.23e-06,
297
+ max=7.0e-06,
298
+ fit=True,
299
+ )
300
+ problem.background_parameters.append(
301
+ name="Background parameter SMW",
302
+ min=1.0e-10,
303
+ value=3.38e-06,
304
+ max=4.99e-06,
305
+ fit=True,
306
+ )
307
+
308
+ problem.backgrounds.append(name="D2O Background", type="constant", value_1="Background parameter D2O")
309
+ problem.backgrounds.append(name="SMW Background", type="constant", value_1="Background parameter SMW")
310
+
311
+ # Now add the data
312
+ data_path = os.path.join(pathlib.Path(__file__).parents[1].resolve(), "data")
313
+
314
+ d2o_dat = np.loadtxt(os.path.join(data_path, "DSPC_D2O.dat"), delimiter=",")
315
+ problem.data.append(name="dspc_bil_D2O", data=d2o_dat)
316
+
317
+ smw_dat = np.loadtxt(os.path.join(data_path, "DSPC_SMW.dat"), delimiter=",")
318
+ problem.data.append(name="dspc_bil_smw", data=smw_dat)
319
+
320
+ # Set the model
321
+ stack = [
322
+ "Oxide",
323
+ "SAM Tails",
324
+ "SAM Heads",
325
+ "Central Water",
326
+ "Bilayer Heads",
327
+ "Bilayer Tails",
328
+ "Bilayer Tails",
329
+ "Bilayer Heads",
330
+ ]
331
+
332
+ # Then make the two contrasts
333
+ problem.contrasts.append(
334
+ name="D2O",
335
+ bulk_in="Silicon",
336
+ bulk_out="D2O",
337
+ background="D2O Background",
338
+ resolution="Resolution 1",
339
+ scalefactor="Scalefactor 1",
340
+ data="dspc_bil_D2O",
341
+ model=stack,
342
+ )
343
+
344
+ problem.contrasts.append(
345
+ name="SMW",
346
+ bulk_in="Silicon",
347
+ bulk_out="SMW",
348
+ background="SMW Background",
349
+ resolution="Resolution 1",
350
+ scalefactor="Scalefactor 2",
351
+ data="dspc_bil_smw",
352
+ model=stack,
353
+ )
354
+
355
+ controls = RAT.Controls()
356
+
357
+ problem, results = RAT.run(problem, controls)
358
+ RAT.plotting.plot_ref_sld(problem, results, True)
File without changes
@@ -0,0 +1,137 @@
1
+ import math
2
+
3
+ import numpy as np
4
+
5
+
6
+ def custom_XY_DSPC(params, bulk_in, bulk_out, contrast):
7
+ """This function makes a model of a supported DSPC bilayer using volume restricted distribution functions."""
8
+ # Split up the parameters
9
+ subRough = params[0]
10
+ oxideThick = params[1]
11
+ oxideHydration = params[2]
12
+ waterThick = params[3]
13
+ lipidAPM = params[4]
14
+ lipidCoverage = params[5]
15
+ bilayerRough = params[6]
16
+
17
+ # We are going to need our Neutron scattering cross-sections, plus the component volumes
18
+ # (the volumes are taken from Armen et al as usual).
19
+ # Define these first
20
+
21
+ # define all the neutron b's.
22
+ bc = 0.6646e-4 # Carbon
23
+ bo = 0.5843e-4 # Oxygen
24
+ bh = -0.3739e-4 # Hydrogen
25
+ bp = 0.513e-4 # Phosphorus
26
+ bn = 0.936e-4 # Nitrogen
27
+
28
+ # Now make the lipid groups
29
+ COO = (4 * bo) + (2 * bc)
30
+ GLYC = (3 * bc) + (5 * bh)
31
+ CH3 = (2 * bc) + (6 * bh)
32
+ PO4 = (1 * bp) + (4 * bo)
33
+ CH2 = (1 * bc) + (2 * bh)
34
+ CHOL = (5 * bc) + (12 * bh) + (1 * bn)
35
+
36
+ # Group these into heads and tails
37
+ heads = CHOL + PO4 + GLYC + COO
38
+ tails = (34 * CH2) + (2 * CH3)
39
+
40
+ # We need volumes for each. Use literature values
41
+ vHead = 319
42
+ vTail = 782
43
+
44
+ # Start making our sections. For each we are using a roughened Heaviside to describe our groups.
45
+ # We will make these as Volume Fractions (i.e. with a height of 1 for full occupancy),
46
+ # which we will correct later for hydration.
47
+
48
+ # Make an array of z values for our model
49
+ z = np.arange(0, 141)
50
+
51
+ # Make our Silicon substrate
52
+ vfSilicon, siSurf = layer(z, -25, 50, 1, subRough, subRough)
53
+
54
+ # Add the Oxide
55
+ vfOxide, oxSurface = layer(z, siSurf, oxideThick, 1, subRough, subRough)
56
+
57
+ # We fill in the water at the end, but there may be a hydration layer between the bilayer and the oxide,
58
+ # so we start the bilayer stack an appropriate distance away
59
+ watSurface = oxSurface + waterThick
60
+
61
+ # Now make the first lipid head group
62
+ # Work out the thickness
63
+ headThick = vHead / lipidAPM
64
+
65
+ # ... and make a box for the volume fraction (1 for now, we correct for coverage later)
66
+ vfHeadL, headLSurface = layer(z, watSurface, headThick, 1, bilayerRough, bilayerRough)
67
+
68
+ # ... also do the same for the tails
69
+ # We'll make both together, so the thickness will be twice the volume
70
+ tailsThick = (2 * vTail) / lipidAPM
71
+ vfTails, tailsSurf = layer(z, headLSurface, tailsThick, 1, bilayerRough, bilayerRough)
72
+
73
+ # Finally the upper head ...
74
+ vfHeadR, headSurface = layer(z, tailsSurf, headThick, 1, bilayerRough, bilayerRough)
75
+
76
+ # Making the model
77
+ # We've created the volume fraction profiles corresponding to each of the groups.
78
+ # We now convert them to SLDs, taking in account of the hydrations to scale the volume fractions
79
+
80
+ # 1. Oxide ...
81
+ vfOxide = vfOxide * (1 - oxideHydration)
82
+
83
+ # 2. Lipid ...
84
+ # Scale both the heads and tails according to overall coverage
85
+ vfTails = vfTails * lipidCoverage
86
+ vfHeadL = vfHeadL * lipidCoverage
87
+ vfHeadR = vfHeadR * lipidCoverage
88
+
89
+ # Some extra work to deal with head hydration, which we take to be an additional 30% always
90
+ vfHeadL = vfHeadL * 0.7
91
+ vfHeadR = vfHeadR * 0.7
92
+
93
+ # Make a total Volume Fraction across the whole interface
94
+ vfTot = vfSilicon + vfOxide + vfHeadL + vfTails + vfHeadR
95
+
96
+ # All the volume that's left, we will fill with water
97
+ vfWat = 1 - vfTot
98
+
99
+ # Now convert all the Volume Fractions to SLDs
100
+ sld_Value_Tails = tails / vTail
101
+ sld_Value_Head = heads / vHead
102
+
103
+ sldSilicon = vfSilicon * 2.073e-6
104
+ sldOxide = vfOxide * 3.41e-6
105
+
106
+ sldHeadL = vfHeadL * sld_Value_Head
107
+ sldHeadR = vfHeadR * sld_Value_Head
108
+ sldTails = vfTails * sld_Value_Tails
109
+ sldWat = vfWat * bulk_out[contrast]
110
+
111
+ # Put this all together
112
+ totSLD = sldSilicon + sldOxide + sldHeadL + sldTails + sldHeadR + sldWat
113
+
114
+ # Make the SLD array for output
115
+ SLD = [[a, b] for (a, b) in zip(z, totSLD)]
116
+
117
+ return SLD, subRough
118
+
119
+
120
+ def layer(z, prevLaySurf, thickness, height, Sigma_L, Sigma_R):
121
+ """This produces a layer, with a defined thickness, height and roughness.
122
+ Each side of the layer has its own roughness value.
123
+ """
124
+ # Find the edges
125
+ left = prevLaySurf
126
+ right = prevLaySurf + thickness
127
+
128
+ # Make our heaviside
129
+ a = (z - left) / ((2**0.5) * Sigma_L)
130
+ b = (z - right) / ((2**0.5) * Sigma_R)
131
+
132
+ erf_a = np.array([math.erf(value) for value in a])
133
+ erf_b = np.array([math.erf(value) for value in b])
134
+
135
+ VF = np.array((height / 2) * (erf_a - erf_b))
136
+
137
+ return VF, right
@@ -0,0 +1,85 @@
1
+ import numpy as np
2
+
3
+
4
+ def custom_bilayer_DSPC(params, bulk_in, bulk_out, contrast):
5
+ """CUSTOMBILAYER RAT Custom Layer Model File.
6
+
7
+ This file accepts 3 vectors containing the values for params, bulk in and bulk out.
8
+ The final parameter is an index of the contrast being calculated.
9
+
10
+ The function should output a matrix of layer values, in the form...
11
+
12
+ Output = [thick 1, SLD 1, Rough 1, Percent Hydration 1, Hydrate how 1
13
+ ....
14
+ thick n, SLD n, Rough n, Percent Hydration n, Hydration how n]
15
+
16
+ The "hydrate how" parameter decides if the layer is hydrated with Bulk out or Bulk in phases.
17
+ Set to 1 for Bulk out, zero for Bulk in.
18
+ Alternatively, leave out hydration and just return...
19
+
20
+ Output = [thick 1, SLD 1, Rough 1,
21
+ ....
22
+ thick n, SLD n, Rough n]
23
+
24
+ The second output parameter should be the substrate roughness.
25
+ """
26
+ sub_rough = params[0]
27
+ oxide_thick = params[1]
28
+ oxide_hydration = params[2]
29
+ lipidAPM = params[3]
30
+ headHydration = params[4]
31
+ bilayerHydration = params[5]
32
+ bilayerRough = params[6]
33
+ waterThick = params[7]
34
+
35
+ # We have a constant SLD for the bilayer
36
+ oxide_SLD = 3.41e-6
37
+
38
+ # Now make the lipid layers
39
+ # Use known lipid volume and compositions to make the layers
40
+
41
+ # define all the neutron b's.
42
+ bc = 0.6646e-4 # Carbon
43
+ bo = 0.5843e-4 # Oxygen
44
+ bh = -0.3739e-4 # Hydrogen
45
+ bp = 0.513e-4 # Phosphorus
46
+ bn = 0.936e-4 # Nitrogen
47
+
48
+ # Now make the lipid groups
49
+ COO = (4 * bo) + (2 * bc)
50
+ GLYC = (3 * bc) + (5 * bh)
51
+ CH3 = (2 * bc) + (6 * bh)
52
+ PO4 = (1 * bp) + (4 * bo)
53
+ CH2 = (1 * bc) + (2 * bh)
54
+ CHOL = (5 * bc) + (12 * bh) + (1 * bn)
55
+
56
+ # Group these into heads and tails:
57
+ Head = CHOL + PO4 + GLYC + COO
58
+ Tails = (34 * CH2) + (2 * CH3)
59
+
60
+ # We need volumes for each. Use literature values:
61
+ vHead = 319
62
+ vTail = 782
63
+
64
+ # We use the volumes to calculate the SLDs
65
+ SLDhead = Head / vHead
66
+ SLDtail = Tails / vTail
67
+
68
+ # We calculate the layer thickness' from the volumes and the APM
69
+ headThick = vHead / lipidAPM
70
+ tailThick = vTail / lipidAPM
71
+
72
+ # Manually deal with hydration for layers in this example.
73
+ oxSLD = (oxide_hydration * bulk_out[contrast]) + ((1 - oxide_hydration) * oxide_SLD)
74
+ headSLD = (headHydration * bulk_out[contrast]) + ((1 - headHydration) * SLDhead)
75
+ tailSLD = (bilayerHydration * bulk_out[contrast]) + ((1 - bilayerHydration) * SLDtail)
76
+
77
+ # Make the layers
78
+ oxide = [oxide_thick, oxSLD, sub_rough]
79
+ water = [waterThick, bulk_out[contrast], bilayerRough]
80
+ head = [headThick, headSLD, bilayerRough]
81
+ tail = [tailThick, tailSLD, bilayerRough]
82
+
83
+ output = np.array([oxide, water, head, tail, tail, head])
84
+
85
+ return output, sub_rough