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,149 @@
1
+ """An example of analysing a Custom XY model."""
2
+
3
+ import pathlib
4
+
5
+ import numpy as np
6
+
7
+ import ratapi as RAT
8
+
9
+
10
+ def DSPC_custom_XY():
11
+ r"""Calculate a Custom XY Example for Supported DSPC layer.
12
+
13
+ In this example, we model the same data (DSPC supported bilayer) as the Custom Layers example, but this time we will
14
+ use continuous distributions of the volume fractions of each component to build up the SLD profiles (as described in
15
+ Shekhar et al, J. Appl. Phys., 110, 102216 (2011).)
16
+
17
+ In this type of model, each 'layer' in the sample is described by a roughened Heaviside step function (really, just
18
+ two error functions back to back). So, in our case, we will need an oxide, a (possible) intervening water layer, and
19
+ then the bilayer itself.
20
+
21
+ We can define our lipid in terms of an Area per Molecule, almost in its entirety, if we recognise that where the
22
+ volume is known, the thickness of the layer is simply given by the layer volume / APM:
23
+
24
+ .. math:: d_{\textrm{layer}} =\frac{V_{\textrm{layer}} }{{\textrm{APM}}_{\textrm{layer}}}.
25
+
26
+ We can then define the Volume Fraction of this layer with a roughened Heaviside of length dlayer and a height of 1.
27
+ Then, the total volume occupied will be given by the sum of the volume fractions across the interface. Of course,
28
+ this does not permit any hydration, so to deal with this, we can simply scale the (full occupation) Heaviside
29
+ functions by relevant coverage parameters. When this is correctly done, we can obtain the remaining water
30
+ distribution as:
31
+
32
+ .. math:: {\textrm{VF}}_{\textrm{wat}} =1-\\sum_n {\textrm{VF}}_n
33
+
34
+ where VFn is the Volume Fraction of the n'th layer.
35
+ """
36
+ # Start by making the class and setting it to a custom XY type:
37
+ problem = RAT.Project(name="Orso lipid example - custom XY", model="custom xy", geometry="substrate/liquid")
38
+
39
+ # We need to add the relevant parameters we are going to need to define the model
40
+ # (note that Substrate Roughness always exists as parameter 1).
41
+ problem.parameters.append(name="Oxide Thickness", min=10.0, value=15.0, max=30.0, fit=True)
42
+ problem.parameters.append(name="Oxide Hydration", min=0.1, value=0.2, max=0.4, fit=True)
43
+ problem.parameters.append(name="Water Thickness", min=0.0, value=5.0, max=20.0, fit=True)
44
+ problem.parameters.append(name="Lipid APM", min=40.0, value=50.0, max=90.0, fit=True)
45
+ problem.parameters.append(name="Lipid Coverage", min=0.9, value=1.0, max=1.0, fit=True)
46
+ problem.parameters.append(name="Bilayer Roughness", min=3.0, value=5.0, max=8.0, fit=True)
47
+
48
+ problem.parameters.set_fields(0, min=1.0, max=10.0)
49
+
50
+ # Need to add the relevant Bulk SLDs. Change the bulk in from air to silicon, and add two additional water
51
+ # contrasts:
52
+ problem.bulk_in.set_fields(0, name="Silicon", min=2.07e-6, value=2.073e-6, max=2.08e-6, fit=False)
53
+
54
+ problem.bulk_out.append(name="SLD SMW", min=1.0e-6, value=2.073e-6, max=3.0e-6, fit=True)
55
+ problem.bulk_out.append(name="SLD H2O", min=-0.6e-6, value=-0.56e-6, max=-0.3e-6, fit=True)
56
+
57
+ problem.bulk_out.set_fields(0, min=5.0e-6, value=6.1e-6, fit=True)
58
+
59
+ # Now add the datafiles. We have three datasets we need to consider - the bilayer against D2O, Silicon Matched
60
+ # Water and H2O. Load these datafiles in and put them in the data block
61
+
62
+ # Read in the datafiles
63
+ data_path = pathlib.Path(__file__).parents[1] / "data"
64
+ D2O_data = np.loadtxt(data_path / "c_PLP0016596.dat", delimiter=",")
65
+ SMW_data = np.loadtxt(data_path / "c_PLP0016601.dat", delimiter=",")
66
+ H2O_data = np.loadtxt(data_path / "c_PLP0016607.dat", delimiter=",")
67
+
68
+ # Add the data to the project - note this data has a resolution 4th column
69
+ problem.data.append(name="Bilayer / D2O", data=D2O_data)
70
+ problem.data.append(name="Bilayer / SMW", data=SMW_data)
71
+ problem.data.append(name="Bilayer / H2O", data=H2O_data)
72
+
73
+ # Add the custom file to the project
74
+ problem.custom_files.append(
75
+ name="DSPC Model",
76
+ filename="custom_XY_DSPC.py",
77
+ language="python",
78
+ path=pathlib.Path(__file__).parent,
79
+ )
80
+
81
+ # Also, add the relevant background parameters - one each for each contrast:
82
+ problem.background_parameters.set_fields(
83
+ 0,
84
+ name="Background parameter D2O",
85
+ fit=True,
86
+ min=1.0e-10,
87
+ max=1.0e-5,
88
+ value=1.0e-07,
89
+ )
90
+
91
+ problem.background_parameters.append(name="Background parameter SMW", min=0.0, value=1.0e-7, max=1.0e-5, fit=True)
92
+ problem.background_parameters.append(name="Background parameter H2O", min=0.0, value=1.0e-7, max=1.0e-5, fit=True)
93
+
94
+ # And add the two new constant backgrounds
95
+ problem.backgrounds.append(name="Background SMW", type="constant", source="Background parameter SMW")
96
+ problem.backgrounds.append(name="Background H2O", type="constant", source="Background parameter H2O")
97
+
98
+ # And edit the other one
99
+ problem.backgrounds.set_fields(0, name="Background D2O", source="Background parameter D2O")
100
+
101
+ # Finally modify some of the other parameters to be more suitable values for a solid / liquid experiment
102
+ problem.scalefactors.set_fields(0, value=1.0, min=0.5, max=2.0, fit=True)
103
+
104
+ # Also, we are going to use the data resolution
105
+ problem.resolutions.append(name="Data Resolution", type="data")
106
+
107
+ # Now add the three contrasts
108
+ problem.contrasts.append(
109
+ name="Bilayer / D2O",
110
+ background="Background D2O",
111
+ resolution="Data Resolution",
112
+ scalefactor="Scalefactor 1",
113
+ bulk_out="SLD D2O",
114
+ bulk_in="Silicon",
115
+ data="Bilayer / D2O",
116
+ model=["DSPC Model"],
117
+ )
118
+
119
+ problem.contrasts.append(
120
+ name="Bilayer / SMW",
121
+ background="Background SMW",
122
+ resolution="Data Resolution",
123
+ scalefactor="Scalefactor 1",
124
+ bulk_out="SLD SMW",
125
+ bulk_in="Silicon",
126
+ data="Bilayer / SMW",
127
+ model=["DSPC Model"],
128
+ )
129
+
130
+ problem.contrasts.append(
131
+ name="Bilayer / H2O",
132
+ background="Background H2O",
133
+ resolution="Data Resolution",
134
+ scalefactor="Scalefactor 1",
135
+ bulk_out="SLD H2O",
136
+ bulk_in="Silicon",
137
+ data="Bilayer / H2O",
138
+ model=["DSPC Model"],
139
+ )
140
+
141
+ controls = RAT.Controls()
142
+ problem, results = RAT.run(problem, controls)
143
+
144
+ return problem, results
145
+
146
+
147
+ if __name__ == "__main__":
148
+ problem, results = DSPC_custom_XY()
149
+ RAT.plotting.plot_ref_sld(problem, results, True)
@@ -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)