refactor(python/composition): updated python comp bindings to use register model
This commit is contained in:
@@ -7,6 +7,8 @@
|
|||||||
#include "composition.h"
|
#include "composition.h"
|
||||||
#include "atomicSpecies.h"
|
#include "atomicSpecies.h"
|
||||||
|
|
||||||
|
#include "bindings.h"
|
||||||
|
|
||||||
namespace py = pybind11;
|
namespace py = pybind11;
|
||||||
|
|
||||||
std::string sv_to_string(std::string_view sv) {
|
std::string sv_to_string(std::string_view sv) {
|
||||||
@@ -19,12 +21,8 @@ std::string get_ostream_str(const composition::Composition& comp) {
|
|||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
PYBIND11_MODULE(fourdsse_bindings, m) { // Module name must match meson.build
|
|
||||||
m.doc() = "Python bindings for the 4DSSE project"; // Optional module docstring
|
|
||||||
|
|
||||||
auto comp_submodule = m.def_submodule("composition", "Bindings for the Composition module");
|
|
||||||
auto chem_submodule = m.def_submodule("species", "Bindings for the Chemical Species module");
|
|
||||||
|
|
||||||
|
void register_comp_bindings(pybind11::module &comp_submodule) {
|
||||||
// --- Bindings for composition and species module ---
|
// --- Bindings for composition and species module ---
|
||||||
py::class_<composition::GlobalComposition>(comp_submodule, "GlobalComposition")
|
py::class_<composition::GlobalComposition>(comp_submodule, "GlobalComposition")
|
||||||
.def_readonly("specificNumberDensity", &composition::GlobalComposition::specificNumberDensity)
|
.def_readonly("specificNumberDensity", &composition::GlobalComposition::specificNumberDensity)
|
||||||
@@ -135,28 +133,31 @@ PYBIND11_MODULE(fourdsse_bindings, m) { // Module name must match meson.build
|
|||||||
return get_ostream_str(comp); // Use helper for C++ operator<<
|
return get_ostream_str(comp); // Use helper for C++ operator<<
|
||||||
});
|
});
|
||||||
|
|
||||||
// --- Bindings for species module ---
|
|
||||||
py::class_<chemSpecies::Species>(chem_submodule, "Species")
|
|
||||||
.def("mass", &chemSpecies::Species::mass, "Get atomic mass (amu)")
|
|
||||||
.def("massUnc", &chemSpecies::Species::massUnc, "Get atomic mass uncertainty (amu)")
|
|
||||||
.def("bindingEnergy", &chemSpecies::Species::bindingEnergy, "Get binding energy (keV/nucleon?)") // Check units
|
|
||||||
.def("betaDecayEnergy", &chemSpecies::Species::betaDecayEnergy, "Get beta decay energy (keV?)") // Check units
|
|
||||||
.def("betaCode", [](const chemSpecies::Species& s){ return sv_to_string(s.betaCode()); }, "Get beta decay code") // Convert string_view
|
|
||||||
.def("name", [](const chemSpecies::Species& s){ return sv_to_string(s.name()); }, "Get species name (e.g., 'H-1')") // Convert string_view
|
|
||||||
.def("el", [](const chemSpecies::Species& s){ return sv_to_string(s.el()); }, "Get element symbol (e.g., 'H')") // Convert string_view
|
|
||||||
.def("nz", &chemSpecies::Species::nz, "Get NZ value")
|
|
||||||
.def("n", &chemSpecies::Species::n, "Get neutron number N")
|
|
||||||
.def("z", &chemSpecies::Species::z, "Get proton number Z")
|
|
||||||
.def("a", &chemSpecies::Species::a, "Get mass number A")
|
|
||||||
|
|
||||||
.def("__repr__",
|
|
||||||
[](const chemSpecies::Species &s) {
|
|
||||||
std::ostringstream oss;
|
|
||||||
oss << s;
|
|
||||||
return oss.str();
|
|
||||||
});
|
|
||||||
|
|
||||||
chem_submodule.attr("species") = py::cast(chemSpecies::species); // Expose the species map
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void register_species_bindings(pybind11::module &chem_submodule) {
|
||||||
|
// --- Bindings for species module ---
|
||||||
|
py::class_<chemSpecies::Species>(chem_submodule, "Species")
|
||||||
|
.def("mass", &chemSpecies::Species::mass, "Get atomic mass (amu)")
|
||||||
|
.def("massUnc", &chemSpecies::Species::massUnc, "Get atomic mass uncertainty (amu)")
|
||||||
|
.def("bindingEnergy", &chemSpecies::Species::bindingEnergy, "Get binding energy (keV/nucleon?)") // Check units
|
||||||
|
.def("betaDecayEnergy", &chemSpecies::Species::betaDecayEnergy, "Get beta decay energy (keV?)") // Check units
|
||||||
|
.def("betaCode", [](const chemSpecies::Species& s){ return sv_to_string(s.betaCode()); }, "Get beta decay code") // Convert string_view
|
||||||
|
.def("name", [](const chemSpecies::Species& s){ return sv_to_string(s.name()); }, "Get species name (e.g., 'H-1')") // Convert string_view
|
||||||
|
.def("el", [](const chemSpecies::Species& s){ return sv_to_string(s.el()); }, "Get element symbol (e.g., 'H')") // Convert string_view
|
||||||
|
.def("nz", &chemSpecies::Species::nz, "Get NZ value")
|
||||||
|
.def("n", &chemSpecies::Species::n, "Get neutron number N")
|
||||||
|
.def("z", &chemSpecies::Species::z, "Get proton number Z")
|
||||||
|
.def("a", &chemSpecies::Species::a, "Get mass number A")
|
||||||
|
|
||||||
|
.def("__repr__",
|
||||||
|
[](const chemSpecies::Species &s) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << s;
|
||||||
|
return oss.str();
|
||||||
|
});
|
||||||
|
|
||||||
|
chem_submodule.attr("species") = py::cast(chemSpecies::species); // Expose the species map
|
||||||
|
}
|
||||||
|
|||||||
6
src/python/composition/bindings.h
Normal file
6
src/python/composition/bindings.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <pybind11/pybind11.h>
|
||||||
|
|
||||||
|
void register_comp_bindings(pybind11::module &m);
|
||||||
|
void register_species_bindings(pybind11::module &m);
|
||||||
Reference in New Issue
Block a user