RATapi 0.0.0.dev3__tar.gz → 0.0.0.dev4__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 (67) hide show
  1. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/PKG-INFO +1 -5
  2. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/classlist.py +99 -7
  3. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/controls.py +90 -5
  4. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/events.py +2 -2
  5. RATapi-0.0.0.dev4/RATapi/examples/__init__.py +23 -0
  6. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/examples/absorption/absorption.py +10 -11
  7. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/examples/absorption/volume_thiol_bilayer.py +1 -1
  8. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/examples/convert_rascal_project/convert_rascal.py +5 -3
  9. RATapi-0.0.0.dev4/RATapi/examples/data/d2o_background_data.dat +82 -0
  10. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/examples/languages/run_custom_file_languages.py +4 -3
  11. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/examples/languages/setup_problem.py +7 -8
  12. {RATapi-0.0.0.dev3/RATapi/examples/non_polarised → RATapi-0.0.0.dev4/RATapi/examples/normal_reflectivity}/DSPC_custom_XY.py +11 -12
  13. {RATapi-0.0.0.dev3/RATapi/examples/non_polarised → RATapi-0.0.0.dev4/RATapi/examples/normal_reflectivity}/DSPC_custom_layers.py +7 -8
  14. RATapi-0.0.0.dev4/RATapi/examples/normal_reflectivity/DSPC_data_background.py +218 -0
  15. RATapi-0.0.0.dev4/RATapi/examples/normal_reflectivity/DSPC_function_background.py +217 -0
  16. {RATapi-0.0.0.dev3/RATapi/examples/non_polarised → RATapi-0.0.0.dev4/RATapi/examples/normal_reflectivity}/DSPC_standard_layers.py +25 -184
  17. RATapi-0.0.0.dev4/RATapi/examples/normal_reflectivity/background_function.py +13 -0
  18. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/inputs.py +312 -238
  19. RATapi-0.0.0.dev4/RATapi/models.py +638 -0
  20. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/outputs.py +8 -4
  21. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/project.py +188 -74
  22. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/run.py +5 -6
  23. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/utils/convert.py +79 -97
  24. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/utils/enums.py +1 -1
  25. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/utils/plotting.py +19 -10
  26. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/wrappers.py +20 -25
  27. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi.egg-info/PKG-INFO +1 -5
  28. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi.egg-info/SOURCES.txt +10 -6
  29. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/cpp/rat.cpp +661 -502
  30. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/pyproject.toml +1 -1
  31. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/setup.py +1 -1
  32. RATapi-0.0.0.dev3/RATapi/examples/__init__.py +0 -19
  33. RATapi-0.0.0.dev3/RATapi/models.py +0 -371
  34. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/MANIFEST.in +0 -0
  35. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/__init__.py +0 -0
  36. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/examples/absorption/__init__.py +0 -0
  37. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/examples/convert_rascal_project/Model_IIb.py +0 -0
  38. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/examples/convert_rascal_project/__init__.py +0 -0
  39. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/examples/data/D2O_spin_down.dat +0 -0
  40. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/examples/data/D2O_spin_up.dat +0 -0
  41. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/examples/data/DSPC_D2O.dat +0 -0
  42. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/examples/data/DSPC_SMW.dat +0 -0
  43. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/examples/data/H2O_spin_down.dat +0 -0
  44. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/examples/data/H2O_spin_up.dat +0 -0
  45. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/examples/data/__init__.py +0 -0
  46. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/examples/data/c_PLP0016596.dat +0 -0
  47. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/examples/data/c_PLP0016601.dat +0 -0
  48. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/examples/data/c_PLP0016607.dat +0 -0
  49. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/examples/domains/__init__.py +0 -0
  50. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/examples/domains/alloy_domains.py +0 -0
  51. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/examples/domains/domains_XY_model.py +0 -0
  52. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/examples/domains/domains_custom_XY.py +0 -0
  53. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/examples/domains/domains_custom_layers.py +0 -0
  54. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/examples/domains/domains_standard_layers.py +0 -0
  55. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/examples/languages/__init__.py +0 -0
  56. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/examples/languages/custom_bilayer.py +0 -0
  57. {RATapi-0.0.0.dev3/RATapi/examples/non_polarised → RATapi-0.0.0.dev4/RATapi/examples/normal_reflectivity}/__init__.py +0 -0
  58. {RATapi-0.0.0.dev3/RATapi/examples/non_polarised → RATapi-0.0.0.dev4/RATapi/examples/normal_reflectivity}/custom_XY_DSPC.py +0 -0
  59. {RATapi-0.0.0.dev3/RATapi/examples/non_polarised → RATapi-0.0.0.dev4/RATapi/examples/normal_reflectivity}/custom_bilayer_DSPC.py +0 -0
  60. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/utils/__init__.py +0 -0
  61. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi/utils/custom_errors.py +0 -0
  62. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi.egg-info/dependency_links.txt +0 -0
  63. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi.egg-info/not-zip-safe +0 -0
  64. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi.egg-info/requires.txt +0 -0
  65. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/RATapi.egg-info/top_level.txt +0 -0
  66. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/README.md +0 -0
  67. {RATapi-0.0.0.dev3 → RATapi-0.0.0.dev4}/setup.cfg +0 -0
@@ -1,12 +1,10 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: RATapi
3
- Version: 0.0.0.dev3
3
+ Version: 0.0.0.dev4
4
4
  Summary: Python extension for the Reflectivity Analysis Toolbox (RAT)
5
5
  Home-page: https://github.com/RascalSoftware/python-RAT
6
6
  Author:
7
7
  Author-email:
8
- License: UNKNOWN
9
- Platform: UNKNOWN
10
8
  Requires-Python: >=3.9
11
9
  Description-Content-Type: text/markdown
12
10
  Provides-Extra: Dev
@@ -43,5 +41,3 @@ To build wheel:
43
41
 
44
42
  pip install build
45
43
  python -m build --wheel
46
-
47
-
@@ -4,6 +4,7 @@ class.
4
4
 
5
5
  import collections
6
6
  import contextlib
7
+ import importlib
7
8
  import warnings
8
9
  from collections.abc import Sequence
9
10
  from typing import Any, Generic, TypeVar, Union
@@ -56,10 +57,42 @@ class ClassList(collections.UserList, Generic[T]):
56
57
  super().__init__(init_list)
57
58
 
58
59
  def __str__(self):
60
+ # `display_fields` gives more control over the items displayed from the list if available
61
+ if not self.data:
62
+ return str([])
59
63
  try:
60
- [model.__dict__ for model in self.data]
64
+ model_display_fields = [model.display_fields for model in self.data]
65
+ # get all items included in at least one list
66
+ # the list comprehension ensures they are in the order that they're in in the model
67
+ required_fields = list(set().union(*model_display_fields))
68
+ table_fields = ["index"] + [i for i in list(self.data[0].__dict__) if i in required_fields]
61
69
  except AttributeError:
62
- output = str(self.data)
70
+ try:
71
+ model_display_fields = [model.__dict__ for model in self.data]
72
+ table_fields = ["index"] + list(self.data[0].__dict__)
73
+ except AttributeError:
74
+ return str(self.data)
75
+
76
+ if any(model_display_fields):
77
+ table = prettytable.PrettyTable()
78
+ table.field_names = [field.replace("_", " ") for field in table_fields]
79
+ rows = []
80
+ for index, model in enumerate(self.data):
81
+ row = [index]
82
+ for field in table_fields[1:]:
83
+ value = getattr(model, field, "")
84
+ if isinstance(value, np.ndarray):
85
+ value = (
86
+ f"{'Data array: [' + ' x '.join(str(i) for i in value.shape) if value.size > 0 else '['}]"
87
+ )
88
+ elif field == "model":
89
+ value = "\n".join(str(element) for element in value)
90
+ else:
91
+ value = str(value)
92
+ row.append(value)
93
+ rows.append(row)
94
+ table.add_rows(rows)
95
+ output = table.get_string()
63
96
  else:
64
97
  if any(model.__dict__ for model in self.data):
65
98
  table = prettytable.PrettyTable()
@@ -68,7 +101,7 @@ class ClassList(collections.UserList, Generic[T]):
68
101
  [
69
102
  [index]
70
103
  + list(
71
- f"{'Data array: ['+' x '.join(str(i) for i in v.shape) if v.size > 0 else '['}]"
104
+ f"{'Data array: [' + ' x '.join(str(i) for i in v.shape) if v.size > 0 else '['}]"
72
105
  if isinstance(v, np.ndarray)
73
106
  else "\n".join(element for element in v)
74
107
  if k == "model"
@@ -261,9 +294,67 @@ class ClassList(collections.UserList, Generic[T]):
261
294
  def set_fields(self, index: int, **kwargs) -> None:
262
295
  """Assign the values of an existing object's attributes using keyword arguments."""
263
296
  self._validate_name_field(kwargs)
264
- class_handle = self.data[index].__class__
265
- new_fields = {**self.data[index].__dict__, **kwargs}
266
- self.data[index] = class_handle(**new_fields)
297
+ pydantic_object = False
298
+
299
+ if importlib.util.find_spec("pydantic"):
300
+ # Pydantic is installed, so set up a context manager that will
301
+ # suppress custom validation errors until all fields have been set.
302
+ from pydantic import BaseModel, ValidationError
303
+
304
+ if isinstance(self.data[index], BaseModel):
305
+ pydantic_object = True
306
+
307
+ # Define a custom context manager
308
+ class SuppressCustomValidation(contextlib.AbstractContextManager):
309
+ """Context manager to suppress "value_error" based validation errors in pydantic.
310
+
311
+ This validation context is necessary because errors can occur whilst individual
312
+ model values are set, which are resolved when all of the input values are set.
313
+
314
+ After the exception is suppressed, execution proceeds with the next
315
+ statement following the with statement.
316
+
317
+ with SuppressCustomValidation():
318
+ setattr(self.data[index], key, value)
319
+ # Execution still resumes here if the attribute cannot be set
320
+ """
321
+
322
+ def __init__(self):
323
+ pass
324
+
325
+ def __enter__(self):
326
+ pass
327
+
328
+ def __exit__(self, exctype, excinst, exctb):
329
+ # If the return of __exit__ is True or truthy, the exception is suppressed.
330
+ # Otherwise, the default behaviour of raising the exception applies.
331
+ #
332
+ # To suppress errors arising from field and model validators in pydantic,
333
+ # we will examine the validation errors raised. If all of the errors
334
+ # listed in the exception have the type "value_error", this indicates
335
+ # they have arisen from field or model validators and will be suppressed.
336
+ # Otherwise, they will be raised.
337
+ if exctype is None:
338
+ return
339
+ if issubclass(exctype, ValidationError) and all(
340
+ [error["type"] == "value_error" for error in excinst.errors()]
341
+ ):
342
+ return True
343
+ return False
344
+
345
+ validation_context = SuppressCustomValidation()
346
+ else:
347
+ validation_context = contextlib.nullcontext()
348
+
349
+ for key, value in kwargs.items():
350
+ with validation_context:
351
+ setattr(self.data[index], key, value)
352
+
353
+ # We have suppressed custom validation errors for pydantic objects.
354
+ # We now must revalidate the pydantic model outside the validation context
355
+ # to catch any errors that remain after setting all of the fields.
356
+ if pydantic_object:
357
+ self._class_handle.model_validate(self.data[index])
267
358
 
268
359
  def get_names(self) -> list[str]:
269
360
  """Return a list of the values of the name_field attribute of each class object in the list.
@@ -364,7 +455,7 @@ class ClassList(collections.UserList, Generic[T]):
364
455
  if new_indices:
365
456
  new_list = ", ".join(str(i) for i in new_indices[:-1])
366
457
  new_string = (
367
- f" item{f's {new_list} and ' if new_list else ' '}" f"{new_indices[-1]} of the input list"
458
+ f" item{f's {new_list} and ' if new_list else ' '}{new_indices[-1]} of the input list"
368
459
  )
369
460
  error_list.append(
370
461
  f" '{name}' is shared between{existing_string}"
@@ -494,6 +585,7 @@ class ClassList(collections.UserList, Generic[T]):
494
585
  core_schema.no_info_wrap_validator_function(coerce, core_schema.is_instance_schema(cls)),
495
586
  core_schema.no_info_wrap_validator_function(validate_items, list_schema),
496
587
  ],
588
+ serialization=core_schema.plain_serializer_function_ser_schema(lambda x: x),
497
589
  )
498
590
 
499
591
  return schema
@@ -2,6 +2,8 @@ import contextlib
2
2
  import os
3
3
  import tempfile
4
4
  import warnings
5
+ from pathlib import Path
6
+ from typing import Union
5
7
 
6
8
  import prettytable
7
9
  from pydantic import (
@@ -36,43 +38,99 @@ fields = {
36
38
  }
37
39
 
38
40
 
39
- class Controls(BaseModel, validate_assignment=True, extra="forbid"):
41
+ class Controls(BaseModel, validate_assignment=True, extra="forbid", use_attribute_docstrings=True):
40
42
  """The full set of controls parameters for all five procedures that are required for the compiled RAT code."""
41
43
 
42
44
  # All Procedures
43
45
  procedure: Procedures = Procedures.Calculate
46
+ """Which procedure RAT should execute. Can be 'calculate', 'simplex', 'de', 'ns', or 'dream'."""
47
+
44
48
  parallel: Parallel = Parallel.Single
49
+ """How the calculation should be parallelised. Can be 'single', 'contrasts' or 'points'."""
50
+
45
51
  calcSldDuringFit: bool = False
52
+ """Whether SLD will be calculated during fit (for live plotting etc.)"""
53
+
46
54
  resampleMinAngle: float = Field(0.9, le=1, gt=0)
55
+ """The upper threshold on the angle between three sampled points for resampling, in units of radians over pi."""
56
+
47
57
  resampleNPoints: int = Field(50, gt=0)
58
+ """The number of initial points to use for resampling."""
59
+
48
60
  display: Display = Display.Iter
61
+ """How much RAT should print to the terminal. Can be 'off', 'iter', 'notify', or 'final'."""
62
+
49
63
  # Simplex
50
64
  xTolerance: float = Field(1.0e-6, gt=0.0)
65
+ """[SIMPLEX] The termination tolerance for step size."""
66
+
51
67
  funcTolerance: float = Field(1.0e-6, gt=0.0)
68
+ """[SIMPLEX] The termination tolerance for change in chi-squared."""
69
+
52
70
  maxFuncEvals: int = Field(10000, gt=0)
71
+ """[SIMPLEX] The maximum number of function evaluations before the algorithm terminates."""
72
+
53
73
  maxIterations: int = Field(1000, gt=0)
74
+ """[SIMPLEX] The maximum number of iterations before the algorithm terminates."""
75
+
54
76
  # Simplex and DE
55
77
  updateFreq: int = 1
78
+ """[SIMPLEX, DE] Number of iterations between printing progress updates to the terminal."""
79
+
56
80
  updatePlotFreq: int = 20
81
+ """[SIMPLEX, DE] Number of iterations between updates to live plots."""
82
+
57
83
  # DE
58
84
  populationSize: int = Field(20, ge=1)
59
- fWeight: float = 0.5
85
+ """[DE] The number of candidate solutions that exist at any time."""
86
+
87
+ fWeight: float = Field(0.5, gt=0.0)
88
+ """[DE] The step size for how different mutations are to their parents."""
89
+
60
90
  crossoverProbability: float = Field(0.8, gt=0.0, lt=1.0)
91
+ """[DE] The probability of exchange of parameters between individuals at any iteration."""
92
+
61
93
  strategy: Strategies = Strategies.RandomWithPerVectorDither
94
+ """[DE] The algorithm used to generate new candidates."""
95
+
62
96
  targetValue: float = Field(1.0, ge=1.0)
97
+ """[DE] The value of chi-squared at which the algorithm will terminate."""
98
+
63
99
  numGenerations: int = Field(500, ge=1)
100
+ """[DE] The maximum number of iterations before the algorithm terminates."""
101
+
64
102
  # NS
65
103
  nLive: int = Field(150, ge=1)
104
+ """[NS] The number of points to sample."""
105
+
66
106
  nMCMC: int = Field(0, ge=0)
107
+ """[NS] If non-zero, an MCMC process with ``nMCMC`` chains will be used instead of MultiNest."""
108
+
67
109
  propScale: float = Field(0.1, gt=0.0, lt=1.0)
110
+ """[NS] A scaling factor for the ellipsoid generated by MultiNest."""
111
+
68
112
  nsTolerance: float = Field(0.1, ge=0.0)
113
+ """[NS] The tolerance threshold for when the algorithm should terminate."""
114
+
69
115
  # Dream
70
116
  nSamples: int = Field(20000, ge=0)
117
+ """[DREAM] The number of samples in the initial population for each chain."""
118
+
71
119
  nChains: int = Field(10, gt=0)
120
+ """[DREAM] The number of Markov chains to use in the algorithm."""
121
+
72
122
  jumpProbability: float = Field(0.5, gt=0.0, lt=1.0)
123
+ """[DREAM] The probability range for the size of jumps in sampling. Larger values mean more variable jumps."""
124
+
73
125
  pUnitGamma: float = Field(0.2, gt=0.0, lt=1.0)
126
+ """[DREAM] The probability that the scaling-down factor of jumps will be ignored and a larger jump will be taken."""
127
+
74
128
  boundHandling: BoundHandling = BoundHandling.Reflect
129
+ """[DREAM] How steps past the space boundaries should be handled. Can be 'off', 'reflect', 'bound', or 'fold'."""
130
+
75
131
  adaptPCR: bool = True
132
+ """[DREAM] Whether the crossover probability for differential evolution should be adapted during the run."""
133
+
76
134
  # Private field for IPC file
77
135
  _IPCFilePath: str = ""
78
136
 
@@ -92,8 +150,8 @@ class Controls(BaseModel, validate_assignment=True, extra="forbid"):
92
150
  procedure = input_dict.get("procedure", Procedures.Calculate)
93
151
  custom_error_msgs = {
94
152
  "extra_forbidden": f'Extra inputs are not permitted. The fields for the "{procedure}"'
95
- f' controls procedure are:\n '
96
- f'{", ".join(fields.get("procedure", []))}\n',
153
+ f" controls procedure are:\n "
154
+ f"{', '.join(fields.get('procedure', []))}\n",
97
155
  }
98
156
  custom_error_list = custom_pydantic_validation_error(exc.errors(), custom_error_msgs)
99
157
  raise ValidationError.from_exception_data(exc.title, custom_error_list, hide_input=True) from None
@@ -116,7 +174,7 @@ class Controls(BaseModel, validate_assignment=True, extra="forbid"):
116
174
  f'\nThe current controls procedure is "{new_procedure}", but the property'
117
175
  f' "{field}" applies instead to the {", ".join(incorrect_procedures)} procedure.\n\n'
118
176
  f' The fields for the "{new_procedure}" controls procedure are:\n'
119
- f' {", ".join(fields[new_procedure])}\n',
177
+ f" {', '.join(fields[new_procedure])}\n",
120
178
  stacklevel=2,
121
179
  )
122
180
 
@@ -164,3 +222,30 @@ class Controls(BaseModel, validate_assignment=True, extra="forbid"):
164
222
  with contextlib.suppress(FileNotFoundError):
165
223
  os.remove(self._IPCFilePath)
166
224
  return None
225
+
226
+ def save(self, path: Union[str, Path], filename: str = "controls"):
227
+ """Save a controls object to a JSON file.
228
+
229
+ Parameters
230
+ ----------
231
+ path : str or Path
232
+ The directory in which the controls object will be written.
233
+ filename : str
234
+ The name for the JSON file containing the controls object.
235
+
236
+ """
237
+ file = Path(path, f"{filename.removesuffix('.json')}.json")
238
+ file.write_text(self.model_dump_json())
239
+
240
+ @classmethod
241
+ def load(cls, path: Union[str, Path]) -> "Controls":
242
+ """Load a controls object from file.
243
+
244
+ Parameters
245
+ ----------
246
+ path : str or Path
247
+ The path to the controls object file.
248
+
249
+ """
250
+ file = Path(path)
251
+ return cls.model_validate_json(file.read_text())
@@ -1,5 +1,5 @@
1
1
  import os
2
- from typing import Callable, List, Union
2
+ from typing import Callable, Union
3
3
 
4
4
  from RATapi.rat_core import EventBridge, EventTypes, PlotEventData, ProgressEventData
5
5
 
@@ -21,7 +21,7 @@ def notify(event_type: EventTypes, data: Union[str, PlotEventData, ProgressEvent
21
21
  callback(data)
22
22
 
23
23
 
24
- def get_event_callback(event_type: EventTypes) -> List[Callable[[Union[str, PlotEventData, ProgressEventData]], None]]:
24
+ def get_event_callback(event_type: EventTypes) -> list[Callable[[Union[str, PlotEventData, ProgressEventData]], None]]:
25
25
  """Returns all callbacks registered for the given event type.
26
26
 
27
27
  Parameters
@@ -0,0 +1,23 @@
1
+ from RATapi.examples.absorption.absorption import absorption
2
+ from RATapi.examples.convert_rascal_project.convert_rascal 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.normal_reflectivity.DSPC_custom_layers import DSPC_custom_layers
7
+ from RATapi.examples.normal_reflectivity.DSPC_custom_XY import DSPC_custom_XY
8
+ from RATapi.examples.normal_reflectivity.DSPC_data_background import DSPC_data_background
9
+ from RATapi.examples.normal_reflectivity.DSPC_function_background import DSPC_function_background
10
+ from RATapi.examples.normal_reflectivity.DSPC_standard_layers import DSPC_standard_layers
11
+
12
+ __all__ = [
13
+ "absorption",
14
+ "domains_custom_layers",
15
+ "domains_custom_XY",
16
+ "domains_standard_layers",
17
+ "DSPC_custom_layers",
18
+ "DSPC_custom_XY",
19
+ "DSPC_standard_layers",
20
+ "DSPC_data_background",
21
+ "DSPC_function_background",
22
+ "convert_rascal",
23
+ ]
@@ -1,4 +1,3 @@
1
- import os
2
1
  import pathlib
3
2
 
4
3
  import numpy as np
@@ -10,7 +9,7 @@ def absorption():
10
9
  """Custom layers model including absorption"""
11
10
  problem = RAT.Project(
12
11
  name="Absorption example",
13
- calculation="non polarised",
12
+ calculation="normal",
14
13
  model="custom layers",
15
14
  geometry="substrate/liquid",
16
15
  absorption=True,
@@ -69,27 +68,27 @@ def absorption():
69
68
  name="Background parameter 4", min=1.0e-06, value=5.61e-06, max=9.0e-05, fit=True
70
69
  )
71
70
 
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")
71
+ problem.backgrounds.append(name="Background 1", type="constant", source="Background parameter 1")
72
+ problem.backgrounds.append(name="Background 2", type="constant", source="Background parameter 2")
73
+ problem.backgrounds.append(name="Background 3", type="constant", source="Background parameter 3")
74
+ problem.backgrounds.append(name="Background 4", type="constant", source="Background parameter 4")
76
75
 
77
76
  # Make the resolution fittable
78
77
  problem.resolution_parameters.set_fields(0, fit=True)
79
78
 
80
79
  # Now add the data we need
81
- data_path = os.path.join(pathlib.Path(__file__).parents[1].resolve(), "data")
80
+ data_path = pathlib.Path(__file__).parents[1] / "data"
82
81
 
83
- data_1 = np.loadtxt(os.path.join(data_path, "D2O_spin_down.dat"))
82
+ data_1 = np.loadtxt(data_path / "D2O_spin_down.dat")
84
83
  problem.data.append(name="D2O_dn", data=data_1)
85
84
 
86
- data_2 = np.loadtxt(os.path.join(data_path, "D2O_spin_up.dat"))
85
+ data_2 = np.loadtxt(data_path / "D2O_spin_up.dat")
87
86
  problem.data.append(name="D2O_up", data=data_2)
88
87
 
89
- data_3 = np.loadtxt(os.path.join(data_path, "H2O_spin_down.dat"))
88
+ data_3 = np.loadtxt(data_path / "H2O_spin_down.dat")
90
89
  problem.data.append(name="H2O_dn", data=data_3)
91
90
 
92
- data_4 = np.loadtxt(os.path.join(data_path, "H2O_spin_up.dat"))
91
+ data_4 = np.loadtxt(data_path / "H2O_spin_up.dat")
93
92
  problem.data.append(name="H2O_up", data=data_4)
94
93
 
95
94
  # Add the custom file
@@ -130,7 +130,7 @@ def volume_thiol_bilayer(params, bulk_in, bulk_out, contrast):
130
130
 
131
131
  CW = [cwThick, bulk_out[contrast], 0, bilayerRough]
132
132
 
133
- if contrast == 1 or contrast == 3:
133
+ if contrast == 0 or contrast == 2:
134
134
  output = [alloyUp, gold, SAMTAILS, SAMHEAD, CW, *BILAYER]
135
135
  else:
136
136
  output = [alloyDown, gold, SAMTAILS, SAMHEAD, CW, *BILAYER]
@@ -1,11 +1,13 @@
1
+ import pathlib
1
2
  from pprint import pp
2
3
 
3
4
  import RATapi as RAT
4
5
 
5
6
 
6
7
  # convert R1 project to Project class
7
- def convert_rascal():
8
- project = RAT.utils.convert.r1_to_project_class("R1monolayerVolumeModel.mat")
8
+ def convert_rascal(mat_filename="lipid_bilayer.mat"):
9
+ project_path = pathlib.Path(__file__).parent / "R1monolayerVolumeModel.mat"
10
+ project = RAT.utils.convert.r1_to_project_class(project_path)
9
11
 
10
12
  # change values if you like, including ones not supported by R1
11
13
  project.parameters["Head Thickness"].prior_type = "gaussian"
@@ -14,7 +16,7 @@ def convert_rascal():
14
16
 
15
17
  # convert DSPC standard layers example to a struct and save as file
16
18
  lipid_bilayer_project = RAT.examples.DSPC_standard_layers()[0]
17
- RAT.utils.convert.project_class_to_r1(lipid_bilayer_project, filename="lipid_bilayer.mat")
19
+ RAT.utils.convert.project_class_to_r1(lipid_bilayer_project, filename=mat_filename)
18
20
 
19
21
  # convert and return as a Python dictionary
20
22
  struct = RAT.utils.convert.project_class_to_r1(lipid_bilayer_project, return_struct=True)
@@ -0,0 +1,82 @@
1
+ 0.011403 1.90034798968076e-06 -9.65035874608547e-07
2
+ 0.011973 1.81361996101478e-06 -4.67852140773275e-09
3
+ 0.012572 1.5763144199176e-06 -1.36151693657437e-06
4
+ 0.013201 2.66861902156408e-06 5.28737972088124e-07
5
+ 0.013861 1.19184137102607e-06 6.5429177234931e-07
6
+ 0.014554 1.75409120253422e-06 -4.50039804064594e-07
7
+ 0.015281 1.51534921649628e-06 3.54060605152339e-07
8
+ 0.016045 1.76294603973655e-06 2.30273872099416e-07
9
+ 0.016848 1.66691808740296e-06 1.02729272466451e-06
10
+ 0.01769 2.2391873415575e-06 2.02710446930881e-07
11
+ 0.018575 1.47947093349392e-06 9.31566506641381e-07
12
+ 0.019503 1.58967045467121e-06 6.58308695637623e-09
13
+ 0.020479 2.05056480300655e-06 -4.18637528083399e-07
14
+ 0.021502 2.54199126843229e-06 6.96150360898885e-08
15
+ 0.022578 1.07273638130851e-06 -5.94598550176916e-08
16
+ 0.023706 2.89987639289405e-06 8.05335897612554e-07
17
+ 0.024892 1.56081284721073e-06 5.50847432744533e-08
18
+ 0.026136 2.32386636321661e-06 -5.72991095509919e-07
19
+ 0.027443 2.52478251612625e-06 -2.38750704688337e-08
20
+ 0.028815 2.66154668842285e-06 1.05087573637142e-06
21
+ 0.030256 1.74132051718101e-06 -2.3192582338868e-07
22
+ 0.031769 2.01215747485553e-06 -4.26893410009117e-07
23
+ 0.033357 1.91881656322323e-06 8.87192534478923e-07
24
+ 0.035025 1.69716945696631e-06 1.80981995646851e-07
25
+ 0.036777 2.13585488200451e-06 -1.90164659296111e-07
26
+ 0.038615 2.17932170608953e-06 -4.91062265460096e-07
27
+ 0.040546 1.82384243860966e-06 -1.08387392818395e-06
28
+ 0.042573 2.06617996409986e-06 2.22697399577916e-07
29
+ 0.044702 3.33679088859971e-06 -1.53613977488785e-07
30
+ 0.046937 1.99621696227773e-06 3.55134601922439e-07
31
+ 0.049284 2.3551514683307e-06 -1.06523727035749e-06
32
+ 0.051748 1.76873031859355e-06 1.15746760150783e-06
33
+ 0.054336 1.73606104969994e-06 4.89763150040874e-07
34
+ 0.057052 1.82710646654775e-06 -1.15330099931726e-06
35
+ 0.059905 2.28227888686718e-06 9.45647703159621e-07
36
+ 0.0629 1.59923042799896e-06 -3.70062237263438e-07
37
+ 0.066045 1.07352660741589e-06 3.41777294345909e-07
38
+ 0.069348 2.02660800872659e-06 2.75569910736786e-07
39
+ 0.072815 1.78179239147256e-06 -6.0256088120987e-07
40
+ 0.076456 2.14000373613308e-06 -2.18911980741668e-06
41
+ 0.080279 2.04230294359047e-06 5.284442372682e-07
42
+ 0.084292 2.36455952978407e-06 -1.73629847921614e-07
43
+ 0.088507 2.45037654782291e-06 -3.78287083788833e-07
44
+ 0.092932 1.33718085273407e-06 4.35130166728242e-07
45
+ 0.097579 1.23771058575749e-06 -4.51744576618967e-07
46
+ 0.10246 2.25121666653143e-06 6.36952833032752e-07
47
+ 0.10758 2.15319571282475e-06 2.20717968415214e-07
48
+ 0.11296 1.53041976734067e-06 -6.93055107868105e-07
49
+ 0.11861 2.61870106321507e-06 7.69463958198665e-07
50
+ 0.12454 2.01650595727752e-06 4.79607176188218e-07
51
+ 0.13077 2.06178415911062e-06 1.10173268381594e-06
52
+ 0.1373 2.13696968977538e-06 -6.14098124528528e-07
53
+ 0.14417 2.3770829041412e-06 -6.16219383494697e-07
54
+ 0.15138 2.7622487528669e-06 3.50660742020884e-07
55
+ 0.15895 1.86901211887215e-06 6.33626529015099e-07
56
+ 0.16689 1.13465824611353e-06 7.62493241842828e-07
57
+ 0.17524 2.50673214999504e-06 1.05207422581854e-07
58
+ 0.184 1.53613195077685e-06 -8.87137577093779e-08
59
+ 0.1932 2.62184014311179e-06 6.22256875962273e-07
60
+ 0.20286 1.70525565120706e-06 1.67162600924891e-06
61
+ 0.213 2.74574086739327e-06 8.07667338780613e-07
62
+ 0.22365 1.59701095264287e-06 1.67629565660922e-07
63
+ 0.23484 1.4437004736234e-06 -3.59611249006791e-07
64
+ 0.24658 2.47846978404969e-06 4.99800504594724e-07
65
+ 0.25891 1.31847420553136e-06 -2.87283586089481e-07
66
+ 0.27185 2.34029248136207e-06 2.90756508518823e-07
67
+ 0.28544 2.21891181128286e-06 7.22598553179947e-07
68
+ 0.29972 1.92836622666398e-06 8.39418345516717e-07
69
+ 0.3147 1.82923374769972e-06 5.70510331434857e-07
70
+ 0.33044 3.02890531703209e-06 1.20234742176368e-06
71
+ 0.34696 1.8127324822871e-06 1.58096394623758e-06
72
+ 0.36431 1.90489840127358e-06 -1.41813181395574e-06
73
+ 0.38252 1.53063379469415e-06 -1.32294734328625e-06
74
+ 0.40165 1.59326881780842e-06 -6.38112989285387e-07
75
+ 0.42173 1.7081906242357e-06 -1.49834166690205e-06
76
+ 0.44282 2.85476268526193e-06 -1.85680046178151e-07
77
+ 0.46496 1.80479009111448e-06 -1.69120607911057e-07
78
+ 0.48821 1.6549673183601e-06 3.00340803829798e-07
79
+ 0.51262 1.77588964903545e-06 3.28929520936145e-07
80
+ 0.53825 2.35718817504981e-06 -4.48934854489947e-07
81
+ 0.56516 1.34213437585845e-06 -5.50651590195596e-07
82
+ 0.59342 2.31356104763158e-06 7.347220470815e-07
@@ -11,12 +11,13 @@ path = pathlib.Path(__file__).parent.resolve()
11
11
 
12
12
  project = setup_problem.make_example_problem()
13
13
  controls = RAT.Controls()
14
+ controls.calcSldDuringFit = True
14
15
 
15
16
  # Python
16
17
  start = time.time()
17
18
  project, results = RAT.run(project, controls)
18
19
  end = time.time()
19
- print(f"Python time is: {end-start}s\n")
20
+ print(f"Python time is: {end - start}s\n")
20
21
 
21
22
  RAT.plotting.plot_ref_sld(project, results)
22
23
 
@@ -26,7 +27,7 @@ project.custom_files.set_fields(0, filename="custom_bilayer.m", language="matlab
26
27
  start = time.time()
27
28
  project, results = RAT.run(project, controls)
28
29
  end = time.time()
29
- print(f"Matlab time is: {end-start}s\n")
30
+ print(f"Matlab time is: {end - start}s\n")
30
31
 
31
32
  RAT.plotting.plot_ref_sld(project, results)
32
33
 
@@ -36,6 +37,6 @@ project.custom_files.set_fields(0, filename="custom_bilayer.dll", language="cpp"
36
37
  start = time.time()
37
38
  project, results = RAT.run(project, controls)
38
39
  end = time.time()
39
- print(f"C++ time is: {end-start}s\n")
40
+ print(f"C++ time is: {end - start}s\n")
40
41
 
41
42
  RAT.plotting.plot_ref_sld(project, results)
@@ -1,4 +1,3 @@
1
- import os
2
1
  import pathlib
3
2
 
4
3
  import numpy as np
@@ -39,10 +38,10 @@ def make_example_problem():
39
38
  # and H2O. Load these datafiles in and put them in the data block
40
39
 
41
40
  # Read in the datafiles
42
- data_path = os.path.join(pathlib.Path(__file__).parents[1].resolve(), "data")
43
- D2O_data = np.loadtxt(os.path.join(data_path, "c_PLP0016596.dat"), delimiter=",")
44
- SMW_data = np.loadtxt(os.path.join(data_path, "c_PLP0016601.dat"), delimiter=",")
45
- H2O_data = np.loadtxt(os.path.join(data_path, "c_PLP0016607.dat"), delimiter=",")
41
+ data_path = pathlib.Path(__file__).parents[1] / "data"
42
+ D2O_data = np.loadtxt(data_path / "c_PLP0016596.dat", delimiter=",")
43
+ SMW_data = np.loadtxt(data_path / "c_PLP0016601.dat", delimiter=",")
44
+ H2O_data = np.loadtxt(data_path / "c_PLP0016607.dat", delimiter=",")
46
45
 
47
46
  # Add the data to the project - note this data has a resolution 4th column
48
47
  problem.data.append(name="Bilayer / D2O", data=D2O_data)
@@ -83,11 +82,11 @@ def make_example_problem():
83
82
  )
84
83
 
85
84
  # And add the two new constant backgrounds
86
- problem.backgrounds.append(name="Background SMW", type="constant", value_1="Background parameter SMW")
87
- problem.backgrounds.append(name="Background H2O", type="constant", value_1="Background parameter H2O")
85
+ problem.backgrounds.append(name="Background SMW", type="constant", source="Background parameter SMW")
86
+ problem.backgrounds.append(name="Background H2O", type="constant", source="Background parameter H2O")
88
87
 
89
88
  # And edit the other one
90
- problem.backgrounds.set_fields(0, name="Background D2O", value_1="Background parameter D2O")
89
+ problem.backgrounds.set_fields(0, name="Background D2O", source="Background parameter D2O")
91
90
 
92
91
  # Finally modify some of the other parameters to be more suitable values for a solid / liquid experiment
93
92
  problem.scalefactors.set_fields(0, value=1.0, min=0.5, max=2.0, fit=True)