Skip to content
Draft
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ tmp/
# Build
_build
docs/.buildinfo
matlab.txt
docs/*.inv
*.rat.cpp
*.so
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include README.md
include README.md matlab.txt
recursive-include cpp *
prune tests
prune */__pycache__
Expand Down
29 changes: 29 additions & 0 deletions RATapi/examples/domains/alloyDomains.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

function [output,subRough] = alloyDomains(params,bulkIn,bulkOut,contrast,domain)

% Simple custom model for testing incoherent summing...
% Simple two layer of permalloy / gold, with up/down domains..

% Split up the parameters....
subRough = params(1);
alloyThick = params(2);
alloySLDup = params(3);
alloySLDdn = params(4);
alloyRough = params(5);
goldThick = params(6);
goldSLD = params(7);
goldRough = params(8);

% Make the layers....
alloyUp = [alloyThick, alloySLDup, alloyRough];
alloyDn = [alloyThick, alloySLDdn, alloyRough];
gold = [goldThick, goldSLD, goldRough];

% Make the model dependiong on which domain we are looking at..
if domain==1
output = [alloyUp ; gold];
else
output = [alloyDn ; gold];
end

end
4 changes: 2 additions & 2 deletions RATapi/examples/domains/domains_custom_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def domains_custom_layers():
# Add the custom file
problem.custom_files.append(
name="Alloy domains",
filename="alloy_domains.py",
language="python",
filename="alloyDomains.m",
language="matlab",
path=pathlib.Path(__file__).parent,
)

Expand Down
5 changes: 3 additions & 2 deletions RATapi/examples/normal_reflectivity/DSPC_custom_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy as np

import RATapi as RAT
import RATapi.wrappers


def DSPC_custom_layers():
Expand Down Expand Up @@ -50,8 +51,8 @@ def DSPC_custom_layers():
# Add the custom file to the project
problem.custom_files.append(
name="DSPC Model",
filename="custom_bilayer_DSPC.py",
language="python",
filename="customBilayerDSPC.m",
language="matlab",
path=pathlib.Path(__file__).parent,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ def DSPC_function_background():

problem.custom_files.append(
name="D2O Background Function",
filename="background_function.py",
language="python",
filename="backgroundFunction.m",
language="matlab",
path=pathlib.Path(__file__).parent,
)

Expand Down
14 changes: 14 additions & 0 deletions RATapi/examples/normal_reflectivity/backgroundFunction.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function background = backgroundFunction(xdata,params)

% Split up the params array....
Ao = params(1);
k = params(2);
backConst = params(3);

% Make an exponential decay background....
background = zeros(numel(xdata),1);
for i = 1:numel(xdata)
background(i) = Ao*exp(-k*xdata(i)) + backConst;
end

end
86 changes: 86 additions & 0 deletions RATapi/examples/normal_reflectivity/customBilayerDSPC.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
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];



5 changes: 2 additions & 3 deletions RATapi/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import numpy as np

import RATapi
import RATapi.controls
import RATapi.wrappers
from RATapi.rat_core import Checks, Control, NameStore, ProblemDefinition
from RATapi.utils.enums import Calculations, Languages, LayerModels, TypeOptions
Expand Down Expand Up @@ -81,9 +80,9 @@ def get_handle(self, index: int):
if custom_file["language"] == Languages.Python:
file_handle = get_python_handle(custom_file["filename"], custom_file["function_name"], custom_file["path"])
elif custom_file["language"] == Languages.Matlab:
file_handle = RATapi.wrappers.MatlabWrapper(full_path).getHandle()
file_handle = RATapi.wrappers.MatlabWrapper(full_path).get_handle()
elif custom_file["language"] == Languages.Cpp:
file_handle = RATapi.wrappers.DylibWrapper(full_path, custom_file["function_name"]).getHandle()
file_handle = RATapi.wrappers.DylibWrapper(full_path, custom_file["function_name"]).get_handle()

return file_handle

Expand Down
Loading