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.
- ratapi/__init__.py +29 -0
- ratapi/classlist.py +620 -0
- ratapi/controls.py +258 -0
- ratapi/eventManager.dll +0 -0
- ratapi/events.py +88 -0
- ratapi/examples/__init__.py +25 -0
- ratapi/examples/absorption/__init__.py +1 -0
- ratapi/examples/absorption/absorption.py +172 -0
- ratapi/examples/absorption/volume_thiol_bilayer.py +141 -0
- ratapi/examples/convert_rascal_project/Model_IIb.py +87 -0
- ratapi/examples/convert_rascal_project/__init__.py +1 -0
- ratapi/examples/convert_rascal_project/convert_rascal.py +49 -0
- ratapi/examples/data/D2O_spin_down.dat +100 -0
- ratapi/examples/data/D2O_spin_up.dat +101 -0
- ratapi/examples/data/DSPC_D2O.dat +82 -0
- ratapi/examples/data/DSPC_SMW.dat +82 -0
- ratapi/examples/data/H2O_spin_down.dat +102 -0
- ratapi/examples/data/H2O_spin_up.dat +102 -0
- ratapi/examples/data/__init__.py +1 -0
- ratapi/examples/data/c_PLP0016596.dat +146 -0
- ratapi/examples/data/c_PLP0016601.dat +97 -0
- ratapi/examples/data/c_PLP0016607.dat +104 -0
- ratapi/examples/data/d2o_background_data.dat +82 -0
- ratapi/examples/domains/__init__.py +1 -0
- ratapi/examples/domains/alloy_domains.py +31 -0
- ratapi/examples/domains/domains_XY_model.py +72 -0
- ratapi/examples/domains/domains_custom_XY.py +86 -0
- ratapi/examples/domains/domains_custom_layers.py +60 -0
- ratapi/examples/domains/domains_standard_layers.py +92 -0
- ratapi/examples/languages/__init__.py +1 -0
- ratapi/examples/languages/custom_bilayer.py +69 -0
- ratapi/examples/languages/run_custom_file_languages.py +41 -0
- ratapi/examples/languages/setup_problem.py +130 -0
- ratapi/examples/normal_reflectivity/DSPC_custom_XY.py +149 -0
- ratapi/examples/normal_reflectivity/DSPC_custom_layers.py +130 -0
- ratapi/examples/normal_reflectivity/DSPC_data_background.py +220 -0
- ratapi/examples/normal_reflectivity/DSPC_function_background.py +219 -0
- ratapi/examples/normal_reflectivity/DSPC_standard_layers.py +210 -0
- ratapi/examples/normal_reflectivity/__init__.py +1 -0
- ratapi/examples/normal_reflectivity/background_function.py +16 -0
- ratapi/examples/normal_reflectivity/custom_XY_DSPC.py +138 -0
- ratapi/examples/normal_reflectivity/custom_bilayer_DSPC.py +87 -0
- ratapi/inputs.py +588 -0
- ratapi/models.py +677 -0
- ratapi/outputs.py +821 -0
- ratapi/project.py +1074 -0
- ratapi/rat_core.cp313-win_amd64.pyd +0 -0
- ratapi/run.py +140 -0
- ratapi/utils/__init__.py +1 -0
- ratapi/utils/convert.py +564 -0
- ratapi/utils/custom_errors.py +40 -0
- ratapi/utils/enums.py +204 -0
- ratapi/utils/orso.py +247 -0
- ratapi/utils/plotting.py +1231 -0
- ratapi/wrappers.py +144 -0
- ratapi-0.0.0.dev10.dist-info/METADATA +61 -0
- ratapi-0.0.0.dev10.dist-info/RECORD +59 -0
- ratapi-0.0.0.dev10.dist-info/WHEEL +5 -0
- ratapi-0.0.0.dev10.dist-info/top_level.txt +1 -0
|
@@ -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,69 @@
|
|
|
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
|
+
sub_rough = params[0]
|
|
9
|
+
oxide_thick = params[1]
|
|
10
|
+
oxide_hydration = params[2]
|
|
11
|
+
lipidAPM = params[3]
|
|
12
|
+
headHydration = params[4]
|
|
13
|
+
bilayerHydration = params[5]
|
|
14
|
+
bilayerRough = params[6]
|
|
15
|
+
waterThick = params[7]
|
|
16
|
+
|
|
17
|
+
# We have a constant SLD for the bilayer
|
|
18
|
+
oxide_SLD = 3.41e-6
|
|
19
|
+
|
|
20
|
+
# Now make the lipid layers
|
|
21
|
+
# Use known lipid volume and compositions
|
|
22
|
+
# to make the layers
|
|
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
|
+
Head = CHOL + PO4 + GLYC + COO
|
|
41
|
+
Tails = (34 * CH2) + (2 * CH3)
|
|
42
|
+
|
|
43
|
+
# We need volumes for each.
|
|
44
|
+
# Use literature values:
|
|
45
|
+
vHead = 319
|
|
46
|
+
vTail = 782
|
|
47
|
+
|
|
48
|
+
# we use the volumes to calculate the SLDs
|
|
49
|
+
SLDhead = Head / vHead
|
|
50
|
+
SLDtail = Tails / vTail
|
|
51
|
+
|
|
52
|
+
# We calculate the layer thickness from the volumes and the APM
|
|
53
|
+
headThick = vHead / lipidAPM
|
|
54
|
+
tailThick = vTail / lipidAPM
|
|
55
|
+
|
|
56
|
+
# Manually deal with hydration for layers in this example.
|
|
57
|
+
oxSLD = (oxide_hydration * bulk_out[contrast]) + ((1 - oxide_hydration) * oxide_SLD)
|
|
58
|
+
headSLD = (headHydration * bulk_out[contrast]) + ((1 - headHydration) * SLDhead)
|
|
59
|
+
tailSLD = (bilayerHydration * bulk_out[contrast]) + ((1 - bilayerHydration) * SLDtail)
|
|
60
|
+
|
|
61
|
+
# Make the layers
|
|
62
|
+
oxide = [oxide_thick, oxSLD, sub_rough]
|
|
63
|
+
water = [waterThick, bulk_out[contrast], bilayerRough]
|
|
64
|
+
head = [headThick, headSLD, bilayerRough]
|
|
65
|
+
tail = [tailThick, tailSLD, bilayerRough]
|
|
66
|
+
|
|
67
|
+
output = np.array([oxide, water, head, tail, tail, head])
|
|
68
|
+
|
|
69
|
+
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
|
|
@@ -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)
|