gen_molecule.h 6.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_MOLECULE_H
  12. #define API_GEN_MOLECULE_H
  13. #include "api/api_common.h"
  14. #include "api/base_introspection_class.h"
  15. namespace MCell {
  16. namespace API {
  17. class Molecule;
  18. class GeometryObject;
  19. class PythonExportContext;
  20. #define MOLECULE_CTOR_NOARGS() \
  21. Molecule( \
  22. ) { \
  23. class_name = "Molecule"; \
  24. id = ID_INVALID; \
  25. type = MoleculeType::UNSET; \
  26. species_id = ID_INVALID; \
  27. pos3d = std::vector<double>(); \
  28. orientation = Orientation::NOT_SET; \
  29. pos2d = std::vector<double>(); \
  30. geometry_object = nullptr; \
  31. wall_index = -1; \
  32. postprocess_in_ctor(); \
  33. check_semantics(); \
  34. } \
  35. Molecule(DefaultCtorArgType) : \
  36. GenMolecule(DefaultCtorArgType()) { \
  37. set_all_attributes_as_default_or_unset(); \
  38. set_all_custom_attributes_to_default(); \
  39. }
  40. class GenMolecule: public BaseIntrospectionClass {
  41. public:
  42. GenMolecule() {
  43. }
  44. GenMolecule(DefaultCtorArgType) {
  45. }
  46. void postprocess_in_ctor() override {}
  47. void check_semantics() const override;
  48. void set_initialized() override;
  49. void set_all_attributes_as_default_or_unset() override;
  50. std::shared_ptr<Molecule> copy_molecule() const;
  51. std::shared_ptr<Molecule> deepcopy_molecule(py::dict = py::dict()) const;
  52. virtual bool __eq__(const Molecule& other) const;
  53. virtual bool eq_nonarray_attributes(const Molecule& other, const bool ignore_name = false) const;
  54. bool operator == (const Molecule& other) const { return __eq__(other);}
  55. bool operator != (const Molecule& other) const { return !__eq__(other);}
  56. std::string to_str(const bool all_details=false, const std::string ind="") const override;
  57. // --- attributes ---
  58. int id;
  59. virtual void set_id(const int new_id_) {
  60. if (initialized) {
  61. throw RuntimeError("Value 'id' of object with name " + name + " (class " + class_name + ") "
  62. "cannot be set after model was initialized.");
  63. }
  64. cached_data_are_uptodate = false;
  65. id = new_id_;
  66. }
  67. virtual int get_id() const {
  68. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  69. return id;
  70. }
  71. MoleculeType type;
  72. virtual void set_type(const MoleculeType new_type_) {
  73. if (initialized) {
  74. throw RuntimeError("Value 'type' of object with name " + name + " (class " + class_name + ") "
  75. "cannot be set after model was initialized.");
  76. }
  77. cached_data_are_uptodate = false;
  78. type = new_type_;
  79. }
  80. virtual MoleculeType get_type() const {
  81. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  82. return type;
  83. }
  84. int species_id;
  85. virtual void set_species_id(const int new_species_id_) {
  86. if (initialized) {
  87. throw RuntimeError("Value 'species_id' of object with name " + name + " (class " + class_name + ") "
  88. "cannot be set after model was initialized.");
  89. }
  90. cached_data_are_uptodate = false;
  91. species_id = new_species_id_;
  92. }
  93. virtual int get_species_id() const {
  94. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  95. return species_id;
  96. }
  97. std::vector<double> pos3d;
  98. virtual void set_pos3d(const std::vector<double> new_pos3d_) {
  99. if (initialized) {
  100. throw RuntimeError("Value 'pos3d' of object with name " + name + " (class " + class_name + ") "
  101. "cannot be set after model was initialized.");
  102. }
  103. cached_data_are_uptodate = false;
  104. pos3d = new_pos3d_;
  105. }
  106. virtual std::vector<double>& get_pos3d() {
  107. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  108. return pos3d;
  109. }
  110. Orientation orientation;
  111. virtual void set_orientation(const Orientation new_orientation_) {
  112. if (initialized) {
  113. throw RuntimeError("Value 'orientation' of object with name " + name + " (class " + class_name + ") "
  114. "cannot be set after model was initialized.");
  115. }
  116. cached_data_are_uptodate = false;
  117. orientation = new_orientation_;
  118. }
  119. virtual Orientation get_orientation() const {
  120. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  121. return orientation;
  122. }
  123. std::vector<double> pos2d;
  124. virtual void set_pos2d(const std::vector<double> new_pos2d_) {
  125. if (initialized) {
  126. throw RuntimeError("Value 'pos2d' of object with name " + name + " (class " + class_name + ") "
  127. "cannot be set after model was initialized.");
  128. }
  129. cached_data_are_uptodate = false;
  130. pos2d = new_pos2d_;
  131. }
  132. virtual std::vector<double>& get_pos2d() {
  133. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  134. return pos2d;
  135. }
  136. std::shared_ptr<GeometryObject> geometry_object;
  137. virtual void set_geometry_object(std::shared_ptr<GeometryObject> new_geometry_object_) {
  138. if (initialized) {
  139. throw RuntimeError("Value 'geometry_object' of object with name " + name + " (class " + class_name + ") "
  140. "cannot be set after model was initialized.");
  141. }
  142. cached_data_are_uptodate = false;
  143. geometry_object = new_geometry_object_;
  144. }
  145. virtual std::shared_ptr<GeometryObject> get_geometry_object() const {
  146. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  147. return geometry_object;
  148. }
  149. int wall_index;
  150. virtual void set_wall_index(const int new_wall_index_) {
  151. if (initialized) {
  152. throw RuntimeError("Value 'wall_index' of object with name " + name + " (class " + class_name + ") "
  153. "cannot be set after model was initialized.");
  154. }
  155. cached_data_are_uptodate = false;
  156. wall_index = new_wall_index_;
  157. }
  158. virtual int get_wall_index() const {
  159. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  160. return wall_index;
  161. }
  162. // --- methods ---
  163. virtual void remove() = 0;
  164. }; // GenMolecule
  165. class Molecule;
  166. py::class_<Molecule> define_pybinding_Molecule(py::module& m);
  167. } // namespace API
  168. } // namespace MCell
  169. #endif // API_GEN_MOLECULE_H