RATapi 0.0.0.dev4__tar.gz → 0.0.0.dev5__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 (79) hide show
  1. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/MANIFEST.in +1 -1
  2. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/PKG-INFO +5 -6
  3. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/__init__.py +7 -0
  4. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/classlist.py +68 -40
  5. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/controls.py +8 -5
  6. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/events.py +10 -7
  7. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/__init__.py +2 -0
  8. RATapi-0.0.0.dev5/RATapi/examples/absorption/__init__.py +1 -0
  9. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/absorption/absorption.py +13 -1
  10. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/absorption/volume_thiol_bilayer.py +3 -0
  11. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/convert_rascal_project/Model_IIb.py +3 -0
  12. RATapi-0.0.0.dev5/RATapi/examples/convert_rascal_project/__init__.py +1 -0
  13. RATapi-0.0.0.dev5/RATapi/examples/convert_rascal_project/convert_rascal.py +49 -0
  14. RATapi-0.0.0.dev5/RATapi/examples/data/__init__.py +1 -0
  15. RATapi-0.0.0.dev5/RATapi/examples/domains/__init__.py +1 -0
  16. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/domains/alloy_domains.py +6 -1
  17. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/domains/domains_XY_model.py +5 -1
  18. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/domains/domains_custom_XY.py +12 -1
  19. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/domains/domains_custom_layers.py +9 -1
  20. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/domains/domains_standard_layers.py +12 -0
  21. RATapi-0.0.0.dev5/RATapi/examples/languages/__init__.py +1 -0
  22. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/languages/custom_bilayer.py +3 -0
  23. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/languages/setup_problem.py +3 -1
  24. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/normal_reflectivity/DSPC_custom_XY.py +3 -1
  25. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/normal_reflectivity/DSPC_custom_layers.py +3 -4
  26. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/normal_reflectivity/DSPC_data_background.py +3 -1
  27. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/normal_reflectivity/DSPC_function_background.py +3 -1
  28. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/normal_reflectivity/DSPC_standard_layers.py +6 -1
  29. RATapi-0.0.0.dev5/RATapi/examples/normal_reflectivity/__init__.py +1 -0
  30. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/normal_reflectivity/background_function.py +4 -1
  31. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/normal_reflectivity/custom_XY_DSPC.py +5 -2
  32. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/normal_reflectivity/custom_bilayer_DSPC.py +3 -1
  33. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/inputs.py +50 -92
  34. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/models.py +35 -25
  35. RATapi-0.0.0.dev5/RATapi/outputs.py +533 -0
  36. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/project.py +160 -60
  37. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/run.py +13 -10
  38. RATapi-0.0.0.dev5/RATapi/utils/__init__.py +1 -0
  39. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/utils/convert.py +11 -7
  40. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/utils/custom_errors.py +4 -4
  41. RATapi-0.0.0.dev5/RATapi/utils/enums.py +207 -0
  42. RATapi-0.0.0.dev5/RATapi/utils/orso.py +248 -0
  43. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/utils/plotting.py +28 -31
  44. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/wrappers.py +13 -6
  45. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi.egg-info/PKG-INFO +5 -6
  46. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi.egg-info/SOURCES.txt +4 -1
  47. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi.egg-info/requires.txt +11 -13
  48. RATapi-0.0.0.dev5/cpp/includes/defines.h +679 -0
  49. RATapi-0.0.0.dev5/cpp/includes/functions.h +500 -0
  50. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/cpp/rat.cpp +214 -1047
  51. RATapi-0.0.0.dev5/pyproject.toml +41 -0
  52. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/setup.py +8 -8
  53. RATapi-0.0.0.dev4/RATapi/examples/absorption/__init__.py +0 -0
  54. RATapi-0.0.0.dev4/RATapi/examples/convert_rascal_project/__init__.py +0 -0
  55. RATapi-0.0.0.dev4/RATapi/examples/convert_rascal_project/convert_rascal.py +0 -30
  56. RATapi-0.0.0.dev4/RATapi/examples/data/__init__.py +0 -0
  57. RATapi-0.0.0.dev4/RATapi/examples/domains/__init__.py +0 -0
  58. RATapi-0.0.0.dev4/RATapi/examples/languages/__init__.py +0 -0
  59. RATapi-0.0.0.dev4/RATapi/examples/normal_reflectivity/__init__.py +0 -0
  60. RATapi-0.0.0.dev4/RATapi/outputs.py +0 -275
  61. RATapi-0.0.0.dev4/RATapi/utils/__init__.py +0 -0
  62. RATapi-0.0.0.dev4/RATapi/utils/enums.py +0 -127
  63. RATapi-0.0.0.dev4/pyproject.toml +0 -19
  64. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/data/D2O_spin_down.dat +0 -0
  65. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/data/D2O_spin_up.dat +0 -0
  66. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/data/DSPC_D2O.dat +0 -0
  67. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/data/DSPC_SMW.dat +0 -0
  68. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/data/H2O_spin_down.dat +0 -0
  69. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/data/H2O_spin_up.dat +0 -0
  70. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/data/c_PLP0016596.dat +0 -0
  71. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/data/c_PLP0016601.dat +0 -0
  72. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/data/c_PLP0016607.dat +0 -0
  73. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/data/d2o_background_data.dat +0 -0
  74. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi/examples/languages/run_custom_file_languages.py +0 -0
  75. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi.egg-info/dependency_links.txt +0 -0
  76. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi.egg-info/not-zip-safe +0 -0
  77. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/RATapi.egg-info/top_level.txt +0 -0
  78. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/README.md +0 -0
  79. {RATapi-0.0.0.dev4 → RATapi-0.0.0.dev5}/setup.cfg +0 -0
@@ -1,5 +1,5 @@
1
1
  include README.md
2
- recursive-include cpp/RAT *
2
+ recursive-include cpp *
3
3
  prune tests
4
4
  prune */__pycache__
5
5
  global-exclude .git
@@ -1,21 +1,20 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: RATapi
3
- Version: 0.0.0.dev4
3
+ Version: 0.0.0.dev5
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
- Requires-Python: >=3.9
8
+ Requires-Python: >=3.10
9
9
  Description-Content-Type: text/markdown
10
10
  Provides-Extra: Dev
11
- Provides-Extra: Matlab_2021a
12
- Provides-Extra: Matlab_2021b
13
- Provides-Extra: Matlab_2022a
14
- Provides-Extra: Matlab_2022b
15
11
  Provides-Extra: Matlab_2023a
16
12
  Provides-Extra: Matlab_2023b
17
13
  Provides-Extra: Matlab_2024a
14
+ Provides-Extra: Matlab_2024b
15
+ Provides-Extra: Matlab_2025a
18
16
  Provides-Extra: Matlab_latest
17
+ Provides-Extra: Orso
19
18
 
20
19
  python-RAT
21
20
  ==========
@@ -1,3 +1,7 @@
1
+ """RATapi is a Python package for modelling, fitting and optimising reflectivity problems."""
2
+
3
+ from contextlib import suppress
4
+
1
5
  import RATapi.examples as examples
2
6
  from RATapi import events, models
3
7
  from RATapi.classlist import ClassList
@@ -6,4 +10,7 @@ from RATapi.project import Project
6
10
  from RATapi.run import run
7
11
  from RATapi.utils import convert, plotting
8
12
 
13
+ with suppress(ImportError): # orsopy is an optional dependency
14
+ from RATapi.utils import orso as orso
15
+
9
16
  __all__ = ["examples", "models", "events", "ClassList", "Controls", "Project", "run", "plotting", "convert"]
@@ -1,6 +1,4 @@
1
- """The classlist module. Contains the ClassList class, which defines a list containing instances of a particular
2
- class.
3
- """
1
+ """The ClassList class, which defines a list containing instances of a particular class."""
4
2
 
5
3
  import collections
6
4
  import contextlib
@@ -24,12 +22,12 @@ class ClassList(collections.UserList, Generic[T]):
24
22
  attribute given in the ClassList's "name_field" attribute (the default is "name"), the ClassList will ensure that
25
23
  all objects within the ClassList have unique values for that attribute. It is then possible to use this attribute
26
24
  of an object in the .remove(), .count(), and .index() routines in place of the full object. Due to the requirement
27
- of unique values of the name_field attribute, the multiplication operators __mul__, __rmul__, and __imul__ have
25
+ of unique values of the ``name_field`` attribute, the multiplication operators __mul__, __rmul__, and __imul__ have
28
26
  been disabled, since they cannot allow for unique attribute values by definition.
29
27
 
30
28
  We extend the UserList class to enable objects to be added and modified using just the keyword arguments, enable
31
- the object name_field attribute to be used in place of the full object, and ensure all elements are of the
32
- specified type, with unique name_field attributes defined.
29
+ the object ``name_field`` attribute to be used in place of the full object, and ensure all elements are of the
30
+ specified type, with unique ``name_field`` attributes defined.
33
31
 
34
32
  Parameters
35
33
  ----------
@@ -171,8 +169,9 @@ class ClassList(collections.UserList, Generic[T]):
171
169
  raise TypeError(f"unsupported operand type(s) for *=: '{self.__class__.__name__}' and '{n.__class__.__name__}'")
172
170
 
173
171
  def append(self, obj: T = None, **kwargs) -> None:
174
- """Append a new object to the ClassList using either the object itself, or keyword arguments to set attribute
175
- values.
172
+ """Append a new object to the ClassList.
173
+
174
+ This method can use the object itself, or can provide attribute values as keyword arguments for a new object.
176
175
 
177
176
  Parameters
178
177
  ----------
@@ -184,7 +183,7 @@ class ClassList(collections.UserList, Generic[T]):
184
183
  Raises
185
184
  ------
186
185
  ValueError
187
- Raised if the input arguments contain a name_field value already defined in the ClassList.
186
+ Raised if the input arguments contain a ``name_field`` value already defined in the ClassList.
188
187
 
189
188
  Warnings
190
189
  --------
@@ -216,8 +215,9 @@ class ClassList(collections.UserList, Generic[T]):
216
215
  self.data.append(self._class_handle(**kwargs))
217
216
 
218
217
  def insert(self, index: int, obj: T = None, **kwargs) -> None:
219
- """Insert a new object into the ClassList at a given index using either the object itself, or keyword arguments
220
- to set attribute values.
218
+ """Insert a new object at a given index.
219
+
220
+ This method can use the object itself, or can provide attribute values as keyword arguments for a new object.
221
221
 
222
222
  Parameters
223
223
  ----------
@@ -231,7 +231,7 @@ class ClassList(collections.UserList, Generic[T]):
231
231
  Raises
232
232
  ------
233
233
  ValueError
234
- Raised if the input arguments contain a name_field value already defined in the ClassList.
234
+ Raised if the input arguments contain a ``name_field`` value already defined in the ClassList.
235
235
 
236
236
  Warnings
237
237
  --------
@@ -263,20 +263,25 @@ class ClassList(collections.UserList, Generic[T]):
263
263
  self.data.insert(index, self._class_handle(**kwargs))
264
264
 
265
265
  def remove(self, item: Union[T, str]) -> None:
266
- """Remove an object from the ClassList using either the object itself or its name_field value."""
266
+ """Remove an object from the ClassList using either the object itself or its ``name_field`` value."""
267
267
  item = self._get_item_from_name_field(item)
268
268
  self.data.remove(item)
269
269
 
270
270
  def count(self, item: Union[T, str]) -> int:
271
- """Return the number of times an object appears in the ClassList using either the object itself or its
272
- name_field value.
271
+ """Return the number of times an object appears in the ClassList.
272
+
273
+ This method can use either the object itself or its ``name_field`` value.
274
+
273
275
  """
274
276
  item = self._get_item_from_name_field(item)
275
277
  return self.data.count(item)
276
278
 
277
279
  def index(self, item: Union[T, str], offset: bool = False, *args) -> int:
278
- """Return the index of a particular object in the ClassList using either the object itself or its
279
- name_field value. If offset is specified, add one to the index. This is used to account for one-based indexing.
280
+ """Return the index of a particular object in the ClassList.
281
+
282
+ This method can use either the object itself or its ``name_field`` value.
283
+ If offset is specified, add one to the index. This is used to account for one-based indexing.
284
+
280
285
  """
281
286
  item = self._get_item_from_name_field(item)
282
287
  return self.data.index(item, *args) + int(offset)
@@ -291,11 +296,33 @@ class ClassList(collections.UserList, Generic[T]):
291
296
  self._check_unique_name_fields(other)
292
297
  self.data.extend(other)
293
298
 
294
- def set_fields(self, index: int, **kwargs) -> None:
299
+ def union(self, other: Sequence[T]) -> None:
300
+ """Extend the ClassList by a sequence, ignoring input items with names that already exist."""
301
+ if other and not (isinstance(other, Sequence) and not isinstance(other, str)):
302
+ other = [other]
303
+
304
+ self.extend(
305
+ [
306
+ item
307
+ for item in other
308
+ if hasattr(item, self.name_field) and getattr(item, self.name_field) not in self.get_names()
309
+ ]
310
+ )
311
+
312
+ def set_fields(self, index: Union[int, slice, str, T], **kwargs) -> None:
295
313
  """Assign the values of an existing object's attributes using keyword arguments."""
296
314
  self._validate_name_field(kwargs)
297
315
  pydantic_object = False
298
316
 
317
+ # Find index if name or object is supplied
318
+ if isinstance(index, (str, self._class_handle)):
319
+ index = self.index(index)
320
+
321
+ # Prioritise changing language to avoid CustomFile validator bug
322
+ value = kwargs.pop("language", None)
323
+ if value is not None:
324
+ kwargs = {"language": value, **kwargs}
325
+
299
326
  if importlib.util.find_spec("pydantic"):
300
327
  # Pydantic is installed, so set up a context manager that will
301
328
  # suppress custom validation errors until all fields have been set.
@@ -357,12 +384,12 @@ class ClassList(collections.UserList, Generic[T]):
357
384
  self._class_handle.model_validate(self.data[index])
358
385
 
359
386
  def get_names(self) -> list[str]:
360
- """Return a list of the values of the name_field attribute of each class object in the list.
387
+ """Return a list of the values of the ``name_field`` attribute of each class object in the list.
361
388
 
362
389
  Returns
363
390
  -------
364
391
  names : list [str]
365
- The value of the name_field attribute of each object in the ClassList.
392
+ The value of the ``name_field`` attribute of each object in the ClassList.
366
393
 
367
394
  """
368
395
  return [getattr(model, self.name_field) for model in self.data if hasattr(model, self.name_field)]
@@ -389,8 +416,7 @@ class ClassList(collections.UserList, Generic[T]):
389
416
  ]
390
417
 
391
418
  def _validate_name_field(self, input_args: dict[str, Any]) -> None:
392
- """Raise a ValueError if the name_field attribute is passed as an object parameter, and its value is already
393
- used within the ClassList.
419
+ """Raise a ValueError if the user tries to add an object with a ``name_field`` already in the ClassList.
394
420
 
395
421
  Parameters
396
422
  ----------
@@ -400,7 +426,7 @@ class ClassList(collections.UserList, Generic[T]):
400
426
  Raises
401
427
  ------
402
428
  ValueError
403
- Raised if the input arguments contain a name_field value already defined in the ClassList.
429
+ Raised if the input arguments contain a ``name_field`` value already defined in the ClassList.
404
430
 
405
431
  """
406
432
  names = [name.lower() for name in self.get_names()]
@@ -413,8 +439,7 @@ class ClassList(collections.UserList, Generic[T]):
413
439
  )
414
440
 
415
441
  def _check_unique_name_fields(self, input_list: Sequence[T]) -> None:
416
- """Raise a ValueError if any value of the name_field attribute is used more than once in a list of class
417
- objects.
442
+ """Raise a ValueError if any value of the ``name_field`` attribute is repeated in a list of class objects.
418
443
 
419
444
  Parameters
420
445
  ----------
@@ -470,17 +495,17 @@ class ClassList(collections.UserList, Generic[T]):
470
495
  )
471
496
 
472
497
  def _check_classes(self, input_list: Sequence[T]) -> None:
473
- """Raise a ValueError if any object in a list of objects is not of the type specified by self._class_handle.
498
+ """Raise a ValueError if any object in a list of objects is not of the type specified by ``self._class_handle``.
474
499
 
475
500
  Parameters
476
501
  ----------
477
502
  input_list : iterable
478
- A list of instances of the class given in self._class_handle.
503
+ A list of instances of the class given in ``self._class_handle``.
479
504
 
480
505
  Raises
481
506
  ------
482
507
  ValueError
483
- Raised if the input list contains objects of any type other than that given in self._class_handle.
508
+ If the input list contains objects of any type other than that given in ``self._class_handle``.
484
509
 
485
510
  """
486
511
  error_list = []
@@ -495,18 +520,18 @@ class ClassList(collections.UserList, Generic[T]):
495
520
  )
496
521
 
497
522
  def _get_item_from_name_field(self, value: Union[T, str]) -> Union[T, str]:
498
- """Return the object with the given value of the name_field attribute in the ClassList.
523
+ """Return the object with the given value of the ``name_field`` attribute in the ClassList.
499
524
 
500
525
  Parameters
501
526
  ----------
502
527
  value : T or str
503
- Either an object in the ClassList, or the value of the name_field attribute of an object in the ClassList.
528
+ Either an object in the ClassList, or the value of the ``name_field`` for an object in the ClassList.
504
529
 
505
530
  Returns
506
531
  -------
507
532
  instance : T or str
508
- Either the object with the value of the name_field attribute given by value, or the input value if an
509
- object with that value of the name_field attribute cannot be found.
533
+ Either the object with the value of the ``name_field`` attribute given by value, or the input value if an
534
+ object with that value of the ``name_field`` attribute cannot be found.
510
535
 
511
536
  """
512
537
  try:
@@ -518,24 +543,27 @@ class ClassList(collections.UserList, Generic[T]):
518
543
 
519
544
  @staticmethod
520
545
  def _determine_class_handle(input_list: Sequence[T]):
521
- """When inputting a sequence of object to a ClassList, the _class_handle should be set as the type of the
522
- element which satisfies "issubclass" for all the other elements.
546
+ """Determine the class handle from a sequence of objects.
547
+
548
+ The ``_class_handle`` of the sequence is the type of the first element in the sequence
549
+ which is a subclass of all elements in the sequence. If no such element exists, the handle
550
+ is set to be the type of the first element in the list.
523
551
 
524
552
  Parameters
525
553
  ----------
526
- input_list : Sequence [object]
554
+ input_list : Sequence[T]
527
555
  A list of instances to populate the ClassList.
528
556
 
529
557
  Returns
530
558
  -------
531
559
  class_handle : type
532
- The type object of the element fulfilling the condition of satisfying "issubclass" for all of the other
533
- elements.
560
+ The type object of the first element which is a subclass of all of the other
561
+ elements, or the first element if no such element exists.
534
562
 
535
563
  """
536
- for this_element in input_list:
537
- if all([issubclass(type(instance), type(this_element)) for instance in input_list]):
538
- class_handle = type(this_element)
564
+ for element in input_list:
565
+ if all(issubclass(type(instance), type(element)) for instance in input_list):
566
+ class_handle = type(element)
539
567
  break
540
568
  else:
541
569
  class_handle = type(input_list[0])
@@ -1,3 +1,5 @@
1
+ """The Controls class for providing RAT algorithm settings."""
2
+
1
3
  import contextlib
2
4
  import os
3
5
  import tempfile
@@ -114,9 +116,9 @@ class Controls(BaseModel, validate_assignment=True, extra="forbid", use_attribut
114
116
 
115
117
  # Dream
116
118
  nSamples: int = Field(20000, ge=0)
117
- """[DREAM] The number of samples in the initial population for each chain."""
119
+ """[DREAM] The total number of function evaluations (number of algorithm generations times number of chains)."""
118
120
 
119
- nChains: int = Field(10, gt=0)
121
+ nChains: int = Field(10, gt=1)
120
122
  """[DREAM] The number of Markov chains to use in the algorithm."""
121
123
 
122
124
  jumpProbability: float = Field(0.5, gt=0.0, lt=1.0)
@@ -153,7 +155,7 @@ class Controls(BaseModel, validate_assignment=True, extra="forbid", use_attribut
153
155
  f" controls procedure are:\n "
154
156
  f"{', '.join(fields.get('procedure', []))}\n",
155
157
  }
156
- custom_error_list = custom_pydantic_validation_error(exc.errors(), custom_error_msgs)
158
+ custom_error_list = custom_pydantic_validation_error(exc.errors(include_url=False), custom_error_msgs)
157
159
  raise ValidationError.from_exception_data(exc.title, custom_error_list, hide_input=True) from None
158
160
 
159
161
  if isinstance(model_input, validated_self.__class__):
@@ -196,19 +198,20 @@ class Controls(BaseModel, validate_assignment=True, extra="forbid", use_attribut
196
198
  return table.get_string()
197
199
 
198
200
  def initialise_IPC(self):
199
- """Setup the inter-process communication file."""
201
+ """Set up the inter-process communication file."""
200
202
  IPC_obj, self._IPCFilePath = tempfile.mkstemp()
201
203
  os.write(IPC_obj, b"0")
202
204
  os.close(IPC_obj)
203
205
  return None
204
206
 
205
207
  def sendStopEvent(self):
206
- """Sends the stop event via the inter-process communication file.
208
+ """Send the stop event via the inter-process communication file.
207
209
 
208
210
  Warnings
209
211
  --------
210
212
  UserWarning
211
213
  Raised if we try to delete an IPC file that was not initialised.
214
+
212
215
  """
213
216
  if os.path.isfile(self._IPCFilePath):
214
217
  with open(self._IPCFilePath, "wb") as f:
@@ -1,3 +1,5 @@
1
+ """Hooks for connecting to run callback events."""
2
+
1
3
  import os
2
4
  from typing import Callable, Union
3
5
 
@@ -5,8 +7,7 @@ from RATapi.rat_core import EventBridge, EventTypes, PlotEventData, ProgressEven
5
7
 
6
8
 
7
9
  def notify(event_type: EventTypes, data: Union[str, PlotEventData, ProgressEventData]) -> None:
8
- """Calls registered callbacks with the data when event type has
9
- been triggered.
10
+ """Call registered callbacks with data when event type has been triggered.
10
11
 
11
12
  Parameters
12
13
  ----------
@@ -22,7 +23,7 @@ def notify(event_type: EventTypes, data: Union[str, PlotEventData, ProgressEvent
22
23
 
23
24
 
24
25
  def get_event_callback(event_type: EventTypes) -> list[Callable[[Union[str, PlotEventData, ProgressEventData]], None]]:
25
- """Returns all callbacks registered for the given event type.
26
+ """Return all callbacks registered for the given event type.
26
27
 
27
28
  Parameters
28
29
  ----------
@@ -39,7 +40,7 @@ def get_event_callback(event_type: EventTypes) -> list[Callable[[Union[str, Plot
39
40
 
40
41
 
41
42
  def register(event_type: EventTypes, callback: Callable[[Union[str, PlotEventData, ProgressEventData]], None]) -> None:
42
- """Registers a new callback for the event type.
43
+ """Register a new callback for the event type.
43
44
 
44
45
  Parameters
45
46
  ----------
@@ -58,12 +59,14 @@ def register(event_type: EventTypes, callback: Callable[[Union[str, PlotEventDat
58
59
 
59
60
 
60
61
  def clear(key=None, callback=None) -> None:
61
- """Clears all event callbacks or specific callback.
62
+ """Clear all event callbacks or specific callback.
62
63
 
63
64
  Parameters
64
65
  ----------
65
- callback : Callable[[Union[str, PlotEventData, ProgressEventData]], None]
66
- The callback for when the event is triggered.
66
+ key : EventTypes, optional
67
+ The event type of the callback to clear if given.
68
+ callback : Callable[[Union[str, PlotEventData, ProgressEventData]], None], optional
69
+ A callback for an event which will be cleared if given.
67
70
 
68
71
  """
69
72
  if key is None and callback is None:
@@ -1,3 +1,5 @@
1
+ """Usage examples for the Python RAT API."""
2
+
1
3
  from RATapi.examples.absorption.absorption import absorption
2
4
  from RATapi.examples.convert_rascal_project.convert_rascal import convert_rascal
3
5
  from RATapi.examples.domains.domains_custom_layers import domains_custom_layers
@@ -0,0 +1 @@
1
+ """An example of using absorption in a RAT project."""
@@ -1,3 +1,5 @@
1
+ """An example for using absorption in RAT."""
2
+
1
3
  import pathlib
2
4
 
3
5
  import numpy as np
@@ -6,7 +8,17 @@ import RATapi as RAT
6
8
 
7
9
 
8
10
  def absorption():
9
- """Custom layers model including absorption"""
11
+ """Run a custom layers model including absorption.
12
+
13
+ RAT allows the use of an imaginary, as well as real part of the SLD.
14
+ The effect of this is usually seen below the critical edge, and must sometimes be accounted for.
15
+
16
+ This is an example of a Custom Layers project using absorption. used here is Custom Layers.
17
+ It analyses a bilayer sample on a permalloy / gold substrate,
18
+ measured using polarised neutrons, against D2O and H2O, leading to 4 contrasts in total.
19
+ Absorption (i.e. imaginary SLD) is defined for Gold and the Permalloy,
20
+ to account for non-flat data below the critical edge.
21
+ """
10
22
  problem = RAT.Project(
11
23
  name="Absorption example",
12
24
  calculation="normal",
@@ -1,3 +1,6 @@
1
+ """Custom layer model file for the absorption example."""
2
+
3
+
1
4
  def volume_thiol_bilayer(params, bulk_in, bulk_out, contrast):
2
5
  """VolumeThiolBilayer RAT Custom Layer Model File.
3
6
 
@@ -1,7 +1,10 @@
1
+ """A custom model file for a monolayer volume model."""
2
+
1
3
  from math import cos, radians
2
4
 
3
5
 
4
6
  def Model_IIb(params, bulk_in, bulk_out, contrast):
7
+ """Calculate layer parameters for a monolayer volume model at two deuterations."""
5
8
  # converted from matlab file Model_IIb.m
6
9
 
7
10
  Roughness, APM, thickHead, theta = params
@@ -0,0 +1 @@
1
+ """An example of converting between RAT and RasCAL-1."""
@@ -0,0 +1,49 @@
1
+ """An example of how to convert a RasCAL-1 project to RAT."""
2
+
3
+ import pathlib
4
+ from pprint import pp
5
+
6
+ import RATapi as RAT
7
+
8
+
9
+ # convert R1 project to Project class
10
+ def convert_rascal(mat_filename="lipid_bilayer.mat"):
11
+ """Convert a project from RasCAL-1 and a project to RasCAL-1.
12
+
13
+ We convert a RasCAL-1 monolayer volume model to RAT, and the DSPC Standard Layers
14
+ example to RasCAL-1.
15
+
16
+ Parameters
17
+ ----------
18
+ mat_filename : str
19
+ The filename of the output of the RAT project converted to RasCAL-2.
20
+
21
+ Returns
22
+ -------
23
+ project, struct
24
+ A RasCAL-1 monolayer volume model converted to a RAT project, and the
25
+ struct of the DSPC standard layers example converted to a RasCAL-1 struct.
26
+
27
+ """
28
+ project_path = pathlib.Path(__file__).parent / "R1monolayerVolumeModel.mat"
29
+ project = RAT.utils.convert.r1_to_project(project_path)
30
+
31
+ # change values if you like, including ones not supported by R1
32
+ project.parameters["Head Thickness"].prior_type = "gaussian"
33
+ project.parameters["Theta"].mu = 2.0
34
+ project.parameters["Area per molecule"].sigma = 50.0
35
+
36
+ # convert DSPC standard layers example to a struct and save as file
37
+ lipid_bilayer_project = RAT.examples.DSPC_standard_layers()[0]
38
+ RAT.utils.convert.project_to_r1(lipid_bilayer_project, filename=mat_filename)
39
+
40
+ # convert and return as a Python dictionary
41
+ struct = RAT.utils.convert.project_to_r1(lipid_bilayer_project, return_struct=True)
42
+
43
+ return project, struct
44
+
45
+
46
+ if __name__ == "__main__":
47
+ project, struct = convert_rascal()
48
+ print(project)
49
+ pp(struct)
@@ -0,0 +1 @@
1
+ """Data files used by the examples."""
@@ -0,0 +1 @@
1
+ """Examples for how to use RAT with domains models."""
@@ -1,5 +1,10 @@
1
+ """Custom model file for the domains custom layers example."""
2
+
3
+
1
4
  def alloy_domains(params, bulkIn, bulkOut, contrast, domain):
2
- """Simple custom model for testing incoherent summing.
5
+ """Calculate custom model layers for a permalloy/gold model with domains.
6
+
7
+ Simple custom model for testing incoherent summing.
3
8
  Simple two layer of permalloy / gold, with up/down domains.
4
9
  """
5
10
  # Split up the parameters
@@ -1,9 +1,12 @@
1
+ """Custom model file for the domains custom XY example."""
2
+
1
3
  import math
2
4
 
3
5
  import numpy as np
4
6
 
5
7
 
6
8
  def domains_XY_model(params, bulk_in, bulk_out, contrast, domain):
9
+ """Calculate the SLD profile for a domains custom XY model."""
7
10
  # Split up the parameters for convenience
8
11
  subRough = params[0]
9
12
  oxideThick = params[1]
@@ -51,7 +54,8 @@ def domains_XY_model(params, bulk_in, bulk_out, contrast, domain):
51
54
 
52
55
 
53
56
  def makeLayer(z, prevLaySurf, thickness, height, Sigma_L, Sigma_R):
54
- """This produces a layer, with a defined thickness, height and roughness.
57
+ """Produce a layer, with a defined thickness, height and roughness.
58
+
55
59
  Each side of the layer has its own roughness value.
56
60
  """
57
61
  # Find the edges
@@ -1,10 +1,21 @@
1
+ """An example of using domains with a Custom XY model."""
2
+
1
3
  import pathlib
2
4
 
3
5
  import RATapi as RAT
4
6
 
5
7
 
6
8
  def domains_custom_XY():
7
- """Simple example of a layer containing domains using a custom XY model"""
9
+ """Calculate an example of a layer containing domains using a custom XY model.
10
+
11
+ Domains custom XY models operate in the same way as domains custom layer models,
12
+ in that there is an additional input to the custom model
13
+ specifying the domain to be calculated.
14
+
15
+ This is then used within the function to calculate the correct SLD profile
16
+ for each contrast and domain. In this example, we simulate a hydrogenated layer
17
+ on a silicon substrate, containing domains of a larger SLD, against D2O, SMW and water.
18
+ """
8
19
  problem = RAT.Project(calculation="domains", model="custom xy", geometry="substrate/liquid")
9
20
 
10
21
  problem.parameters.append(name="Oxide Thickness", min=10.0, value=20.0, max=50.0, fit=True)
@@ -1,10 +1,18 @@
1
+ """An example of using domains with custom layer models."""
2
+
1
3
  import pathlib
2
4
 
3
5
  import RATapi as RAT
4
6
 
5
7
 
6
8
  def domains_custom_layers():
7
- """An example custom layers domains project involving incoherent summing on a permalloy layer"""
9
+ """Calculate an example custom layers domains project involving incoherent summing on a permalloy layer.
10
+
11
+ For a custom layers model, rather than being forced to define our layers as [Thick SLD Rough…. etc],
12
+ we can parameterise however we like and then use a function to calculate the parameters for each layer.
13
+ So for example, if the volume of lipid tails are known (from the literature),
14
+ then all we need is the Area per molecule to calculate the layers.
15
+ """
8
16
  problem = RAT.Project(calculation="domains", model="custom layers", geometry="substrate/liquid")
9
17
 
10
18
  # Make some parameters...
@@ -1,7 +1,19 @@
1
+ """An example using domains with standard layers."""
2
+
1
3
  import RATapi as RAT
2
4
 
3
5
 
4
6
  def domains_standard_layers():
7
+ """Calculate an example for using standard layers with domains.
8
+
9
+ Domains standard layers projects proceed in much the same way as a normal standard layers problem,
10
+ except that there is an additional grouping step between layers and contrasts.
11
+
12
+ Layers are grouped into ‘Domain Contrasts’. The model for the actual experimental contrast
13
+ is built from these domain contrasts rather than from layers. There are exactly
14
+ two domains for each contrast, with the the ratio of them controlled by
15
+ a fittable ‘domain ratio’ parameter.
16
+ """
5
17
  problem = RAT.Project(calculation="domains")
6
18
 
7
19
  # Define the parameters we need to define our two domains
@@ -0,0 +1 @@
1
+ """A benchmark for using RAT custom files in three different languages."""
@@ -1,7 +1,10 @@
1
+ """A custom bilayer model for the custom file languages benchmark."""
2
+
1
3
  import numpy as np
2
4
 
3
5
 
4
6
  def custom_bilayer(params, bulk_in, bulk_out, contrast):
7
+ """Calculate the layer parameters for a custom bilayer model."""
5
8
  sub_rough = params[0]
6
9
  oxide_thick = params[1]
7
10
  oxide_hydration = params[2]
@@ -1,3 +1,5 @@
1
+ """A custom example problem for the languages benchmark."""
2
+
1
3
  import pathlib
2
4
 
3
5
  import numpy as np
@@ -6,7 +8,7 @@ import RATapi as RAT
6
8
 
7
9
 
8
10
  def make_example_problem():
9
- """Custom Layers example for Supported DSPC layer.
11
+ """Generate a Custom Layers example for Supported DSPC layer.
10
12
 
11
13
  Example of using custom layers to model a DSPC supported bilayer.
12
14
  """