In this example, we can make use of the fact that the volumes, and of course the atomistic composition are known. So, for lipid tails for example, then we can
take a literature value for the tails volume, have a fittable parameter for the lipid area per molecule, and then the tail thickness will simply be
Since the volume is known, then the SLD of the tails is also obviously easily calculable.
In addition, the datasets for this example, have a resolution (per point) in their fourth column. We use this resolution in our analysis, rather than declaring a constant, fittable one.
This example can be run as a script or interactively using the instructions below.
Custom Layers Example for Supported DSPC layer.
Example of using Custom layers to model a DSPC supportd bilayer.
Start by making the class and setting it to a custom layers type:
problem = createProject(name='oDSPC - Custom Layers', calcType='normal', model='custom layers', geometry='substrate/liquid', absorption=false);
problem.showPriors = true;
For a custom layers model, rather than being forced to define out layers as [Thick SLD Rough.... etc], we can parameterise however we like and then use a function to calculate the [d rho sigma] arrangement for each layer. So for example, if the volume of lipid tails are known (from the literature), then all we need is the Area per molecule, because then....
,where d is the thickness and V is the volume.
Likewise, the SLD is
as usual.
In this folder there is a pre-prepared Matlab custom model for a DSPC on a Silicon substrate. We can display it here to see what we mean.....
type('customBilayerDSPC')
function [output,sub_rough] = customBilayerDSPC(params,bulk_in,bulk_out,contrast)
%CUSTOMBILAYER RASCAL Custom Layer Model File.
%
%
% This file accepts 3 vectors containing the values for
% Params, bulk in and bulk out
% The final parameter is an index of the contrast being calculated
% The m-file should output a matrix of layer values, in the form..
% Output = [thick 1, SLD 1, Rough 1, Percent Hydration 1, Hydrate how 1
% ....
% thick n, SLD n, Rough n, Percent Hydration n, Hydration how n]
% The "hydrate how" parameter decides if the layer is hydrated with
% Bulk out or Bulk in phases. Set to 1 for Bulk out, zero for Bulk in.
% Alternatively, leave out hydration and just return..
% Output = [thick 1, SLD 1, Rough 1,
% ....
% thick n, SLD n, Rough n] };
% The second output parameter should be the substrate roughness
sub_rough = params(1);
oxide_thick = params(2);
oxide_hydration = params(3);
lipidAPM = params(4);
headHydration = params(5);
bilayerHydration = params(6);
bilayerRough = params(7);
waterThick = params(8);
% We have a constant SLD for the bilayer
oxide_SLD = 3.41e-6;
% Now make the lipid layers..
% Use known lipid volume and compositions
% to make the layers
% define all the neutron b's.
bc = 0.6646e-4; %Carbon
bo = 0.5843e-4; %Oxygen
bh = -0.3739e-4; %Hydrogen
bp = 0.513e-4; %Phosphorus
bn = 0.936e-4; %Nitrogen
bd = 0.6671e-4; %Deuterium
% Now make the lipid groups..
COO = (4*bo) + (2*bc);
GLYC = (3*bc) + (5*bh);
CH3 = (2*bc) + (6*bh);
PO4 = (1*bp) + (4*bo);
CH2 = (1*bc) + (2*bh);
CHOL = (5*bc) + (12*bh) + (1*bn);
% Group these into heads and tails:
Head = CHOL + PO4 + GLYC + COO;
Tails = (34*CH2) + (2*CH3);
% We need volumes for each.
% Use literature values:
vHead = 319;
vTail = 782;
% we use the volumes to calculate the SLD's
SLDhead = Head / vHead;
SLDtail = Tails / vTail;
% We calculate the layer thickness' from
% the volumes and the APM...
headThick = vHead / lipidAPM;
tailThick = vTail / lipidAPM;
% 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);
% Make the layers
oxide = [oxide_thick oxSLD sub_rough];
water = [waterThick bulk_out(contrast) bilayerRough];
head = [headThick headSLD bilayerRough];
tail = [tailThick tailSLD bilayerRough];
output = [oxide ; water ; head ; tail ; tail ; head];
We need to add the parameters we are going to need to define the model (note that Substrate Roughness' always exists as parameter 1 as before, and that we are setting a Gaussian prior on Head Hydration here).
{'Oxide thick', 5, 20, 60, true };
{'Oxide Hydration' 0, 0.2, 0.5, true };
{'Lipid APM' 45 55 65 true };
{'Head Hydration' 0 0.2 0.7 true 'gaussian' 0.3 0.03};
{'Bilayer Hydration' 0 0.1 0.2 true };
{'Bilayer Roughness' 2 4 8 true };
{'Water Thickness' 0 2 10 true };
problem.addParameterGroup(Parameters);
problem.setParameter(1,'min',1,'max',10); % Change the substrate roughness limits
Need to add the relevant Bulk SLD's. Change the bulk in from air to silicon, and add two additional water contrasts:
% Change bulk in from air to silicon....
problem.setBulkIn(1,'name','Silicon','min',2.07e-6,'value',2.073e-6,'max',2.08e-6,'fit',false);
% Add two more values for bulk out....
problem.addBulkOut('SLD SMW',1e-6,2.073e-6,3e-6,true);
problem.addBulkOut('SLD H2O',-0.6e-6,-0.56e-6,-0.3e-6,true);
problem.setBulkOut(1,'fit',true,'min',5e-6);
Now add the datafiles. We have three datasets we need to consider - the bilayer against D2O, Silicon Matched water and H2O. Load these datafiles in and put them in the data block....
D2O_data = dlmread('c_PLP0016596.dat');
SMW_data = dlmread('c_PLP0016601.dat');
H2O_data = dlmread('c_PLP0016607.dat');
% Add the data to the project
problem.addData('Bilayer / D2O', D2O_data);
problem.addData('Bilayer / SMW', SMW_data);
problem.addData('Bilayer / H2O', H2O_data);
problem.setData(2,'dataRange',[0.013 0.37]);
problem.setData(3,'dataRange',[0.013 0.32996]);
problem.setData(4,'dataRange',[0.013 0.33048]);
Add the custom file to the project....
problem.addCustomFile('DSPC Model', 'customBilayerDSPC.m', 'matlab', pwd);
Also, add the relevant background parameters - one each for each contrast:
% Change the name of the existing parameters to refer to D2O
problem.setBackgroundParam(1,'name','Backs par D2O','fit',true,'min',1e-10,'max',1e-5,'value',1e-6);
% Add two new backs parameters for the other two..
problem.addBackgroundParam('Backs par SMW',1e-10,1e-6,1e-5,true);
problem.addBackgroundParam('Backs par H2O',1e-10,1e-6,1e-5,true);
% And add the two new constant backgrounds..
problem.addBackground('Background SMW','constant','Backs par SMW');
problem.addBackground('Background H2O','constant','Backs par H2O');
% And edit the other one....
problem.setBackground(1,'name','Background D2O','source','Backs par D2O');
% Finally modify some of the other parameters
problem.setScalefactor(1,'Value',1,'min',0.5,'max',2,'fit',true);
We need to use the data resolution (i.e. the fourch column of our datafiles). Do do this, we need to add a 'Data' resolution object to our resolutions table...
problem.addResolution('Data Resolution','data');
Now add the three contrasts as before. To set the model, we point to the custom file we've just added to the project:
problem.addContrast('name', 'Bilayer / D2O',...
'background', 'Background D2O',...
'resolution', 'Data Resolution',...
'scalefactor', 'Scalefactor 1',...
'data', 'Bilayer / D2O',...
problem.addContrast('name', 'Bilayer / SMW',...
'background', 'Background SMW',...
'resolution', 'Data Resolution',...
'scalefactor', 'Scalefactor 1',...
'data', 'Bilayer / SMW',...
problem.addContrast('name', 'Bilayer / H2O',...
'background', 'Background H2O',...
'resolution', 'Data Resolution',...
'scalefactor', 'Scalefactor 1',...
'data', 'Bilayer / H2O',...
Look at the complete model definition before sending it to RAT;
disp(problem)
modelType: 'custom layers'
experimentName: 'oDSPC - Custom Layers'
geometry: 'substrate/liquid'
Parameters: ----------------------------------------------------------------------------------------------
p Name Min Value Max Fit? Prior Type mu sigma
_ _____________________ ___ _____ ___ _____ __________ ___ _____
1 "Substrate Roughness" 1 3 10 true "uniform" 0 Inf
2 "Oxide thick" 5 20 60 true "uniform" 0 Inf
3 "Oxide Hydration" 0 0.2 0.5 true "uniform" 0 Inf
4 "Lipid APM" 45 55 65 true "uniform" 0 Inf
5 "Head Hydration" 0 0.2 0.7 true "gaussian" 0.3 0.03
6 "Bilayer Hydration" 0 0.1 0.2 true "uniform" 0 Inf
7 "Bilayer Roughness" 2 4 8 true "uniform" 0 Inf
8 "Water Thickness" 0 2 10 true "uniform" 0 Inf
Bulk In: --------------------------------------------------------------------------------------------------
p Name Min Value Max Fit? Prior Type mu sigma
_ _________ ________ _________ ________ _____ __________ __ _____
1 "Silicon" 2.07e-06 2.073e-06 2.08e-06 false "uniform" 0 Inf
Bulk Out: -------------------------------------------------------------------------------------------------
p Name Min Value Max Fit? Prior Type mu sigma
_ _________ ______ _________ ________ _____ __________ __ _____
1 "SLD D2O" 5e-06 6.35e-06 6.35e-06 true "uniform" 0 Inf
2 "SLD SMW" 1e-06 2.073e-06 3e-06 true "uniform" 0 Inf
3 "SLD H2O" -6e-07 -5.6e-07 -3e-07 true "uniform" 0 Inf
Scalefactors: -------------------------------------------------------------------------------------------------
p Name Min Value Max Fit? Prior Type mu sigma
_ _______________ ___ _____ ___ _____ __________ __ _____
1 "Scalefactor 1" 0.5 1 2 true "uniform" 0 Inf
Backgrounds: -----------------------------------------------------------------------------------------------
(a) Background Parameters:
p Name Min Value Max Fit? Prior Type mu sigma
_ _______________ _____ _____ _____ _____ __________ __ _____
1 "Backs par D2O" 1e-10 1e-06 1e-05 true "uniform" 0 Inf
2 "Backs par SMW" 1e-10 1e-06 1e-05 true "uniform" 0 Inf
3 "Backs par H2O" 1e-10 1e-06 1e-05 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 par D2O" "" "" "" "" ""
2 "Background SMW" "constant" "Backs par SMW" "" "" "" "" ""
3 "Background H2O" "constant" "Backs par H2O" "" "" "" "" ""
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" "" "" "" "" ""
2 "Data Resolution" "data" "" "" "" "" "" ""
Custom Files: ------------------------------------------------------------------------------------------------------
Name Filename Function Name Language Path
____________ _____________________ _____________ ________ ________________________________________________________
"DSPC Model" "customBilayerDSPC.m" "-" "matlab" "...T-Docs/API/examples/normalReflectivity/customLayers"
Data: ------------------------------------------------------------------------------------------------------
Name Data Data Range Simulation Range
_______________ _______________________ _____________________ _____________________
"Simulation" "No Data" "-" "[ 0.0050 , 0.7000 ]"
"Bilayer / D2O" "Data array: [146 x 4]" "[ 0.0130 , 0.3700 ]" "[ 0.0057 , 0.3961 ]"
"Bilayer / SMW" "Data array: [97 x 4]" "[ 0.0130 , 0.3300 ]" "[ 0.0076 , 0.3300 ]"
"Bilayer / H2O" "Data array: [104 x 4]" "[ 0.0130 , 0.3305 ]" "[ 0.0063 , 0.3305 ]"
Contrasts: -----------------------------------------------------------------------------------------------
p 1 2 3
___________________ _________________ _________________ _________________
"Name" "Bilayer / D2O" "Bilayer / SMW" "Bilayer / H2O"
"Data" "Bilayer / D2O" "Bilayer / SMW" "Bilayer / H2O"
"Background" "Background D2O" "Background SMW" "Background H2O"
"Background Action" "add" "add" "add"
"Bulk in" "Silicon" "Silicon" "Silicon"
"Bulk out" "SLD D2O" "SLD SMW" "SLD H2O"
"Scalefactor" "Scalefactor 1" "Scalefactor 1" "Scalefactor 1"
"Resolution" "Data Resolution" "Data Resolution" "Data Resolution"
"Resample" "false" "false" "false"
"Model" "DSPC Model" "DSPC Model" "DSPC Model"
To run it, we need to make a controls block....
controls = controlsClass()
controls =
controlsClass with properties:
parallel: 'single'
procedure: 'calculate'
calcSldDuringFit: 0
display: 'iter'
resampleMinAngle: 0.9000
resampleNPoints: 50
And send this to RAT...
[problem,results] = RAT(problem,controls);
Starting RAT ________________________________________________________________________________________________
Elapsed time is 0.026932 seconds.
Finished RAT ______________________________________________________________________________________________
plotRefSLD(problem,results);
Our guess values were not too bad here. We can proceed directly to the Bayesian Analysis.....
controls.procedure = 'dream';
Warning: Negative data ignored
controls.nSamples = 25000;
controls.parallel = 'contrasts';
controls.adaptPCR = true
controls =
controlsClass with properties:
parallel: 'contrasts'
procedure: 'dream'
calcSldDuringFit: 0
display: 'iter'
resampleMinAngle: 0.9000
resampleNPoints: 50
nSamples: 25000
nChains: 10
jumpProbability: 0.5000
pUnitGamma: 0.2000
boundHandling: 'reflect'
adaptPCR: 1
Send this to RAT....
[problem,results] = RAT(problem,controls);
Starting RAT ________________________________________________________________________________________________
Running DREAM
------------------ Summary of the main settings used ------------------
nParams: 15
nChains: 10
nGenerations: 2500
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.0% [........................................]
Warning: Negative data ignored
DREAM: 100.0% [****************************************]
Elapsed time is 67.651504 seconds.
Finished RAT ______________________________________________________________________________________________
Now plot our the results....
bayesShadedPlot(problem, results,'KeepAxes',true,'interval',65,'q4',false);
plotHists(results,'figure',h2,'smooth',true);
h3 = figure
h3 =
Figure (10) with properties:
Number: 10
Name: ''
Color: [0.9400 0.9400 0.9400]
Position: [220 120 583 437]
Units: 'pixels'
Use GET to show all properties
h4 = figure
h4 =
Figure (11) with properties:
Number: 11
Name: ''
Color: [0.9400 0.9400 0.9400]
Position: [220 120 583 437]
Units: 'pixels'
Use GET to show all properties
cornerPlot(results,'figure',h4,'smooth',false);
Warning: Negative data ignored
...and we're done.