Unifies the contrast number used by python and cpp to be same with ma… · RascalSoftware/python-RAT@2bbfb41 · GitHub
Skip to content

Commit 2bbfb41

Browse files
committed
Unifies the contrast number used by python and cpp to be same with matlab
1 parent 69c5fef commit 2bbfb41

13 files changed

Lines changed: 200 additions & 172 deletions

File tree

ratapi/examples/absorption/volume_thiol_bilayer.py

Lines changed: 12 additions & 9 deletions

ratapi/examples/bayes_benchmark/bayes_benchmark.ipynb

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@
188188
"back_param = project.background_parameters[0]\n",
189189
"background = np.linspace(back_param.min, back_param.max, 30)\n",
190190
"\n",
191-
"controls = RAT.Controls(procedure=\"calculate\", calcSldDuringFit=True, display=\"off\")\n",
191+
"controls = RAT.Controls(procedure=\"calculate\", display=\"off\")\n",
192192
"\n",
193193
"# function to calculate exp(-chi_squared / 2) for a given pair of roughness/background values\n",
194194
"def calculate_posterior(roughness_index: int, background_index: int) -> float:\n",
@@ -339,13 +339,6 @@
339339
"fig.tight_layout()\n",
340340
"fig.show()"
341341
]
342-
},
343-
{
344-
"cell_type": "code",
345-
"execution_count": null,
346-
"metadata": {},
347-
"outputs": [],
348-
"source": []
349342
}
350343
],
351344
"metadata": {
@@ -364,7 +357,7 @@
364357
"name": "python",
365358
"nbconvert_exporter": "python",
366359
"pygments_lexer": "ipython3",
367-
"version": "3.10.12"
360+
"version": "3.10.16"
368361
}
369362
},
370363
"nbformat": 4,

ratapi/examples/convert_rascal_project/Model_IIb.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
def Model_IIb(params, bulk_in, bulk_out, contrast):
77
"""Calculate layer parameters for a monolayer volume model at two deuterations."""
8+
# Note - The first contrast number is 1 (not 0) so be careful if you use
9+
# this variable for array indexing. Same applies to the domain number.
10+
811
# converted from matlab file Model_IIb.m
912

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

5154
# make SLDs
52-
thisMask = deut[contrast]
55+
thisMask = deut[contrast - 1]
5356

5457
if thisMask[0] == 0:
5558
thisWater = (H2O * 0.9249) + (D2O * 0.0871)
5659
else:
5760
thisWater = D2O
5861

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

6366
if thisMask[1] == 0:

ratapi/examples/domains/alloy_domains.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ def alloy_domains(params, bulkIn, bulkOut, contrast, domain):
77
Simple custom model for testing incoherent summing.
88
Simple two layer of permalloy / gold, with up/down domains.
99
"""
10+
# Note - The first contrast number is 1 (not 0) so be careful if you use
11+
# this variable for array indexing. Same applies to the domain number.
12+
1013
# Split up the parameters
1114
subRough = params[0]
1215
alloyThick = params[1]
@@ -23,7 +26,7 @@ def alloy_domains(params, bulkIn, bulkOut, contrast, domain):
2326
gold = [goldThick, goldSLD, goldRough]
2427

2528
# Make the model depending on which domain we are looking at
26-
if domain == 0:
29+
if domain == 1:
2730
output = [alloyUp, gold]
2831
else:
2932
output = [alloyDn, gold]

ratapi/examples/domains/domains_XY_model.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
def domains_XY_model(params, bulk_in, bulk_out, contrast, domain):
1010
"""Calculate the SLD profile for a domains custom XY model."""
11+
# Note - The first contrast number is 1 (not 0) so be careful if you use
12+
# this variable for array indexing. Same applies to the domain number.
13+
1114
# Split up the parameters for convenience
1215
subRough = params[0]
1316
oxideThick = params[1]
@@ -37,13 +40,13 @@ def domains_XY_model(params, bulk_in, bulk_out, contrast, domain):
3740
oxSLD = vfOxide * 3.41e-6
3841

3942
# Layer SLD depends on whether we are calculating the domain or not
40-
if domain == 0:
43+
if domain == 1:
4144
laySLD = vfLayer * layerSLD
4245
else:
4346
laySLD = vfLayer * domainSLD
4447

4548
# ... and finally the water SLD.
46-
waterSLD = vfWater * bulk_out[contrast]
49+
waterSLD = vfWater * bulk_out[contrast - 1]
4750

4851
# Make the total SLD by just adding them all up
4952
totalSLD = siSLD + oxSLD + laySLD + waterSLD

ratapi/examples/languages/custom_bilayer.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ extern "C" {
1313

1414
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)
1515
{
16+
// Note - The first contrast number is 1 (not 0) so be careful if you use
17+
// this variable for array indexing.
1618
double subRough = params[0];
1719
double oxideThick = params[1];
1820
double oxideHydration = params[2];
@@ -65,9 +67,9 @@ extern "C" {
6567

6668
// Manually deal with hydration for layers in
6769
// this example.
68-
double oxSLD = (oxideHydration * bulkOut[contrast]) + ((1 - oxideHydration) * oxideSLD);
69-
double headSLD = (headHydration * bulkOut[contrast]) + ((1 - headHydration) * SLDhead);
70-
double tailSLD = (bilayerHydration * bulkOut[contrast]) + ((1 - bilayerHydration) * SLDtail);
70+
double oxSLD = (oxideHydration * bulkOut[contrast-1]) + ((1 - oxideHydration) * oxideSLD);
71+
double headSLD = (headHydration * bulkOut[contrast-1]) + ((1 - headHydration) * SLDhead);
72+
double tailSLD = (bilayerHydration * bulkOut[contrast-1]) + ((1 - bilayerHydration) * SLDtail);
7173

7274
// Make the layers
7375
// oxide...
@@ -77,7 +79,7 @@ extern "C" {
7779

7880
// Water...
7981
output.push_back(waterThick);
80-
output.push_back(bulkOut[contrast]);
82+
output.push_back(bulkOut[contrast-1]);
8183
output.push_back(bilayerRough);
8284

8385
// Heads...

ratapi/examples/languages/custom_bilayer.py

Lines changed: 7 additions & 4 deletions

0 commit comments

Comments
 (0)