RATapi 0.0.0.dev0__cp312-cp312-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.cp312-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,69 @@
1
+ """Simple example of a layer containing domains using a custom XY model"""
2
+
3
+ import pathlib
4
+
5
+ import RATapi as RAT
6
+
7
+ problem = RAT.Project(calculation="domains", model="custom xy", geometry="substrate/liquid")
8
+
9
+ problem.parameters.append(name="Oxide Thickness", min=10.0, value=20.0, max=50.0, fit=True)
10
+ problem.parameters.append(name="Layer Thickness", min=1.0, value=30.0, max=500.0, fit=True)
11
+ problem.parameters.append(name="Layer SLD", min=-0.5e-6, value=-0.5e-6, max=0.0, fit=True)
12
+ problem.parameters.append(name="Layer Roughness", min=2.0, value=5.0, max=7.0, fit=True)
13
+ problem.parameters.append(name="Domain SLD", min=1.0e-6, value=1.0e-6, max=5.0e-6, fit=True)
14
+
15
+ problem.bulk_in.set_fields(0, name="Silicon", value=2.073e-6, max=1.0, fit=False)
16
+ problem.scalefactors.set_fields(0, min=0.8, value=1.0, max=1.1, fit=True)
17
+
18
+ problem.bulk_out.append(name="SLD SMW", min=2.0e-6, value=2.073e-6, max=2.1e-6)
19
+ problem.bulk_out.append(name="SLD H2O", min=-0.6e-6, value=-0.56e-6, max=-0.5e-6)
20
+
21
+ # Add the custom file
22
+ problem.custom_files.append(
23
+ name="Domain Layer",
24
+ filename="domains_XY_model.py",
25
+ language="python",
26
+ path=pathlib.Path(__file__).parent.resolve(),
27
+ )
28
+
29
+ # Make contrasts
30
+ problem.contrasts.append(
31
+ name="D2O",
32
+ background="Background 1",
33
+ resolution="Resolution 1",
34
+ scalefactor="Scalefactor 1",
35
+ bulk_in="Silicon",
36
+ bulk_out="SLD D2O",
37
+ domain_ratio="Domain Ratio 1",
38
+ data="Simulation",
39
+ model=["Domain Layer"],
40
+ )
41
+
42
+ problem.contrasts.append(
43
+ name="SMW",
44
+ background="Background 1",
45
+ resolution="Resolution 1",
46
+ scalefactor="Scalefactor 1",
47
+ bulk_in="Silicon",
48
+ bulk_out="SLD SMW",
49
+ domain_ratio="Domain Ratio 1",
50
+ data="Simulation",
51
+ model=["Domain Layer"],
52
+ )
53
+
54
+ problem.contrasts.append(
55
+ name="H2O",
56
+ background="Background 1",
57
+ resolution="Resolution 1",
58
+ scalefactor="Scalefactor 1",
59
+ bulk_in="Silicon",
60
+ bulk_out="SLD H2O",
61
+ domain_ratio="Domain Ratio 1",
62
+ data="Simulation",
63
+ model=["Domain Layer"],
64
+ )
65
+
66
+ controls = RAT.Controls()
67
+ problem, results = RAT.run(problem, controls)
68
+
69
+ RAT.plotting.plot_ref_sld(problem, results, True)
@@ -0,0 +1,46 @@
1
+ """An example custom layers domains project involving incoherent summing on a permalloy layer"""
2
+
3
+ import pathlib
4
+
5
+ import RATapi as RAT
6
+
7
+ problem = RAT.Project(calculation="domains", model="custom layers", geometry="substrate/liquid")
8
+
9
+ # Make some parameters...
10
+ problem.parameters.append(name="Alloy Thickness", min=100.0, value=150.0, max=200.0, fit=True)
11
+ problem.parameters.append(name="Alloy SLD up", min=9.0e-6, value=11.0e-6, max=13.0e-6, fit=True)
12
+ problem.parameters.append(name="Alloy SLD down", min=5.0e-6, value=7.0e-6, max=10.0e-6, fit=True)
13
+ problem.parameters.append(name="Alloy Roughness", min=5.0, value=7.0, max=11.0, fit=True)
14
+ problem.parameters.append(name="Gold Thickness", min=100.0, value=150.0, max=200.0, fit=True)
15
+ problem.parameters.append(name="Gold SLD", min=4.0e-6, value=4.5e-6, max=5.0e-6, fit=True)
16
+ problem.parameters.append(name="Gold Roughness", min=5.0, value=7.0, max=11.0, fit=True)
17
+
18
+ # Set the bulk SLD
19
+ problem.bulk_in.set_fields(0, name="Silicon", value=2.073e-6, max=1.0)
20
+
21
+ # Add the custom file
22
+ problem.custom_files.append(
23
+ name="Alloy domains",
24
+ filename="alloy_domains.py",
25
+ language="python",
26
+ path=pathlib.Path(__file__).parent.resolve(),
27
+ )
28
+
29
+ # Make a contrast
30
+ problem.contrasts.append(
31
+ name="D2O Contrast",
32
+ data="Simulation",
33
+ background="Background 1",
34
+ bulk_in="Silicon",
35
+ bulk_out="SLD D2O",
36
+ scalefactor="Scalefactor 1",
37
+ resolution="Resolution 1",
38
+ resample=False,
39
+ domain_ratio="Domain Ratio 1",
40
+ model=["Alloy domains"],
41
+ )
42
+
43
+ controls = RAT.Controls()
44
+
45
+ problem, results = RAT.run(problem, controls)
46
+ RAT.plotting.plot_ref_sld(problem, results, True)
@@ -0,0 +1,75 @@
1
+ import RATapi as RAT
2
+
3
+ problem = RAT.Project(calculation="domains")
4
+
5
+ # Define the parameters we need to define our two domains
6
+ problem.parameters.append(name="L1 Thickness", min=5.0, value=20.0, max=60.0, fit=True)
7
+ problem.parameters.append(name="L1 SLD", min=3.0e-6, value=4.1e-6, max=5.0e-6, fit=False)
8
+ problem.parameters.append(name="L1 Roughness", min=2.0, value=5.0, max=20.0, fit=True)
9
+ problem.parameters.append(name="L1 Hydration", min=10.0, value=20.0, max=30.0, fit=True)
10
+
11
+ problem.parameters.append(name="L2 Thickness", min=5.0, value=60.0, max=100.0, fit=True)
12
+ problem.parameters.append(name="L2 SLD", min=2.1e-6, value=3.0e-6, max=5.0e-6, fit=False)
13
+ problem.parameters.append(name="L2 Roughness", min=2.0, value=5.0, max=20.0, fit=True)
14
+ problem.parameters.append(name="L2 Hydration", min=10.0, value=20.0, max=30.0, fit=True)
15
+
16
+ problem.parameters.append(name="L3 Thickness", min=5.0, value=200.0, max=300.0, fit=True)
17
+ problem.parameters.append(name="L3 SLD", min=3.0e-6, value=7.0e-6, max=8.0e-6, fit=False)
18
+ problem.parameters.append(name="L3 Roughness", min=2.0, value=5.0, max=20.0, fit=True)
19
+ problem.parameters.append(name="L3 Hydration", min=10.0, value=20.0, max=30.0, fit=True)
20
+
21
+
22
+ # Now group these parameters into layers
23
+ problem.layers.append(
24
+ name="Layer 1",
25
+ thickness="L1 Thickness",
26
+ SLD="L1 SLD",
27
+ roughness="L1 Roughness",
28
+ hydration="L1 Hydration",
29
+ hydrate_with="bulk out",
30
+ )
31
+
32
+ problem.layers.append(
33
+ name="Layer 2",
34
+ thickness="L2 Thickness",
35
+ SLD="L2 SLD",
36
+ roughness="L2 Roughness",
37
+ hydration="L2 Hydration",
38
+ hydrate_with="bulk out",
39
+ )
40
+
41
+ problem.layers.append(
42
+ name="Layer 3",
43
+ thickness="L3 Thickness",
44
+ SLD="L3 SLD",
45
+ roughness="L3 Roughness",
46
+ hydration="L3 Hydration",
47
+ hydrate_with="bulk out",
48
+ )
49
+
50
+
51
+ # If we look at the project, there are two extra groups as compared to a normal standard layers calculation:
52
+ # Domain Contrasts and Domain Ratios
53
+ problem.domain_contrasts.append(name="Domain 1", model=["Layer 1"])
54
+ problem.domain_contrasts.append(name="Domain 2", model=["Layer 2", "Layer 3"])
55
+
56
+ # Now make a contrast as with standard models, but this time also including the default domain ratio ("Domain Ratio 1")
57
+ problem.contrasts.append(
58
+ name="Domain Test",
59
+ background="Background 1",
60
+ resolution="Resolution 1",
61
+ scalefactor="Scalefactor 1",
62
+ resample=False,
63
+ bulk_in="SLD Air",
64
+ bulk_out="SLD D2O",
65
+ domain_ratio="Domain Ratio 1",
66
+ data="Simulation",
67
+ model=["Domain 1", "Domain 2"],
68
+ )
69
+
70
+
71
+ # Now we can run our simulation as usual, and plot the results
72
+ controls = RAT.Controls()
73
+
74
+ problem, results = RAT.run(problem, controls)
75
+ RAT.plotting.plot_ref_sld(problem, results, True)
File without changes
@@ -0,0 +1,66 @@
1
+ import numpy as np
2
+
3
+
4
+ def custom_bilayer(params, bulk_in, bulk_out, contrast):
5
+ sub_rough = params[0]
6
+ oxide_thick = params[1]
7
+ oxide_hydration = params[2]
8
+ lipidAPM = params[3]
9
+ headHydration = params[4]
10
+ bilayerHydration = params[5]
11
+ bilayerRough = params[6]
12
+ waterThick = params[7]
13
+
14
+ # We have a constant SLD for the bilayer
15
+ oxide_SLD = 3.41e-6
16
+
17
+ # Now make the lipid layers
18
+ # Use known lipid volume and compositions
19
+ # to make the layers
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
+ Head = CHOL + PO4 + GLYC + COO
38
+ Tails = (34 * CH2) + (2 * CH3)
39
+
40
+ # We need volumes for each.
41
+ # Use literature values:
42
+ vHead = 319
43
+ vTail = 782
44
+
45
+ # we use the volumes to calculate the SLDs
46
+ SLDhead = Head / vHead
47
+ SLDtail = Tails / vTail
48
+
49
+ # We calculate the layer thickness from the volumes and the APM
50
+ headThick = vHead / lipidAPM
51
+ tailThick = vTail / lipidAPM
52
+
53
+ # Manually deal with hydration for layers in this example.
54
+ oxSLD = (oxide_hydration * bulk_out[contrast]) + ((1 - oxide_hydration) * oxide_SLD)
55
+ headSLD = (headHydration * bulk_out[contrast]) + ((1 - headHydration) * SLDhead)
56
+ tailSLD = (bilayerHydration * bulk_out[contrast]) + ((1 - bilayerHydration) * SLDtail)
57
+
58
+ # Make the layers
59
+ oxide = [oxide_thick, oxSLD, sub_rough]
60
+ water = [waterThick, bulk_out[contrast], bilayerRough]
61
+ head = [headThick, headSLD, bilayerRough]
62
+ tail = [tailThick, tailSLD, bilayerRough]
63
+
64
+ output = np.array([oxide, water, head, tail, tail, head])
65
+
66
+ return output, sub_rough
@@ -0,0 +1,41 @@
1
+ """Test custom function languages."""
2
+
3
+ import pathlib
4
+ import time
5
+
6
+ import setup_problem
7
+
8
+ import RATapi as RAT
9
+
10
+ path = pathlib.Path(__file__).parent.resolve()
11
+
12
+ project = setup_problem.make_example_problem()
13
+ controls = RAT.Controls()
14
+
15
+ # Python
16
+ start = time.time()
17
+ project, results = RAT.run(project, controls)
18
+ end = time.time()
19
+ print(f"Python time is: {end-start}s\n")
20
+
21
+ RAT.plotting.plot_ref_sld(project, results)
22
+
23
+ # Matlab
24
+ project.custom_files.set_fields(0, filename="custom_bilayer.m", language="matlab", path=path)
25
+
26
+ start = time.time()
27
+ project, results = RAT.run(project, controls)
28
+ end = time.time()
29
+ print(f"Matlab time is: {end-start}s\n")
30
+
31
+ RAT.plotting.plot_ref_sld(project, results)
32
+
33
+ # C++
34
+ project.custom_files.set_fields(0, filename="custom_bilayer.dll", language="cpp", path=path)
35
+
36
+ start = time.time()
37
+ project, results = RAT.run(project, controls)
38
+ end = time.time()
39
+ print(f"C++ time is: {end-start}s\n")
40
+
41
+ RAT.plotting.plot_ref_sld(project, results)
@@ -0,0 +1,130 @@
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
+
14
+ def make_example_problem():
15
+ problem = RAT.Project(name="Orso lipid example - custom layers", model="custom layers", geometry="substrate/liquid")
16
+
17
+ # First we need to set up a parameters group. We will be using a pre-prepared custom model file, so we need to add
18
+ # the relevant parameters we are going to need to define the model (note that Substrate Roughness always exists as
19
+ # parameter 1).
20
+ problem.parameters.append(name="Oxide Thickness", min=5.0, value=20.0, max=60.0, fit=True)
21
+ problem.parameters.append(name="Oxide Hydration", min=0.0, value=0.2, max=0.5, fit=True)
22
+ problem.parameters.append(name="Lipid APM", min=45.0, value=55.0, max=65.0, fit=True)
23
+ problem.parameters.append(name="Head Hydration", min=00.0, value=0.2, max=0.5, fit=True)
24
+ problem.parameters.append(name="Bilayer Hydration", min=0.0, value=0.1, max=0.2, fit=True)
25
+ problem.parameters.append(name="Bilayer Roughness", min=2.0, value=4.0, max=8.0, fit=True)
26
+ problem.parameters.append(name="Water Thickness", min=0.0, value=2.0, max=10.0, fit=True)
27
+
28
+ problem.parameters.set_fields(0, min=1.0, max=10.0)
29
+
30
+ # Need to add the relevant Bulk SLDs.
31
+ # Change the bulk in from air to silicon, and add two additional water contrasts:
32
+ problem.bulk_in.set_fields(0, name="Silicon", min=2.07e-6, value=2.073e-6, max=2.08e-6, fit=False)
33
+
34
+ problem.bulk_out.append(name="SLD SMW", min=1.0e-6, value=2.073e-6, max=3.0e-6, fit=True)
35
+ problem.bulk_out.append(name="SLD H2O", min=-0.6e-6, value=-0.56e-6, max=-0.3e-6, fit=True)
36
+
37
+ problem.bulk_out.set_fields(0, min=5.0e-6, fit=True)
38
+
39
+ # Now add the datafiles. We have three datasets we need to consider - the bilayer against D2O, Silicon Matched Water
40
+ # and H2O. Load these datafiles in and put them in the data block
41
+
42
+ # Read in the datafiles
43
+ data_path = os.path.join(pathlib.Path(__file__).parents[1].resolve(), "data")
44
+ D2O_data = np.loadtxt(os.path.join(data_path, "c_PLP0016596.dat"), delimiter=",")
45
+ SMW_data = np.loadtxt(os.path.join(data_path, "c_PLP0016601.dat"), delimiter=",")
46
+ H2O_data = np.loadtxt(os.path.join(data_path, "c_PLP0016607.dat"), delimiter=",")
47
+
48
+ # Add the data to the project - note this data has a resolution 4th column
49
+ problem.data.append(name="Bilayer / D2O", data=D2O_data)
50
+ problem.data.append(name="Bilayer / SMW", data=SMW_data)
51
+ problem.data.append(name="Bilayer / H2O", data=H2O_data)
52
+
53
+ # Add the custom file to the project
54
+ problem.custom_files.append(
55
+ name="DSPC Model",
56
+ filename="custom_bilayer.py",
57
+ language="python",
58
+ path=pathlib.Path(__file__).parent.resolve(),
59
+ )
60
+
61
+ # Also, add the relevant background parameters - one each for each contrast:
62
+ problem.background_parameters.set_fields(
63
+ 0,
64
+ name="Background parameter D2O",
65
+ fit=True,
66
+ min=1.0e-10,
67
+ max=1.0e-5,
68
+ value=1.0e-07,
69
+ )
70
+
71
+ problem.background_parameters.append(
72
+ name="Background parameter SMW",
73
+ min=1.0e-10,
74
+ value=1.0e-7,
75
+ max=1.0e-5,
76
+ fit=True,
77
+ )
78
+ problem.background_parameters.append(
79
+ name="Background parameter H2O",
80
+ min=1.0e-10,
81
+ value=1.0e-7,
82
+ max=1.0e-5,
83
+ fit=True,
84
+ )
85
+
86
+ # And add the two new constant backgrounds
87
+ problem.backgrounds.append(name="Background SMW", type="constant", value_1="Background parameter SMW")
88
+ problem.backgrounds.append(name="Background H2O", type="constant", value_1="Background parameter H2O")
89
+
90
+ # And edit the other one
91
+ problem.backgrounds.set_fields(0, name="Background D2O", value_1="Background parameter D2O")
92
+
93
+ # Finally modify some of the other parameters to be more suitable values for a solid / liquid experiment
94
+ problem.scalefactors.set_fields(0, value=1.0, min=0.5, max=2.0, fit=True)
95
+
96
+ # Now add the three contrasts
97
+ problem.contrasts.append(
98
+ name="Bilayer / D2O",
99
+ background="Background D2O",
100
+ resolution="Resolution 1",
101
+ scalefactor="Scalefactor 1",
102
+ bulk_out="SLD D2O",
103
+ bulk_in="Silicon",
104
+ data="Bilayer / D2O",
105
+ model=["DSPC Model"],
106
+ )
107
+
108
+ problem.contrasts.append(
109
+ name="Bilayer / SMW",
110
+ background="Background SMW",
111
+ resolution="Resolution 1",
112
+ scalefactor="Scalefactor 1",
113
+ bulk_out="SLD SMW",
114
+ bulk_in="Silicon",
115
+ data="Bilayer / SMW",
116
+ model=["DSPC Model"],
117
+ )
118
+
119
+ problem.contrasts.append(
120
+ name="Bilayer / H2O",
121
+ background="Background H2O",
122
+ resolution="Resolution 1",
123
+ scalefactor="Scalefactor 1",
124
+ bulk_out="SLD H2O",
125
+ bulk_in="Silicon",
126
+ data="Bilayer / H2O",
127
+ model=["DSPC Model"],
128
+ )
129
+
130
+ return problem
@@ -0,0 +1,140 @@
1
+ """Custom XY Example for Supported DSPC layer.
2
+
3
+ In this example, we model the same data (DSPC supported bilayer) as the Custom Layers example, but this time we will
4
+ use continuous distributions of the volume fractions of each component to build up the SLD profiles (as described in
5
+ Shekhar et al, J. Appl. Phys., 110, 102216 (2011).)
6
+
7
+ In this type of model, each 'layer' in the sample is described by a roughened Heaviside step function (really, just two
8
+ error functions back to back). So, in our case, we will need an oxide, a (possible) intervening water layer, and then
9
+ the bilayer itself.
10
+
11
+ We can define our lipid in terms of an Area per Molecule, almost in its entirety, if we recognise that where the volume
12
+ is known, the thickness of the layer is simply given by the layer volume / APM
13
+
14
+ $d_{\textrm{layer}} =\frac{V_{\textrm{layer}} }{{\textrm{APM}}_{\textrm{layer}}}$.
15
+
16
+ We can then define the Volume Fraction of this layer with a roughened Heaviside of length dlayer and a height of 1.
17
+ Then, the total volume occupied will be given by the sum of the volume fractions across the interface. Of course, this
18
+ does not permit any hydration, so to deal with this, we can simply scale the (full occupation) Heaviside functions by
19
+ relevant coverage parameters. When this is correctly done, we can obtain the remaining water distribution as
20
+
21
+ $${\textrm{VF}}_{\textrm{wat}} =1-\\sum_n {\textrm{VF}}_n$$
22
+
23
+ where VFn is the Volume Fraction of the n'th layer.
24
+ """
25
+
26
+ import os
27
+ import pathlib
28
+
29
+ import numpy as np
30
+
31
+ import RATapi as RAT
32
+
33
+ # Start by making the class and setting it to a custom layers type:
34
+ problem = RAT.Project(name="Orso lipid example - custom XY", model="custom xy", geometry="substrate/liquid")
35
+
36
+ # We need to add the relevant parameters we are going to need to define the model
37
+ # (note that Substrate Roughness always exists as parameter 1).
38
+ problem.parameters.append(name="Oxide Thickness", min=10.0, value=15.0, max=30.0, fit=True)
39
+ problem.parameters.append(name="Oxide Hydration", min=0.1, value=0.2, max=0.4, fit=True)
40
+ problem.parameters.append(name="Water Thickness", min=0.0, value=5.0, max=20.0, fit=True)
41
+ problem.parameters.append(name="Lipid APM", min=40.0, value=50.0, max=90.0, fit=True)
42
+ problem.parameters.append(name="Lipid Coverage", min=0.9, value=1.0, max=1.0, fit=True)
43
+ problem.parameters.append(name="Bilayer Roughness", min=3.0, value=5.0, max=8.0, fit=True)
44
+
45
+ problem.parameters.set_fields(0, min=1.0, max=10.0)
46
+
47
+ # Need to add the relevant Bulk SLDs. Change the bulk in from air to silicon, and add two additional water contrasts:
48
+ problem.bulk_in.set_fields(0, name="Silicon", min=2.07e-6, value=2.073e-6, max=2.08e-6, fit=False)
49
+
50
+ problem.bulk_out.append(name="SLD SMW", min=1.0e-6, value=2.073e-6, max=3.0e-6, fit=True)
51
+ problem.bulk_out.append(name="SLD H2O", min=-0.6e-6, value=-0.56e-6, max=-0.3e-6, fit=True)
52
+
53
+ problem.bulk_out.set_fields(0, min=5.0e-6, value=6.1e-6, fit=True)
54
+
55
+ # Now add the datafiles. We have three datasets we need to consider - the bilayer against D2O, Silicon Matched Water
56
+ # and H2O.Load these datafiles in and put them in the data block
57
+
58
+ # Read in the datafiles
59
+ data_path = os.path.join(pathlib.Path(__file__).parents[1].resolve(), "data")
60
+ D2O_data = np.loadtxt(os.path.join(data_path, "c_PLP0016596.dat"), delimiter=",")
61
+ SMW_data = np.loadtxt(os.path.join(data_path, "c_PLP0016601.dat"), delimiter=",")
62
+ H2O_data = np.loadtxt(os.path.join(data_path, "c_PLP0016607.dat"), delimiter=",")
63
+
64
+ # Add the data to the project - note this data has a resolution 4th column
65
+ problem.data.append(name="Bilayer / D2O", data=D2O_data)
66
+ problem.data.append(name="Bilayer / SMW", data=SMW_data)
67
+ problem.data.append(name="Bilayer / H2O", data=H2O_data)
68
+
69
+ # Add the custom file to the project
70
+ problem.custom_files.append(
71
+ name="DSPC Model",
72
+ filename="custom_XY_DSPC.py",
73
+ language="python",
74
+ path=pathlib.Path(__file__).parent.resolve(),
75
+ )
76
+
77
+ # Also, add the relevant background parameters - one each for each contrast:
78
+ problem.background_parameters.set_fields(
79
+ 0,
80
+ name="Background parameter D2O",
81
+ fit=True,
82
+ min=1.0e-10,
83
+ max=1.0e-5,
84
+ value=1.0e-07,
85
+ )
86
+
87
+ problem.background_parameters.append(name="Background parameter SMW", min=0.0, value=1.0e-7, max=1.0e-5, fit=True)
88
+ problem.background_parameters.append(name="Background parameter H2O", min=0.0, value=1.0e-7, max=1.0e-5, fit=True)
89
+
90
+ # And add the two new constant backgrounds
91
+ problem.backgrounds.append(name="Background SMW", type="constant", value_1="Background parameter SMW")
92
+ problem.backgrounds.append(name="Background H2O", type="constant", value_1="Background parameter H2O")
93
+
94
+ # And edit the other one
95
+ problem.backgrounds.set_fields(0, name="Background D2O", value_1="Background parameter D2O")
96
+
97
+ # Finally modify some of the other parameters to be more suitable values for a solid / liquid experiment
98
+ problem.scalefactors.set_fields(0, value=1.0, min=0.5, max=2.0, fit=True)
99
+
100
+ # Also, we are going to use the data resolution
101
+ problem.resolutions.append(name="Data Resolution", type="data")
102
+
103
+ # Now add the three contrasts
104
+ problem.contrasts.append(
105
+ name="Bilayer / D2O",
106
+ background="Background D2O",
107
+ resolution="Data Resolution",
108
+ scalefactor="Scalefactor 1",
109
+ bulk_out="SLD D2O",
110
+ bulk_in="Silicon",
111
+ data="Bilayer / D2O",
112
+ model=["DSPC Model"],
113
+ )
114
+
115
+ problem.contrasts.append(
116
+ name="Bilayer / SMW",
117
+ background="Background SMW",
118
+ resolution="Data Resolution",
119
+ scalefactor="Scalefactor 1",
120
+ bulk_out="SLD SMW",
121
+ bulk_in="Silicon",
122
+ data="Bilayer / SMW",
123
+ model=["DSPC Model"],
124
+ )
125
+
126
+ problem.contrasts.append(
127
+ name="Bilayer / H2O",
128
+ background="Background H2O",
129
+ resolution="Data Resolution",
130
+ scalefactor="Scalefactor 1",
131
+ bulk_out="SLD H2O",
132
+ bulk_in="Silicon",
133
+ data="Bilayer / H2O",
134
+ model=["DSPC Model"],
135
+ )
136
+
137
+ controls = RAT.Controls()
138
+
139
+ problem, results = RAT.run(problem, controls)
140
+ RAT.plotting.plot_ref_sld(problem, results, True)