RATapi 0.0.0.dev0__tar.gz → 0.0.0.dev1__tar.gz

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 (71) hide show
  1. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/PKG-INFO +1 -1
  2. RATapi-0.0.0.dev1/RATapi/__init__.py +9 -0
  3. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/classlist.py +21 -5
  4. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/controls.py +1 -1
  5. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/events.py +20 -5
  6. RATapi-0.0.0.dev1/RATapi/examples/__init__.py +19 -0
  7. RATapi-0.0.0.dev1/RATapi/examples/absorption/absorption.py +161 -0
  8. RATapi-0.0.0.dev1/RATapi/examples/convert_rascal_project/Model_IIb.py +84 -0
  9. RATapi-0.0.0.dev1/RATapi/examples/convert_rascal_project/convert_rascal.py +28 -0
  10. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/examples/domains/alloy_domains.py +1 -1
  11. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/examples/domains/domains_XY_model.py +1 -1
  12. RATapi-0.0.0.dev1/RATapi/examples/domains/domains_custom_XY.py +75 -0
  13. RATapi-0.0.0.dev1/RATapi/examples/domains/domains_custom_layers.py +52 -0
  14. RATapi-0.0.0.dev1/RATapi/examples/domains/domains_standard_layers.py +80 -0
  15. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/examples/languages/setup_problem.py +4 -5
  16. RATapi-0.0.0.dev1/RATapi/examples/non_polarised/DSPC_custom_XY.py +148 -0
  17. RATapi-0.0.0.dev1/RATapi/examples/non_polarised/DSPC_custom_layers.py +132 -0
  18. RATapi-0.0.0.dev1/RATapi/examples/non_polarised/DSPC_standard_layers.py +364 -0
  19. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/inputs.py +1 -0
  20. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/models.py +61 -0
  21. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/outputs.py +66 -9
  22. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/project.py +74 -16
  23. RATapi-0.0.0.dev1/RATapi/run.py +94 -0
  24. RATapi-0.0.0.dev1/RATapi/utils/convert.py +500 -0
  25. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/utils/enums.py +56 -43
  26. RATapi-0.0.0.dev1/RATapi/utils/plotting.py +833 -0
  27. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi.egg-info/PKG-INFO +1 -1
  28. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi.egg-info/SOURCES.txt +4 -0
  29. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi.egg-info/requires.txt +2 -0
  30. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/cpp/rat.cpp +36 -17
  31. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/setup.py +9 -2
  32. RATapi-0.0.0.dev0/RATapi/__init__.py +0 -8
  33. RATapi-0.0.0.dev0/RATapi/examples/absorption/absorption.py +0 -148
  34. RATapi-0.0.0.dev0/RATapi/examples/domains/domains_custom_XY.py +0 -69
  35. RATapi-0.0.0.dev0/RATapi/examples/domains/domains_custom_layers.py +0 -46
  36. RATapi-0.0.0.dev0/RATapi/examples/domains/domains_standard_layers.py +0 -75
  37. RATapi-0.0.0.dev0/RATapi/examples/non_polarised/DSPC_custom_XY.py +0 -140
  38. RATapi-0.0.0.dev0/RATapi/examples/non_polarised/DSPC_custom_layers.py +0 -121
  39. RATapi-0.0.0.dev0/RATapi/examples/non_polarised/DSPC_standard_layers.py +0 -358
  40. RATapi-0.0.0.dev0/RATapi/run.py +0 -35
  41. RATapi-0.0.0.dev0/RATapi/utils/plotting.py +0 -211
  42. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/MANIFEST.in +0 -0
  43. {RATapi-0.0.0.dev0/RATapi/examples → RATapi-0.0.0.dev1/RATapi/examples/absorption}/__init__.py +0 -0
  44. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/examples/absorption/volume_thiol_bilayer.py +0 -0
  45. {RATapi-0.0.0.dev0/RATapi/examples/absorption → RATapi-0.0.0.dev1/RATapi/examples/convert_rascal_project}/__init__.py +0 -0
  46. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/examples/data/D2O_spin_down.dat +0 -0
  47. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/examples/data/D2O_spin_up.dat +0 -0
  48. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/examples/data/DSPC_D2O.dat +0 -0
  49. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/examples/data/DSPC_SMW.dat +0 -0
  50. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/examples/data/H2O_spin_down.dat +0 -0
  51. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/examples/data/H2O_spin_up.dat +0 -0
  52. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/examples/data/__init__.py +0 -0
  53. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/examples/data/c_PLP0016596.dat +0 -0
  54. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/examples/data/c_PLP0016601.dat +0 -0
  55. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/examples/data/c_PLP0016607.dat +0 -0
  56. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/examples/domains/__init__.py +0 -0
  57. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/examples/languages/__init__.py +0 -0
  58. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/examples/languages/custom_bilayer.py +0 -0
  59. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/examples/languages/run_custom_file_languages.py +0 -0
  60. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/examples/non_polarised/__init__.py +0 -0
  61. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/examples/non_polarised/custom_XY_DSPC.py +0 -0
  62. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/examples/non_polarised/custom_bilayer_DSPC.py +0 -0
  63. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/utils/__init__.py +0 -0
  64. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/utils/custom_errors.py +0 -0
  65. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi/wrappers.py +0 -0
  66. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi.egg-info/dependency_links.txt +0 -0
  67. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi.egg-info/not-zip-safe +0 -0
  68. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/RATapi.egg-info/top_level.txt +0 -0
  69. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/README.md +0 -0
  70. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/pyproject.toml +0 -0
  71. {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: RATapi
3
- Version: 0.0.0.dev0
3
+ Version: 0.0.0.dev1
4
4
  Summary: Python extension for the Reflectivity Analysis Toolbox (RAT)
5
5
  Home-page: https://github.com/RascalSoftware/python-RAT
6
6
  Author:
@@ -0,0 +1,9 @@
1
+ import RATapi.examples as examples
2
+ from RATapi import events, models
3
+ from RATapi.classlist import ClassList
4
+ from RATapi.controls import Controls
5
+ from RATapi.project import Project
6
+ from RATapi.run import run
7
+ from RATapi.utils import convert, plotting
8
+
9
+ __all__ = ["examples", "models", "events", "ClassList", "Controls", "Project", "run", "plotting", "convert"]
@@ -68,8 +68,10 @@ class ClassList(collections.UserList):
68
68
  + list(
69
69
  f"{'Data array: ['+' x '.join(str(i) for i in v.shape) if v.size > 0 else '['}]"
70
70
  if isinstance(v, np.ndarray)
71
+ else "\n".join(element for element in v)
72
+ if k == "model"
71
73
  else str(v)
72
- for v in model.__dict__.values()
74
+ for k, v in model.__dict__.items()
73
75
  )
74
76
  for index, model in enumerate(self.data)
75
77
  ]
@@ -79,6 +81,15 @@ class ClassList(collections.UserList):
79
81
  output = str(self.data)
80
82
  return output
81
83
 
84
+ def __getitem__(self, index: Union[int, slice, str, object]) -> object:
85
+ """Get an item by its index, name, a slice, or the object itself."""
86
+ if isinstance(index, (int, slice)):
87
+ return self.data[index]
88
+ elif isinstance(index, (str, object)):
89
+ return self.data[self.index(index)]
90
+ else:
91
+ raise IndexError("ClassLists can only be indexed by integers, slices, name strings, or objects.")
92
+
82
93
  def __setitem__(self, index: int, item: object) -> None:
83
94
  """Replace the object at an existing index of the ClassList."""
84
95
  self._setitem(index, item)
@@ -299,9 +310,9 @@ class ClassList(collections.UserList):
299
310
  Raised if the input arguments contain a name_field value already defined in the ClassList.
300
311
 
301
312
  """
302
- names = self.get_names()
313
+ names = [name.lower() for name in self.get_names()]
303
314
  with contextlib.suppress(KeyError):
304
- if input_args[self.name_field] in names:
315
+ if input_args[self.name_field].lower() in names:
305
316
  raise ValueError(
306
317
  f"Input arguments contain the {self.name_field} '{input_args[self.name_field]}', "
307
318
  f"which is already specified in the ClassList",
@@ -322,7 +333,7 @@ class ClassList(collections.UserList):
322
333
  Raised if the input list defines more than one object with the same value of name_field.
323
334
 
324
335
  """
325
- names = [getattr(model, self.name_field) for model in input_list if hasattr(model, self.name_field)]
336
+ names = [getattr(model, self.name_field).lower() for model in input_list if hasattr(model, self.name_field)]
326
337
  if len(set(names)) != len(names):
327
338
  raise ValueError(f"Input list contains objects with the same value of the {self.name_field} attribute")
328
339
 
@@ -358,7 +369,12 @@ class ClassList(collections.UserList):
358
369
  object with that value of the name_field attribute cannot be found.
359
370
 
360
371
  """
361
- return next((model for model in self.data if getattr(model, self.name_field) == value), value)
372
+ try:
373
+ lower_value = value.lower()
374
+ except AttributeError:
375
+ lower_value = value
376
+
377
+ return next((model for model in self.data if getattr(model, self.name_field).lower() == lower_value), value)
362
378
 
363
379
  @staticmethod
364
380
  def _determine_class_handle(input_list: Sequence[object]):
@@ -91,7 +91,7 @@ class Controls(BaseModel, validate_assignment=True, extra="forbid"):
91
91
  f'{", ".join(fields.get("procedure", []))}\n',
92
92
  }
93
93
  custom_error_list = custom_pydantic_validation_error(exc.errors(), custom_error_msgs)
94
- raise ValidationError.from_exception_data(exc.title, custom_error_list) from None
94
+ raise ValidationError.from_exception_data(exc.title, custom_error_list, hide_input=True) from None
95
95
 
96
96
  if isinstance(model_input, validated_self.__class__):
97
97
  # This is for changing fields in a defined model
@@ -57,11 +57,26 @@ def register(event_type: EventTypes, callback: Callable[[Union[str, PlotEventDat
57
57
  __event_callbacks[event_type].add(callback)
58
58
 
59
59
 
60
- def clear() -> None:
61
- """Clears all event callbacks."""
62
- __event_impl.clear()
63
- for key in __event_callbacks:
64
- __event_callbacks[key] = set()
60
+ def clear(key=None, callback=None) -> None:
61
+ """Clears all event callbacks or specific callback.
62
+
63
+ Parameters
64
+ ----------
65
+ callback : Callable[[Union[str, PlotEventData, ProgressEventData]], None]
66
+ The callback for when the event is triggered.
67
+
68
+ """
69
+ if key is None and callback is None:
70
+ for key in __event_callbacks:
71
+ __event_callbacks[key] = set()
72
+ elif key is not None and callback is not None:
73
+ __event_callbacks[key].remove(callback)
74
+
75
+ for value in __event_callbacks.values():
76
+ if value:
77
+ break
78
+ else:
79
+ __event_impl.clear()
65
80
 
66
81
 
67
82
  dir_path = os.path.dirname(os.path.realpath(__file__))
@@ -0,0 +1,19 @@
1
+ from RATapi.examples.absorption.absorption import absorption
2
+ from RATapi.examples.convert_rascal_project import convert_rascal
3
+ from RATapi.examples.domains.domains_custom_layers import domains_custom_layers
4
+ from RATapi.examples.domains.domains_custom_XY import domains_custom_XY
5
+ from RATapi.examples.domains.domains_standard_layers import domains_standard_layers
6
+ from RATapi.examples.non_polarised.DSPC_custom_layers import DSPC_custom_layers
7
+ from RATapi.examples.non_polarised.DSPC_custom_XY import DSPC_custom_XY
8
+ from RATapi.examples.non_polarised.DSPC_standard_layers import DSPC_standard_layers
9
+
10
+ __all__ = [
11
+ "absorption",
12
+ "domains_custom_layers",
13
+ "domains_custom_XY",
14
+ "domains_standard_layers",
15
+ "DSPC_custom_layers",
16
+ "DSPC_custom_XY",
17
+ "DSPC_standard_layers",
18
+ "convert_rascal",
19
+ ]
@@ -0,0 +1,161 @@
1
+ import os
2
+ import pathlib
3
+
4
+ import numpy as np
5
+
6
+ import RATapi as RAT
7
+
8
+
9
+ def absorption():
10
+ """Custom layers model including absorption"""
11
+ problem = RAT.Project(
12
+ name="Absorption example",
13
+ calculation="non polarised",
14
+ model="custom layers",
15
+ geometry="substrate/liquid",
16
+ absorption=True,
17
+ )
18
+
19
+ # Add the required parameters (substrate roughness is already there by default)
20
+ problem.parameters.append(name="Alloy Thickness", min=100.0, value=135.6, max=200.0, fit=True)
21
+ problem.parameters.append(name="Alloy SLD up", min=6.0e-6, value=9.87e-6, max=1.2e-5, fit=True)
22
+ problem.parameters.append(name="Alloy SLD imaginary up", min=1.0e-9, value=4.87e-8, max=1.0e-7, fit=True)
23
+ problem.parameters.append(name="Alloy SLD down", min=6.0e-6, value=7.05e-6, max=1.3e-5, fit=True)
24
+ problem.parameters.append(name="Alloy SLD imaginary down", min=1.0e-9, value=4.87e-8, max=1.0e-7, fit=True)
25
+ problem.parameters.append(name="Alloy Roughness", min=2.0, value=5.71, max=10.0, fit=True)
26
+ problem.parameters.append(name="Gold Thickness", min=100.0, value=154.7, max=200.0, fit=True)
27
+ problem.parameters.append(name="Gold Roughness", min=0.1, value=5.42, max=10.0, fit=True)
28
+ problem.parameters.append(name="Gold SLD", min=4.0e-6, value=4.49e-6, max=5.0e-6, fit=True)
29
+ problem.parameters.append(name="Gold SLD imaginary", min=1.0e-9, value=4.20e-8, max=1.0e-7, fit=True)
30
+
31
+ problem.parameters.append(name="Thiol APM", min=40.0, value=56.27, max=100.0, fit=True)
32
+ problem.parameters.append(name="Thiol Head Hydration", min=20.0, value=30.0, max=50.0, fit=True)
33
+ problem.parameters.append(name="Thiol Coverage", min=0.5, value=0.9, max=1.0, fit=True)
34
+
35
+ problem.parameters.append(name="CW Thickness", min=1.0, value=12.87, max=25.0, fit=True)
36
+ problem.parameters.append(name="Bilayer APM", min=48.0, value=65.86, max=90.0, fit=True)
37
+ problem.parameters.append(name="Bilayer Head Hydration", min=20.0, value=30.0, max=50.0, fit=True)
38
+ problem.parameters.append(name="Bilayer Roughness", min=1.0, value=3.87, max=10.0, fit=True)
39
+ problem.parameters.append(name="Bilayer Coverage", min=0.5, value=0.94, max=1.0, fit=True)
40
+
41
+ # Change the existing Bulk In parameter to be Silicon
42
+ problem.bulk_in.set_fields(0, name="Silicon", min=2.0e-6, value=2.073e-6, max=2.1e-6)
43
+
44
+ # We need 2 bulk outs - D2O and H2O
45
+ problem.bulk_out.set_fields(0, name="D2O", min=5.8e-06, value=6.21e-06, max=6.35e-06, fit=True)
46
+ problem.bulk_out.append(name="H2O", min=-5.6e-07, value=-3.15e-07, max=0.0, fit=True)
47
+
48
+ # Use a different scalefactor for each dataset
49
+ del problem.scalefactors[0]
50
+ problem.scalefactors.append(name="Scalefactor 1", min=0.5, value=1, max=1.5, fit=True)
51
+ problem.scalefactors.append(name="Scalefactor 2", min=0.5, value=1, max=1.5, fit=True)
52
+ problem.scalefactors.append(name="Scalefactor 3", min=0.5, value=1, max=1.5, fit=True)
53
+ problem.scalefactors.append(name="Scalefactor 4", min=0.5, value=1, max=1.5, fit=True)
54
+
55
+ # Similarly, use an individual background for each dataset
56
+ del problem.backgrounds[0]
57
+ del problem.background_parameters[0]
58
+
59
+ problem.background_parameters.append(
60
+ name="Background parameter 1", min=5.0e-08, value=7.88e-06, max=9.0e-05, fit=True
61
+ )
62
+ problem.background_parameters.append(
63
+ name="Background parameter 2", min=1.0e-08, value=5.46e-06, max=9.0e-05, fit=True
64
+ )
65
+ problem.background_parameters.append(
66
+ name="Background parameter 3", min=1.0e-06, value=9.01e-06, max=9.0e-05, fit=True
67
+ )
68
+ problem.background_parameters.append(
69
+ name="Background parameter 4", min=1.0e-06, value=5.61e-06, max=9.0e-05, fit=True
70
+ )
71
+
72
+ problem.backgrounds.append(name="Background 1", type="constant", value_1="Background parameter 1")
73
+ problem.backgrounds.append(name="Background 2", type="constant", value_1="Background parameter 2")
74
+ problem.backgrounds.append(name="Background 3", type="constant", value_1="Background parameter 3")
75
+ problem.backgrounds.append(name="Background 4", type="constant", value_1="Background parameter 4")
76
+
77
+ # Make the resolution fittable
78
+ problem.resolution_parameters.set_fields(0, fit=True)
79
+
80
+ # Now add the data we need
81
+ data_path = os.path.join(pathlib.Path(__file__).parents[1].resolve(), "data")
82
+
83
+ data_1 = np.loadtxt(os.path.join(data_path, "D2O_spin_down.dat"))
84
+ problem.data.append(name="D2O_dn", data=data_1)
85
+
86
+ data_2 = np.loadtxt(os.path.join(data_path, "D2O_spin_up.dat"))
87
+ problem.data.append(name="D2O_up", data=data_2)
88
+
89
+ data_3 = np.loadtxt(os.path.join(data_path, "H2O_spin_down.dat"))
90
+ problem.data.append(name="H2O_dn", data=data_3)
91
+
92
+ data_4 = np.loadtxt(os.path.join(data_path, "H2O_spin_up.dat"))
93
+ problem.data.append(name="H2O_up", data=data_4)
94
+
95
+ # Add the custom file
96
+ problem.custom_files.append(
97
+ name="DPPC absorption",
98
+ filename="volume_thiol_bilayer.py",
99
+ language="python",
100
+ path=pathlib.Path(__file__).parent.resolve(),
101
+ )
102
+
103
+ # Finally add the contrasts
104
+ problem.contrasts.append(
105
+ name="D2O Down",
106
+ data="D2O_dn",
107
+ background="Background 1",
108
+ bulk_in="Silicon",
109
+ bulk_out="D2O",
110
+ scalefactor="Scalefactor 1",
111
+ resolution="Resolution 1",
112
+ resample=True,
113
+ model=["DPPC absorption"],
114
+ )
115
+
116
+ problem.contrasts.append(
117
+ name="D2O Up",
118
+ data="D2O_up",
119
+ background="Background 2",
120
+ bulk_in="Silicon",
121
+ bulk_out="D2O",
122
+ scalefactor="Scalefactor 2",
123
+ resolution="Resolution 1",
124
+ resample=True,
125
+ model=["DPPC absorption"],
126
+ )
127
+
128
+ problem.contrasts.append(
129
+ name="H2O Down",
130
+ data="H2O_dn",
131
+ background="Background 3",
132
+ bulk_in="Silicon",
133
+ bulk_out="H2O",
134
+ scalefactor="Scalefactor 3",
135
+ resolution="Resolution 1",
136
+ resample=True,
137
+ model=["DPPC absorption"],
138
+ )
139
+
140
+ problem.contrasts.append(
141
+ name="H2O Up",
142
+ data="H2O_up",
143
+ background="Background 4",
144
+ bulk_in="Silicon",
145
+ bulk_out="H2O",
146
+ scalefactor="Scalefactor 4",
147
+ resolution="Resolution 1",
148
+ resample=True,
149
+ model=["DPPC absorption"],
150
+ )
151
+
152
+ # Now make a controls block and run the code
153
+ controls = RAT.Controls(parallel="contrasts", resampleParams=[0.9, 150.0])
154
+ problem, results = RAT.run(problem, controls)
155
+
156
+ return problem, results
157
+
158
+
159
+ if __name__ == "__main__":
160
+ problem, results = absorption()
161
+ RAT.plotting.plot_ref_sld(problem, results, True)
@@ -0,0 +1,84 @@
1
+ from math import cos, radians
2
+
3
+
4
+ def Model_IIb(params, bulk_in, bulk_out, contrast):
5
+ # converted from matlab file Model_IIb.m
6
+
7
+ Roughness, APM, thickHead, theta = params
8
+
9
+ # Make a flag to say which deuteration this is calculating
10
+ # [subs head tail]
11
+ deut = [[0, 0, 1], [1, 0, 1], [0, 1, 0], [1, 1, 0], [0, 1, 1], [1, 1, 1], [1, 0, 0]]
12
+
13
+ bc = 0.6646e-4 # Carbon
14
+ bo = 0.5843e-4 # Oxygen
15
+ bh = -0.3739e-4 # Hydrogen
16
+ bp = 0.513e-4 # Phosphorus
17
+ bn = 0.936e-4 # Nitrogen
18
+ bd = 0.6671e-4 # Deuterium
19
+
20
+ # Work out the total scattering length in each fragment
21
+ # for hydrogenated:
22
+ COO = (4 * bo) + (2 * bc)
23
+ GLYC = (3 * bc) + (5 * bh)
24
+ CH3 = (2 * bc) + (6 * bh)
25
+ PO4 = (1 * bp) + (4 * bo)
26
+ CH2 = (1 * bc) + (2 * bh)
27
+ CHOL = (5 * bc) + (12 * bh) + (1 * bn)
28
+ H2O = (2 * bh) + (1 * bo)
29
+
30
+ # for deuterated:
31
+ dCH3 = (2 * bc) + (6 * bd)
32
+ dCH2 = (1 * bc) + (2 * bd)
33
+ dCHOL = (5 * bc) + (12 * bd) + (1 * bn)
34
+ D2O = (2 * bd) + (1 * bo)
35
+
36
+ # for volumes:
37
+ vCH3 = 52.7
38
+ vCH2 = 28.1
39
+ vCOO = 39.0
40
+ vGLYC = 68.8
41
+ vPO4 = 53.7
42
+ vCHOL = 120.4
43
+ vWAT = 30.4
44
+
45
+ vHead = vCHOL + vPO4 + vGLYC + 2 * vCOO
46
+ vTail = 2 * (16 * vCH2) + 2 * (vCH3)
47
+
48
+ # make SLDs
49
+ thisMask = deut[contrast]
50
+
51
+ if thisMask[0] == 0:
52
+ thisWater = (H2O * 0.9249) + (D2O * 0.0871)
53
+ else:
54
+ thisWater = D2O
55
+
56
+ # Calculate mole fraction of D2O from the bulk SLD
57
+ d2o_molfr = (1 / D2O - H2O) * ((bulk_out[contrast] / 0.036182336306) - H2O)
58
+ thisWater = (d2o_molfr * D2O) + ((1 - d2o_molfr) * H2O)
59
+
60
+ if thisMask[1] == 0:
61
+ thisHead = CHOL + PO4 + GLYC + COO
62
+ else:
63
+ thisHead = dCHOL + PO4 + GLYC + COO
64
+
65
+ if thisMask[2] == 0:
66
+ thisTail = (32 * CH2) + CH3
67
+ else:
68
+ thisTail = (32 * dCH2) + dCH3
69
+
70
+ noWat = ((thickHead * APM) - vHead) / vWAT
71
+ thisHead = thisHead + noWat * thisWater
72
+ vHead = vHead + noWat * vWAT
73
+
74
+ sldHead = thisHead / vHead
75
+
76
+ sldTail = thisTail / vTail
77
+
78
+ thickTail = (1.5 + 16 * 1.265) * cos(radians(theta))
79
+
80
+ output = [[thickTail, sldTail, Roughness], [thickHead, sldHead, Roughness]]
81
+
82
+ sub_rough = Roughness
83
+
84
+ return output, sub_rough
@@ -0,0 +1,28 @@
1
+ from pprint import pp
2
+
3
+ import RATapi as RAT
4
+
5
+
6
+ # convert R1 project to Project class
7
+ def convert_rascal():
8
+ project = RAT.utils.convert.r1_to_project_class("R1monolayerVolumeModel.mat")
9
+
10
+ # change values if you like, including ones not supported by R1
11
+ project.parameters["Head Thickness"].prior_type = "gaussian"
12
+ project.parameters["Theta"].mu = 2.0
13
+ project.parameters["Area per molecule"].sigma = 50.0
14
+
15
+ # convert DSPC standard layers example to a struct and save as file
16
+ lipid_bilayer_project = RAT.examples.DSPC_standard_layers()[0]
17
+ RAT.utils.convert.project_class_to_r1(lipid_bilayer_project, filename="lipid_bilayer.mat")
18
+
19
+ # convert and return as a Python dictionary
20
+ struct = RAT.utils.convert.project_class_to_r1(lipid_bilayer_project, return_struct=True)
21
+
22
+ return project, struct
23
+
24
+
25
+ if __name__ == "__main__":
26
+ project, struct = convert_rascal()
27
+ print(project)
28
+ pp(struct)
@@ -18,7 +18,7 @@ def alloy_domains(params, bulkIn, bulkOut, contrast, domain):
18
18
  gold = [goldThick, goldSLD, goldRough]
19
19
 
20
20
  # Make the model depending on which domain we are looking at
21
- if domain == 1:
21
+ if domain == 0:
22
22
  output = [alloyUp, gold]
23
23
  else:
24
24
  output = [alloyDn, gold]
@@ -33,7 +33,7 @@ def domains_XY_model(params, bulk_in, bulk_out, contrast, domain):
33
33
  oxSLD = vfOxide * 3.41e-6
34
34
 
35
35
  # Layer SLD depends on whether we are calculating the domain or not
36
- if domain == 1:
36
+ if domain == 0:
37
37
  laySLD = vfLayer * layerSLD
38
38
  else:
39
39
  laySLD = vfLayer * domainSLD
@@ -0,0 +1,75 @@
1
+ import pathlib
2
+
3
+ import RATapi as RAT
4
+
5
+
6
+ def domains_custom_XY():
7
+ """Simple example of a layer containing domains using a custom XY model"""
8
+ problem = RAT.Project(calculation="domains", model="custom xy", geometry="substrate/liquid")
9
+
10
+ problem.parameters.append(name="Oxide Thickness", min=10.0, value=20.0, max=50.0, fit=True)
11
+ problem.parameters.append(name="Layer Thickness", min=1.0, value=30.0, max=500.0, fit=True)
12
+ problem.parameters.append(name="Layer SLD", min=-0.5e-6, value=-0.5e-6, max=0.0, fit=True)
13
+ problem.parameters.append(name="Layer Roughness", min=2.0, value=5.0, max=7.0, fit=True)
14
+ problem.parameters.append(name="Domain SLD", min=1.0e-6, value=1.0e-6, max=5.0e-6, fit=True)
15
+
16
+ problem.bulk_in.set_fields(0, name="Silicon", value=2.073e-6, max=1.0, fit=False)
17
+ problem.scalefactors.set_fields(0, min=0.8, value=1.0, max=1.1, fit=True)
18
+
19
+ problem.bulk_out.append(name="SLD SMW", min=2.0e-6, value=2.073e-6, max=2.1e-6)
20
+ problem.bulk_out.append(name="SLD H2O", min=-0.6e-6, value=-0.56e-6, max=-0.5e-6)
21
+
22
+ # Add the custom file
23
+ problem.custom_files.append(
24
+ name="Domain Layer",
25
+ filename="domains_XY_model.py",
26
+ language="python",
27
+ path=pathlib.Path(__file__).parent.resolve(),
28
+ )
29
+
30
+ # Make contrasts
31
+ problem.contrasts.append(
32
+ name="D2O",
33
+ background="Background 1",
34
+ resolution="Resolution 1",
35
+ scalefactor="Scalefactor 1",
36
+ bulk_in="Silicon",
37
+ bulk_out="SLD D2O",
38
+ domain_ratio="Domain Ratio 1",
39
+ data="Simulation",
40
+ model=["Domain Layer"],
41
+ )
42
+
43
+ problem.contrasts.append(
44
+ name="SMW",
45
+ background="Background 1",
46
+ resolution="Resolution 1",
47
+ scalefactor="Scalefactor 1",
48
+ bulk_in="Silicon",
49
+ bulk_out="SLD SMW",
50
+ domain_ratio="Domain Ratio 1",
51
+ data="Simulation",
52
+ model=["Domain Layer"],
53
+ )
54
+
55
+ problem.contrasts.append(
56
+ name="H2O",
57
+ background="Background 1",
58
+ resolution="Resolution 1",
59
+ scalefactor="Scalefactor 1",
60
+ bulk_in="Silicon",
61
+ bulk_out="SLD H2O",
62
+ domain_ratio="Domain Ratio 1",
63
+ data="Simulation",
64
+ model=["Domain Layer"],
65
+ )
66
+
67
+ controls = RAT.Controls()
68
+ problem, results = RAT.run(problem, controls)
69
+
70
+ return problem, results
71
+
72
+
73
+ if __name__ == "__main__":
74
+ problem, results = domains_custom_XY()
75
+ RAT.plotting.plot_ref_sld(problem, results, True)
@@ -0,0 +1,52 @@
1
+ import pathlib
2
+
3
+ import RATapi as RAT
4
+
5
+
6
+ def domains_custom_layers():
7
+ """An example custom layers domains project involving incoherent summing on a permalloy layer"""
8
+ problem = RAT.Project(calculation="domains", model="custom layers", geometry="substrate/liquid")
9
+
10
+ # Make some parameters...
11
+ problem.parameters.append(name="Alloy Thickness", min=100.0, value=150.0, max=200.0, fit=True)
12
+ problem.parameters.append(name="Alloy SLD up", min=9.0e-6, value=11.0e-6, max=13.0e-6, fit=True)
13
+ problem.parameters.append(name="Alloy SLD down", min=5.0e-6, value=7.0e-6, max=10.0e-6, fit=True)
14
+ problem.parameters.append(name="Alloy Roughness", min=5.0, value=7.0, max=11.0, fit=True)
15
+ problem.parameters.append(name="Gold Thickness", min=100.0, value=150.0, max=200.0, fit=True)
16
+ problem.parameters.append(name="Gold SLD", min=4.0e-6, value=4.5e-6, max=5.0e-6, fit=True)
17
+ problem.parameters.append(name="Gold Roughness", min=5.0, value=7.0, max=11.0, fit=True)
18
+
19
+ # Set the bulk SLD
20
+ problem.bulk_in.set_fields(0, name="Silicon", value=2.073e-6, max=1.0)
21
+
22
+ # Add the custom file
23
+ problem.custom_files.append(
24
+ name="Alloy domains",
25
+ filename="alloy_domains.py",
26
+ language="python",
27
+ path=pathlib.Path(__file__).parent.resolve(),
28
+ )
29
+
30
+ # Make a contrast
31
+ problem.contrasts.append(
32
+ name="D2O Contrast",
33
+ data="Simulation",
34
+ background="Background 1",
35
+ bulk_in="Silicon",
36
+ bulk_out="SLD D2O",
37
+ scalefactor="Scalefactor 1",
38
+ resolution="Resolution 1",
39
+ resample=False,
40
+ domain_ratio="Domain Ratio 1",
41
+ model=["Alloy domains"],
42
+ )
43
+
44
+ controls = RAT.Controls()
45
+ problem, results = RAT.run(problem, controls)
46
+
47
+ return problem, results
48
+
49
+
50
+ if __name__ == "__main__":
51
+ problem, results = domains_custom_layers()
52
+ RAT.plotting.plot_ref_sld(problem, results, True)
@@ -0,0 +1,80 @@
1
+ import RATapi as RAT
2
+
3
+
4
+ def domains_standard_layers():
5
+ problem = RAT.Project(calculation="domains")
6
+
7
+ # Define the parameters we need to define our two domains
8
+ problem.parameters.append(name="L1 Thickness", min=5.0, value=20.0, max=60.0, fit=True)
9
+ problem.parameters.append(name="L1 SLD", min=3.0e-6, value=4.1e-6, max=5.0e-6, fit=False)
10
+ problem.parameters.append(name="L1 Roughness", min=2.0, value=5.0, max=20.0, fit=True)
11
+ problem.parameters.append(name="L1 Hydration", min=10.0, value=20.0, max=30.0, fit=True)
12
+
13
+ problem.parameters.append(name="L2 Thickness", min=5.0, value=60.0, max=100.0, fit=True)
14
+ problem.parameters.append(name="L2 SLD", min=2.1e-6, value=3.0e-6, max=5.0e-6, fit=False)
15
+ problem.parameters.append(name="L2 Roughness", min=2.0, value=5.0, max=20.0, fit=True)
16
+ problem.parameters.append(name="L2 Hydration", min=10.0, value=20.0, max=30.0, fit=True)
17
+
18
+ problem.parameters.append(name="L3 Thickness", min=5.0, value=200.0, max=300.0, fit=True)
19
+ problem.parameters.append(name="L3 SLD", min=3.0e-6, value=7.0e-6, max=8.0e-6, fit=False)
20
+ problem.parameters.append(name="L3 Roughness", min=2.0, value=5.0, max=20.0, fit=True)
21
+ problem.parameters.append(name="L3 Hydration", min=10.0, value=20.0, max=30.0, fit=True)
22
+
23
+ # Now group these parameters into layers
24
+ problem.layers.append(
25
+ name="Layer 1",
26
+ thickness="L1 Thickness",
27
+ SLD="L1 SLD",
28
+ roughness="L1 Roughness",
29
+ hydration="L1 Hydration",
30
+ hydrate_with="bulk out",
31
+ )
32
+
33
+ problem.layers.append(
34
+ name="Layer 2",
35
+ thickness="L2 Thickness",
36
+ SLD="L2 SLD",
37
+ roughness="L2 Roughness",
38
+ hydration="L2 Hydration",
39
+ hydrate_with="bulk out",
40
+ )
41
+
42
+ problem.layers.append(
43
+ name="Layer 3",
44
+ thickness="L3 Thickness",
45
+ SLD="L3 SLD",
46
+ roughness="L3 Roughness",
47
+ hydration="L3 Hydration",
48
+ hydrate_with="bulk out",
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
57
+ # ("Domain Ratio 1")
58
+ problem.contrasts.append(
59
+ name="Domain Test",
60
+ background="Background 1",
61
+ resolution="Resolution 1",
62
+ scalefactor="Scalefactor 1",
63
+ resample=False,
64
+ bulk_in="SLD Air",
65
+ bulk_out="SLD D2O",
66
+ domain_ratio="Domain Ratio 1",
67
+ data="Simulation",
68
+ model=["Domain 1", "Domain 2"],
69
+ )
70
+
71
+ # Now we can run our simulation as usual
72
+ controls = RAT.Controls()
73
+ problem, results = RAT.run(problem, controls)
74
+
75
+ return problem, results
76
+
77
+
78
+ if __name__ == "__main__":
79
+ problem, results = domains_standard_layers()
80
+ RAT.plotting.plot_ref_sld(problem, results, True)
@@ -1,8 +1,3 @@
1
- """Custom Layers example for Supported DSPC layer.
2
-
3
- Example of using custom layers to model a DSPC supported bilayer.
4
- """
5
-
6
1
  import os
7
2
  import pathlib
8
3
 
@@ -12,6 +7,10 @@ import RATapi as RAT
12
7
 
13
8
 
14
9
  def make_example_problem():
10
+ """Custom Layers example for Supported DSPC layer.
11
+
12
+ Example of using custom layers to model a DSPC supported bilayer.
13
+ """
15
14
  problem = RAT.Project(name="Orso lipid example - custom layers", model="custom layers", geometry="substrate/liquid")
16
15
 
17
16
  # First we need to set up a parameters group. We will be using a pre-prepared custom model file, so we need to add