If you have projects from RasCAL1, there is a simple utility supplied with the toolbox that makes converting between formats easy as explained in Convert between RAT and RasCAL-1.
This example shows the conversion of a RasCAL-1 custom layers project into a RAT project and vice versa, because this is a custom layers project, the custom model
function Model_IIb.m which in the example directory is required to run the converted RAT project successfully.
This example can be run using the instructions below.
Converting a RasCAL1Project to RAT format.
If you have a number of old rascal projects that you would like to load into RAT, it's not necessary to re-make the project from scratch. Rather, you can simply run the converstion utility supplied with the RAT repo to translate the project directly.
The project we are going to use for demonstrations comes from the RasCAL_2019 distro, and is an alaysis of a monolayer of DSPC analysed at multiple contrasts. We use various deuterations of DSPC, so either tail-deuterated, head deuterated, fully deuterated or hydrogenated....
..and these are measured either on D2O or ACMW, to give 7 contrasts in all.
The original R1 project is in 'monolayerVolumeModel.mat'. The custom model is 'Model_IIb.m'. To do the conversion, we simply run the utility....
problem = r1ToProjectClass('monolayerVolumeModel.mat')
problem.setCustomFile(1,'path', 'examples/miscellaneous/convertRascal1Project');
...and that's it! We have a full RAT projectClass with all the relevant parameters in the correct place.
To run this, we make a controls.block as ususal, send it to RAT and see what we end up with...
controls = controlsClass();
[problem,results] = RAT(problem,controls);
Starting RAT ________________________________________________________________________________________________
Elapsed time is 0.020530 seconds.
Finished RAT ______________________________________________________________________________________________
plotRefSLD(problem,results);
Looking at the project, we see a couple of things that we might like to change...
- The bulk out parameters are not being fit, we would like to fit these, so change the fit values of these to 'true'..
- The same goes for the scalefactor
- We would like to do a Bayesian analysis, so set the priors to be visible..
- Set some priors on the 'bulk out' parameters
We do this by modifying our projectClass with the class methods as usual....
problem.setBulkOut(1,'fit',true);
Warning: Negative data ignored
problem.setBulkOut(2,'fit',true);
problem.setScalefactor(1,'fit',true);
problem.showPriors = true;
problem.bulkOut.setPrior(1,'gaussian',6.35e-6,1e-8);
problem.bulkOut.setPrior(2,'gaussian',0,1e-7);
disp(problem)
modelType: 'custom layers'
experimentName: 'monolayerVolumeModel'
geometry: 'air/substrate'
Parameters: ----------------------------------------------------------------------------------------------
p Name Min Value Max Fit? Prior Type mu sigma
_ _____________________ ___ ______ ___ _____ __________ __ _____
1 "Substrate Roughness" 1 2.998 8 true "uniform" 0 Inf
2 "Area per molecule" 47 53.053 100 true "uniform" 0 Inf
3 "Head Thickness" 7 12.276 20 true "uniform" 0 Inf
4 "Theta" 0 28.871 50 true "uniform" 0 Inf
Bulk In: --------------------------------------------------------------------------------------------------
p Name Min Value Max Fit? Prior Type mu sigma
_ _____ ___ _____ ___ _____ __________ __ _____
1 "Air" 0 0 0 false "uniform" 0 Inf
Bulk Out: -------------------------------------------------------------------------------------------------
p Name Min Value Max Fit? Prior Type mu sigma
_ ______ _______ ________ _______ _____ __________ ________ _____
1 "D2O" 6.3e-06 6.35e-06 6.4e-06 true "gaussian" 6.35e-06 1e-08
2 "ACMW" -5e-07 0 5e-07 true "gaussian" 0 1e-07
Scalefactors: -------------------------------------------------------------------------------------------------
p Name Min Value Max Fit? Prior Type mu sigma
_ _______________ ___ _______ ___ _____ __________ __ _____
1 "Scalefactor 1" 0.1 0.22727 0.4 true "uniform" 0 Inf
Backgrounds: -----------------------------------------------------------------------------------------------
(a) Background Parameters:
p Name Min Value Max Fit? Prior Type mu sigma
_ ___________________ _____ __________ _____ _____ __________ __ _____
1 "Backs parameter 1" 1e-07 2.2653e-06 7e-06 true "uniform" 0 Inf
2 "Backs parameter 2" 1e-07 5.7432e-06 7e-06 true "uniform" 0 Inf
(b) Backgrounds:
p Name Type Source Value 1 Value 2 Value 3 Value 4 Value 5
_ _________________ __________ ___________________ _______ _______ _______ _______ _______
1 "Background D2O" "constant" "Backs parameter 1" "" "" "" "" ""
2 "Background ACMW" "constant" "Backs parameter 2" "" "" "" "" ""
Resolutions: ---------------------------------------------------------------------------------------------
(a) Resolutions Parameters:
p Name Min Value Max Fit? Prior Type mu sigma
_ __________________ ____ _____ ____ _____ __________ __ _____
1 "Resolution par 1" 0.01 0.03 0.05 false "uniform" 0 Inf
(b) Resolutions:
p Name Type Source Value 1 Value 2 Value 3 Value 4 Value 5
_ ______________ __________ __________________ _______ _______ _______ _______ _______
1 "Resolution 1" "constant" "Resolution par 1" "" "" "" "" ""
Custom Files: ------------------------------------------------------------------------------------------------------
Name Filename Function Name Language Path
___________ _____________ _____________ ________ ______________________________________________
"Model_IIb" "Model_IIb.m" "-" "matlab" "examples/miscellaneous/convertRascal1Project"
Data: ------------------------------------------------------------------------------------------------------
Name Data Data Range Simulation Range
____________ ______________________ _____________________ _____________________
"Simulation" "No Data" "[ 0.0518 , 0.5888 ]" "[ 0.0518 , 0.5888 ]"
"d70acmw20" "Data array: [51 x 3]" "[ 0.0518 , 0.5888 ]" "[ 0.0518 , 0.5888 ]"
"d70d2o20" "Data array: [51 x 3]" "[ 0.0518 , 0.5888 ]" "[ 0.0518 , 0.5888 ]"
"d13acmw20" "Data array: [51 x 3]" "[ 0.0518 , 0.5888 ]" "[ 0.0518 , 0.5888 ]"
"d13d2o20" "Data array: [51 x 3]" "[ 0.0518 , 0.5888 ]" "[ 0.0518 , 0.5888 ]"
"d83acmw20" "Data array: [51 x 3]" "[ 0.0518 , 0.5888 ]" "[ 0.0518 , 0.5888 ]"
"d83d2o20" "Data array: [51 x 3]" "[ 0.0518 , 0.5888 ]" "[ 0.0518 , 0.5888 ]"
"hd2o20" "Data array: [51 x 3]" "[ 0.0518 , 0.5888 ]" "[ 0.0518 , 0.5888 ]"
Contrasts: -----------------------------------------------------------------------------------------------
p 1 2 3 4 5 6 7
___________________ _________________ _________________ _________________ _________________ _________________ _________________ _________________
"Name" "d70, acmw" "d70 d2o" "d13 acmw" "d13 d2o" "d83 acmw" "d83 d2o" "fully h, D2O"
"Data" "d70acmw20" "d70d2o20" "d13acmw20" "d13d2o20" "d83acmw20" "d83d2o20" "hd2o20"
"Background" "Background ACMW" "Background D2O" "Background ACMW" "Background D2O" "Background ACMW" "Background D2O" "Background D2O"
"Background Action" "add" "add" "add" "add" "add" "add" "add"
"Bulk in" "Air" "Air" "Air" "Air" "Air" "Air" "Air"
"Bulk out" "ACMW" "D2O" "ACMW" "D2O" "ACMW" "D2O" "D2O"
"Scalefactor" "Scalefactor 1" "Scalefactor 1" "Scalefactor 1" "Scalefactor 1" "Scalefactor 1" "Scalefactor 1" "Scalefactor 1"
"Resolution" "Resolution 1" "Resolution 1" "Resolution 1" "Resolution 1" "Resolution 1" "Resolution 1" "Resolution 1"
"Resample" "false" "false" "false" "false" "false" "false" "false"
"Model" "Model_IIb" "Model_IIb" "Model_IIb" "Model_IIb" "Model_IIb" "Model_IIb" "Model_IIb"
Running a full analysis..
We will, as usual, run a Bayesian analysis using DREAM.
Set our controls block to parallelise over contrasts, and select the Bayes sampler....
controls.parallel = 'contrasts';
controls.procedure = 'dream'
controls =
controlsClass with properties:
parallel: 'contrasts'
procedure: 'dream'
calcSldDuringFit: 0
display: 'iter'
resampleMinAngle: 0.9000
resampleNPoints: 50
nSamples: 20000
nChains: 10
jumpProbability: 0.5000
pUnitGamma: 0.2000
boundHandling: 'reflect'
adaptPCR: 1
..and run the fit (using the defaults).
[problem,results] = RAT(problem,controls);
Starting RAT ________________________________________________________________________________________________
Running DREAM
------------------ Summary of the main settings used ------------------
nParams: 9
nChains: 10
nGenerations: 2000
parallel: false
CPU: 1
jumpProbability: 0.5
pUnitGamma: 0.2
nCR: 3
delta: 3
steps: 50
zeta: 1e-12
outlier: 'iqr'
adaptPCR: true
thinning: 1
ABC: false
epsilon: 0.025
IO: false
storeOutput: false
R: [10x10 double]
-----------------------------------------------------------------------
DREAM: 0.1% [........................................]
Warning: Negative data ignored
DREAM: 100.0% [****************************************]
Elapsed time is 32.897800 seconds.
Finished RAT ______________________________________________________________________________________________
Plot everything out and we're done.....
bayesShadedPlot(problem,results,'KeepAxes',true,'interval',95,'q4',false);
plotHists(results,'figure',h3,'smooth',true);
cornerPlot(results,'figure',h4,'smooth',false)
Warning: Negative data ignored