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
82 changes: 82 additions & 0 deletions examples/tutorialFiles/twoContrastExample.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
% Full Example
problem = projectClass('DSPC monolayers');% Define the parameters:
Parameters = {
% Name min val max fit?
{'Tails Thickness', 10, 20, 30, true};
{'Heads Thickness', 3, 11, 16, true};
{'Tails Roughness', 2, 5, 9, true};
{'Heads Roughness', 2, 5, 9, true};
{'Deuterated Tails SLD', 4e-6, 6e-6, 2e-5, true};
{'Hydrogenated Tails SLD', -0.6e-6, -0.4e-6, 0, true};
{'Deuterated Heads SLD', 1e-6, 3e-6, 8e-6, true};
{'Hydrogenated Heads SLD', 0.1e-6, 1.4e-6, 3e-6, true};
{'Heads Hydration', 0, 0.3, 0.5, true};
};

problem.addParameterGroup(Parameters);
H_Heads = {'Hydrogenated Heads',...
'Heads Thickness',...
'Hydrogenated Heads SLD',...
'Heads Roughness',...
'Heads Hydration',...
'bulk out' };

D_Heads = {'Deuterated Heads',...
'Heads Thickness',...
'Deuterated Heads SLD',...
'Heads Roughness',...
'Heads Hydration',...
'bulk out' };

D_Tails = {'Deuterated Tails',...
'Tails Thickness',...
'Deuterated Tails SLD',...
'Tails Roughness'};

H_Tails = {'Hydrogenated Tails',...
'Tails Thickness',...
'Hydrogenated Tails SLD',...
'Tails Roughness'};

problem.addLayerGroup({H_Heads; D_Heads; H_Tails; D_Tails});
problem.setBackgroundParamName(1, 'Backs Value ACMW'); % Use existing backsPar
problem.setBackgroundParamValue(1, 5.5e-6);
problem.addBackgroundParam('Backs Value D2O', 1e-8, 2.8e-6, 1e-5);
problem.addBackground('Background D2O', 'constant', 'Backs Value D2O');
problem.setBackground(1, 'name', 'Background ACMW', 'source', 'Backs Value ACMW');
problem.addBulkOut('SLD ACMW', -1e-6, 0.0, 1e-6, true);

root = getappdata(0, 'root');
dataPath = '/examples/miscellaneous/convertRascal1Project/';
d13ACM = readmatrix(fullfile(root, dataPath, 'd13acmw20.dat'));
d70d2O = readmatrix(fullfile(root, dataPath, 'd70d2o20.dat'));
problem.addData('H-tail / D-head / ACMW', d13ACM);
problem.addData('D-tail / H-head / D2O', d70d2O);

problem.addContrast('name', 'D-tail/H-Head/D2O',...
'background', 'Background D2O',...
'resolution', 'Resolution 1',...
'scalefactor', 'Scalefactor 1',...
'BulkOut', 'SLD D2O',...
'BulkIn', 'SLD Air',...
'data', 'D-tail / H-head / D2O');

problem.addContrast('name', 'H-tail/D-Head/ACMW',...
'background', 'Background ACMW',...
'resolution', 'Resolution 1',...
'scalefactor', 'Scalefactor 1',...
'BulkOut', 'SLD ACMW',...
'BulkIn', 'SLD Air',...
'data', 'H-tail / D-head / ACMW');
problem.setContrastModel(1, {'Deuterated Tails','Hydrogenated Heads'});
problem.setContrastModel(2, {'Hydrogenated Tails','Deuterated Heads'});

problem.setBackgroundParam(1,'fit', true);
problem.setBackgroundParam(2,'fit', true);
problem.setScalefactor(1,'fit', true);
problem.setBulkOut(1,'fit', true);

%% Save problem
[path, ~, ~] = fileparts(mfilename("fullpath"));
save([path filesep 'twoContrastExample.mat'], 'problem');

Binary file modified examples/tutorialFiles/twoContrastExample.mat
Binary file not shown.
17 changes: 15 additions & 2 deletions tests/testExamples.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
['miscellaneous' filesep 'backgroundTypes'],...
['miscellaneous' filesep 'bayesBenchmark'],...
['miscellaneous' filesep 'roundRobin'],...
['miscellaneous' filesep 'convertRascal1Project']};
['miscellaneous' filesep 'convertRascal1Project'],...
'tutorialFiles'};
exampleLiveScriptFile = {'domainsStandardLayersSheet', 'domainsCustomLayersSheet',...
'domainsCustomXYSheet', 'bayesBenchmark', 'convertRascal'}
'domainsCustomXYSheet', 'bayesBenchmark', 'convertRascal'};
tutorialFiles = {'twoContrastExample'};
% exampleLiveScriptFile = {'domainsStandardLayersSheet', 'domainsCustomLayerSheet', 'domainsCustomXYSheet',...
% 'customLayersDSPCSheet', 'standardLayersDSPCSheet', 'customXYDSPCSheet',...
% 'roundRobin', 'bayesBenchmark', 'convertRascal'}
Expand Down Expand Up @@ -140,6 +142,17 @@ function testLiveScriptExamples(testCase, exampleLiveScriptFile)
close all;
end

function testTutorialFiles(testCase, tutorialFiles)
% runs the example live script file
testExamples.setupCurrentDir(testCase, tutorialFiles)
problem1 = load('twoContrastExample.mat');
problem1 = problem1.problem;
evalc(tutorialFiles);
problem2 = load('twoContrastExample.mat');
problem2 = problem2.problem;
testCase.verifyEqual(problem1, problem2, 'twoContrastExample.mat is not correctly updated. Update the mat file by manually running twoContrastExample.m');
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if this test fails after the evalc, and is then re-run. Presumerably, the problem saved to twoContrastExample.mat is incorrect and the test will always fail?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original 'twoContrastExample.mat' is never changed as the test is run in a temp directory


function testWriteScript(testCase, exampleScriptFile)
% Test that a the example projectClass objects can be written
% to a script that can regenerate the object
Expand Down