forked from RascalSoftware/python-RAT
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDSPC_function_background.py
More file actions
219 lines (188 loc) · 7.23 KB
/
DSPC_function_background.py
File metadata and controls
219 lines (188 loc) · 7.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
"""A standard layers example with a function background."""
import pathlib
import numpy as np
import RATapi as RAT
def DSPC_function_background():
"""Calculate a standard Layers fit of a DSPC floating bilayer with a function background."""
problem = RAT.Project(name="original_dspc_bilayer", model="standard layers", geometry="substrate/liquid")
# Set up the relevant parameters
problem.parameters.append(name="Oxide Thickness", min=5.0, value=19.54, max=60.0, fit=True)
problem.parameters.append(name="Oxide SLD", min=3.39e-06, value=3.39e-06, max=3.41e-06, fit=False)
problem.parameters.append(name="SAM Tails Thickness", min=15.0, value=22.66, max=35.0, fit=True)
problem.parameters.append(name="SAM Tails SLD", min=-5e-07, value=-4.01e-07, max=-3e-07, fit=False)
problem.parameters.append(name="SAM Tails Hydration", min=1.0, value=5.252, max=50.0, fit=True)
problem.parameters.append(name="SAM Roughness", min=1.0, value=5.64, max=15.0, fit=True)
problem.parameters.append(name="CW Thickness", min=10.0, value=17.12, max=28.0, fit=True)
problem.parameters.append(name="CW SLD", min=0.0, value=0.0, max=1e-09, fit=False)
problem.parameters.append(
name="SAM Heads Thickness",
min=5.0,
value=8.56,
max=17.0,
fit=True,
prior_type="gaussian",
mu=10.0,
sigma=2.0,
)
problem.parameters.append(name="SAM Heads SLD", min=1.0e-07, value=1.75e-06, max=2.0e-06, fit=False)
problem.parameters.append(
name="SAM Heads Hydration",
min=10.0,
value=45.45,
max=50.0,
fit=True,
prior_type="gaussian",
mu=30.0,
sigma=3.0,
)
problem.parameters.append(
name="Bilayer Heads Thickness",
min=7.0,
value=10.7,
max=17.0,
fit=True,
prior_type="gaussian",
mu=10.0,
sigma=2.0,
)
problem.parameters.append(name="Bilayer Heads SLD", min=5.0e-07, value=1.47e-06, max=1.5e-06, fit=False)
problem.parameters.append(name="Bilayer Roughness", min=2.0, value=6.014, max=15.0, fit=True)
problem.parameters.append(name="Bilayer Tails Thickness", min=14.0, value=17.82, max=22.0, fit=True)
problem.parameters.append(name="Bilayer Tails SLD", min=-5.0e-07, value=-4.61e-07, max=0.0, fit=False)
problem.parameters.append(name="Bilayer Tails Hydration", min=10.0, value=17.64, max=50.0, fit=True)
problem.parameters.append(name="Bilayer Heads Hydration", min=10.0, value=36.15, max=50.0, fit=True)
problem.parameters.append(name="CW Hydration", min=99.9, value=100.0, max=100.0, fit=False)
problem.parameters.append(name="Oxide Hydration", min=0.0, value=23.61, max=60.0, fit=True)
problem.parameters.set_fields(0, max=10)
# Group these into layers
problem.layers.append(
name="Oxide",
thickness="Oxide Thickness",
SLD="Oxide SLD",
roughness="Substrate Roughness",
hydration="Oxide Hydration",
hydrate_with="bulk out",
)
problem.layers.append(
name="SAM Tails",
thickness="SAM Tails Thickness",
SLD="SAM Tails SLD",
roughness="SAM Roughness",
hydration="SAM Tails Hydration",
hydrate_with="bulk out",
)
problem.layers.append(
name="SAM Heads",
thickness="SAM Heads Thickness",
SLD="SAM Heads SLD",
roughness="SAM Roughness",
hydration="SAM Heads Hydration",
hydrate_with="bulk out",
)
problem.layers.append(
name="Central Water",
thickness="CW Thickness",
SLD="CW SLD",
roughness="Bilayer Roughness",
hydration="CW Hydration",
hydrate_with="bulk out",
)
problem.layers.append(
name="Bilayer Heads",
thickness="Bilayer Heads Thickness",
SLD="Bilayer Heads SLD",
roughness="Bilayer Roughness",
hydration="Bilayer Heads Hydration",
hydrate_with="bulk out",
)
problem.layers.append(
name="Bilayer Tails",
thickness="Bilayer Tails Thickness",
SLD="Bilayer Tails SLD",
roughness="Bilayer Roughness",
hydration="Bilayer Tails Hydration",
hydrate_with="bulk out",
)
# Make the bulk SLDs
del problem.bulk_in[0]
problem.bulk_in.append(name="Silicon", min=2.0e-06, value=2.073e-06, max=2.1e-06, fit=False)
del problem.bulk_out[0]
problem.bulk_out.append(name="D2O", min=5.50e-06, value=5.98e-06, max=6.4e-06, fit=True)
problem.bulk_out.append(name="SMW", min=1.0e-06, value=2.21e-06, max=4.99e-06, fit=True)
# Set the scalefactors - use one for each contrast
del problem.scalefactors[0]
problem.scalefactors.append(name="Scalefactor 1", min=0.05, value=0.10, max=0.2, fit=False)
problem.scalefactors.append(name="Scalefactor 2", min=0.05, value=0.15, max=0.2, fit=False)
# Now deal with the backgrounds
# SMW has a constant background
del problem.backgrounds[0]
del problem.background_parameters[0]
problem.background_parameters.append(
name="Background parameter SMW",
min=1.0e-10,
value=3.38e-06,
max=4.99e-06,
fit=True,
)
problem.backgrounds.append(name="SMW Background", type="constant", source="Background parameter SMW")
problem.custom_files.append(
name="D2O Background Function",
filename="background_function.py",
language="python",
path=pathlib.Path(__file__).parent,
)
problem.background_parameters.append(name="Fn Ao", min=5e-7, value=8e-6, max=5e-5)
problem.background_parameters.append(name="Fn k", min=40, value=70, max=90)
problem.background_parameters.append(name="Fn Const", min=1e-7, value=8e-6, max=1e-5)
problem.backgrounds.append(
name="D2O Function Background",
type="function",
source="D2O Background Function",
value_1="Fn Ao",
value_2="Fn k",
value_3="Fn Const",
)
# Now add the data
data_path = pathlib.Path(__file__).parents[1] / "data"
d2o_dat = np.loadtxt(data_path / "DSPC_D2O.dat", delimiter=",")
problem.data.append(name="dspc_bil_D2O", data=d2o_dat)
smw_dat = np.loadtxt(data_path / "DSPC_SMW.dat", delimiter=",")
problem.data.append(name="dspc_bil_smw", data=smw_dat)
# Set the model
stack = [
"Oxide",
"SAM Tails",
"SAM Heads",
"Central Water",
"Bilayer Heads",
"Bilayer Tails",
"Bilayer Tails",
"Bilayer Heads",
]
# Then make the two contrasts
problem.contrasts.append(
name="D2O",
bulk_in="Silicon",
bulk_out="D2O",
background="D2O Function Background",
resolution="Resolution 1",
scalefactor="Scalefactor 1",
data="dspc_bil_D2O",
model=stack,
)
problem.contrasts.append(
name="SMW",
bulk_in="Silicon",
bulk_out="SMW",
background="SMW Background",
resolution="Resolution 1",
scalefactor="Scalefactor 2",
data="dspc_bil_smw",
model=stack,
)
controls = RAT.Controls()
problem, results = RAT.run(problem, controls)
return problem, results
if __name__ == "__main__":
problem, results = DSPC_function_background()
RAT.plotting.plot_ref_sld(problem, results, True)