123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- /******************************************************************************
- *
- * Copyright (C) 2021 by
- * The Salk Institute for Biological Studies
- *
- * Use of this source code is governed by an MIT-style
- * license that can be found in the LICENSE file or at
- * https://opensource.org/licenses/MIT.
- *
- ******************************************************************************/
- #include <sstream>
- #include "api/pybind11_stl_include.h"
- #include "api/python_export_utils.h"
- #include "gen_base_chkpt_mol.h"
- #include "api/base_chkpt_mol.h"
- #include "api/species.h"
- namespace MCell {
- namespace API {
- void GenBaseChkptMol::check_semantics() const {
- if (!is_set(id)) {
- throw ValueError("Parameter 'id' must be set.");
- }
- if (!is_set(species)) {
- throw ValueError("Parameter 'species' must be set.");
- }
- if (!is_set(diffusion_time)) {
- throw ValueError("Parameter 'diffusion_time' must be set.");
- }
- if (!is_set(birthday)) {
- throw ValueError("Parameter 'birthday' must be set.");
- }
- if (!is_set(flags)) {
- throw ValueError("Parameter 'flags' must be set.");
- }
- }
- void GenBaseChkptMol::set_initialized() {
- if (is_set(species)) {
- species->set_initialized();
- }
- initialized = true;
- }
- void GenBaseChkptMol::set_all_attributes_as_default_or_unset() {
- class_name = "BaseChkptMol";
- id = INT_UNSET;
- species = nullptr;
- diffusion_time = FLT_UNSET;
- birthday = FLT_UNSET;
- flags = INT_UNSET;
- unimol_rxn_time = FLT_UNSET;
- }
- std::shared_ptr<BaseChkptMol> GenBaseChkptMol::copy_base_chkpt_mol() const {
- std::shared_ptr<BaseChkptMol> res = std::make_shared<BaseChkptMol>(DefaultCtorArgType());
- res->class_name = class_name;
- res->id = id;
- res->species = species;
- res->diffusion_time = diffusion_time;
- res->birthday = birthday;
- res->flags = flags;
- res->unimol_rxn_time = unimol_rxn_time;
- return res;
- }
- std::shared_ptr<BaseChkptMol> GenBaseChkptMol::deepcopy_base_chkpt_mol(py::dict) const {
- std::shared_ptr<BaseChkptMol> res = std::make_shared<BaseChkptMol>(DefaultCtorArgType());
- res->class_name = class_name;
- res->id = id;
- res->species = is_set(species) ? species->deepcopy_species() : nullptr;
- res->diffusion_time = diffusion_time;
- res->birthday = birthday;
- res->flags = flags;
- res->unimol_rxn_time = unimol_rxn_time;
- return res;
- }
- bool GenBaseChkptMol::__eq__(const BaseChkptMol& other) const {
- return
- id == other.id &&
- (
- (is_set(species)) ?
- (is_set(other.species) ?
- (species->__eq__(*other.species)) :
- false
- ) :
- (is_set(other.species) ?
- false :
- true
- )
- ) &&
- diffusion_time == other.diffusion_time &&
- birthday == other.birthday &&
- flags == other.flags &&
- unimol_rxn_time == other.unimol_rxn_time;
- }
- bool GenBaseChkptMol::eq_nonarray_attributes(const BaseChkptMol& other, const bool ignore_name) const {
- return
- id == other.id &&
- (
- (is_set(species)) ?
- (is_set(other.species) ?
- (species->__eq__(*other.species)) :
- false
- ) :
- (is_set(other.species) ?
- false :
- true
- )
- ) &&
- diffusion_time == other.diffusion_time &&
- birthday == other.birthday &&
- flags == other.flags &&
- unimol_rxn_time == other.unimol_rxn_time;
- }
- std::string GenBaseChkptMol::to_str(const bool all_details, const std::string ind) const {
- std::stringstream ss;
- ss << get_object_name() << ": " <<
- "id=" << id << ", " <<
- "\n" << ind + " " << "species=" << "(" << ((species != nullptr) ? species->to_str(all_details, ind + " ") : "null" ) << ")" << ", " << "\n" << ind + " " <<
- "diffusion_time=" << diffusion_time << ", " <<
- "birthday=" << birthday << ", " <<
- "flags=" << flags << ", " <<
- "unimol_rxn_time=" << unimol_rxn_time;
- return ss.str();
- }
- py::class_<BaseChkptMol> define_pybinding_BaseChkptMol(py::module& m) {
- return py::class_<BaseChkptMol, std::shared_ptr<BaseChkptMol>>(m, "BaseChkptMol", "Base class for checkpointed molecules.\nNot to be used directly. All times are in seconds.\n")
- .def(
- py::init<
- const int,
- std::shared_ptr<Species>,
- const double,
- const double,
- const int,
- const double
- >(),
- py::arg("id"),
- py::arg("species"),
- py::arg("diffusion_time"),
- py::arg("birthday"),
- py::arg("flags"),
- py::arg("unimol_rxn_time") = FLT_UNSET
- )
- .def("check_semantics", &BaseChkptMol::check_semantics)
- .def("__copy__", &BaseChkptMol::copy_base_chkpt_mol)
- .def("__deepcopy__", &BaseChkptMol::deepcopy_base_chkpt_mol, py::arg("memo"))
- .def("__str__", &BaseChkptMol::to_str, py::arg("all_details") = false, py::arg("ind") = std::string(""))
- .def("__eq__", &BaseChkptMol::__eq__, py::arg("other"))
- .def("dump", &BaseChkptMol::dump)
- .def_property("id", &BaseChkptMol::get_id, &BaseChkptMol::set_id)
- .def_property("species", &BaseChkptMol::get_species, &BaseChkptMol::set_species)
- .def_property("diffusion_time", &BaseChkptMol::get_diffusion_time, &BaseChkptMol::set_diffusion_time)
- .def_property("birthday", &BaseChkptMol::get_birthday, &BaseChkptMol::set_birthday)
- .def_property("flags", &BaseChkptMol::get_flags, &BaseChkptMol::set_flags)
- .def_property("unimol_rxn_time", &BaseChkptMol::get_unimol_rxn_time, &BaseChkptMol::set_unimol_rxn_time)
- ;
- }
- std::string GenBaseChkptMol::export_to_python(std::ostream& out, PythonExportContext& ctx) {
- if (!export_even_if_already_exported() && ctx.already_exported(this)) {
- return ctx.get_exported_name(this);
- }
- std::string exported_name = "base_chkpt_mol_" + std::to_string(ctx.postinc_counter("base_chkpt_mol"));
- if (!export_even_if_already_exported()) {
- ctx.add_exported(this, exported_name);
- }
- bool str_export = export_as_string_without_newlines();
- std::string nl = "";
- std::string ind = " ";
- std::stringstream ss;
- if (!str_export) {
- nl = "\n";
- ind = " ";
- ss << exported_name << " = ";
- }
- ss << "m.BaseChkptMol(" << nl;
- ss << ind << "id = " << id << "," << nl;
- ss << ind << "species = " << species->export_to_python(out, ctx) << "," << nl;
- ss << ind << "diffusion_time = " << f_to_str(diffusion_time) << "," << nl;
- ss << ind << "birthday = " << f_to_str(birthday) << "," << nl;
- ss << ind << "flags = " << flags << "," << nl;
- if (unimol_rxn_time != FLT_UNSET) {
- ss << ind << "unimol_rxn_time = " << f_to_str(unimol_rxn_time) << "," << nl;
- }
- ss << ")" << nl << nl;
- if (!str_export) {
- out << ss.str();
- return exported_name;
- }
- else {
- return ss.str();
- }
- }
- } // namespace API
- } // namespace MCell
|