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
14 changes: 7 additions & 7 deletions .github/workflows/build_wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: true
matrix:
platform: [windows-latest, ubuntu-latest, macos-13, macos-14]
platform: [windows-2022, ubuntu-latest, macos-13, macos-14]
env:
CIBW_SKIP: 'pp*'
CIBW_ARCHS: 'auto64'
Expand All @@ -34,19 +34,19 @@ jobs:
- name: Install OMP (MacOS Intel)
if: matrix.platform == 'macos-13'
run: |
brew install llvm libomp
echo "export CC=/usr/local/opt/llvm/bin/clang" >> ~/.bashrc
echo "export CXX=/usr/local/opt/llvm/bin/clang++" >> ~/.bashrc
brew install llvm@20 libomp
echo "export CC=/usr/local/opt/llvm@20/bin/clang" >> ~/.bashrc
echo "export CXX=/usr/local/opt/llvm@20/bin/clang++" >> ~/.bashrc
echo "export CFLAGS=\"$CFLAGS -I/usr/local/opt/libomp/include\"" >> ~/.bashrc
echo "export CXXFLAGS=\"$CXXFLAGS -I/usr/local/opt/libomp/include\"" >> ~/.bashrc
echo "export LDFLAGS=\"$LDFLAGS -Wl,-rpath,/usr/local/opt/libomp/lib -L/usr/local/opt/libomp/lib -lomp\"" >> ~/.bashrc
source ~/.bashrc
- name: Install OMP (MacOS M1)
if: matrix.platform == 'macos-14'
run: |
brew install llvm libomp
echo "export CC=/opt/homebrew/opt/llvm/bin/clang" >> ~/.bashrc
echo "export CXX=/opt/homebrew/opt/llvm/bin/clang++" >> ~/.bashrc
brew install llvm@20 libomp
echo "export CC=/opt/homebrew/opt/llvm@20/bin/clang" >> ~/.bashrc
echo "export CXX=/opt/homebrew/opt/llvm@20/bin/clang++" >> ~/.bashrc
echo "export CFLAGS=\"$CFLAGS -I/opt/homebrew/opt/libomp/include\"" >> ~/.bashrc
echo "export CXXFLAGS=\"$CXXFLAGS -I/opt/homebrew/opt/libomp/include\"" >> ~/.bashrc
echo "export LDFLAGS=\"$LDFLAGS -Wl,-rpath,/opt/homebrew/opt/libomp/lib -L/opt/homebrew/opt/libomp/lib -lomp\"" >> ~/.bashrc
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
fail-fast: false
matrix:
platform: [windows-latest, ubuntu-latest, macos-13, macos-14]
platform: [windows-2022, ubuntu-latest, macos-13, macos-14]
version: ["3.10", "3.13"]
defaults:
run:
Expand All @@ -38,19 +38,19 @@ jobs:
- name: Install OMP (MacOS Intel)
if: matrix.platform == 'macos-13'
run: |
brew install llvm libomp
echo "export CC=/usr/local/opt/llvm/bin/clang" >> ~/.bashrc
echo "export CXX=/usr/local/opt/llvm/bin/clang++" >> ~/.bashrc
brew install llvm@20 libomp
echo "export CC=/usr/local/opt/llvm@20/bin/clang" >> ~/.bashrc
echo "export CXX=/usr/local/opt/llvm@20/bin/clang++" >> ~/.bashrc
echo "export CFLAGS=\"$CFLAGS -I/usr/local/opt/libomp/include\"" >> ~/.bashrc
echo "export CXXFLAGS=\"$CXXFLAGS -I/usr/local/opt/libomp/include\"" >> ~/.bashrc
echo "export LDFLAGS=\"$LDFLAGS -Wl,-rpath,/usr/local/opt/libomp/lib -L/usr/local/opt/libomp/lib -lomp\"" >> ~/.bashrc
source ~/.bashrc
- name: Install OMP (MacOS M1)
if: matrix.platform == 'macos-14'
run: |
brew install llvm libomp
echo "export CC=/opt/homebrew/opt/llvm/bin/clang" >> ~/.bashrc
echo "export CXX=/opt/homebrew/opt/llvm/bin/clang++" >> ~/.bashrc
brew install llvm@20 libomp
echo "export CC=/opt/homebrew/opt/llvm@20/bin/clang" >> ~/.bashrc
echo "export CXX=/opt/homebrew/opt/llvm@20/bin/clang++" >> ~/.bashrc
echo "export CFLAGS=\"$CFLAGS -I/opt/homebrew/opt/libomp/include\"" >> ~/.bashrc
echo "export CXXFLAGS=\"$CXXFLAGS -I/opt/homebrew/opt/libomp/include\"" >> ~/.bashrc
echo "export LDFLAGS=\"$LDFLAGS -Wl,-rpath,/opt/homebrew/opt/libomp/lib -L/opt/homebrew/opt/libomp/lib -lomp\"" >> ~/.bashrc
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ mark-parentheses = false
[tool.ruff.lint.pydocstyle]
convention = "numpy"


[tool.ruff.lint.isort]
known-first-party = ["ratapi.rat_core"]
13 changes: 5 additions & 8 deletions ratapi/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,19 +233,16 @@ def delete_IPC(self):
os.remove(self._IPCFilePath)
return None

def save(self, path: Union[str, Path], filename: str = "controls"):
def save(self, filepath: Union[str, Path] = "./controls.json"):
"""Save a controls object to a JSON file.

Parameters
----------
path : str or Path
The directory in which the controls object will be written.
filename : str
The name for the JSON file containing the controls object.

filepath : str or Path
The path to where the controls file will be written.
"""
file = Path(path, f"{filename.removesuffix('.json')}.json")
file.write_text(self.model_dump_json())
filepath = Path(filepath).with_suffix(".json")
filepath.write_text(self.model_dump_json())

@classmethod
def load(cls, path: Union[str, Path]) -> "Controls":
Expand Down
20 changes: 9 additions & 11 deletions ratapi/examples/domains/domains_XY_model.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Custom model file for the domains custom XY example."""

import math
from math import sqrt

import numpy as np
from scipy.special import erf


def domains_XY_model(params, bulk_in, bulk_out, contrast, domain):
Expand All @@ -19,13 +20,13 @@ def domains_XY_model(params, bulk_in, bulk_out, contrast, domain):
z = np.arange(0, 141)

# Make the volume fraction distribution for our Silicon substrate
[vfSilicon, siSurf] = makeLayer(z, -25, 50, 1, subRough, subRough)
[vfSilicon, siSurf] = make_layer(z, -25, 50, 1, subRough, subRough)

# ... and the Oxide ...
[vfOxide, oxSurface] = makeLayer(z, siSurf, oxideThick, 1, subRough, subRough)
[vfOxide, oxSurface] = make_layer(z, siSurf, oxideThick, 1, subRough, subRough)

# ... and also our layer.
[vfLayer, laySurface] = makeLayer(z, oxSurface, layerThick, 1, subRough, layerRough)
[vfLayer, laySurface] = make_layer(z, oxSurface, layerThick, 1, subRough, layerRough)

# Everything that is not already occupied will be filled will water
totalVF = vfSilicon + vfOxide + vfLayer
Expand Down Expand Up @@ -53,7 +54,7 @@ def domains_XY_model(params, bulk_in, bulk_out, contrast, domain):
return SLD, subRough


def makeLayer(z, prevLaySurf, thickness, height, Sigma_L, Sigma_R):
def make_layer(z, prevLaySurf, thickness, height, Sigma_L, Sigma_R):
"""Produce a layer, with a defined thickness, height and roughness.

Each side of the layer has its own roughness value.
Expand All @@ -63,12 +64,9 @@ def makeLayer(z, prevLaySurf, thickness, height, Sigma_L, Sigma_R):
right = prevLaySurf + thickness

# Make our heaviside
a = (z - left) / ((2**0.5) * Sigma_L)
b = (z - right) / ((2**0.5) * Sigma_R)
erf_left = erf((z - left) / (sqrt(2) * Sigma_L))
erf_right = erf((z - right) / (sqrt(2) * Sigma_R))

erf_a = np.array([math.erf(value) for value in a])
erf_b = np.array([math.erf(value) for value in b])

VF = np.array((height / 2) * (erf_a - erf_b))
VF = np.array((0.5 * height) * (erf_left - erf_right))

return VF, right
26 changes: 12 additions & 14 deletions ratapi/examples/normal_reflectivity/custom_XY_DSPC.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""A custom XY model for a supported DSPC bilayer."""

import math
from math import sqrt

import numpy as np
from scipy.special import erf


def custom_XY_DSPC(params, bulk_in, bulk_out, contrast):
Expand Down Expand Up @@ -51,10 +52,10 @@ def custom_XY_DSPC(params, bulk_in, bulk_out, contrast):
z = np.arange(0, 141)

# Make our Silicon substrate
vfSilicon, siSurf = layer(z, -25, 50, 1, subRough, subRough)
vfSilicon, siSurf = make_layer(z, -25, 50, 1, subRough, subRough)

# Add the Oxide
vfOxide, oxSurface = layer(z, siSurf, oxideThick, 1, subRough, subRough)
vfOxide, oxSurface = make_layer(z, siSurf, oxideThick, 1, subRough, subRough)

# We fill in the water at the end, but there may be a hydration layer between the bilayer and the oxide,
# so we start the bilayer stack an appropriate distance away
Expand All @@ -65,15 +66,15 @@ def custom_XY_DSPC(params, bulk_in, bulk_out, contrast):
headThick = vHead / lipidAPM

# ... and make a box for the volume fraction (1 for now, we correct for coverage later)
vfHeadL, headLSurface = layer(z, watSurface, headThick, 1, bilayerRough, bilayerRough)
vfHeadL, headLSurface = make_layer(z, watSurface, headThick, 1, bilayerRough, bilayerRough)

# ... also do the same for the tails
# We'll make both together, so the thickness will be twice the volume
tailsThick = (2 * vTail) / lipidAPM
vfTails, tailsSurf = layer(z, headLSurface, tailsThick, 1, bilayerRough, bilayerRough)
vfTails, tailsSurf = make_layer(z, headLSurface, tailsThick, 1, bilayerRough, bilayerRough)

# Finally the upper head ...
vfHeadR, headSurface = layer(z, tailsSurf, headThick, 1, bilayerRough, bilayerRough)
vfHeadR, headSurface = make_layer(z, tailsSurf, headThick, 1, bilayerRough, bilayerRough)

# Making the model
# We've created the volume fraction profiles corresponding to each of the groups.
Expand Down Expand Up @@ -114,12 +115,12 @@ def custom_XY_DSPC(params, bulk_in, bulk_out, contrast):
totSLD = sldSilicon + sldOxide + sldHeadL + sldTails + sldHeadR + sldWat

# Make the SLD array for output
SLD = [[a, b] for (a, b) in zip(z, totSLD)]
SLD = np.column_stack((z, totSLD))

return SLD, subRough


def layer(z, prevLaySurf, thickness, height, Sigma_L, Sigma_R):
def make_layer(z, prevLaySurf, thickness, height, Sigma_L, Sigma_R):
"""Produce a layer, with a defined thickness, height and roughness.

Each side of the layer has its own roughness value.
Expand All @@ -129,12 +130,9 @@ def layer(z, prevLaySurf, thickness, height, Sigma_L, Sigma_R):
right = prevLaySurf + thickness

# Make our heaviside
a = (z - left) / ((2**0.5) * Sigma_L)
b = (z - right) / ((2**0.5) * Sigma_R)
erf_left = erf((z - left) / (sqrt(2) * Sigma_L))
erf_right = erf((z - right) / (sqrt(2) * Sigma_R))

erf_a = np.array([math.erf(value) for value in a])
erf_b = np.array([math.erf(value) for value in b])

VF = np.array((height / 2) * (erf_a - erf_b))
VF = np.array((0.5 * height) * (erf_left - erf_right))

return VF, right
Loading
Loading