gen_notifications.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2021 by
  4. * The Salk Institute for Biological Studies
  5. *
  6. * Use of this source code is governed by an MIT-style
  7. * license that can be found in the LICENSE file or at
  8. * https://opensource.org/licenses/MIT.
  9. *
  10. ******************************************************************************/
  11. #include <sstream>
  12. #include "api/pybind11_stl_include.h"
  13. #include "api/python_export_utils.h"
  14. #include "gen_notifications.h"
  15. #include "api/notifications.h"
  16. namespace MCell {
  17. namespace API {
  18. void GenNotifications::check_semantics() const {
  19. }
  20. void GenNotifications::set_initialized() {
  21. initialized = true;
  22. }
  23. void GenNotifications::set_all_attributes_as_default_or_unset() {
  24. class_name = "Notifications";
  25. bng_verbosity_level = 0;
  26. rxn_and_species_report = false;
  27. simulation_stats_every_n_iterations = 0;
  28. rxn_probability_changed = true;
  29. iteration_report = true;
  30. wall_overlap_report = false;
  31. }
  32. std::shared_ptr<Notifications> GenNotifications::copy_notifications() const {
  33. std::shared_ptr<Notifications> res = std::make_shared<Notifications>(DefaultCtorArgType());
  34. res->class_name = class_name;
  35. res->bng_verbosity_level = bng_verbosity_level;
  36. res->rxn_and_species_report = rxn_and_species_report;
  37. res->simulation_stats_every_n_iterations = simulation_stats_every_n_iterations;
  38. res->rxn_probability_changed = rxn_probability_changed;
  39. res->iteration_report = iteration_report;
  40. res->wall_overlap_report = wall_overlap_report;
  41. return res;
  42. }
  43. std::shared_ptr<Notifications> GenNotifications::deepcopy_notifications(py::dict) const {
  44. std::shared_ptr<Notifications> res = std::make_shared<Notifications>(DefaultCtorArgType());
  45. res->class_name = class_name;
  46. res->bng_verbosity_level = bng_verbosity_level;
  47. res->rxn_and_species_report = rxn_and_species_report;
  48. res->simulation_stats_every_n_iterations = simulation_stats_every_n_iterations;
  49. res->rxn_probability_changed = rxn_probability_changed;
  50. res->iteration_report = iteration_report;
  51. res->wall_overlap_report = wall_overlap_report;
  52. return res;
  53. }
  54. bool GenNotifications::__eq__(const Notifications& other) const {
  55. return
  56. bng_verbosity_level == other.bng_verbosity_level &&
  57. rxn_and_species_report == other.rxn_and_species_report &&
  58. simulation_stats_every_n_iterations == other.simulation_stats_every_n_iterations &&
  59. rxn_probability_changed == other.rxn_probability_changed &&
  60. iteration_report == other.iteration_report &&
  61. wall_overlap_report == other.wall_overlap_report;
  62. }
  63. bool GenNotifications::eq_nonarray_attributes(const Notifications& other, const bool ignore_name) const {
  64. return
  65. bng_verbosity_level == other.bng_verbosity_level &&
  66. rxn_and_species_report == other.rxn_and_species_report &&
  67. simulation_stats_every_n_iterations == other.simulation_stats_every_n_iterations &&
  68. rxn_probability_changed == other.rxn_probability_changed &&
  69. iteration_report == other.iteration_report &&
  70. wall_overlap_report == other.wall_overlap_report;
  71. }
  72. std::string GenNotifications::to_str(const bool all_details, const std::string ind) const {
  73. std::stringstream ss;
  74. ss << get_object_name() << ": " <<
  75. "bng_verbosity_level=" << bng_verbosity_level << ", " <<
  76. "rxn_and_species_report=" << rxn_and_species_report << ", " <<
  77. "simulation_stats_every_n_iterations=" << simulation_stats_every_n_iterations << ", " <<
  78. "rxn_probability_changed=" << rxn_probability_changed << ", " <<
  79. "iteration_report=" << iteration_report << ", " <<
  80. "wall_overlap_report=" << wall_overlap_report;
  81. return ss.str();
  82. }
  83. py::class_<Notifications> define_pybinding_Notifications(py::module& m) {
  84. return py::class_<Notifications, std::shared_ptr<Notifications>>(m, "Notifications")
  85. .def(
  86. py::init<
  87. const int,
  88. const bool,
  89. const int,
  90. const bool,
  91. const bool,
  92. const bool
  93. >(),
  94. py::arg("bng_verbosity_level") = 0,
  95. py::arg("rxn_and_species_report") = false,
  96. py::arg("simulation_stats_every_n_iterations") = 0,
  97. py::arg("rxn_probability_changed") = true,
  98. py::arg("iteration_report") = true,
  99. py::arg("wall_overlap_report") = false
  100. )
  101. .def("check_semantics", &Notifications::check_semantics)
  102. .def("__copy__", &Notifications::copy_notifications)
  103. .def("__deepcopy__", &Notifications::deepcopy_notifications, py::arg("memo"))
  104. .def("__str__", &Notifications::to_str, py::arg("all_details") = false, py::arg("ind") = std::string(""))
  105. .def("__eq__", &Notifications::__eq__, py::arg("other"))
  106. .def("dump", &Notifications::dump)
  107. .def_property("bng_verbosity_level", &Notifications::get_bng_verbosity_level, &Notifications::set_bng_verbosity_level, "Sets verbosity level that enables printouts of extra information on BioNetGen \nspecies and rules created and used during simulation.\n")
  108. .def_property("rxn_and_species_report", &Notifications::get_rxn_and_species_report, &Notifications::set_rxn_and_species_report, "When set to True, simulation generates files rxn_report_SEED.txt, and \nspecies_report_SEED.txt that contain details on reaction classes and species \nthat were created based on reaction rules. \n")
  109. .def_property("simulation_stats_every_n_iterations", &Notifications::get_simulation_stats_every_n_iterations, &Notifications::set_simulation_stats_every_n_iterations, "When set to a value other than 0, internal simulation stats will be printed. \n")
  110. .def_property("rxn_probability_changed", &Notifications::get_rxn_probability_changed, &Notifications::set_rxn_probability_changed, "When True, information that a reaction's probability has changed is printed during simulation. \n")
  111. .def_property("iteration_report", &Notifications::get_iteration_report, &Notifications::set_iteration_report, "When True, a running report of how many iterations have completed, chosen based \non the total number of iterations, will be printed during simulation.\n")
  112. .def_property("wall_overlap_report", &Notifications::get_wall_overlap_report, &Notifications::set_wall_overlap_report, "When True, information on wall overlaps will be printed. \n")
  113. ;
  114. }
  115. std::string GenNotifications::export_to_python(std::ostream& out, PythonExportContext& ctx) {
  116. if (!export_even_if_already_exported() && ctx.already_exported(this)) {
  117. return ctx.get_exported_name(this);
  118. }
  119. std::string exported_name = "notifications_" + std::to_string(ctx.postinc_counter("notifications"));
  120. if (!export_even_if_already_exported()) {
  121. ctx.add_exported(this, exported_name);
  122. }
  123. bool str_export = export_as_string_without_newlines();
  124. std::string nl = "";
  125. std::string ind = " ";
  126. std::stringstream ss;
  127. if (!str_export) {
  128. nl = "\n";
  129. ind = " ";
  130. ss << exported_name << " = ";
  131. }
  132. ss << "m.Notifications(" << nl;
  133. if (bng_verbosity_level != 0) {
  134. ss << ind << "bng_verbosity_level = " << bng_verbosity_level << "," << nl;
  135. }
  136. if (rxn_and_species_report != false) {
  137. ss << ind << "rxn_and_species_report = " << rxn_and_species_report << "," << nl;
  138. }
  139. if (simulation_stats_every_n_iterations != 0) {
  140. ss << ind << "simulation_stats_every_n_iterations = " << simulation_stats_every_n_iterations << "," << nl;
  141. }
  142. if (rxn_probability_changed != true) {
  143. ss << ind << "rxn_probability_changed = " << rxn_probability_changed << "," << nl;
  144. }
  145. if (iteration_report != true) {
  146. ss << ind << "iteration_report = " << iteration_report << "," << nl;
  147. }
  148. if (wall_overlap_report != false) {
  149. ss << ind << "wall_overlap_report = " << wall_overlap_report << "," << nl;
  150. }
  151. ss << ")" << nl << nl;
  152. if (!str_export) {
  153. out << ss.str();
  154. return exported_name;
  155. }
  156. else {
  157. return ss.str();
  158. }
  159. }
  160. } // namespace API
  161. } // namespace MCell