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,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=1e-09, 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=False)
135
+ problem.scalefactors.append(name="Scalefactor 2", min=0.05, value=0.15, max=0.2, fit=False)
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,138 @@
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
+ # Split up the parameters
12
+ subRough = params[0]
13
+ oxideThick = params[1]
14
+ oxideHydration = params[2]
15
+ waterThick = params[3]
16
+ lipidAPM = params[4]
17
+ lipidCoverage = params[5]
18
+ bilayerRough = params[6]
19
+
20
+ # We are going to need our Neutron scattering cross-sections, plus the component volumes
21
+ # (the volumes are taken from Armen et al as usual).
22
+ # Define these first
23
+
24
+ # define all the neutron b's.
25
+ bc = 0.6646e-4 # Carbon
26
+ bo = 0.5843e-4 # Oxygen
27
+ bh = -0.3739e-4 # Hydrogen
28
+ bp = 0.513e-4 # Phosphorus
29
+ bn = 0.936e-4 # Nitrogen
30
+
31
+ # Now make the lipid groups
32
+ COO = (4 * bo) + (2 * bc)
33
+ GLYC = (3 * bc) + (5 * bh)
34
+ CH3 = (2 * bc) + (6 * bh)
35
+ PO4 = (1 * bp) + (4 * bo)
36
+ CH2 = (1 * bc) + (2 * bh)
37
+ CHOL = (5 * bc) + (12 * bh) + (1 * bn)
38
+
39
+ # Group these into heads and tails
40
+ heads = CHOL + PO4 + GLYC + COO
41
+ tails = (34 * CH2) + (2 * CH3)
42
+
43
+ # We need volumes for each. Use literature values
44
+ vHead = 319
45
+ vTail = 782
46
+
47
+ # Start making our sections. For each we are using a roughened Heaviside to describe our groups.
48
+ # We will make these as Volume Fractions (i.e. with a height of 1 for full occupancy),
49
+ # which we will correct later for hydration.
50
+
51
+ # Make an array of z values for our model
52
+ z = np.arange(0, 141)
53
+
54
+ # Make our Silicon substrate
55
+ vfSilicon, siSurf = make_layer(z, -25, 50, 1, subRough, subRough)
56
+
57
+ # Add the Oxide
58
+ vfOxide, oxSurface = make_layer(z, siSurf, oxideThick, 1, subRough, subRough)
59
+
60
+ # We fill in the water at the end, but there may be a hydration layer between the bilayer and the oxide,
61
+ # so we start the bilayer stack an appropriate distance away
62
+ watSurface = oxSurface + waterThick
63
+
64
+ # Now make the first lipid head group
65
+ # Work out the thickness
66
+ headThick = vHead / lipidAPM
67
+
68
+ # ... and make a box for the volume fraction (1 for now, we correct for coverage later)
69
+ vfHeadL, headLSurface = make_layer(z, watSurface, headThick, 1, bilayerRough, bilayerRough)
70
+
71
+ # ... also do the same for the tails
72
+ # We'll make both together, so the thickness will be twice the volume
73
+ tailsThick = (2 * vTail) / lipidAPM
74
+ vfTails, tailsSurf = make_layer(z, headLSurface, tailsThick, 1, bilayerRough, bilayerRough)
75
+
76
+ # Finally the upper head ...
77
+ vfHeadR, headSurface = make_layer(z, tailsSurf, headThick, 1, bilayerRough, bilayerRough)
78
+
79
+ # Making the model
80
+ # We've created the volume fraction profiles corresponding to each of the groups.
81
+ # We now convert them to SLDs, taking in account of the hydrations to scale the volume fractions
82
+
83
+ # 1. Oxide ...
84
+ vfOxide = vfOxide * (1 - oxideHydration)
85
+
86
+ # 2. Lipid ...
87
+ # Scale both the heads and tails according to overall coverage
88
+ vfTails = vfTails * lipidCoverage
89
+ vfHeadL = vfHeadL * lipidCoverage
90
+ vfHeadR = vfHeadR * lipidCoverage
91
+
92
+ # Some extra work to deal with head hydration, which we take to be an additional 30% always
93
+ vfHeadL = vfHeadL * 0.7
94
+ vfHeadR = vfHeadR * 0.7
95
+
96
+ # Make a total Volume Fraction across the whole interface
97
+ vfTot = vfSilicon + vfOxide + vfHeadL + vfTails + vfHeadR
98
+
99
+ # All the volume that's left, we will fill with water
100
+ vfWat = 1 - vfTot
101
+
102
+ # Now convert all the Volume Fractions to SLDs
103
+ sld_Value_Tails = tails / vTail
104
+ sld_Value_Head = heads / vHead
105
+
106
+ sldSilicon = vfSilicon * 2.073e-6
107
+ sldOxide = vfOxide * 3.41e-6
108
+
109
+ sldHeadL = vfHeadL * sld_Value_Head
110
+ sldHeadR = vfHeadR * sld_Value_Head
111
+ sldTails = vfTails * sld_Value_Tails
112
+ sldWat = vfWat * bulk_out[contrast]
113
+
114
+ # Put this all together
115
+ totSLD = sldSilicon + sldOxide + sldHeadL + sldTails + sldHeadR + sldWat
116
+
117
+ # Make the SLD array for output
118
+ SLD = np.column_stack((z, totSLD))
119
+
120
+ return SLD, subRough
121
+
122
+
123
+ def make_layer(z, prevLaySurf, thickness, height, Sigma_L, Sigma_R):
124
+ """Produce a layer, with a defined thickness, height and roughness.
125
+
126
+ Each side of the layer has its own roughness value.
127
+ """
128
+ # Find the edges
129
+ left = prevLaySurf
130
+ right = prevLaySurf + thickness
131
+
132
+ # Make our heaviside
133
+ erf_left = erf((z - left) / (sqrt(2) * Sigma_L))
134
+ erf_right = erf((z - right) / (sqrt(2) * Sigma_R))
135
+
136
+ VF = np.array((0.5 * height) * (erf_left - erf_right))
137
+
138
+ return VF, right
@@ -0,0 +1,87 @@
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
+ sub_rough = params[0]
29
+ oxide_thick = params[1]
30
+ oxide_hydration = params[2]
31
+ lipidAPM = params[3]
32
+ headHydration = params[4]
33
+ bilayerHydration = params[5]
34
+ bilayerRough = params[6]
35
+ waterThick = params[7]
36
+
37
+ # We have a constant SLD for the bilayer
38
+ oxide_SLD = 3.41e-6
39
+
40
+ # Now make the lipid layers
41
+ # Use known lipid volume and compositions to make the layers
42
+
43
+ # define all the neutron b's.
44
+ bc = 0.6646e-4 # Carbon
45
+ bo = 0.5843e-4 # Oxygen
46
+ bh = -0.3739e-4 # Hydrogen
47
+ bp = 0.513e-4 # Phosphorus
48
+ bn = 0.936e-4 # Nitrogen
49
+
50
+ # Now make the lipid groups
51
+ COO = (4 * bo) + (2 * bc)
52
+ GLYC = (3 * bc) + (5 * bh)
53
+ CH3 = (2 * bc) + (6 * bh)
54
+ PO4 = (1 * bp) + (4 * bo)
55
+ CH2 = (1 * bc) + (2 * bh)
56
+ CHOL = (5 * bc) + (12 * bh) + (1 * bn)
57
+
58
+ # Group these into heads and tails:
59
+ Head = CHOL + PO4 + GLYC + COO
60
+ Tails = (34 * CH2) + (2 * CH3)
61
+
62
+ # We need volumes for each. Use literature values:
63
+ vHead = 319
64
+ vTail = 782
65
+
66
+ # We use the volumes to calculate the SLDs
67
+ SLDhead = Head / vHead
68
+ SLDtail = Tails / vTail
69
+
70
+ # We calculate the layer thickness' from the volumes and the APM
71
+ headThick = vHead / lipidAPM
72
+ tailThick = vTail / lipidAPM
73
+
74
+ # Manually deal with hydration for layers in this example.
75
+ oxSLD = (oxide_hydration * bulk_out[contrast]) + ((1 - oxide_hydration) * oxide_SLD)
76
+ headSLD = (headHydration * bulk_out[contrast]) + ((1 - headHydration) * SLDhead)
77
+ tailSLD = (bilayerHydration * bulk_out[contrast]) + ((1 - bilayerHydration) * SLDtail)
78
+
79
+ # Make the layers
80
+ oxide = [oxide_thick, oxSLD, sub_rough]
81
+ water = [waterThick, bulk_out[contrast], bilayerRough]
82
+ head = [headThick, headSLD, bilayerRough]
83
+ tail = [tailThick, tailSLD, bilayerRough]
84
+
85
+ output = np.array([oxide, water, head, tail, tail, head])
86
+
87
+ return output, sub_rough