gen_config.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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_CONFIG_H
  12. #define API_GEN_CONFIG_H
  13. #include "api/api_common.h"
  14. #include "api/base_data_class.h"
  15. namespace MCell {
  16. namespace API {
  17. class Config;
  18. class RngState;
  19. class PythonExportContext;
  20. #define CONFIG_CTOR() \
  21. Config( \
  22. const int seed_ = 1, \
  23. const double time_step_ = 1e-6, \
  24. const bool use_bng_units_ = false, \
  25. const double surface_grid_density_ = 10000, \
  26. const double interaction_radius_ = FLT_UNSET, \
  27. const double intermembrane_interaction_radius_ = FLT_UNSET, \
  28. const double vacancy_search_distance_ = 10, \
  29. const bool center_molecules_on_grid_ = false, \
  30. const double partition_dimension_ = 10, \
  31. const std::vector<double> initial_partition_origin_ = std::vector<double>(), \
  32. const double subpartition_dimension_ = 0.5, \
  33. const double total_iterations_ = 1000000, \
  34. const bool check_overlapped_walls_ = true, \
  35. const int reaction_class_cleanup_periodicity_ = 500, \
  36. const int species_cleanup_periodicity_ = 10000, \
  37. const int molecules_order_random_shuffle_periodicity_ = 10000, \
  38. const bool sort_molecules_ = false, \
  39. const int memory_limit_gb_ = -1, \
  40. const uint64_t initial_iteration_ = 0, \
  41. const double initial_time_ = 0, \
  42. std::shared_ptr<RngState> initial_rng_state_ = nullptr, \
  43. const bool append_to_count_output_data_ = false, \
  44. const bool continue_after_sigalrm_ = false \
  45. ) { \
  46. class_name = "Config"; \
  47. seed = seed_; \
  48. time_step = time_step_; \
  49. use_bng_units = use_bng_units_; \
  50. surface_grid_density = surface_grid_density_; \
  51. interaction_radius = interaction_radius_; \
  52. intermembrane_interaction_radius = intermembrane_interaction_radius_; \
  53. vacancy_search_distance = vacancy_search_distance_; \
  54. center_molecules_on_grid = center_molecules_on_grid_; \
  55. partition_dimension = partition_dimension_; \
  56. initial_partition_origin = initial_partition_origin_; \
  57. subpartition_dimension = subpartition_dimension_; \
  58. total_iterations = total_iterations_; \
  59. check_overlapped_walls = check_overlapped_walls_; \
  60. reaction_class_cleanup_periodicity = reaction_class_cleanup_periodicity_; \
  61. species_cleanup_periodicity = species_cleanup_periodicity_; \
  62. molecules_order_random_shuffle_periodicity = molecules_order_random_shuffle_periodicity_; \
  63. sort_molecules = sort_molecules_; \
  64. memory_limit_gb = memory_limit_gb_; \
  65. initial_iteration = initial_iteration_; \
  66. initial_time = initial_time_; \
  67. initial_rng_state = initial_rng_state_; \
  68. append_to_count_output_data = append_to_count_output_data_; \
  69. continue_after_sigalrm = continue_after_sigalrm_; \
  70. postprocess_in_ctor(); \
  71. check_semantics(); \
  72. } \
  73. Config(DefaultCtorArgType) : \
  74. GenConfig(DefaultCtorArgType()) { \
  75. set_all_attributes_as_default_or_unset(); \
  76. set_all_custom_attributes_to_default(); \
  77. }
  78. class GenConfig: public BaseDataClass {
  79. public:
  80. GenConfig() {
  81. }
  82. GenConfig(DefaultCtorArgType) {
  83. }
  84. void postprocess_in_ctor() override {}
  85. void check_semantics() const override;
  86. void set_initialized() override;
  87. void set_all_attributes_as_default_or_unset() override;
  88. std::shared_ptr<Config> copy_config() const;
  89. std::shared_ptr<Config> deepcopy_config(py::dict = py::dict()) const;
  90. virtual bool __eq__(const Config& other) const;
  91. virtual bool eq_nonarray_attributes(const Config& other, const bool ignore_name = false) const;
  92. bool operator == (const Config& other) const { return __eq__(other);}
  93. bool operator != (const Config& other) const { return !__eq__(other);}
  94. std::string to_str(const bool all_details=false, const std::string ind="") const override;
  95. std::string export_to_python(std::ostream& out, PythonExportContext& ctx) override;
  96. virtual std::string export_vec_initial_partition_origin(std::ostream& out, PythonExportContext& ctx, const std::string& parent_name);
  97. // --- attributes ---
  98. int seed;
  99. virtual void set_seed(const int new_seed_) {
  100. if (initialized) {
  101. throw RuntimeError("Value 'seed' of object with name " + name + " (class " + class_name + ") "
  102. "cannot be set after model was initialized.");
  103. }
  104. cached_data_are_uptodate = false;
  105. seed = new_seed_;
  106. }
  107. virtual int get_seed() const {
  108. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  109. return seed;
  110. }
  111. double time_step;
  112. virtual void set_time_step(const double new_time_step_) {
  113. if (initialized) {
  114. throw RuntimeError("Value 'time_step' of object with name " + name + " (class " + class_name + ") "
  115. "cannot be set after model was initialized.");
  116. }
  117. cached_data_are_uptodate = false;
  118. time_step = new_time_step_;
  119. }
  120. virtual double get_time_step() const {
  121. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  122. return time_step;
  123. }
  124. bool use_bng_units;
  125. virtual void set_use_bng_units(const bool new_use_bng_units_) {
  126. if (initialized) {
  127. throw RuntimeError("Value 'use_bng_units' of object with name " + name + " (class " + class_name + ") "
  128. "cannot be set after model was initialized.");
  129. }
  130. cached_data_are_uptodate = false;
  131. use_bng_units = new_use_bng_units_;
  132. }
  133. virtual bool get_use_bng_units() const {
  134. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  135. return use_bng_units;
  136. }
  137. double surface_grid_density;
  138. virtual void set_surface_grid_density(const double new_surface_grid_density_) {
  139. if (initialized) {
  140. throw RuntimeError("Value 'surface_grid_density' of object with name " + name + " (class " + class_name + ") "
  141. "cannot be set after model was initialized.");
  142. }
  143. cached_data_are_uptodate = false;
  144. surface_grid_density = new_surface_grid_density_;
  145. }
  146. virtual double get_surface_grid_density() const {
  147. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  148. return surface_grid_density;
  149. }
  150. double interaction_radius;
  151. virtual void set_interaction_radius(const double new_interaction_radius_) {
  152. if (initialized) {
  153. throw RuntimeError("Value 'interaction_radius' of object with name " + name + " (class " + class_name + ") "
  154. "cannot be set after model was initialized.");
  155. }
  156. cached_data_are_uptodate = false;
  157. interaction_radius = new_interaction_radius_;
  158. }
  159. virtual double get_interaction_radius() const {
  160. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  161. return interaction_radius;
  162. }
  163. double intermembrane_interaction_radius;
  164. virtual void set_intermembrane_interaction_radius(const double new_intermembrane_interaction_radius_) {
  165. if (initialized) {
  166. throw RuntimeError("Value 'intermembrane_interaction_radius' of object with name " + name + " (class " + class_name + ") "
  167. "cannot be set after model was initialized.");
  168. }
  169. cached_data_are_uptodate = false;
  170. intermembrane_interaction_radius = new_intermembrane_interaction_radius_;
  171. }
  172. virtual double get_intermembrane_interaction_radius() const {
  173. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  174. return intermembrane_interaction_radius;
  175. }
  176. double vacancy_search_distance;
  177. virtual void set_vacancy_search_distance(const double new_vacancy_search_distance_) {
  178. if (initialized) {
  179. throw RuntimeError("Value 'vacancy_search_distance' of object with name " + name + " (class " + class_name + ") "
  180. "cannot be set after model was initialized.");
  181. }
  182. cached_data_are_uptodate = false;
  183. vacancy_search_distance = new_vacancy_search_distance_;
  184. }
  185. virtual double get_vacancy_search_distance() const {
  186. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  187. return vacancy_search_distance;
  188. }
  189. bool center_molecules_on_grid;
  190. virtual void set_center_molecules_on_grid(const bool new_center_molecules_on_grid_) {
  191. if (initialized) {
  192. throw RuntimeError("Value 'center_molecules_on_grid' of object with name " + name + " (class " + class_name + ") "
  193. "cannot be set after model was initialized.");
  194. }
  195. cached_data_are_uptodate = false;
  196. center_molecules_on_grid = new_center_molecules_on_grid_;
  197. }
  198. virtual bool get_center_molecules_on_grid() const {
  199. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  200. return center_molecules_on_grid;
  201. }
  202. double partition_dimension;
  203. virtual void set_partition_dimension(const double new_partition_dimension_) {
  204. if (initialized) {
  205. throw RuntimeError("Value 'partition_dimension' of object with name " + name + " (class " + class_name + ") "
  206. "cannot be set after model was initialized.");
  207. }
  208. cached_data_are_uptodate = false;
  209. partition_dimension = new_partition_dimension_;
  210. }
  211. virtual double get_partition_dimension() const {
  212. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  213. return partition_dimension;
  214. }
  215. std::vector<double> initial_partition_origin;
  216. virtual void set_initial_partition_origin(const std::vector<double> new_initial_partition_origin_) {
  217. if (initialized) {
  218. throw RuntimeError("Value 'initial_partition_origin' of object with name " + name + " (class " + class_name + ") "
  219. "cannot be set after model was initialized.");
  220. }
  221. cached_data_are_uptodate = false;
  222. initial_partition_origin = new_initial_partition_origin_;
  223. }
  224. virtual std::vector<double>& get_initial_partition_origin() {
  225. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  226. return initial_partition_origin;
  227. }
  228. double subpartition_dimension;
  229. virtual void set_subpartition_dimension(const double new_subpartition_dimension_) {
  230. if (initialized) {
  231. throw RuntimeError("Value 'subpartition_dimension' of object with name " + name + " (class " + class_name + ") "
  232. "cannot be set after model was initialized.");
  233. }
  234. cached_data_are_uptodate = false;
  235. subpartition_dimension = new_subpartition_dimension_;
  236. }
  237. virtual double get_subpartition_dimension() const {
  238. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  239. return subpartition_dimension;
  240. }
  241. double total_iterations;
  242. virtual void set_total_iterations(const double new_total_iterations_) {
  243. if (initialized) {
  244. throw RuntimeError("Value 'total_iterations' of object with name " + name + " (class " + class_name + ") "
  245. "cannot be set after model was initialized.");
  246. }
  247. cached_data_are_uptodate = false;
  248. total_iterations = new_total_iterations_;
  249. }
  250. virtual double get_total_iterations() const {
  251. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  252. return total_iterations;
  253. }
  254. bool check_overlapped_walls;
  255. virtual void set_check_overlapped_walls(const bool new_check_overlapped_walls_) {
  256. if (initialized) {
  257. throw RuntimeError("Value 'check_overlapped_walls' of object with name " + name + " (class " + class_name + ") "
  258. "cannot be set after model was initialized.");
  259. }
  260. cached_data_are_uptodate = false;
  261. check_overlapped_walls = new_check_overlapped_walls_;
  262. }
  263. virtual bool get_check_overlapped_walls() const {
  264. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  265. return check_overlapped_walls;
  266. }
  267. int reaction_class_cleanup_periodicity;
  268. virtual void set_reaction_class_cleanup_periodicity(const int new_reaction_class_cleanup_periodicity_) {
  269. if (initialized) {
  270. throw RuntimeError("Value 'reaction_class_cleanup_periodicity' of object with name " + name + " (class " + class_name + ") "
  271. "cannot be set after model was initialized.");
  272. }
  273. cached_data_are_uptodate = false;
  274. reaction_class_cleanup_periodicity = new_reaction_class_cleanup_periodicity_;
  275. }
  276. virtual int get_reaction_class_cleanup_periodicity() const {
  277. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  278. return reaction_class_cleanup_periodicity;
  279. }
  280. int species_cleanup_periodicity;
  281. virtual void set_species_cleanup_periodicity(const int new_species_cleanup_periodicity_) {
  282. if (initialized) {
  283. throw RuntimeError("Value 'species_cleanup_periodicity' of object with name " + name + " (class " + class_name + ") "
  284. "cannot be set after model was initialized.");
  285. }
  286. cached_data_are_uptodate = false;
  287. species_cleanup_periodicity = new_species_cleanup_periodicity_;
  288. }
  289. virtual int get_species_cleanup_periodicity() const {
  290. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  291. return species_cleanup_periodicity;
  292. }
  293. int molecules_order_random_shuffle_periodicity;
  294. virtual void set_molecules_order_random_shuffle_periodicity(const int new_molecules_order_random_shuffle_periodicity_) {
  295. if (initialized) {
  296. throw RuntimeError("Value 'molecules_order_random_shuffle_periodicity' of object with name " + name + " (class " + class_name + ") "
  297. "cannot be set after model was initialized.");
  298. }
  299. cached_data_are_uptodate = false;
  300. molecules_order_random_shuffle_periodicity = new_molecules_order_random_shuffle_periodicity_;
  301. }
  302. virtual int get_molecules_order_random_shuffle_periodicity() const {
  303. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  304. return molecules_order_random_shuffle_periodicity;
  305. }
  306. bool sort_molecules;
  307. virtual void set_sort_molecules(const bool new_sort_molecules_) {
  308. if (initialized) {
  309. throw RuntimeError("Value 'sort_molecules' of object with name " + name + " (class " + class_name + ") "
  310. "cannot be set after model was initialized.");
  311. }
  312. cached_data_are_uptodate = false;
  313. sort_molecules = new_sort_molecules_;
  314. }
  315. virtual bool get_sort_molecules() const {
  316. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  317. return sort_molecules;
  318. }
  319. int memory_limit_gb;
  320. virtual void set_memory_limit_gb(const int new_memory_limit_gb_) {
  321. if (initialized) {
  322. throw RuntimeError("Value 'memory_limit_gb' of object with name " + name + " (class " + class_name + ") "
  323. "cannot be set after model was initialized.");
  324. }
  325. cached_data_are_uptodate = false;
  326. memory_limit_gb = new_memory_limit_gb_;
  327. }
  328. virtual int get_memory_limit_gb() const {
  329. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  330. return memory_limit_gb;
  331. }
  332. uint64_t initial_iteration;
  333. virtual void set_initial_iteration(const uint64_t new_initial_iteration_) {
  334. if (initialized) {
  335. throw RuntimeError("Value 'initial_iteration' of object with name " + name + " (class " + class_name + ") "
  336. "cannot be set after model was initialized.");
  337. }
  338. cached_data_are_uptodate = false;
  339. initial_iteration = new_initial_iteration_;
  340. }
  341. virtual uint64_t get_initial_iteration() const {
  342. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  343. return initial_iteration;
  344. }
  345. double initial_time;
  346. virtual void set_initial_time(const double new_initial_time_) {
  347. if (initialized) {
  348. throw RuntimeError("Value 'initial_time' of object with name " + name + " (class " + class_name + ") "
  349. "cannot be set after model was initialized.");
  350. }
  351. cached_data_are_uptodate = false;
  352. initial_time = new_initial_time_;
  353. }
  354. virtual double get_initial_time() const {
  355. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  356. return initial_time;
  357. }
  358. std::shared_ptr<RngState> initial_rng_state;
  359. virtual void set_initial_rng_state(std::shared_ptr<RngState> new_initial_rng_state_) {
  360. if (initialized) {
  361. throw RuntimeError("Value 'initial_rng_state' of object with name " + name + " (class " + class_name + ") "
  362. "cannot be set after model was initialized.");
  363. }
  364. cached_data_are_uptodate = false;
  365. initial_rng_state = new_initial_rng_state_;
  366. }
  367. virtual std::shared_ptr<RngState> get_initial_rng_state() const {
  368. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  369. return initial_rng_state;
  370. }
  371. bool append_to_count_output_data;
  372. virtual void set_append_to_count_output_data(const bool new_append_to_count_output_data_) {
  373. if (initialized) {
  374. throw RuntimeError("Value 'append_to_count_output_data' of object with name " + name + " (class " + class_name + ") "
  375. "cannot be set after model was initialized.");
  376. }
  377. cached_data_are_uptodate = false;
  378. append_to_count_output_data = new_append_to_count_output_data_;
  379. }
  380. virtual bool get_append_to_count_output_data() const {
  381. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  382. return append_to_count_output_data;
  383. }
  384. bool continue_after_sigalrm;
  385. virtual void set_continue_after_sigalrm(const bool new_continue_after_sigalrm_) {
  386. if (initialized) {
  387. throw RuntimeError("Value 'continue_after_sigalrm' of object with name " + name + " (class " + class_name + ") "
  388. "cannot be set after model was initialized.");
  389. }
  390. cached_data_are_uptodate = false;
  391. continue_after_sigalrm = new_continue_after_sigalrm_;
  392. }
  393. virtual bool get_continue_after_sigalrm() const {
  394. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  395. return continue_after_sigalrm;
  396. }
  397. // --- methods ---
  398. }; // GenConfig
  399. class Config;
  400. py::class_<Config> define_pybinding_Config(py::module& m);
  401. } // namespace API
  402. } // namespace MCell
  403. #endif // API_GEN_CONFIG_H