Skip to content
Snippets Groups Projects
Select Git revision
  • 6e6051e44f80a3e155da16c611280e44b158d611
  • master default protected
  • github/fork/hrani/master
  • github/fork/dilawar/master
  • chamcham
  • chhennapoda
  • wheel
  • 3.2.0-pre0
  • v3.1.3
  • 3.1.2
  • 3.1.1
  • chamcham-3.1.1
  • 3.1.0
  • ghevar_3.0.2_pre2
  • ghevar_3.0.2
15 results

API.txt

Blame
  • cable_cell_io.cpp 3.94 KiB
    #include <pybind11/pybind11.h>
    #include <pybind11/stl.h>
    
    #include <fstream>
    #include <iomanip>
    
    #include <arbor/cable_cell.hpp>
    
    #include <arborio/cableio.hpp>
    
    #include "error.hpp"
    #include "strprintf.hpp"
    
    namespace pyarb {
    
    arborio::cable_cell_component load_component(const std::string& fname) {
        std::ifstream fid{fname};
        if (!fid.good()) {
            throw pyarb_error("Can't open file '{}'" + fname);
        }
        auto component = arborio::parse_component(fid);
        if (!component) {
            throw pyarb_error("Error while trying to load component from \"" + fname + "\": " + component.error().what());
        }
        return component.value();
    };
    
    template<typename T>
    void write_component(const T& component, const std::string& fname) {
        std::ofstream fid(fname);
        arborio::write_component(fid, component, arborio::meta_data{});
    }
    
    void write_component(const arborio::cable_cell_component& component, const std::string& fname) {
        std::ofstream fid(fname);
        arborio::write_component(fid, component);
    }
    
    void register_cable_loader(pybind11::module& m) {
        m.def("load_component",
              &load_component,
              pybind11::arg_v("filename", "the name of the file."),
              "Load arbor-component (decor, morphology, label_dict, cable_cell) from file.");
    
        m.def("write_component",
              [](const arborio::cable_cell_component& d, const std::string& fname) {
                return write_component(d, fname);
              },
              pybind11::arg_v("object", "the cable_component object."),
              pybind11::arg_v("filename", "the name of the file."),
              "Write cable_component to file.");
    
        m.def("write_component",
              [](const arb::decor& d, const std::string& fname) {
                return write_component<arb::decor>(d, fname);
              },
              pybind11::arg_v("object", "the decor object."),
              pybind11::arg_v("filename", "the name of the file."),
              "Write decor to file.");
    
        m.def("write_component",
              [](const arb::label_dict& d, const std::string& fname) {
                return write_component<arb::label_dict>(d, fname);
              },
              pybind11::arg_v("object", "the label_dict object."),
              pybind11::arg_v("filename", "the name of the file."),
              "Write label_dict to file.");
    
        m.def("write_component",
              [](const arb::morphology& d, const std::string& fname) {