-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbase.py
More file actions
100 lines (83 loc) · 2.75 KB
/
Copy pathbase.py
File metadata and controls
100 lines (83 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# SPDX-FileCopyrightText: 2025 EasyScience contributors <https://github.com/easyscience>
# SPDX-License-Identifier: BSD-3-Clause
"""Abstract base API for diffraction calculation backends."""
from __future__ import annotations
from abc import ABC
from abc import abstractmethod
from dataclasses import dataclass
from typing import TYPE_CHECKING
if TYPE_CHECKING:
import numpy as np
from easydiffraction.datablocks.experiment.item.base import ExperimentBase
from easydiffraction.datablocks.structure.collection import Structures
from easydiffraction.datablocks.structure.item.base import Structure
@dataclass(frozen=True)
class PowderReflnRecord:
"""Calculated powder reflection metadata for one reflection row."""
phase_id: str
d_spacing: float
sin_theta_over_lambda: float
index_h: int
index_k: int
index_l: int
f_calc: float
f_squared_calc: float
two_theta: float | None = None
time_of_flight: float | None = None
class CalculatorBase(ABC):
"""Base API for diffraction calculation engines."""
@property
@abstractmethod
def name(self) -> str:
"""Short identifier of the calculation engine."""
@property
@abstractmethod
def engine_imported(self) -> bool:
"""True if the underlying calculation library is available."""
@abstractmethod
def calculate_structure_factors(
self,
structure: Structure,
experiment: ExperimentBase,
*,
called_by_minimizer: bool,
) -> None:
"""Calculate structure factors for one experiment."""
@abstractmethod
def calculate_pattern(
self,
structure: Structures, # TODO: Structure?
experiment: ExperimentBase,
*,
called_by_minimizer: bool,
) -> np.ndarray:
"""
Calculate diffraction pattern for one structure-experiment pair.
Parameters
----------
structure : Structures
The structure object.
experiment : ExperimentBase
The experiment object.
called_by_minimizer : bool
Whether the calculation is called by a minimizer. Default is
False.
Returns
-------
np.ndarray
The calculated diffraction pattern as a NumPy array.
"""
def last_powder_refln_records(
self,
structure: Structure,
experiment: ExperimentBase,
*,
phase_id: str,
) -> list[PowderReflnRecord] | None:
"""
Return the last powder reflection records for one phase.
Backends that do not expose powder reflection metadata return
``None`` so callers can clear stale reflection rows and warn.
"""
del self, structure, experiment, phase_id
return None