Skip to content

Commit

Permalink
reinstall missing morph bindings.
Browse files Browse the repository at this point in the history
  • Loading branch information
thorstenhater committed Mar 5, 2024
1 parent ca7a7a6 commit 6a61a5f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 35 additions & 1 deletion python/morphology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ void register_morphology(py::module& m) {
.def("__repr__",
[](const arb::mpoint& p) {return util::pprintf("{}", p);});

py::implicitly_convertible<std::tuple<double, double, double, double>, arb::mpoint>();
py::implicitly_convertible<const std::tuple<double, double, double, double>&, arb::mpoint>();
py::implicitly_convertible<py::tuple, arb::mpoint>();

// arb::msegment
msegment
Expand Down Expand Up @@ -294,6 +295,39 @@ void register_morphology(py::module& m) {
.def("__str__", [](const arb::segment_tree& s) {
return util::pprintf("<arbor.segment_tree:\n{}>", 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("<arbor.morphology:\n{}>", m);
});

py::implicitly_convertible<arb::segment_tree, arb::morphology>();

// 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",
Expand Down
2 changes: 2 additions & 0 deletions python/pyarb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <arbor/version.hpp>

#include "pyarb.hpp"
#include "arbor/morph/primitives.hpp"

// Forward declarations of functions used to register API
// types and functions to be exposed to Python.
Expand Down Expand Up @@ -96,6 +97,7 @@ PYBIND11_MODULE(_arbor, m) {
pybind11::register_exception<arb::file_not_found_error>(m, "ArbFileNotFoundError", PyExc_FileNotFoundError);
pybind11::register_exception<arb::zero_thread_requested_error>(m, "ArbValueError", PyExc_ValueError);

pybind11::implicitly_convertible<const std::tuple<double, double, double, double>&, arb::mpoint>();

#ifdef ARB_MPI_ENABLED
pyarb::register_mpi(m);
Expand Down

0 comments on commit 6a61a5f

Please sign in to comment.