Skip to content

Commit 810ae68

Browse files
authored
Update custom file examples (#53)
1 parent 85838c7 commit 810ae68

File tree

6 files changed

+26
-28
lines changed

6 files changed

+26
-28
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ folder while the build will be placed in a build folder. The build requires a py
99
in the requirements.txt. You need MATLAB version and python version or RAT software installed in your system.
1010

1111
```bash
12-
conda create -n RAT python=3.9
12+
conda create -n RAT python=3.10
1313
conda activate RAT
1414
pip install -r requirements.txt
1515
```

source/advanced/customLanguages.rst

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Python Custom Models
1919
.. note::
2020
Before you use Python from your MATLAB session, please ensure that Python is `configured correctly on your system. <https://uk.mathworks.com/help/matlab/matlab_external/create-object-from-python-class.html>`_
2121

22+
.. warning::
23+
The value of contrast and domain number will always start from 1 (not 0) so be careful if contrast/domain number is used for array indexing.
24+
You will need to subtract one from contrast e.g :code:`bulk_in[contrast - 1]` to avoid code failure.
2225

2326
Custom models in Python and MATLAB are very similar in structure as shown below:
2427

@@ -156,13 +159,13 @@ Custom models in Python and MATLAB are very similar in structure as shown below:
156159
157160
# Manually deal with hydration for layers in
158161
# this example.
159-
oxSLD = (oxide_hydration * bulk_out[contrast]) + ((1 - oxide_hydration) * oxide_SLD)
160-
headSLD = (headHydration * bulk_out[contrast]) + ((1 - headHydration) * SLDhead)
161-
tailSLD = (bilayerHydration * bulk_out[contrast]) + ((1 - bilayerHydration) * SLDtail)
162+
oxSLD = (oxide_hydration * bulk_out[contrast-1]) + ((1 - oxide_hydration) * oxide_SLD)
163+
headSLD = (headHydration * bulk_out[contrast-1]) + ((1 - headHydration) * SLDhead)
164+
tailSLD = (bilayerHydration * bulk_out[contrast-1]) + ((1 - bilayerHydration) * SLDtail)
162165
163166
# Make the layers
164167
oxide = [oxide_thick, oxSLD, sub_rough]
165-
water = [waterThick, bulk_out[contrast], bilayerRough]
168+
water = [waterThick, bulk_out[contrast-1], bilayerRough]
166169
head = [headThick, headSLD, bilayerRough]
167170
tail = [tailThick, tailSLD, bilayerRough]
168171
@@ -259,9 +262,9 @@ Following on from our custom bilayer examples, the equivalent C++ custom model s
259262

260263
// Manually deal with hydration for layers in
261264
// this example.
262-
double oxSLD = (oxideHydration * bulkOut[contrast]) + ((1 - oxideHydration) * oxideSLD);
263-
double headSLD = (headHydration * bulkOut[contrast]) + ((1 - headHydration) * SLDhead);
264-
double tailSLD = (bilayerHydration * bulkOut[contrast]) + ((1 - bilayerHydration) * SLDtail);
265+
double oxSLD = (oxideHydration * bulkOut[contrast-1]) + ((1 - oxideHydration) * oxideSLD);
266+
double headSLD = (headHydration * bulkOut[contrast-1]) + ((1 - headHydration) * SLDhead);
267+
double tailSLD = (bilayerHydration * bulkOut[contrast-1]) + ((1 - bilayerHydration) * SLDtail);
265268

266269
// Make the layers
267270
// oxide...
@@ -271,7 +274,7 @@ Following on from our custom bilayer examples, the equivalent C++ custom model s
271274

272275
// Water...
273276
output.push_back(waterThick);
274-
output.push_back(bulkOut[contrast]);
277+
output.push_back(bulkOut[contrast-1]);
275278
output.push_back(bilayerRough);
276279

277280
// Heads...

source/api.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ Controls Class
376376
==============
377377

378378
ControlsClass is all about control. It is necessary in determine the way RAT works. It deals with how the user interacts with the software. From type of parallelization
379-
to whether the users wants to calculate SLD during fit and even how many iteration an algorithm should do ..etc.
379+
to how many iterations an algorithm should do etc.
380380

381381

382382
There are 5 different `controlsClass.procedures` that can be used with RAT. They are:
@@ -397,9 +397,9 @@ if yes, what to parallelize on. (Points or Contrasts or all)
397397
:caption: Sample usage of controlsClass.
398398
399399
controls = controlsClass();
400-
controls.calcSldDuringFit = false;
401-
controls.nsimu = 7000;
402-
controls.repeats = 3;
400+
controls.procedure = 'dream';
401+
controls.nSamples = 6000;
402+
controls.nChains = 10;
403403
controls.parallel = 'contrasts';
404404
405405
.. code-block:: MATLAB
@@ -429,12 +429,12 @@ After the user has defined the projectClass and controlsClass, the user can run
429429
[problem,results] = RAT(problem,controls);
430430
431431
432-
When the RAT function is called, the classes are passed into internal functions like `RatParseClassToStructs_new` which takes the classes and breaks them down into cells,
432+
When the RAT function is called, the classes are passed into internal functions like `parseClassToStructs` which takes the classes and breaks them down into cells,
433433
limits,prior and more importantly converts the project class to struct.
434434

435435
Then, the `RATMain` function redirects the control flow based on what procedure is selected in controlsClass. One of the redirecting functions will call the reflectivityCalculation
436436
which starts the reflectivity calculation.
437437

438438

439439
Some interesting data type changes are needed because of how things work with coder. Coder wont accept variable sized cell arrays contains variable sized arrays (strings for eg)
440-
in a field of a struct. So, look at `RatParseClassToStructs_new` function to understand how the data is converted.
440+
in a field of a struct. So, look at `parseClassToStructs` function to understand how the data is converted.

source/matlab_examples.pdf

-44.8 KB
Binary file not shown.

source/tutorial/controls.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,6 @@ How the calculation should be :ref:`parallelised<parallelisation>`. Currently th
106106

107107
Which option is more efficient will depend on the number of contrasts and the size of your data.
108108

109-
``calcSldDuringFit``
110-
^^^^^^^^^^^^^^^^^^^^
111-
A boolean (true or false) value which determines whether SLD will be calculated during the fit
112-
(for :ref:`live plotting<livePlot>` etc.)
113-
114109
``display``
115110
^^^^^^^^^^^
116111
How much RAT should print to the terminal. The current options are:

source/tutorial/customModels.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,13 @@ At this point it is useful to look at our custom function and then go through it
341341
342342
# Manually deal with hydration for layers in
343343
# this example.
344-
oxSLD = (oxide_hydration * bulk_out[contrast]) + ((1 - oxide_hydration) * oxide_SLD)
345-
headSLD = (headHydration * bulk_out[contrast]) + ((1 - headHydration) * SLDhead)
346-
tailSLD = (bilayerHydration * bulk_out[contrast]) + ((1 - bilayerHydration) * SLDtail)
344+
oxSLD = (oxide_hydration * bulk_out[contrast-1]) + ((1 - oxide_hydration) * oxide_SLD)
345+
headSLD = (headHydration * bulk_out[contrast-1]) + ((1 - headHydration) * SLDhead)
346+
tailSLD = (bilayerHydration * bulk_out[contrast-1]) + ((1 - bilayerHydration) * SLDtail)
347347
348348
# Make the layers
349349
oxide = [oxide_thick, oxSLD, sub_rough]
350-
water = [waterThick, bulk_out[contrast], bilayerRough]
350+
water = [waterThick, bulk_out[contrast-1], bilayerRough]
351351
head = [headThick, headSLD, bilayerRough]
352352
tail = [tailThick, tailSLD, bilayerRough]
353353
@@ -408,7 +408,7 @@ Therefore, the effective SLD of the oxide layer at a particular contrast is give
408408
.. code-block:: Python
409409
410410
oxide_SLD = 3.41e-6
411-
oxSLD = (oxide_hydration * bulk_out[contrast]) + ((1 - oxide_hydration) * oxide_SLD)
411+
oxSLD = (oxide_hydration * bulk_out[contrast-1]) + ((1 - oxide_hydration) * oxide_SLD)
412412
413413
To work out the thickness of the lipid layers, we use literature values for the head and tails volumes,
414414
and divide these by the APM (the fourth input parameter in ``params``):
@@ -503,8 +503,8 @@ We also do the coverage correction as we did for the Oxide:
503503
504504
.. code-block:: Python
505505
506-
headSLD = (headHydration * bulk_out[contrast]) + ((1 - headHydration) * SLDhead)
507-
tailSLD = (bilayerHydration * bulk_out[contrast]) + ((1 - bilayerHydration) * SLDtail)
506+
headSLD = (headHydration * bulk_out[contrast-1]) + ((1 - headHydration) * SLDhead)
507+
tailSLD = (bilayerHydration * bulk_out[contrast-1]) + ((1 - bilayerHydration) * SLDtail)
508508
509509
This gives us all the parameters we need to define our layers.
510510
In other words, we have a thickness, SLD and roughness for each layer then put these together to make our stack:
@@ -524,7 +524,7 @@ In other words, we have a thickness, SLD and roughness for each layer then put t
524524
525525
# Make the layers
526526
oxide = [oxide_thick, oxSLD, sub_rough]
527-
water = [waterThick, bulk_out[contrast], bilayerRough]
527+
water = [waterThick, bulk_out[contrast-1], bilayerRough]
528528
head = [headThick, headSLD, bilayerRough]
529529
tail = [tailThick, tailSLD, bilayerRough]
530530

0 commit comments

Comments
 (0)