gen_species.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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_SPECIES_H
  12. #define API_GEN_SPECIES_H
  13. #include "api/api_common.h"
  14. #include "api/complex.h"
  15. namespace MCell {
  16. namespace API {
  17. class Complex;
  18. class ElementaryMolecule;
  19. class Species;
  20. class PythonExportContext;
  21. #define SPECIES_CTOR() \
  22. Species( \
  23. const std::string& name_ = STR_UNSET, \
  24. const double diffusion_constant_2d_ = FLT_UNSET, \
  25. const double diffusion_constant_3d_ = FLT_UNSET, \
  26. const double custom_time_step_ = FLT_UNSET, \
  27. const double custom_space_step_ = FLT_UNSET, \
  28. const bool target_only_ = false, \
  29. const std::vector<std::shared_ptr<ElementaryMolecule>> elementary_molecules_ = std::vector<std::shared_ptr<ElementaryMolecule>>(), \
  30. const Orientation orientation_ = Orientation::DEFAULT, \
  31. const std::string& compartment_name_ = STR_UNSET \
  32. ) : GenSpecies(name_,elementary_molecules_,orientation_,compartment_name_) { \
  33. class_name = "Species"; \
  34. name = name_; \
  35. diffusion_constant_2d = diffusion_constant_2d_; \
  36. diffusion_constant_3d = diffusion_constant_3d_; \
  37. custom_time_step = custom_time_step_; \
  38. custom_space_step = custom_space_step_; \
  39. target_only = target_only_; \
  40. elementary_molecules = elementary_molecules_; \
  41. orientation = orientation_; \
  42. compartment_name = compartment_name_; \
  43. postprocess_in_ctor(); \
  44. check_semantics(); \
  45. } \
  46. Species(DefaultCtorArgType) : \
  47. GenSpecies(DefaultCtorArgType()) { \
  48. set_all_attributes_as_default_or_unset(); \
  49. set_all_custom_attributes_to_default(); \
  50. }
  51. class GenSpecies: public Complex {
  52. public:
  53. GenSpecies(
  54. const std::string& name_ = STR_UNSET,
  55. const std::vector<std::shared_ptr<ElementaryMolecule>> elementary_molecules_ = std::vector<std::shared_ptr<ElementaryMolecule>>(),
  56. const Orientation orientation_ = Orientation::DEFAULT,
  57. const std::string& compartment_name_ = STR_UNSET
  58. ) : Complex(name_,elementary_molecules_,orientation_,compartment_name_) {
  59. }
  60. GenSpecies(DefaultCtorArgType) {
  61. }
  62. void postprocess_in_ctor() override {}
  63. void check_semantics() const override;
  64. void set_initialized() override;
  65. void set_all_attributes_as_default_or_unset() override;
  66. std::shared_ptr<Species> copy_species() const;
  67. std::shared_ptr<Species> deepcopy_species(py::dict = py::dict()) const;
  68. virtual bool __eq__(const Species& other) const;
  69. virtual bool eq_nonarray_attributes(const Species& other, const bool ignore_name = false) const;
  70. bool operator == (const Species& other) const { return __eq__(other);}
  71. bool operator != (const Species& other) const { return !__eq__(other);}
  72. std::string to_str(const bool all_details=false, const std::string ind="") const override;
  73. virtual std::string export_to_python(std::ostream& out, PythonExportContext& ctx);
  74. virtual std::string export_vec_elementary_molecules(std::ostream& out, PythonExportContext& ctx, const std::string& parent_name);
  75. // --- attributes ---
  76. double diffusion_constant_2d;
  77. virtual void set_diffusion_constant_2d(const double new_diffusion_constant_2d_) {
  78. if (initialized) {
  79. throw RuntimeError("Value 'diffusion_constant_2d' of object with name " + name + " (class " + class_name + ") "
  80. "cannot be set after model was initialized.");
  81. }
  82. cached_data_are_uptodate = false;
  83. diffusion_constant_2d = new_diffusion_constant_2d_;
  84. }
  85. virtual double get_diffusion_constant_2d() const {
  86. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  87. return diffusion_constant_2d;
  88. }
  89. double diffusion_constant_3d;
  90. virtual void set_diffusion_constant_3d(const double new_diffusion_constant_3d_) {
  91. if (initialized) {
  92. throw RuntimeError("Value 'diffusion_constant_3d' of object with name " + name + " (class " + class_name + ") "
  93. "cannot be set after model was initialized.");
  94. }
  95. cached_data_are_uptodate = false;
  96. diffusion_constant_3d = new_diffusion_constant_3d_;
  97. }
  98. virtual double get_diffusion_constant_3d() const {
  99. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  100. return diffusion_constant_3d;
  101. }
  102. double custom_time_step;
  103. virtual void set_custom_time_step(const double new_custom_time_step_) {
  104. if (initialized) {
  105. throw RuntimeError("Value 'custom_time_step' of object with name " + name + " (class " + class_name + ") "
  106. "cannot be set after model was initialized.");
  107. }
  108. cached_data_are_uptodate = false;
  109. custom_time_step = new_custom_time_step_;
  110. }
  111. virtual double get_custom_time_step() const {
  112. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  113. return custom_time_step;
  114. }
  115. double custom_space_step;
  116. virtual void set_custom_space_step(const double new_custom_space_step_) {
  117. if (initialized) {
  118. throw RuntimeError("Value 'custom_space_step' of object with name " + name + " (class " + class_name + ") "
  119. "cannot be set after model was initialized.");
  120. }
  121. cached_data_are_uptodate = false;
  122. custom_space_step = new_custom_space_step_;
  123. }
  124. virtual double get_custom_space_step() const {
  125. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  126. return custom_space_step;
  127. }
  128. bool target_only;
  129. virtual void set_target_only(const bool new_target_only_) {
  130. if (initialized) {
  131. throw RuntimeError("Value 'target_only' of object with name " + name + " (class " + class_name + ") "
  132. "cannot be set after model was initialized.");
  133. }
  134. cached_data_are_uptodate = false;
  135. target_only = new_target_only_;
  136. }
  137. virtual bool get_target_only() const {
  138. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  139. return target_only;
  140. }
  141. // --- methods ---
  142. virtual std::shared_ptr<Complex> inst(const Orientation orientation = Orientation::DEFAULT, const std::string& compartment_name = STR_UNSET) = 0;
  143. }; // GenSpecies
  144. class Species;
  145. py::class_<Species> define_pybinding_Species(py::module& m);
  146. } // namespace API
  147. } // namespace MCell
  148. #endif // API_GEN_SPECIES_H