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
4 changes: 2 additions & 2 deletions pixi.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ select = [
# Ignore specific rules globally
ignore = [
'COM812', # https://docs.astral.sh/ruff/rules/missing-trailing-comma/
# The following is replaced by 'D'/[tool.ruff.lint.pydocstyle] and [tool.pydoclint]
'DOC', # https://docs.astral.sh/ruff/rules/#pydoclint-doc
# The following is replaced by 'D'/[tool.ruff.lint.pydocstyle] and [tool.pydoclint] 'DOC', # https://docs.astral.sh/ruff/rules/#pydoclint-doc
# Disable, as [tool.format_docstring] split one-line docstrings into the canonical multi-line layout
'D200', # https://docs.astral.sh/ruff/rules/unnecessary-multiline-docstring/
]
Expand Down
10 changes: 10 additions & 0 deletions src/easydynamics/base_classes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# SPDX-FileCopyrightText: 2026 EasyScience contributors <https://github.com/easyscience>
# SPDX-License-Identifier: BSD-3-Clause

from easydynamics.base_classes.easydynamics_base import EasyDynamicsBase
from easydynamics.base_classes.easydynamics_modelbase import EasyDynamicsModelBase

__all__ = [
'EasyDynamicsModelBase',
'EasyDynamicsBase',
]
69 changes: 69 additions & 0 deletions src/easydynamics/base_classes/easydynamics_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# SPDX-FileCopyrightText: 2026 EasyScience contributors <https://github.com/easyscience>
# SPDX-License-Identifier: BSD-3-Clause

from easyscience.base_classes.new_base import NewBase


class EasyDynamicsBase(NewBase):
"""Base class for all EasyDynamics classes."""

def __init__(
self,
name: str | None = 'MyEasyDynamicsModel',
display_name: str | None = 'MyEasyDynamicsModel',
unique_name: str | None = None,
) -> None:
"""
Initialize the EasyDynamicsBase.

Parameters
----------
name : str | None, default='MyEasyDynamicsModel'
Name of the model.
display_name : str | None, default='MyEasyDynamicsModel'
Display name of the model.
unique_name : str | None, default=None
Unique name of the model. If None, a unique name will be generated.

Raises
------
TypeError
If name is not a string or None.
"""
super().__init__(display_name=display_name, unique_name=unique_name)

if name is not None and not isinstance(name, str):
raise TypeError('Name must be a string or None.')
self._name = name

@property
def name(self) -> str | None:
"""
Get the name of the model.

Returns
-------
str | None
The name of the model.
"""
return self._name

@name.setter
def name(self, name_str: str | None) -> None:
"""
Set the name of the model.

Parameters
----------
name_str : str | None
The new name to set.

Raises
------
TypeError
If name_str is not a string or None.
"""

if name_str is not None and not isinstance(name_str, str):
raise TypeError('Name must be a string or None.')
self._name = name_str
109 changes: 109 additions & 0 deletions src/easydynamics/base_classes/easydynamics_modelbase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# SPDX-FileCopyrightText: 2026 EasyScience contributors <https://github.com/easyscience>
# SPDX-License-Identifier: BSD-3-Clause

import scipp as sc
from easyscience.base_classes import ModelBase

from easydynamics.utils.utils import _validate_unit


class EasyDynamicsModelBase(ModelBase):
"""Base class for all EasyDynamics models."""

def __init__(
self,
unit: str | sc.Unit = 'meV',
name: str | None = 'MyEasyDynamicsModel',
display_name: str | None = 'MyEasyDynamicsModel',
unique_name: str | None = None,
) -> None:
"""
Initialize the EasyDynamicsModelBase.

Parameters
----------
unit : str | sc.Unit, default='meV'
Unit of the model.
name : str | None, default='MyEasyDynamicsModel'
Name of the model.
display_name : str | None, default='MyEasyDynamicsModel'
Display name of the model.
unique_name : str | None, default=None
Unique name of the model. If None, a unique name will be generated.

Raises
------
TypeError
If name is not a string or None.
"""
super().__init__(display_name=display_name, unique_name=unique_name)
self._unit = _validate_unit(unit)

if name is not None and not isinstance(name, str):
raise TypeError('Name must be a string or None.')
self._name = name

@property
def unit(self) -> str | sc.Unit | None:
"""
Get the unit of the model.

Returns
-------
str | sc.Unit | None
The unit of the model.
"""

return self._unit

@unit.setter
def unit(self, _unit_str: str) -> None:
"""
Unit is read-only and cannot be set directly.

Parameters
----------
_unit_str : str
The new unit to set (ignored).

Raises
------
AttributeError
Always raised to indicate that the unit is read-only.
"""
raise AttributeError(
f'Unit is read-only. Use convert_unit to change the unit between allowed types '
f'or create a new {self.__class__.__name__} with the desired unit.'
) # noqa: E501

@property
def name(self) -> str | None:
"""
Get the name of the model.

Returns
-------
str | None
The name of the model.
"""
return self._name

@name.setter
def name(self, name_str: str) -> None:
"""
Set the name of the model.

Parameters
----------
name_str : str
The new name to set.

Raises
------
TypeError
If name_str is not a string or None.
"""

if name_str is not None and not isinstance(name_str, str):
raise TypeError('Name must be a string or None.')
self._name = name_str
14 changes: 11 additions & 3 deletions src/easydynamics/convolution/analytical_convolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ class AnalyticalConvolution(ConvolutionBase):
def __init__(
self,
energy: np.ndarray | sc.Variable,
energy_unit: str | sc.Unit = 'meV',
unit: str | sc.Unit = 'meV',
sample_components: ComponentCollection | ModelComponent | None = None,
resolution_components: ComponentCollection | ModelComponent | None = None,
energy_offset: Numeric | Parameter = 0.0,
display_name: str | None = 'MyConvolution',
unique_name: str | None = None,
) -> None:
"""
Initialize an AnalyticalConvolution.
Expand All @@ -50,21 +52,27 @@ def __init__(
----------
energy : np.ndarray | sc.Variable
1D array of energy values where the convolution is evaluated.
energy_unit : str | sc.Unit, default='meV'
unit : str | sc.Unit, default='meV'
The unit of the energy.
sample_components : ComponentCollection | ModelComponent | None, default=None
The sample model to be convolved.
resolution_components : ComponentCollection | ModelComponent | None, default=None
The resolution model to convolve with.
energy_offset : Numeric | Parameter, default=0.0
An offset to shift the energy values by.
display_name : str | None, default='MyConvolution'
Display name of the model.
unique_name : str | None, default=None
Unique name of the model. If None, a unique name will be generated.
"""
super().__init__(
energy=energy,
energy_unit=energy_unit,
unit=unit,
sample_components=sample_components,
resolution_components=resolution_components,
energy_offset=energy_offset,
display_name=display_name,
unique_name=unique_name,
)

def convolution(
Expand Down
14 changes: 11 additions & 3 deletions src/easydynamics/convolution/convolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ def __init__(
extension_factor: Numeric | None = 0.2,
temperature: Parameter | Numeric | None = None,
temperature_unit: str | sc.Unit = 'K',
energy_unit: str | sc.Unit = 'meV',
unit: str | sc.Unit = 'meV',
normalize_detailed_balance: bool = True,
display_name: str | None = 'MyConvolution',
unique_name: str | None = None,
) -> None:
"""
Initialize the Convolution class.
Expand All @@ -80,10 +82,14 @@ def __init__(
The temperature to use for detailed balance correction.
temperature_unit : str | sc.Unit, default='K'
The unit of the temperature parameter.
energy_unit : str | sc.Unit, default='meV'
unit : str | sc.Unit, default='meV'
The unit of the energy.
normalize_detailed_balance : bool, default=True
Whether to normalize the detailed balance correction. Default is True.
display_name : str | None, default='MyConvolution'
Display name of the model.
unique_name : str | None, default=None
Unique name of the model. If None, a unique name will be generated.
"""

self._convolution_plan_is_valid = False
Expand All @@ -97,8 +103,10 @@ def __init__(
extension_factor=extension_factor,
temperature=temperature,
temperature_unit=temperature_unit,
energy_unit=energy_unit,
unit=unit,
normalize_detailed_balance=normalize_detailed_balance,
display_name=display_name,
unique_name=unique_name,
)

self._reactions_enabled = True
Expand Down
Loading
Loading