use laddu_physics::math::{
BarrierKind, Sheet, blatt_weisskopf as rust_blatt_weisskopf,
blatt_weisskopf_custom as rust_blatt_weisskopf_custom, chew_mandelstam as rust_chew_mandelstam,
q as rust_q, rho as rust_rho, spherical_harmonic as rust_spherical_harmonic,
};
use pyo3::{prelude::*, types::PyAny};
use super::{
error::to_py_err,
expr::{PyExpr, extract_expr},
quantum::{extract_l, extract_projection},
};
#[pyclass(name = "Sheet", module = "laddu", frozen, skip_from_py_object)]
#[derive(Clone, Copy)]
pub struct PySheet {
inner: Sheet,
}
#[pymethods]
impl PySheet {
#[classattr]
#[pyo3(name = "PHYSICAL")]
fn physical() -> Self {
Self {
inner: Sheet::Physical,
}
}
#[classattr]
#[pyo3(name = "UNPHYSICAL")]
fn unphysical() -> Self {
Self {
inner: Sheet::Unphysical,
}
}
fn __repr__(&self) -> &'static str {
match self.inner {
Sheet::Physical => "Sheet.PHYSICAL",
Sheet::Unphysical => "Sheet.UNPHYSICAL",
}
}
}
#[pyclass(name = "BarrierKind", module = "laddu", frozen, skip_from_py_object)]
#[derive(Clone, Copy)]
pub struct PyBarrierKind {
inner: BarrierKind,
}
#[pymethods]
impl PyBarrierKind {
#[classattr]
#[pyo3(name = "FULL")]
fn full() -> Self {
Self {
inner: BarrierKind::Full,
}
}
#[classattr]
#[pyo3(name = "TENSOR")]
fn tensor() -> Self {
Self {
inner: BarrierKind::Tensor,
}
}
fn __repr__(&self) -> &'static str {
match self.inner {
BarrierKind::Full => "BarrierKind.FULL",
BarrierKind::Tensor => "BarrierKind.TENSOR",
}
}
}
#[pyfunction]
#[pyo3(signature = (
l: "L | J | S | int | float",
m: "M | int | float",
costheta: "Expr | int | float",
phi: "Expr | int | float"
))]
pub fn spherical_harmonic(
l: &Bound<'_, PyAny>,
m: &Bound<'_, PyAny>,
costheta: &Bound<'_, PyAny>,
phi: &Bound<'_, PyAny>,
) -> PyResult<PyExpr> {
rust_spherical_harmonic(
extract_l(l)?,
extract_projection(m)?,
extract_expr(costheta)?,
extract_expr(phi)?,
)
.map(PyExpr::from)
.map_err(to_py_err)
}
#[pyfunction]
#[pyo3(signature = (
s: "Expr | int | float",
mass1: "Expr | int | float",
mass2: "Expr | int | float",
*,
sheet=None
))]
pub fn q(
s: &Bound<'_, PyAny>,
mass1: &Bound<'_, PyAny>,
mass2: &Bound<'_, PyAny>,
sheet: Option<&PySheet>,
) -> PyResult<PyExpr> {
Ok(rust_q(
extract_expr(s)?,
extract_expr(mass1)?,
extract_expr(mass2)?,
sheet.map_or(Sheet::Physical, |sheet| sheet.inner),
)
.into())
}
#[pyfunction]
#[pyo3(signature = (
s: "Expr | int | float",
mass1: "Expr | int | float",
mass2: "Expr | int | float",
*,
sheet=None
))]
pub fn rho(
s: &Bound<'_, PyAny>,
mass1: &Bound<'_, PyAny>,
mass2: &Bound<'_, PyAny>,
sheet: Option<&PySheet>,
) -> PyResult<PyExpr> {
Ok(rust_rho(
extract_expr(s)?,
extract_expr(mass1)?,
extract_expr(mass2)?,
sheet.map_or(Sheet::Physical, |sheet| sheet.inner),
)
.into())
}
#[pyfunction]
#[pyo3(signature = (
s: "Expr | int | float",
mass1: "Expr | int | float",
mass2: "Expr | int | float"
))]
pub fn chew_mandelstam(
s: &Bound<'_, PyAny>,
mass1: &Bound<'_, PyAny>,
mass2: &Bound<'_, PyAny>,
) -> PyResult<PyExpr> {
Ok(rust_chew_mandelstam(extract_expr(s)?, extract_expr(mass1)?, extract_expr(mass2)?).into())
}
#[pyfunction]
#[pyo3(signature = (
q: "Expr | int | float",
l: "L | J | S | int | float",
kind
))]
pub fn blatt_weisskopf(
q: &Bound<'_, PyAny>,
l: &Bound<'_, PyAny>,
kind: &PyBarrierKind,
) -> PyResult<PyExpr> {
rust_blatt_weisskopf(extract_expr(q)?, extract_l(l)?, kind.inner)
.map(PyExpr::from)
.map_err(to_py_err)
}
#[pyfunction]
#[pyo3(signature = (
q: "Expr | int | float",
l: "L | J | S | int | float",
kind,
q_r
))]
pub fn blatt_weisskopf_custom(
q: &Bound<'_, PyAny>,
l: &Bound<'_, PyAny>,
kind: &PyBarrierKind,
q_r: f64,
) -> PyResult<PyExpr> {
rust_blatt_weisskopf_custom(extract_expr(q)?, extract_l(l)?, kind.inner, q_r)
.map(PyExpr::from)
.map_err(to_py_err)
}