RATapi 0.0.0.dev0__tar.gz → 0.0.0.dev2__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.
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/PKG-INFO +1 -1
- RATapi-0.0.0.dev2/RATapi/__init__.py +9 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/classlist.py +21 -5
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/controls.py +5 -15
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/events.py +20 -5
- RATapi-0.0.0.dev2/RATapi/examples/__init__.py +19 -0
- RATapi-0.0.0.dev2/RATapi/examples/absorption/absorption.py +161 -0
- RATapi-0.0.0.dev2/RATapi/examples/convert_rascal_project/Model_IIb.py +84 -0
- RATapi-0.0.0.dev2/RATapi/examples/convert_rascal_project/convert_rascal.py +28 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/examples/domains/alloy_domains.py +1 -1
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/examples/domains/domains_XY_model.py +1 -1
- RATapi-0.0.0.dev2/RATapi/examples/domains/domains_custom_XY.py +75 -0
- RATapi-0.0.0.dev2/RATapi/examples/domains/domains_custom_layers.py +52 -0
- RATapi-0.0.0.dev2/RATapi/examples/domains/domains_standard_layers.py +80 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/examples/languages/setup_problem.py +4 -5
- RATapi-0.0.0.dev2/RATapi/examples/non_polarised/DSPC_custom_XY.py +148 -0
- RATapi-0.0.0.dev2/RATapi/examples/non_polarised/DSPC_custom_layers.py +132 -0
- RATapi-0.0.0.dev2/RATapi/examples/non_polarised/DSPC_standard_layers.py +364 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/inputs.py +10 -8
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/models.py +61 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/outputs.py +66 -9
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/project.py +75 -17
- RATapi-0.0.0.dev2/RATapi/run.py +136 -0
- RATapi-0.0.0.dev2/RATapi/utils/convert.py +500 -0
- RATapi-0.0.0.dev2/RATapi/utils/enums.py +127 -0
- RATapi-0.0.0.dev2/RATapi/utils/plotting.py +833 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi.egg-info/PKG-INFO +1 -1
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi.egg-info/SOURCES.txt +4 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi.egg-info/requires.txt +3 -1
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/cpp/rat.cpp +412 -99
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/pyproject.toml +1 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/setup.py +10 -3
- RATapi-0.0.0.dev0/RATapi/__init__.py +0 -8
- RATapi-0.0.0.dev0/RATapi/examples/absorption/absorption.py +0 -148
- RATapi-0.0.0.dev0/RATapi/examples/domains/domains_custom_XY.py +0 -69
- RATapi-0.0.0.dev0/RATapi/examples/domains/domains_custom_layers.py +0 -46
- RATapi-0.0.0.dev0/RATapi/examples/domains/domains_standard_layers.py +0 -75
- RATapi-0.0.0.dev0/RATapi/examples/non_polarised/DSPC_custom_XY.py +0 -140
- RATapi-0.0.0.dev0/RATapi/examples/non_polarised/DSPC_custom_layers.py +0 -121
- RATapi-0.0.0.dev0/RATapi/examples/non_polarised/DSPC_standard_layers.py +0 -358
- RATapi-0.0.0.dev0/RATapi/run.py +0 -35
- RATapi-0.0.0.dev0/RATapi/utils/enums.py +0 -101
- RATapi-0.0.0.dev0/RATapi/utils/plotting.py +0 -211
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/MANIFEST.in +0 -0
- {RATapi-0.0.0.dev0/RATapi/examples → RATapi-0.0.0.dev2/RATapi/examples/absorption}/__init__.py +0 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/examples/absorption/volume_thiol_bilayer.py +0 -0
- {RATapi-0.0.0.dev0/RATapi/examples/absorption → RATapi-0.0.0.dev2/RATapi/examples/convert_rascal_project}/__init__.py +0 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/examples/data/D2O_spin_down.dat +0 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/examples/data/D2O_spin_up.dat +0 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/examples/data/DSPC_D2O.dat +0 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/examples/data/DSPC_SMW.dat +0 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/examples/data/H2O_spin_down.dat +0 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/examples/data/H2O_spin_up.dat +0 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/examples/data/__init__.py +0 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/examples/data/c_PLP0016596.dat +0 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/examples/data/c_PLP0016601.dat +0 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/examples/data/c_PLP0016607.dat +0 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/examples/domains/__init__.py +0 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/examples/languages/__init__.py +0 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/examples/languages/custom_bilayer.py +0 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/examples/languages/run_custom_file_languages.py +0 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/examples/non_polarised/__init__.py +0 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/examples/non_polarised/custom_XY_DSPC.py +0 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/examples/non_polarised/custom_bilayer_DSPC.py +0 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/utils/__init__.py +0 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/utils/custom_errors.py +0 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi/wrappers.py +0 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi.egg-info/dependency_links.txt +0 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi.egg-info/not-zip-safe +0 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/RATapi.egg-info/top_level.txt +0 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/README.md +0 -0
- {RATapi-0.0.0.dev0 → RATapi-0.0.0.dev2}/setup.cfg +0 -0
|
@@ -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__.
|
|
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
|
-
|
|
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]):
|
|
@@ -6,7 +6,6 @@ from pydantic import (
|
|
|
6
6
|
Field,
|
|
7
7
|
ValidationError,
|
|
8
8
|
ValidatorFunctionWrapHandler,
|
|
9
|
-
field_validator,
|
|
10
9
|
model_serializer,
|
|
11
10
|
model_validator,
|
|
12
11
|
)
|
|
@@ -14,7 +13,7 @@ from pydantic import (
|
|
|
14
13
|
from RATapi.utils.custom_errors import custom_pydantic_validation_error
|
|
15
14
|
from RATapi.utils.enums import BoundHandling, Display, Parallel, Procedures, Strategies
|
|
16
15
|
|
|
17
|
-
common_fields = ["procedure", "parallel", "calcSldDuringFit", "
|
|
16
|
+
common_fields = ["procedure", "parallel", "calcSldDuringFit", "resampleMinAngle", "resampleNPoints", "display"]
|
|
18
17
|
update_fields = ["updateFreq", "updatePlotFreq"]
|
|
19
18
|
fields = {
|
|
20
19
|
"calculate": common_fields,
|
|
@@ -41,7 +40,8 @@ class Controls(BaseModel, validate_assignment=True, extra="forbid"):
|
|
|
41
40
|
procedure: Procedures = Procedures.Calculate
|
|
42
41
|
parallel: Parallel = Parallel.Single
|
|
43
42
|
calcSldDuringFit: bool = False
|
|
44
|
-
|
|
43
|
+
resampleMinAngle: float = Field(0.9, le=1, gt=0)
|
|
44
|
+
resampleNPoints: int = Field(50, gt=0)
|
|
45
45
|
display: Display = Display.Iter
|
|
46
46
|
# Simplex
|
|
47
47
|
xTolerance: float = Field(1.0e-6, gt=0.0)
|
|
@@ -60,7 +60,7 @@ class Controls(BaseModel, validate_assignment=True, extra="forbid"):
|
|
|
60
60
|
numGenerations: int = Field(500, ge=1)
|
|
61
61
|
# NS
|
|
62
62
|
nLive: int = Field(150, ge=1)
|
|
63
|
-
nMCMC:
|
|
63
|
+
nMCMC: int = Field(0, ge=0)
|
|
64
64
|
propScale: float = Field(0.1, gt=0.0, lt=1.0)
|
|
65
65
|
nsTolerance: float = Field(0.1, ge=0.0)
|
|
66
66
|
# Dream
|
|
@@ -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
|
|
@@ -117,16 +117,6 @@ class Controls(BaseModel, validate_assignment=True, extra="forbid"):
|
|
|
117
117
|
|
|
118
118
|
return validated_self
|
|
119
119
|
|
|
120
|
-
@field_validator("resampleParams")
|
|
121
|
-
@classmethod
|
|
122
|
-
def check_resample_params(cls, values: list[float]) -> list[float]:
|
|
123
|
-
"""Make sure each of the two values of resampleParams satisfy their conditions."""
|
|
124
|
-
if not 0 < values[0] < 1:
|
|
125
|
-
raise ValueError("resampleParams[0] must be between 0 and 1")
|
|
126
|
-
if values[1] < 0:
|
|
127
|
-
raise ValueError("resampleParams[1] must be greater than or equal to 0")
|
|
128
|
-
return values
|
|
129
|
-
|
|
130
120
|
@model_serializer
|
|
131
121
|
def serialize(self):
|
|
132
122
|
"""Filter fields so only those applying to the chosen procedure are serialized."""
|
|
@@ -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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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", resampleNPoints=150)
|
|
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 ==
|
|
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 ==
|
|
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)
|