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,75 @@
1
+ """Custom model file for the domains custom XY example."""
2
+
3
+ from math import sqrt
4
+
5
+ import numpy as np
6
+ from scipy.special import erf
7
+
8
+
9
+ def domains_XY_model(params, bulk_in, bulk_out, contrast, domain):
10
+ """Calculate the SLD profile for a domains custom XY model."""
11
+ # Note - The first contrast number is 1 (not 0) so be careful if you use
12
+ # this variable for array indexing. Same applies to the domain number.
13
+
14
+ # Split up the parameters for convenience
15
+ subRough = params[0]
16
+ oxideThick = params[1]
17
+ layerThick = params[2]
18
+ layerSLD = params[3]
19
+ layerRough = params[4]
20
+ domainSLD = params[5]
21
+
22
+ # Make an array of z values for our model
23
+ z = np.arange(0, 141)
24
+
25
+ # Make the volume fraction distribution for our Silicon substrate
26
+ [vfSilicon, siSurf] = make_layer(z, -25, 50, 1, subRough, subRough)
27
+
28
+ # ... and the Oxide ...
29
+ [vfOxide, oxSurface] = make_layer(z, siSurf, oxideThick, 1, subRough, subRough)
30
+
31
+ # ... and also our layer.
32
+ [vfLayer, laySurface] = make_layer(z, oxSurface, layerThick, 1, subRough, layerRough)
33
+
34
+ # Everything that is not already occupied will be filled will water
35
+ totalVF = vfSilicon + vfOxide + vfLayer
36
+ vfWater = 1 - totalVF
37
+
38
+ # Now convert the Volume Fractions to SLDs
39
+ siSLD = vfSilicon * bulk_in[contrast - 1]
40
+ oxSLD = vfOxide * 3.41e-6
41
+
42
+ # Layer SLD depends on whether we are calculating the domain or not
43
+ if domain == 1:
44
+ laySLD = vfLayer * layerSLD
45
+ elif domain == 2:
46
+ laySLD = vfLayer * domainSLD
47
+
48
+ # ... and finally the water SLD.
49
+ waterSLD = vfWater * bulk_out[contrast - 1]
50
+
51
+ # Make the total SLD by just adding them all up
52
+ totalSLD = siSLD + oxSLD + laySLD + waterSLD
53
+
54
+ # The output is just a [n x 2] array of z against SLD
55
+ SLD = np.column_stack([z, totalSLD])
56
+
57
+ return SLD, subRough
58
+
59
+
60
+ def make_layer(z, prevLaySurf, thickness, height, Sigma_L, Sigma_R):
61
+ """Produce a layer, with a defined thickness, height and roughness.
62
+
63
+ Each side of the layer has its own roughness value.
64
+ """
65
+ # Find the edges
66
+ left = prevLaySurf
67
+ right = prevLaySurf + thickness
68
+
69
+ # Make our heaviside
70
+ erf_left = erf((z - left) / (sqrt(2) * Sigma_L))
71
+ erf_right = erf((z - right) / (sqrt(2) * Sigma_R))
72
+
73
+ VF = np.array((0.5 * height) * (erf_left - erf_right))
74
+
75
+ return VF, right
@@ -0,0 +1,86 @@
1
+ """An example of using domains with a Custom XY model."""
2
+
3
+ import pathlib
4
+
5
+ import ratapi as RAT
6
+
7
+
8
+ def domains_custom_XY():
9
+ """Calculate an example of a layer containing domains using a custom XY model.
10
+
11
+ Domains custom XY models operate in the same way as domains custom layer models,
12
+ in that there is an additional input to the custom model
13
+ specifying the domain to be calculated.
14
+
15
+ This is then used within the function to calculate the correct SLD profile
16
+ for each contrast and domain. In this example, we simulate a hydrogenated layer
17
+ on a silicon substrate, containing domains of a larger SLD, against D2O, SMW and water.
18
+ """
19
+ problem = RAT.Project(calculation="domains", model="custom xy", geometry="substrate/liquid")
20
+
21
+ problem.parameters.append(name="Oxide Thickness", min=10.0, value=20.0, max=50.0, fit=True)
22
+ problem.parameters.append(name="Layer Thickness", min=1.0, value=30.0, max=500.0, fit=True)
23
+ problem.parameters.append(name="Layer SLD", min=-0.5e-6, value=-0.5e-6, max=0.0, fit=True)
24
+ problem.parameters.append(name="Layer Roughness", min=2.0, value=5.0, max=7.0, fit=True)
25
+ problem.parameters.append(name="Domain SLD", min=1.0e-6, value=1.0e-6, max=5.0e-6, fit=True)
26
+
27
+ problem.bulk_in.set_fields(0, name="Silicon", value=2.073e-6, max=1.0, fit=False)
28
+ problem.scalefactors.set_fields(0, min=0.8, value=1.0, max=1.1, fit=True)
29
+
30
+ problem.bulk_out.append(name="SLD SMW", min=2.0e-6, value=2.073e-6, max=2.1e-6)
31
+ problem.bulk_out.append(name="SLD H2O", min=-0.6e-6, value=-0.56e-6, max=-0.5e-6)
32
+
33
+ # Add the custom file
34
+ problem.custom_files.append(
35
+ name="Domain Layer",
36
+ filename="domains_XY_model.py",
37
+ language="python",
38
+ path=pathlib.Path(__file__).parent,
39
+ )
40
+
41
+ # Make contrasts
42
+ problem.contrasts.append(
43
+ name="D2O",
44
+ background="Background 1",
45
+ resolution="Resolution 1",
46
+ scalefactor="Scalefactor 1",
47
+ bulk_in="Silicon",
48
+ bulk_out="SLD D2O",
49
+ domain_ratio="Domain Ratio 1",
50
+ data="Simulation",
51
+ model=["Domain Layer"],
52
+ )
53
+
54
+ problem.contrasts.append(
55
+ name="SMW",
56
+ background="Background 1",
57
+ resolution="Resolution 1",
58
+ scalefactor="Scalefactor 1",
59
+ bulk_in="Silicon",
60
+ bulk_out="SLD SMW",
61
+ domain_ratio="Domain Ratio 1",
62
+ data="Simulation",
63
+ model=["Domain Layer"],
64
+ )
65
+
66
+ problem.contrasts.append(
67
+ name="H2O",
68
+ background="Background 1",
69
+ resolution="Resolution 1",
70
+ scalefactor="Scalefactor 1",
71
+ bulk_in="Silicon",
72
+ bulk_out="SLD H2O",
73
+ domain_ratio="Domain Ratio 1",
74
+ data="Simulation",
75
+ model=["Domain Layer"],
76
+ )
77
+
78
+ controls = RAT.Controls()
79
+ problem, results = RAT.run(problem, controls)
80
+
81
+ return problem, results
82
+
83
+
84
+ if __name__ == "__main__":
85
+ problem, results = domains_custom_XY()
86
+ RAT.plotting.plot_ref_sld(problem, results, True)
@@ -0,0 +1,60 @@
1
+ """An example of using domains with custom layer models."""
2
+
3
+ import pathlib
4
+
5
+ import ratapi as RAT
6
+
7
+
8
+ def domains_custom_layers():
9
+ """Calculate an example custom layers domains project involving incoherent summing on a permalloy layer.
10
+
11
+ For a custom layers model, rather than being forced to define our layers as [Thick SLD Rough…. etc],
12
+ we can parameterise however we like and then use a function to calculate the parameters for each layer.
13
+ So for example, if the volume of lipid tails are known (from the literature),
14
+ then all we need is the Area per molecule to calculate the layers.
15
+ """
16
+ problem = RAT.Project(calculation="domains", model="custom layers", geometry="substrate/liquid")
17
+
18
+ # Make some parameters...
19
+ problem.parameters.append(name="Alloy Thickness", min=100.0, value=150.0, max=200.0, fit=True)
20
+ problem.parameters.append(name="Alloy SLD up", min=9.0e-6, value=11.0e-6, max=13.0e-6, fit=True)
21
+ problem.parameters.append(name="Alloy SLD down", min=5.0e-6, value=7.0e-6, max=10.0e-6, fit=True)
22
+ problem.parameters.append(name="Alloy Roughness", min=5.0, value=7.0, max=11.0, fit=True)
23
+ problem.parameters.append(name="Gold Thickness", min=100.0, value=150.0, max=200.0, fit=True)
24
+ problem.parameters.append(name="Gold SLD", min=4.0e-6, value=4.5e-6, max=5.0e-6, fit=True)
25
+ problem.parameters.append(name="Gold Roughness", min=5.0, value=7.0, max=11.0, fit=True)
26
+
27
+ # Set the bulk SLD
28
+ problem.bulk_in.set_fields(0, name="Silicon", value=2.073e-6, max=1.0)
29
+
30
+ # Add the custom file
31
+ problem.custom_files.append(
32
+ name="Alloy domains",
33
+ filename="alloy_domains.py",
34
+ language="python",
35
+ path=pathlib.Path(__file__).parent,
36
+ )
37
+
38
+ # Make a contrast
39
+ problem.contrasts.append(
40
+ name="D2O Contrast",
41
+ data="Simulation",
42
+ background="Background 1",
43
+ bulk_in="Silicon",
44
+ bulk_out="SLD D2O",
45
+ scalefactor="Scalefactor 1",
46
+ resolution="Resolution 1",
47
+ resample=False,
48
+ domain_ratio="Domain Ratio 1",
49
+ model=["Alloy domains"],
50
+ )
51
+
52
+ controls = RAT.Controls()
53
+ problem, results = RAT.run(problem, controls)
54
+
55
+ return problem, results
56
+
57
+
58
+ if __name__ == "__main__":
59
+ problem, results = domains_custom_layers()
60
+ RAT.plotting.plot_ref_sld(problem, results, True)
@@ -0,0 +1,92 @@
1
+ """An example using domains with standard layers."""
2
+
3
+ import ratapi as RAT
4
+
5
+
6
+ def domains_standard_layers():
7
+ """Calculate an example for using standard layers with domains.
8
+
9
+ Domains standard layers projects proceed in much the same way as a normal standard layers problem,
10
+ except that there is an additional grouping step between layers and contrasts.
11
+
12
+ Layers are grouped into ‘Domain Contrasts’. The model for the actual experimental contrast
13
+ is built from these domain contrasts rather than from layers. There are exactly
14
+ two domains for each contrast, with the the ratio of them controlled by
15
+ a fittable ‘domain ratio’ parameter.
16
+ """
17
+ problem = RAT.Project(calculation="domains")
18
+
19
+ # Define the parameters we need to define our two domains
20
+ problem.parameters.append(name="L1 Thickness", min=5.0, value=20.0, max=60.0, fit=True)
21
+ problem.parameters.append(name="L1 SLD", min=3.0e-6, value=4.1e-6, max=5.0e-6, fit=False)
22
+ problem.parameters.append(name="L1 Roughness", min=2.0, value=5.0, max=20.0, fit=True)
23
+ problem.parameters.append(name="L1 Hydration", min=10.0, value=20.0, max=30.0, fit=True)
24
+
25
+ problem.parameters.append(name="L2 Thickness", min=5.0, value=60.0, max=100.0, fit=True)
26
+ problem.parameters.append(name="L2 SLD", min=2.1e-6, value=3.0e-6, max=5.0e-6, fit=False)
27
+ problem.parameters.append(name="L2 Roughness", min=2.0, value=5.0, max=20.0, fit=True)
28
+ problem.parameters.append(name="L2 Hydration", min=10.0, value=20.0, max=30.0, fit=True)
29
+
30
+ problem.parameters.append(name="L3 Thickness", min=5.0, value=200.0, max=300.0, fit=True)
31
+ problem.parameters.append(name="L3 SLD", min=3.0e-6, value=7.0e-6, max=8.0e-6, fit=False)
32
+ problem.parameters.append(name="L3 Roughness", min=2.0, value=5.0, max=20.0, fit=True)
33
+ problem.parameters.append(name="L3 Hydration", min=10.0, value=20.0, max=30.0, fit=True)
34
+
35
+ # Now group these parameters into layers
36
+ problem.layers.append(
37
+ name="Layer 1",
38
+ thickness="L1 Thickness",
39
+ SLD="L1 SLD",
40
+ roughness="L1 Roughness",
41
+ hydration="L1 Hydration",
42
+ hydrate_with="bulk out",
43
+ )
44
+
45
+ problem.layers.append(
46
+ name="Layer 2",
47
+ thickness="L2 Thickness",
48
+ SLD="L2 SLD",
49
+ roughness="L2 Roughness",
50
+ hydration="L2 Hydration",
51
+ hydrate_with="bulk out",
52
+ )
53
+
54
+ problem.layers.append(
55
+ name="Layer 3",
56
+ thickness="L3 Thickness",
57
+ SLD="L3 SLD",
58
+ roughness="L3 Roughness",
59
+ hydration="L3 Hydration",
60
+ hydrate_with="bulk out",
61
+ )
62
+
63
+ # If we look at the project, there are two extra groups as compared to a normal standard layers calculation:
64
+ # Domain Contrasts and Domain Ratios
65
+ problem.domain_contrasts.append(name="Domain 1", model=["Layer 1"])
66
+ problem.domain_contrasts.append(name="Domain 2", model=["Layer 2", "Layer 3"])
67
+
68
+ # Now make a contrast as with standard models, but this time also including the default domain ratio
69
+ # ("Domain Ratio 1")
70
+ problem.contrasts.append(
71
+ name="Domain Test",
72
+ background="Background 1",
73
+ resolution="Resolution 1",
74
+ scalefactor="Scalefactor 1",
75
+ resample=False,
76
+ bulk_in="SLD Air",
77
+ bulk_out="SLD D2O",
78
+ domain_ratio="Domain Ratio 1",
79
+ data="Simulation",
80
+ model=["Domain 1", "Domain 2"],
81
+ )
82
+
83
+ # Now we can run our simulation as usual
84
+ controls = RAT.Controls()
85
+ problem, results = RAT.run(problem, controls)
86
+
87
+ return problem, results
88
+
89
+
90
+ if __name__ == "__main__":
91
+ problem, results = domains_standard_layers()
92
+ RAT.plotting.plot_ref_sld(problem, results, True)
@@ -0,0 +1 @@
1
+ """A benchmark for using RAT custom files in three different languages."""
@@ -0,0 +1,72 @@
1
+ """A custom bilayer model for the custom file languages benchmark."""
2
+
3
+ import numpy as np
4
+
5
+
6
+ def custom_bilayer(params, bulk_in, bulk_out, contrast):
7
+ """Calculate the layer parameters for a custom bilayer model."""
8
+ # Note - The first contrast number is 1 (not 0) so be careful if you use
9
+ # this variable for array indexing.
10
+
11
+ sub_rough = params[0]
12
+ oxide_thick = params[1]
13
+ oxide_hydration = params[2]
14
+ lipidAPM = params[3]
15
+ headHydration = params[4]
16
+ bilayerHydration = params[5]
17
+ bilayerRough = params[6]
18
+ waterThick = params[7]
19
+
20
+ # We have a constant SLD for the bilayer
21
+ oxide_SLD = 3.41e-6
22
+
23
+ # Now make the lipid layers
24
+ # Use known lipid volume and compositions
25
+ # to make the layers
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
+ Head = CHOL + PO4 + GLYC + COO
44
+ Tails = (34 * CH2) + (2 * CH3)
45
+
46
+ # We need volumes for each.
47
+ # Use literature values:
48
+ vHead = 319
49
+ vTail = 782
50
+
51
+ # we use the volumes to calculate the SLDs
52
+ SLDhead = Head / vHead
53
+ SLDtail = Tails / vTail
54
+
55
+ # We calculate the layer thickness from the volumes and the APM
56
+ headThick = vHead / lipidAPM
57
+ tailThick = vTail / lipidAPM
58
+
59
+ # Manually deal with hydration for layers in this example.
60
+ oxSLD = (oxide_hydration * bulk_out[contrast - 1]) + ((1 - oxide_hydration) * oxide_SLD)
61
+ headSLD = (headHydration * bulk_out[contrast - 1]) + ((1 - headHydration) * SLDhead)
62
+ tailSLD = (bilayerHydration * bulk_out[contrast - 1]) + ((1 - bilayerHydration) * SLDtail)
63
+
64
+ # Make the layers
65
+ oxide = [oxide_thick, oxSLD, sub_rough]
66
+ water = [waterThick, bulk_out[contrast - 1], bilayerRough]
67
+ head = [headThick, headSLD, bilayerRough]
68
+ tail = [tailThick, tailSLD, bilayerRough]
69
+
70
+ output = np.array([oxide, water, head, tail, tail, head])
71
+
72
+ 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
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
+ """A custom example problem for the languages benchmark."""
2
+
3
+ import pathlib
4
+
5
+ import numpy as np
6
+
7
+ import ratapi as RAT
8
+
9
+
10
+ def make_example_problem():
11
+ """Generate a Custom Layers example for Supported DSPC layer.
12
+
13
+ Example of using custom layers to model a DSPC supported bilayer.
14
+ """
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 = pathlib.Path(__file__).parents[1] / "data"
44
+ D2O_data = np.loadtxt(data_path / "c_PLP0016596.dat", delimiter=",")
45
+ SMW_data = np.loadtxt(data_path / "c_PLP0016601.dat", delimiter=",")
46
+ H2O_data = np.loadtxt(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,
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", source="Background parameter SMW")
88
+ problem.backgrounds.append(name="Background H2O", type="constant", source="Background parameter H2O")
89
+
90
+ # And edit the other one
91
+ problem.backgrounds.set_fields(0, name="Background D2O", source="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