Skip to content

Commit

Permalink
Allows custom file model to accept pathlib.Path objects
Browse files Browse the repository at this point in the history
  • Loading branch information
DrPaulSharp committed Jun 20, 2024
1 parent c62bdc1 commit 082e3f1
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion RAT/examples/absorption/absorption.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@

# Add the custom file
problem.custom_files.append(name="DPPC absorption", filename="volume_thiol_bilayer.py", language="python",
path=str(pathlib.Path(__file__).parent.resolve()))
path=pathlib.Path(__file__).parent.resolve())

# Finally add the contrasts
problem.contrasts.append(name="D2O Down", data="D2O_dn", background="Background 1", bulk_in="Silicon",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

# Add the custom file
problem.custom_files.append(name="Domain Layer", filename="domains_XY_model.py", language="python",
path=str(pathlib.Path(__file__).parent.resolve()))
path=pathlib.Path(__file__).parent.resolve())

# Make contrasts
problem.contrasts.append(name="D2O", background="Background 1", resolution="Resolution 1", scalefactor="Scalefactor 1",
Expand Down
2 changes: 1 addition & 1 deletion RAT/examples/domains/domains_custom_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

# Add the custom file
problem.custom_files.append(name="Alloy domains", filename="alloy_domains.py", language="python",
path=str(pathlib.Path(__file__).parent.resolve()))
path=pathlib.Path(__file__).parent.resolve())

# Make a contrast
problem.contrasts.append(name="D2O Contrast", data="Simulation", background="Background 1", bulk_in="Silicon",
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions RAT/examples/languages/run_custom_file_languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import setup_problem
import time

path = pathlib.Path(__file__).parent.resolve()

project = setup_problem.make_example_problem()
controls = RAT.set_controls()

Expand All @@ -17,8 +19,7 @@
RAT.utils.plotting.plot_ref_sld(project, results)

# Matlab
project.custom_files.set_fields(0, filename='custom_bilayer.m', language='matlab',
path=str(pathlib.Path(__file__).parent.resolve()))
project.custom_files.set_fields(0, filename='custom_bilayer.m', language='matlab', path=path)

start = time.time()
project, results = RAT.run(project, controls)
Expand All @@ -28,8 +29,7 @@
RAT.utils.plotting.plot_ref_sld(project, results)

# C++
project.custom_files.set_fields(0, filename='custom_bilayer.dll', language='cpp',
path=str(pathlib.Path(__file__).parent.resolve()))
project.custom_files.set_fields(0, filename='custom_bilayer.dll', language='cpp', path=path)

start = time.time()
project, results = RAT.run(project, controls)
Expand Down
2 changes: 1 addition & 1 deletion RAT/examples/languages/setup_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def make_example_problem():

# Add the custom file to the project
problem.custom_files.append(name="DSPC Model", filename="custom_bilayer.py", language="python",
path=str(pathlib.Path(__file__).parent.resolve()))
path=pathlib.Path(__file__).parent.resolve())

# Also, add the relevant background parameters - one each for each contrast:
problem.background_parameters.set_fields(0, name="Background parameter D2O", fit=True, min=1.0e-10, max=1.0e-5,
Expand Down
2 changes: 1 addition & 1 deletion RAT/examples/non_polarised/DSPC_custom_XY.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@

# Add the custom file to the project
problem.custom_files.append(name="DSPC Model", filename="custom_XY_DSPC.py", language="python",
path=str(pathlib.Path(__file__).parent.resolve()))
path=pathlib.Path(__file__).parent.resolve())

# Also, add the relevant background parameters - one each for each contrast:
problem.background_parameters.set_fields(0, name="Background parameter D2O", fit=True, min=1.0e-10, max=1.0e-5,
Expand Down
2 changes: 1 addition & 1 deletion RAT/examples/non_polarised/DSPC_custom_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

# Add the custom file to the project
problem.custom_files.append(name="DSPC Model", filename="custom_bilayer_DSPC.py", language="python",
path=str(pathlib.Path(__file__).parent.resolve()))
path=pathlib.Path(__file__).parent.resolve())

# Also, add the relevant background parameters - one each for each contrast:
problem.background_parameters.set_fields(0, name="Background parameter D2O", fit=True, min=1.0e-10, max=1.0e-5, value=1.0e-07)
Expand Down
4 changes: 2 additions & 2 deletions RAT/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
from pydantic import BaseModel, Field, ValidationInfo, field_validator, model_validator
import pathlib
from typing import Any
from typing import Any, Union

from RAT.utils.enums import BackgroundActions, Hydration, Languages, Priors, TypeOptions

Expand Down Expand Up @@ -90,7 +90,7 @@ class CustomFile(RATModel):
filename: str = ''
function_name: str = ''
language: Languages = Languages.Python
path: str = ''
path: Union[str, pathlib.Path] = ''

def model_post_init(self, __context: Any) -> None:
"""If a "filename" is supplied but the "function_name" field is not set, the "function_name" should be set to
Expand Down

0 comments on commit 082e3f1

Please sign in to comment.