Skip to content
Open
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 cpp/RAT
21 changes: 12 additions & 9 deletions ratapi/examples/absorption/volume_thiol_bilayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def volume_thiol_bilayer(params, bulk_in, bulk_out, contrast):

The second output parameter should be the substrate roughness.
"""
# Note - The first contrast number is 1 (not 0) so be careful if you use
# this variable for array indexing.

subRough = params[0]
alloyThick = params[1]
alloySLDUp = params[2]
Expand Down Expand Up @@ -92,11 +95,11 @@ def volume_thiol_bilayer(params, bulk_in, bulk_out, contrast):

# Correct head SLD based on hydration
thiolHeadHydr = thiolHeadHydr / 100
sldHead = sldHead * (1 - thiolHeadHydr) + (thiolHeadHydr * bulk_out[contrast])
sldHead = sldHead * (1 - thiolHeadHydr) + (thiolHeadHydr * bulk_out[contrast - 1])

# Now correct both the SLDs for the coverage parameter
sldTail = (thiolCoverage * sldTail) + ((1 - thiolCoverage) * bulk_out[contrast])
sldHead = (thiolCoverage * sldHead) + ((1 - thiolCoverage) * bulk_out[contrast])
sldTail = (thiolCoverage * sldTail) + ((1 - thiolCoverage) * bulk_out[contrast - 1])
sldHead = (thiolCoverage * sldHead) + ((1 - thiolCoverage) * bulk_out[contrast - 1])

SAMTAILS = [thickTail, sldTail, 0, goldRough]
SAMHEAD = [thickHead, sldHead, 0, goldRough]
Expand All @@ -113,27 +116,27 @@ def volume_thiol_bilayer(params, bulk_in, bulk_out, contrast):
sldHead = sumbHead / vHead
thickHead = vHead / bilayerAPM
bilHeadHydr = bilHeadHydr / 100
sldHead = sldHead * (1 - bilHeadHydr) + (bilHeadHydr * bulk_out[contrast])
sldHead = sldHead * (1 - bilHeadHydr) + (bilHeadHydr * bulk_out[contrast - 1])

sldTail = sumbTail / vTail
thickTail = vTail / bilayerAPM

sldMe = sumbMe / vMe
thickMe = vMe / bilayerAPM

sldTail = (bilayerCoverage * sldTail) + ((1 - bilayerCoverage) * bulk_out[contrast])
sldHead = (bilayerCoverage * sldHead) + ((1 - bilayerCoverage) * bulk_out[contrast])
sldMe = (bilayerCoverage * sldMe) + ((1 - bilayerCoverage) * bulk_out[contrast])
sldTail = (bilayerCoverage * sldTail) + ((1 - bilayerCoverage) * bulk_out[contrast - 1])
sldHead = (bilayerCoverage * sldHead) + ((1 - bilayerCoverage) * bulk_out[contrast - 1])
sldMe = (bilayerCoverage * sldMe) + ((1 - bilayerCoverage) * bulk_out[contrast - 1])

BILTAILS = [thickTail, sldTail, 0, bilayerRough]
BILHEAD = [thickHead, sldHead, 0, bilayerRough]
BILME = [thickMe, sldMe, 0, bilayerRough]

BILAYER = [BILHEAD, BILTAILS, BILME, BILME, BILTAILS, BILHEAD]

CW = [cwThick, bulk_out[contrast], 0, bilayerRough]
CW = [cwThick, bulk_out[contrast - 1], 0, bilayerRough]

if contrast == 1 or contrast == 3:
if contrast == 2 or contrast == 4:
output = [alloyUp, gold, SAMTAILS, SAMHEAD, CW, *BILAYER]
else:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it worth changing this line to elif contrast == 1 or contrast == 3: to improve clarity?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Same with elsewhere in this PR.

output = [alloyDown, gold, SAMTAILS, SAMHEAD, CW, *BILAYER]
Expand Down
11 changes: 2 additions & 9 deletions ratapi/examples/bayes_benchmark/bayes_benchmark.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
"back_param = project.background_parameters[0]\n",
"background = np.linspace(back_param.min, back_param.max, 30)\n",
"\n",
"controls = RAT.Controls(procedure=\"calculate\", calcSldDuringFit=True, display=\"off\")\n",
"controls = RAT.Controls(procedure=\"calculate\", display=\"off\")\n",
"\n",
"# function to calculate exp(-chi_squared / 2) for a given pair of roughness/background values\n",
"def calculate_posterior(roughness_index: int, background_index: int) -> float:\n",
Expand Down Expand Up @@ -339,13 +339,6 @@
"fig.tight_layout()\n",
"fig.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -364,7 +357,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.10.16"
}
},
"nbformat": 4,
Expand Down
7 changes: 5 additions & 2 deletions ratapi/examples/convert_rascal_project/Model_IIb.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

def Model_IIb(params, bulk_in, bulk_out, contrast):
"""Calculate layer parameters for a monolayer volume model at two deuterations."""
# Note - The first contrast number is 1 (not 0) so be careful if you use
# this variable for array indexing. Same applies to the domain number.

# converted from matlab file Model_IIb.m

Roughness, APM, thickHead, theta = params
Expand Down Expand Up @@ -49,15 +52,15 @@ def Model_IIb(params, bulk_in, bulk_out, contrast):
vTail = 2 * (16 * vCH2) + 2 * (vCH3)

# make SLDs
thisMask = deut[contrast]
thisMask = deut[contrast - 1]

if thisMask[0] == 0:
thisWater = (H2O * 0.9249) + (D2O * 0.0871)
else:
thisWater = D2O

# Calculate mole fraction of D2O from the bulk SLD
d2o_molfr = (1 / D2O - H2O) * ((bulk_out[contrast] / 0.036182336306) - H2O)
d2o_molfr = (1 / D2O - H2O) * ((bulk_out[contrast - 1] / 0.036182336306) - H2O)
thisWater = (d2o_molfr * D2O) + ((1 - d2o_molfr) * H2O)

if thisMask[1] == 0:
Expand Down
5 changes: 4 additions & 1 deletion ratapi/examples/domains/alloy_domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ def alloy_domains(params, bulkIn, bulkOut, contrast, domain):
Simple custom model for testing incoherent summing.
Simple two layer of permalloy / gold, with up/down domains.
"""
# Note - The first contrast number is 1 (not 0) so be careful if you use
# this variable for array indexing. Same applies to the domain number.

# Split up the parameters
subRough = params[0]
alloyThick = params[1]
Expand All @@ -23,7 +26,7 @@ def alloy_domains(params, bulkIn, bulkOut, contrast, domain):
gold = [goldThick, goldSLD, goldRough]

# Make the model depending on which domain we are looking at
if domain == 0:
if domain == 1:
output = [alloyUp, gold]
else:
output = [alloyDn, gold]
Expand Down
7 changes: 5 additions & 2 deletions ratapi/examples/domains/domains_XY_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

def domains_XY_model(params, bulk_in, bulk_out, contrast, domain):
"""Calculate the SLD profile for a domains custom XY model."""
# Note - The first contrast number is 1 (not 0) so be careful if you use
# this variable for array indexing. Same applies to the domain number.

# Split up the parameters for convenience
subRough = params[0]
oxideThick = params[1]
Expand Down Expand Up @@ -37,13 +40,13 @@ def domains_XY_model(params, bulk_in, bulk_out, contrast, domain):
oxSLD = vfOxide * 3.41e-6

# Layer SLD depends on whether we are calculating the domain or not
if domain == 0:
if domain == 1:
laySLD = vfLayer * layerSLD
else:
laySLD = vfLayer * domainSLD

# ... and finally the water SLD.
waterSLD = vfWater * bulk_out[contrast]
waterSLD = vfWater * bulk_out[contrast - 1]

# Make the total SLD by just adding them all up
totalSLD = siSLD + oxSLD + laySLD + waterSLD
Expand Down
10 changes: 6 additions & 4 deletions ratapi/examples/languages/custom_bilayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ extern "C" {

LIB_EXPORT void custom_bilayer(std::vector<double>& params, std::vector<double>& bulkIn, std::vector<double>& bulkOut, int contrast, std::vector<double>& output, double* outputSize, double* rough)
{
// Note - The first contrast number is 1 (not 0) so be careful if you use
// this variable for array indexing.
double subRough = params[0];
double oxideThick = params[1];
double oxideHydration = params[2];
Expand Down Expand Up @@ -65,9 +67,9 @@ extern "C" {

// 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 @@ -77,7 +79,7 @@ extern "C" {

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

// Heads...
Expand Down
11 changes: 7 additions & 4 deletions ratapi/examples/languages/custom_bilayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

def custom_bilayer(params, bulk_in, bulk_out, contrast):
"""Calculate the layer parameters for a custom bilayer model."""
# Note - The first contrast number is 1 (not 0) so be careful if you use
# this variable for array indexing.

sub_rough = params[0]
oxide_thick = params[1]
oxide_hydration = params[2]
Expand Down Expand Up @@ -54,13 +57,13 @@ def custom_bilayer(params, bulk_in, bulk_out, contrast):
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)
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
Loading