Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ folder while the build will be placed in a build folder. The build requires a py
in the requirements.txt. You need MATLAB version and python version or RAT software installed in your system.

```bash
conda create -n RAT python=3.9
conda create -n RAT python=3.10
conda activate RAT
pip install -r requirements.txt
```
Expand Down
19 changes: 11 additions & 8 deletions source/advanced/customLanguages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Python Custom Models
.. note::
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>`_

.. warning::
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.
You will need to subtract one from contrast e.g :code:`bulk_in[contrast - 1]` to avoid code failure.

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

Expand Down Expand Up @@ -156,13 +159,13 @@ Custom models in Python and MATLAB are very similar in structure as shown below:

# Manually deal with hydration for layers in
# this example.
oxSLD = (oxide_hydration * bulk_out[contrast]) + ((1 - oxide_hydration) * oxide_SLD)
headSLD = (headHydration * bulk_out[contrast]) + ((1 - headHydration) * SLDhead)
tailSLD = (bilayerHydration * bulk_out[contrast]) + ((1 - bilayerHydration) * SLDtail)
oxSLD = (oxide_hydration * bulk_out[contrast-1]) + ((1 - oxide_hydration) * oxide_SLD)
headSLD = (headHydration * bulk_out[contrast-1]) + ((1 - headHydration) * SLDhead)
tailSLD = (bilayerHydration * bulk_out[contrast-1]) + ((1 - bilayerHydration) * SLDtail)

# Make the layers
oxide = [oxide_thick, oxSLD, sub_rough]
water = [waterThick, bulk_out[contrast], bilayerRough]
water = [waterThick, bulk_out[contrast-1], bilayerRough]
head = [headThick, headSLD, bilayerRough]
tail = [tailThick, tailSLD, bilayerRough]

Expand Down Expand Up @@ -259,9 +262,9 @@ Following on from our custom bilayer examples, the equivalent C++ custom model s

// Manually deal with hydration for layers in
// this example.
double oxSLD = (oxideHydration * bulkOut[contrast]) + ((1 - oxideHydration) * oxideSLD);
double headSLD = (headHydration * bulkOut[contrast]) + ((1 - headHydration) * SLDhead);
double tailSLD = (bilayerHydration * bulkOut[contrast]) + ((1 - bilayerHydration) * SLDtail);
double oxSLD = (oxideHydration * bulkOut[contrast-1]) + ((1 - oxideHydration) * oxideSLD);
double headSLD = (headHydration * bulkOut[contrast-1]) + ((1 - headHydration) * SLDhead);
double tailSLD = (bilayerHydration * bulkOut[contrast-1]) + ((1 - bilayerHydration) * SLDtail);

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

// Water...
output.push_back(waterThick);
output.push_back(bulkOut[contrast]);
output.push_back(bulkOut[contrast-1]);
output.push_back(bilayerRough);

// Heads...
Expand Down
12 changes: 6 additions & 6 deletions source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ Controls Class
==============

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
to whether the users wants to calculate SLD during fit and even how many iteration an algorithm should do ..etc.
to how many iterations an algorithm should do etc.


There are 5 different `controlsClass.procedures` that can be used with RAT. They are:
Expand All @@ -397,9 +397,9 @@ if yes, what to parallelize on. (Points or Contrasts or all)
:caption: Sample usage of controlsClass.

controls = controlsClass();
controls.calcSldDuringFit = false;
controls.nsimu = 7000;
controls.repeats = 3;
controls.procedure = 'dream';
controls.nSamples = 6000;
controls.nChains = 10;
controls.parallel = 'contrasts';

.. code-block:: MATLAB
Expand Down Expand Up @@ -429,12 +429,12 @@ After the user has defined the projectClass and controlsClass, the user can run
[problem,results] = RAT(problem,controls);


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,
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,
limits,prior and more importantly converts the project class to struct.

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
which starts the reflectivity calculation.


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)
in a field of a struct. So, look at `RatParseClassToStructs_new` function to understand how the data is converted.
in a field of a struct. So, look at `parseClassToStructs` function to understand how the data is converted.
Binary file removed source/matlab_examples.pdf
Binary file not shown.
5 changes: 0 additions & 5 deletions source/tutorial/controls.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,6 @@ How the calculation should be :ref:`parallelised<parallelisation>`. Currently th

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

``calcSldDuringFit``
^^^^^^^^^^^^^^^^^^^^
A boolean (true or false) value which determines whether SLD will be calculated during the fit
(for :ref:`live plotting<livePlot>` etc.)

``display``
^^^^^^^^^^^
How much RAT should print to the terminal. The current options are:
Expand Down
16 changes: 8 additions & 8 deletions source/tutorial/customModels.rst
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,13 @@ At this point it is useful to look at our custom function and then go through it

# Manually deal with hydration for layers in
# this example.
oxSLD = (oxide_hydration * bulk_out[contrast]) + ((1 - oxide_hydration) * oxide_SLD)
headSLD = (headHydration * bulk_out[contrast]) + ((1 - headHydration) * SLDhead)
tailSLD = (bilayerHydration * bulk_out[contrast]) + ((1 - bilayerHydration) * SLDtail)
oxSLD = (oxide_hydration * bulk_out[contrast-1]) + ((1 - oxide_hydration) * oxide_SLD)
headSLD = (headHydration * bulk_out[contrast-1]) + ((1 - headHydration) * SLDhead)
tailSLD = (bilayerHydration * bulk_out[contrast-1]) + ((1 - bilayerHydration) * SLDtail)

# Make the layers
oxide = [oxide_thick, oxSLD, sub_rough]
water = [waterThick, bulk_out[contrast], bilayerRough]
water = [waterThick, bulk_out[contrast-1], bilayerRough]
head = [headThick, headSLD, bilayerRough]
tail = [tailThick, tailSLD, bilayerRough]

Expand Down Expand Up @@ -408,7 +408,7 @@ Therefore, the effective SLD of the oxide layer at a particular contrast is give
.. code-block:: Python

oxide_SLD = 3.41e-6
oxSLD = (oxide_hydration * bulk_out[contrast]) + ((1 - oxide_hydration) * oxide_SLD)
oxSLD = (oxide_hydration * bulk_out[contrast-1]) + ((1 - oxide_hydration) * oxide_SLD)

To work out the thickness of the lipid layers, we use literature values for the head and tails volumes,
and divide these by the APM (the fourth input parameter in ``params``):
Expand Down Expand Up @@ -503,8 +503,8 @@ We also do the coverage correction as we did for the Oxide:

.. code-block:: Python

headSLD = (headHydration * bulk_out[contrast]) + ((1 - headHydration) * SLDhead)
tailSLD = (bilayerHydration * bulk_out[contrast]) + ((1 - bilayerHydration) * SLDtail)
headSLD = (headHydration * bulk_out[contrast-1]) + ((1 - headHydration) * SLDhead)
tailSLD = (bilayerHydration * bulk_out[contrast-1]) + ((1 - bilayerHydration) * SLDtail)

This gives us all the parameters we need to define our layers.
In other words, we have a thickness, SLD and roughness for each layer then put these together to make our stack:
Expand All @@ -524,7 +524,7 @@ In other words, we have a thickness, SLD and roughness for each layer then put t

# Make the layers
oxide = [oxide_thick, oxSLD, sub_rough]
water = [waterThick, bulk_out[contrast], bilayerRough]
water = [waterThick, bulk_out[contrast-1], bilayerRough]
head = [headThick, headSLD, bilayerRough]
tail = [tailThick, tailSLD, bilayerRough]

Expand Down