gen_reaction_rule.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. #ifndef API_GEN_REACTION_RULE_H
  12. #define API_GEN_REACTION_RULE_H
  13. #include "api/api_common.h"
  14. #include "api/base_data_class.h"
  15. namespace MCell {
  16. namespace API {
  17. class ReactionRule;
  18. class Complex;
  19. class PythonExportContext;
  20. #define REACTION_RULE_CTOR() \
  21. ReactionRule( \
  22. const std::string& name_ = STR_UNSET, \
  23. const std::vector<std::shared_ptr<Complex>> reactants_ = std::vector<std::shared_ptr<Complex>>(), \
  24. const std::vector<std::shared_ptr<Complex>> products_ = std::vector<std::shared_ptr<Complex>>(), \
  25. const double fwd_rate_ = FLT_UNSET, \
  26. const std::string& rev_name_ = STR_UNSET, \
  27. const double rev_rate_ = FLT_UNSET, \
  28. const std::vector<std::vector<double>> variable_rate_ = std::vector<std::vector<double>>(), \
  29. const bool is_intermembrane_surface_reaction_ = false \
  30. ) { \
  31. class_name = "ReactionRule"; \
  32. name = name_; \
  33. reactants = reactants_; \
  34. products = products_; \
  35. fwd_rate = fwd_rate_; \
  36. rev_name = rev_name_; \
  37. rev_rate = rev_rate_; \
  38. variable_rate = variable_rate_; \
  39. is_intermembrane_surface_reaction = is_intermembrane_surface_reaction_; \
  40. postprocess_in_ctor(); \
  41. check_semantics(); \
  42. } \
  43. ReactionRule(DefaultCtorArgType) : \
  44. GenReactionRule(DefaultCtorArgType()) { \
  45. set_all_attributes_as_default_or_unset(); \
  46. set_all_custom_attributes_to_default(); \
  47. }
  48. class GenReactionRule: public BaseDataClass {
  49. public:
  50. GenReactionRule() {
  51. }
  52. GenReactionRule(DefaultCtorArgType) {
  53. }
  54. void postprocess_in_ctor() override {}
  55. void check_semantics() const override;
  56. void set_initialized() override;
  57. void set_all_attributes_as_default_or_unset() override;
  58. std::shared_ptr<ReactionRule> copy_reaction_rule() const;
  59. std::shared_ptr<ReactionRule> deepcopy_reaction_rule(py::dict = py::dict()) const;
  60. virtual bool __eq__(const ReactionRule& other) const;
  61. virtual bool eq_nonarray_attributes(const ReactionRule& other, const bool ignore_name = false) const;
  62. bool operator == (const ReactionRule& other) const { return __eq__(other);}
  63. bool operator != (const ReactionRule& other) const { return !__eq__(other);}
  64. std::string to_str(const bool all_details=false, const std::string ind="") const override;
  65. std::string export_to_python(std::ostream& out, PythonExportContext& ctx) override;
  66. virtual std::string export_vec_reactants(std::ostream& out, PythonExportContext& ctx, const std::string& parent_name);
  67. virtual std::string export_vec_products(std::ostream& out, PythonExportContext& ctx, const std::string& parent_name);
  68. virtual std::string export_vec_variable_rate(std::ostream& out, PythonExportContext& ctx, const std::string& parent_name);
  69. // --- attributes ---
  70. std::vector<std::shared_ptr<Complex>> reactants;
  71. virtual void set_reactants(const std::vector<std::shared_ptr<Complex>> new_reactants_) {
  72. if (initialized) {
  73. throw RuntimeError("Value 'reactants' of object with name " + name + " (class " + class_name + ") "
  74. "cannot be set after model was initialized.");
  75. }
  76. cached_data_are_uptodate = false;
  77. reactants = new_reactants_;
  78. }
  79. virtual std::vector<std::shared_ptr<Complex>>& get_reactants() {
  80. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  81. return reactants;
  82. }
  83. std::vector<std::shared_ptr<Complex>> products;
  84. virtual void set_products(const std::vector<std::shared_ptr<Complex>> new_products_) {
  85. if (initialized) {
  86. throw RuntimeError("Value 'products' of object with name " + name + " (class " + class_name + ") "
  87. "cannot be set after model was initialized.");
  88. }
  89. cached_data_are_uptodate = false;
  90. products = new_products_;
  91. }
  92. virtual std::vector<std::shared_ptr<Complex>>& get_products() {
  93. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  94. return products;
  95. }
  96. double fwd_rate;
  97. virtual void set_fwd_rate(const double new_fwd_rate_) {
  98. if (initialized) {
  99. throw RuntimeError("Value 'fwd_rate' of object with name " + name + " (class " + class_name + ") "
  100. "cannot be set after model was initialized.");
  101. }
  102. cached_data_are_uptodate = false;
  103. fwd_rate = new_fwd_rate_;
  104. }
  105. virtual double get_fwd_rate() const {
  106. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  107. return fwd_rate;
  108. }
  109. std::string rev_name;
  110. virtual void set_rev_name(const std::string& new_rev_name_) {
  111. if (initialized) {
  112. throw RuntimeError("Value 'rev_name' of object with name " + name + " (class " + class_name + ") "
  113. "cannot be set after model was initialized.");
  114. }
  115. cached_data_are_uptodate = false;
  116. rev_name = new_rev_name_;
  117. }
  118. virtual const std::string& get_rev_name() const {
  119. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  120. return rev_name;
  121. }
  122. double rev_rate;
  123. virtual void set_rev_rate(const double new_rev_rate_) {
  124. if (initialized) {
  125. throw RuntimeError("Value 'rev_rate' of object with name " + name + " (class " + class_name + ") "
  126. "cannot be set after model was initialized.");
  127. }
  128. cached_data_are_uptodate = false;
  129. rev_rate = new_rev_rate_;
  130. }
  131. virtual double get_rev_rate() const {
  132. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  133. return rev_rate;
  134. }
  135. std::vector<std::vector<double>> variable_rate;
  136. virtual void set_variable_rate(const std::vector<std::vector<double>> new_variable_rate_) {
  137. if (initialized) {
  138. throw RuntimeError("Value 'variable_rate' of object with name " + name + " (class " + class_name + ") "
  139. "cannot be set after model was initialized.");
  140. }
  141. cached_data_are_uptodate = false;
  142. variable_rate = new_variable_rate_;
  143. }
  144. virtual std::vector<std::vector<double>>& get_variable_rate() {
  145. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  146. return variable_rate;
  147. }
  148. bool is_intermembrane_surface_reaction;
  149. virtual void set_is_intermembrane_surface_reaction(const bool new_is_intermembrane_surface_reaction_) {
  150. if (initialized) {
  151. throw RuntimeError("Value 'is_intermembrane_surface_reaction' of object with name " + name + " (class " + class_name + ") "
  152. "cannot be set after model was initialized.");
  153. }
  154. cached_data_are_uptodate = false;
  155. is_intermembrane_surface_reaction = new_is_intermembrane_surface_reaction_;
  156. }
  157. virtual bool get_is_intermembrane_surface_reaction() const {
  158. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  159. return is_intermembrane_surface_reaction;
  160. }
  161. // --- methods ---
  162. virtual std::string to_bngl_str() const = 0;
  163. }; // GenReactionRule
  164. class ReactionRule;
  165. py::class_<ReactionRule> define_pybinding_ReactionRule(py::module& m);
  166. } // namespace API
  167. } // namespace MCell
  168. #endif // API_GEN_REACTION_RULE_H