From 6a61a5fadaa7387ecbe7c64320c25808bdc6dfef Mon Sep 17 00:00:00 2001 From: Thorsten Hater <24411438+thorstenhater@users.noreply.github.com> Date: Tue, 5 Mar 2024 09:53:28 +0100 Subject: [PATCH] reinstall missing morph bindings. --- python/morphology.cpp | 36 +++++++++++++++++++++++++++++++++++- python/pyarb.cpp | 2 ++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/python/morphology.cpp b/python/morphology.cpp index 117515f065..1a3c305e48 100644 --- a/python/morphology.cpp +++ b/python/morphology.cpp @@ -111,7 +111,8 @@ void register_morphology(py::module& m) { .def("__repr__", [](const arb::mpoint& p) {return util::pprintf("{}", p);}); - py::implicitly_convertible, arb::mpoint>(); + py::implicitly_convertible&, arb::mpoint>(); + py::implicitly_convertible(); // arb::msegment msegment @@ -294,6 +295,39 @@ void register_morphology(py::module& m) { .def("__str__", [](const arb::segment_tree& s) { return util::pprintf("", s);}); + // arb::morphology + morph + // constructors + .def(py::init( + [](arb::segment_tree t){ + return arb::morphology(std::move(t)); + })) + // morphology's interface is read-only by design, so most of it can + // be implemented as read-only properties. + .def_property_readonly("empty", + [](const arb::morphology& m){return m.empty();}, + "Whether the morphology is empty.") + .def_property_readonly("num_branches", + [](const arb::morphology& m){return m.num_branches();}, + "The number of branches in the morphology.") + .def("branch_parent", &arb::morphology::branch_parent, + "i"_a, "The parent branch of branch i.") + .def("branch_children", &arb::morphology::branch_children, + "i"_a, "The child branches of branch i.") + .def("branch_segments", + [](const arb::morphology& m, arb::msize_t i) { + return m.branch_segments(i); + }, + "i"_a, "A list of the segments in branch i, ordered from proximal to distal ends of the branch.") + .def("to_segment_tree", &arb::morphology::to_segment_tree, + "Convert this morphology to a segment_tree.") + .def("__str__", + [](const arb::morphology& m) { + return util::pprintf("", m); + }); + + py::implicitly_convertible(); + // Function that creates a morphology/segment_tree from an swc file. // Wraps calls to C++ functions arborio::parse_swc() and arborio::load_swc_arbor(). m.def("load_swc_arbor", diff --git a/python/pyarb.cpp b/python/pyarb.cpp index a835da7963..7f77d673a2 100644 --- a/python/pyarb.cpp +++ b/python/pyarb.cpp @@ -9,6 +9,7 @@ #include #include "pyarb.hpp" +#include "arbor/morph/primitives.hpp" // Forward declarations of functions used to register API // types and functions to be exposed to Python. @@ -96,6 +97,7 @@ PYBIND11_MODULE(_arbor, m) { pybind11::register_exception(m, "ArbFileNotFoundError", PyExc_FileNotFoundError); pybind11::register_exception(m, "ArbValueError", PyExc_ValueError); + pybind11::implicitly_convertible&, arb::mpoint>(); #ifdef ARB_MPI_ENABLED pyarb::register_mpi(m);