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.
Files changed (63) hide show
  1. ratapi/__init__.py +42 -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 +144 -0
  10. ratapi/examples/convert_rascal_project/Model_IIb.py +90 -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 +34 -0
  26. ratapi/examples/domains/domains_XY_model.py +75 -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 +72 -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 +141 -0
  42. ratapi/examples/normal_reflectivity/custom_bilayer_DSPC.py +89 -0
  43. ratapi/inputs.py +603 -0
  44. ratapi/models.py +717 -0
  45. ratapi/outputs.py +821 -0
  46. ratapi/project.py +1091 -0
  47. ratapi/rat_core.cp315-win_amd64.pyd +0 -0
  48. ratapi/run.py +142 -0
  49. ratapi/utils/__init__.py +1 -0
  50. ratapi/utils/convert.py +597 -0
  51. ratapi/utils/custom_errors.py +40 -0
  52. ratapi/utils/enums.py +203 -0
  53. ratapi/utils/matlab.py +254 -0
  54. ratapi/utils/orso.py +247 -0
  55. ratapi/utils/plotting.py +1316 -0
  56. ratapi/wrappers.py +147 -0
  57. ratapi-0.0.0.dev16.dist-info/DELVEWHEEL +2 -0
  58. ratapi-0.0.0.dev16.dist-info/METADATA +61 -0
  59. ratapi-0.0.0.dev16.dist-info/RECORD +63 -0
  60. ratapi-0.0.0.dev16.dist-info/WHEEL +5 -0
  61. ratapi-0.0.0.dev16.dist-info/top_level.txt +1 -0
  62. ratapi.libs/msvcp140-a4c2229bdc2a2a630acdc095b4d86008.dll +0 -0
  63. ratapi.libs/vcomp140-f96f3a14d88d8846f31f3ab38a490304.dll +0 -0
@@ -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)
@@ -0,0 +1,210 @@
1
+ """An example of a standard layers model in RAT."""
2
+
3
+ import pathlib
4
+
5
+ import numpy as np
6
+
7
+ import ratapi as RAT
8
+
9
+
10
+ def DSPC_standard_layers():
11
+ """Calculate a standard Layers fit of a DSPC floating bilayer.
12
+
13
+ The sample consists of a DSPC bilayer, on a silane SAM on Silicon.
14
+ """
15
+ problem = RAT.Project(name="original_dspc_bilayer", model="standard layers", geometry="substrate/liquid")
16
+
17
+ # Set up the relevant parameters
18
+ problem.parameters.append(name="Oxide Thickness", min=5.0, value=19.54, max=60.0, fit=True)
19
+ problem.parameters.append(name="Oxide SLD", min=3.39e-06, value=3.39e-06, max=3.41e-06, fit=False)
20
+ problem.parameters.append(name="SAM Tails Thickness", min=15.0, value=22.66, max=35.0, fit=True)
21
+ problem.parameters.append(name="SAM Tails SLD", min=-5e-07, value=-4.01e-07, max=-3e-07, fit=False)
22
+ problem.parameters.append(name="SAM Tails Hydration", min=1.0, value=5.252, max=50.0, fit=True)
23
+ problem.parameters.append(name="SAM Roughness", min=1.0, value=5.64, max=15.0, fit=True)
24
+ problem.parameters.append(name="CW Thickness", min=10.0, value=17.12, max=28.0, fit=True)
25
+ problem.parameters.append(name="CW SLD", min=0.0, value=0.0, max=0.0, fit=False)
26
+
27
+ problem.parameters.append(
28
+ name="SAM Heads Thickness",
29
+ min=5.0,
30
+ value=8.56,
31
+ max=17.0,
32
+ fit=True,
33
+ prior_type="gaussian",
34
+ mu=10.0,
35
+ sigma=2.0,
36
+ )
37
+ problem.parameters.append(name="SAM Heads SLD", min=1.0e-07, value=1.75e-06, max=2.0e-06, fit=False)
38
+ problem.parameters.append(
39
+ name="SAM Heads Hydration",
40
+ min=10.0,
41
+ value=45.45,
42
+ max=50.0,
43
+ fit=True,
44
+ prior_type="gaussian",
45
+ mu=30.0,
46
+ sigma=3.0,
47
+ )
48
+ problem.parameters.append(
49
+ name="Bilayer Heads Thickness",
50
+ min=7.0,
51
+ value=10.7,
52
+ max=17.0,
53
+ fit=True,
54
+ prior_type="gaussian",
55
+ mu=10.0,
56
+ sigma=2.0,
57
+ )
58
+ problem.parameters.append(name="Bilayer Heads SLD", min=5.0e-07, value=1.47e-06, max=1.5e-06, fit=False)
59
+ problem.parameters.append(name="Bilayer Roughness", min=2.0, value=6.014, max=15.0, fit=True)
60
+ problem.parameters.append(name="Bilayer Tails Thickness", min=14.0, value=17.82, max=22.0, fit=True)
61
+ problem.parameters.append(name="Bilayer Tails SLD", min=-5.0e-07, value=-4.61e-07, max=0.0, fit=False)
62
+ problem.parameters.append(name="Bilayer Tails Hydration", min=10.0, value=17.64, max=50.0, fit=True)
63
+ problem.parameters.append(name="Bilayer Heads Hydration", min=10.0, value=36.15, max=50.0, fit=True)
64
+ problem.parameters.append(name="CW Hydration", min=99.9, value=100.0, max=100.0, fit=False)
65
+ problem.parameters.append(name="Oxide Hydration", min=0.0, value=23.61, max=60.0, fit=True)
66
+
67
+ problem.parameters.set_fields(0, max=10)
68
+
69
+ # Group these into layers
70
+ problem.layers.append(
71
+ name="Oxide",
72
+ thickness="Oxide Thickness",
73
+ SLD="Oxide SLD",
74
+ roughness="Substrate Roughness",
75
+ hydration="Oxide Hydration",
76
+ hydrate_with="bulk out",
77
+ )
78
+
79
+ problem.layers.append(
80
+ name="SAM Tails",
81
+ thickness="SAM Tails Thickness",
82
+ SLD="SAM Tails SLD",
83
+ roughness="SAM Roughness",
84
+ hydration="SAM Tails Hydration",
85
+ hydrate_with="bulk out",
86
+ )
87
+
88
+ problem.layers.append(
89
+ name="SAM Heads",
90
+ thickness="SAM Heads Thickness",
91
+ SLD="SAM Heads SLD",
92
+ roughness="SAM Roughness",
93
+ hydration="SAM Heads Hydration",
94
+ hydrate_with="bulk out",
95
+ )
96
+
97
+ problem.layers.append(
98
+ name="Central Water",
99
+ thickness="CW Thickness",
100
+ SLD="CW SLD",
101
+ roughness="Bilayer Roughness",
102
+ hydration="CW Hydration",
103
+ hydrate_with="bulk out",
104
+ )
105
+
106
+ problem.layers.append(
107
+ name="Bilayer Heads",
108
+ thickness="Bilayer Heads Thickness",
109
+ SLD="Bilayer Heads SLD",
110
+ roughness="Bilayer Roughness",
111
+ hydration="Bilayer Heads Hydration",
112
+ hydrate_with="bulk out",
113
+ )
114
+
115
+ problem.layers.append(
116
+ name="Bilayer Tails",
117
+ thickness="Bilayer Tails Thickness",
118
+ SLD="Bilayer Tails SLD",
119
+ roughness="Bilayer Roughness",
120
+ hydration="Bilayer Tails Hydration",
121
+ hydrate_with="bulk out",
122
+ )
123
+
124
+ # Make the bulk SLDs
125
+ del problem.bulk_in[0]
126
+ problem.bulk_in.append(name="Silicon", min=2.0e-06, value=2.073e-06, max=2.1e-06, fit=False)
127
+
128
+ del problem.bulk_out[0]
129
+ problem.bulk_out.append(name="D2O", min=5.50e-06, value=5.98e-06, max=6.4e-06, fit=True)
130
+ problem.bulk_out.append(name="SMW", min=1.0e-06, value=2.21e-06, max=4.99e-06, fit=True)
131
+
132
+ # Set the scalefactors - use one for each contrast
133
+ del problem.scalefactors[0]
134
+ problem.scalefactors.append(name="Scalefactor 1", min=0.05, value=0.10, max=0.2, fit=True)
135
+ problem.scalefactors.append(name="Scalefactor 2", min=0.05, value=0.15, max=0.2, fit=True)
136
+
137
+ # Now deal with the backgrounds
138
+ del problem.backgrounds[0]
139
+ del problem.background_parameters[0]
140
+ problem.background_parameters.append(
141
+ name="Background parameter D2O",
142
+ min=5.0e-10,
143
+ value=2.23e-06,
144
+ max=7.0e-06,
145
+ fit=True,
146
+ )
147
+ problem.background_parameters.append(
148
+ name="Background parameter SMW",
149
+ min=1.0e-10,
150
+ value=3.38e-06,
151
+ max=4.99e-06,
152
+ fit=True,
153
+ )
154
+
155
+ problem.backgrounds.append(name="D2O Background", type="constant", source="Background parameter D2O")
156
+ problem.backgrounds.append(name="SMW Background", type="constant", source="Background parameter SMW")
157
+
158
+ # Now add the data
159
+ data_path = pathlib.Path(__file__).parents[1] / "data"
160
+
161
+ d2o_dat = np.loadtxt(data_path / "DSPC_D2O.dat", delimiter=",")
162
+ problem.data.append(name="dspc_bil_D2O", data=d2o_dat)
163
+
164
+ smw_dat = np.loadtxt(data_path / "DSPC_SMW.dat", delimiter=",")
165
+ problem.data.append(name="dspc_bil_smw", data=smw_dat)
166
+
167
+ # Set the model
168
+ stack = [
169
+ "Oxide",
170
+ "SAM Tails",
171
+ "SAM Heads",
172
+ "Central Water",
173
+ "Bilayer Heads",
174
+ "Bilayer Tails",
175
+ "Bilayer Tails",
176
+ "Bilayer Heads",
177
+ ]
178
+
179
+ # Then make the two contrasts
180
+ problem.contrasts.append(
181
+ name="D2O",
182
+ bulk_in="Silicon",
183
+ bulk_out="D2O",
184
+ background="D2O Background",
185
+ resolution="Resolution 1",
186
+ scalefactor="Scalefactor 1",
187
+ data="dspc_bil_D2O",
188
+ model=stack,
189
+ )
190
+
191
+ problem.contrasts.append(
192
+ name="SMW",
193
+ bulk_in="Silicon",
194
+ bulk_out="SMW",
195
+ background="SMW Background",
196
+ resolution="Resolution 1",
197
+ scalefactor="Scalefactor 2",
198
+ data="dspc_bil_smw",
199
+ model=stack,
200
+ )
201
+
202
+ controls = RAT.Controls()
203
+ problem, results = RAT.run(problem, controls)
204
+
205
+ return problem, results
206
+
207
+
208
+ if __name__ == "__main__":
209
+ problem, results = DSPC_standard_layers()
210
+ RAT.plotting.plot_ref_sld(problem, results, True)
@@ -0,0 +1 @@
1
+ """Examples of normal reflectivity calculations in RAT."""
@@ -0,0 +1,16 @@
1
+ """A background function for an example."""
2
+
3
+ import numpy as np
4
+
5
+
6
+ def background_function(xdata, params):
7
+ """Return the background function for a given set of points in q."""
8
+ # Split up the params array
9
+ Ao = params[0]
10
+ k = params[1]
11
+ back_const = params[2]
12
+
13
+ # Make an exponential decay background
14
+ background = Ao * np.exp(-k * np.array(xdata)) + back_const
15
+
16
+ return background
@@ -0,0 +1,141 @@
1
+ """A custom XY model for a supported DSPC bilayer."""
2
+
3
+ from math import sqrt
4
+
5
+ import numpy as np
6
+ from scipy.special import erf
7
+
8
+
9
+ def custom_XY_DSPC(params, bulk_in, bulk_out, contrast):
10
+ """Calculate the continuous SLD of a supported DSPC bilayer using volume restricted distribution functions."""
11
+ # Note - The first contrast number is 1 (not 0) so be careful if you use
12
+ # this variable for array indexing.
13
+
14
+ # Split up the parameters
15
+ subRough = params[0]
16
+ oxideThick = params[1]
17
+ oxideHydration = params[2]
18
+ waterThick = params[3]
19
+ lipidAPM = params[4]
20
+ lipidCoverage = params[5]
21
+ bilayerRough = params[6]
22
+
23
+ # We are going to need our Neutron scattering cross-sections, plus the component volumes
24
+ # (the volumes are taken from Armen et al as usual).
25
+ # Define these first
26
+
27
+ # define all the neutron b's.
28
+ bc = 0.6646e-4 # Carbon
29
+ bo = 0.5843e-4 # Oxygen
30
+ bh = -0.3739e-4 # Hydrogen
31
+ bp = 0.513e-4 # Phosphorus
32
+ bn = 0.936e-4 # Nitrogen
33
+
34
+ # Now make the lipid groups
35
+ COO = (4 * bo) + (2 * bc)
36
+ GLYC = (3 * bc) + (5 * bh)
37
+ CH3 = (2 * bc) + (6 * bh)
38
+ PO4 = (1 * bp) + (4 * bo)
39
+ CH2 = (1 * bc) + (2 * bh)
40
+ CHOL = (5 * bc) + (12 * bh) + (1 * bn)
41
+
42
+ # Group these into heads and tails
43
+ heads = CHOL + PO4 + GLYC + COO
44
+ tails = (34 * CH2) + (2 * CH3)
45
+
46
+ # We need volumes for each. Use literature values
47
+ vHead = 319
48
+ vTail = 782
49
+
50
+ # Start making our sections. For each we are using a roughened Heaviside to describe our groups.
51
+ # We will make these as Volume Fractions (i.e. with a height of 1 for full occupancy),
52
+ # which we will correct later for hydration.
53
+
54
+ # Make an array of z values for our model
55
+ z = np.arange(0, 141)
56
+
57
+ # Make our Silicon substrate
58
+ vfSilicon, siSurf = make_layer(z, -25, 50, 1, subRough, subRough)
59
+
60
+ # Add the Oxide
61
+ vfOxide, oxSurface = make_layer(z, siSurf, oxideThick, 1, subRough, subRough)
62
+
63
+ # We fill in the water at the end, but there may be a hydration layer between the bilayer and the oxide,
64
+ # so we start the bilayer stack an appropriate distance away
65
+ watSurface = oxSurface + waterThick
66
+
67
+ # Now make the first lipid head group
68
+ # Work out the thickness
69
+ headThick = vHead / lipidAPM
70
+
71
+ # ... and make a box for the volume fraction (1 for now, we correct for coverage later)
72
+ vfHeadL, headLSurface = make_layer(z, watSurface, headThick, 1, bilayerRough, bilayerRough)
73
+
74
+ # ... also do the same for the tails
75
+ # We'll make both together, so the thickness will be twice the volume
76
+ tailsThick = (2 * vTail) / lipidAPM
77
+ vfTails, tailsSurf = make_layer(z, headLSurface, tailsThick, 1, bilayerRough, bilayerRough)
78
+
79
+ # Finally the upper head ...
80
+ vfHeadR, headSurface = make_layer(z, tailsSurf, headThick, 1, bilayerRough, bilayerRough)
81
+
82
+ # Making the model
83
+ # We've created the volume fraction profiles corresponding to each of the groups.
84
+ # We now convert them to SLDs, taking in account of the hydrations to scale the volume fractions
85
+
86
+ # 1. Oxide ...
87
+ vfOxide = vfOxide * (1 - oxideHydration)
88
+
89
+ # 2. Lipid ...
90
+ # Scale both the heads and tails according to overall coverage
91
+ vfTails = vfTails * lipidCoverage
92
+ vfHeadL = vfHeadL * lipidCoverage
93
+ vfHeadR = vfHeadR * lipidCoverage
94
+
95
+ # Some extra work to deal with head hydration, which we take to be an additional 30% always
96
+ vfHeadL = vfHeadL * 0.7
97
+ vfHeadR = vfHeadR * 0.7
98
+
99
+ # Make a total Volume Fraction across the whole interface
100
+ vfTot = vfSilicon + vfOxide + vfHeadL + vfTails + vfHeadR
101
+
102
+ # All the volume that's left, we will fill with water
103
+ vfWat = 1 - vfTot
104
+
105
+ # Now convert all the Volume Fractions to SLDs
106
+ sld_Value_Tails = tails / vTail
107
+ sld_Value_Head = heads / vHead
108
+
109
+ sldSilicon = vfSilicon * 2.073e-6
110
+ sldOxide = vfOxide * 3.41e-6
111
+
112
+ sldHeadL = vfHeadL * sld_Value_Head
113
+ sldHeadR = vfHeadR * sld_Value_Head
114
+ sldTails = vfTails * sld_Value_Tails
115
+ sldWat = vfWat * bulk_out[contrast - 1]
116
+
117
+ # Put this all together
118
+ totSLD = sldSilicon + sldOxide + sldHeadL + sldTails + sldHeadR + sldWat
119
+
120
+ # Make the SLD array for output
121
+ SLD = np.column_stack((z, totSLD))
122
+
123
+ return SLD, subRough
124
+
125
+
126
+ def make_layer(z, prevLaySurf, thickness, height, Sigma_L, Sigma_R):
127
+ """Produce a layer, with a defined thickness, height and roughness.
128
+
129
+ Each side of the layer has its own roughness value.
130
+ """
131
+ # Find the edges
132
+ left = prevLaySurf
133
+ right = prevLaySurf + thickness
134
+
135
+ # Make our heaviside
136
+ erf_left = erf((z - left) / (sqrt(2) * Sigma_L))
137
+ erf_right = erf((z - right) / (sqrt(2) * Sigma_R))
138
+
139
+ VF = np.array((0.5 * height) * (erf_left - erf_right))
140
+
141
+ return VF, right
@@ -0,0 +1,89 @@
1
+ """A custom layer model for a DSPC supported bilayer."""
2
+
3
+ import numpy as np
4
+
5
+
6
+ def custom_bilayer_DSPC(params, bulk_in, bulk_out, contrast):
7
+ """Calculate layer parameters for a DSPC supported bilayer.
8
+
9
+ This file accepts 3 vectors containing the values for params, bulk in and bulk out.
10
+ The final parameter is an index of the contrast being calculated.
11
+
12
+ The function should output a matrix of layer values, in the form...
13
+
14
+ Output = [thick 1, SLD 1, Rough 1, Percent Hydration 1, Hydrate how 1
15
+ ....
16
+ thick n, SLD n, Rough n, Percent Hydration n, Hydration how n]
17
+
18
+ The "hydrate how" parameter decides if the layer is hydrated with Bulk out or Bulk in phases.
19
+ Set to 1 for Bulk out, zero for Bulk in.
20
+ Alternatively, leave out hydration and just return...
21
+
22
+ Output = [thick 1, SLD 1, Rough 1,
23
+ ....
24
+ thick n, SLD n, Rough n]
25
+
26
+ The second output parameter should be the substrate roughness.
27
+ """
28
+ # Note - The first contrast number is 1 (not 0) so be careful if you use
29
+ # this variable for array indexing.
30
+ sub_rough = params[0]
31
+ oxide_thick = params[1]
32
+ oxide_hydration = params[2]
33
+ lipidAPM = params[3]
34
+ headHydration = params[4]
35
+ bilayerHydration = params[5]
36
+ bilayerRough = params[6]
37
+ waterThick = params[7]
38
+
39
+ # We have a constant SLD for the bilayer
40
+ oxide_SLD = 3.41e-6
41
+
42
+ # Now make the lipid layers
43
+ # Use known lipid volume and compositions to make the layers
44
+
45
+ # define all the neutron b's.
46
+ bc = 0.6646e-4 # Carbon
47
+ bo = 0.5843e-4 # Oxygen
48
+ bh = -0.3739e-4 # Hydrogen
49
+ bp = 0.513e-4 # Phosphorus
50
+ bn = 0.936e-4 # Nitrogen
51
+
52
+ # Now make the lipid groups
53
+ COO = (4 * bo) + (2 * bc)
54
+ GLYC = (3 * bc) + (5 * bh)
55
+ CH3 = (2 * bc) + (6 * bh)
56
+ PO4 = (1 * bp) + (4 * bo)
57
+ CH2 = (1 * bc) + (2 * bh)
58
+ CHOL = (5 * bc) + (12 * bh) + (1 * bn)
59
+
60
+ # Group these into heads and tails:
61
+ Head = CHOL + PO4 + GLYC + COO
62
+ Tails = (34 * CH2) + (2 * CH3)
63
+
64
+ # We need volumes for each. Use literature values:
65
+ vHead = 319
66
+ vTail = 782
67
+
68
+ # We use the volumes to calculate the SLDs
69
+ SLDhead = Head / vHead
70
+ SLDtail = Tails / vTail
71
+
72
+ # We calculate the layer thickness' from the volumes and the APM
73
+ headThick = vHead / lipidAPM
74
+ tailThick = vTail / lipidAPM
75
+
76
+ # Manually deal with hydration for layers in this example.
77
+ oxSLD = (oxide_hydration * bulk_out[contrast - 1]) + ((1 - oxide_hydration) * oxide_SLD)
78
+ headSLD = (headHydration * bulk_out[contrast - 1]) + ((1 - headHydration) * SLDhead)
79
+ tailSLD = (bilayerHydration * bulk_out[contrast - 1]) + ((1 - bilayerHydration) * SLDtail)
80
+
81
+ # Make the layers
82
+ oxide = [oxide_thick, oxSLD, sub_rough]
83
+ water = [waterThick, bulk_out[contrast - 1], bilayerRough]
84
+ head = [headThick, headSLD, bilayerRough]
85
+ tail = [tailThick, tailSLD, bilayerRough]
86
+
87
+ output = np.array([oxide, water, head, tail, tail, head])
88
+
89
+ return output, sub_rough