gen_config.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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_config.h"
  15. #include "api/api_config.h"
  16. #include "api/rng_state.h"
  17. namespace MCell {
  18. namespace API {
  19. void GenConfig::check_semantics() const {
  20. }
  21. void GenConfig::set_initialized() {
  22. if (is_set(initial_rng_state)) {
  23. initial_rng_state->set_initialized();
  24. }
  25. initialized = true;
  26. }
  27. void GenConfig::set_all_attributes_as_default_or_unset() {
  28. class_name = "Config";
  29. seed = 1;
  30. time_step = 1e-6;
  31. use_bng_units = false;
  32. surface_grid_density = 10000;
  33. interaction_radius = FLT_UNSET;
  34. intermembrane_interaction_radius = FLT_UNSET;
  35. vacancy_search_distance = 10;
  36. center_molecules_on_grid = false;
  37. partition_dimension = 10;
  38. initial_partition_origin = std::vector<double>();
  39. subpartition_dimension = 0.5;
  40. total_iterations = 1000000;
  41. check_overlapped_walls = true;
  42. reaction_class_cleanup_periodicity = 500;
  43. species_cleanup_periodicity = 10000;
  44. molecules_order_random_shuffle_periodicity = 10000;
  45. sort_molecules = false;
  46. memory_limit_gb = -1;
  47. initial_iteration = 0;
  48. initial_time = 0;
  49. initial_rng_state = nullptr;
  50. append_to_count_output_data = false;
  51. continue_after_sigalrm = false;
  52. }
  53. std::shared_ptr<Config> GenConfig::copy_config() const {
  54. std::shared_ptr<Config> res = std::make_shared<Config>(DefaultCtorArgType());
  55. res->class_name = class_name;
  56. res->seed = seed;
  57. res->time_step = time_step;
  58. res->use_bng_units = use_bng_units;
  59. res->surface_grid_density = surface_grid_density;
  60. res->interaction_radius = interaction_radius;
  61. res->intermembrane_interaction_radius = intermembrane_interaction_radius;
  62. res->vacancy_search_distance = vacancy_search_distance;
  63. res->center_molecules_on_grid = center_molecules_on_grid;
  64. res->partition_dimension = partition_dimension;
  65. res->initial_partition_origin = initial_partition_origin;
  66. res->subpartition_dimension = subpartition_dimension;
  67. res->total_iterations = total_iterations;
  68. res->check_overlapped_walls = check_overlapped_walls;
  69. res->reaction_class_cleanup_periodicity = reaction_class_cleanup_periodicity;
  70. res->species_cleanup_periodicity = species_cleanup_periodicity;
  71. res->molecules_order_random_shuffle_periodicity = molecules_order_random_shuffle_periodicity;
  72. res->sort_molecules = sort_molecules;
  73. res->memory_limit_gb = memory_limit_gb;
  74. res->initial_iteration = initial_iteration;
  75. res->initial_time = initial_time;
  76. res->initial_rng_state = initial_rng_state;
  77. res->append_to_count_output_data = append_to_count_output_data;
  78. res->continue_after_sigalrm = continue_after_sigalrm;
  79. return res;
  80. }
  81. std::shared_ptr<Config> GenConfig::deepcopy_config(py::dict) const {
  82. std::shared_ptr<Config> res = std::make_shared<Config>(DefaultCtorArgType());
  83. res->class_name = class_name;
  84. res->seed = seed;
  85. res->time_step = time_step;
  86. res->use_bng_units = use_bng_units;
  87. res->surface_grid_density = surface_grid_density;
  88. res->interaction_radius = interaction_radius;
  89. res->intermembrane_interaction_radius = intermembrane_interaction_radius;
  90. res->vacancy_search_distance = vacancy_search_distance;
  91. res->center_molecules_on_grid = center_molecules_on_grid;
  92. res->partition_dimension = partition_dimension;
  93. res->initial_partition_origin = initial_partition_origin;
  94. res->subpartition_dimension = subpartition_dimension;
  95. res->total_iterations = total_iterations;
  96. res->check_overlapped_walls = check_overlapped_walls;
  97. res->reaction_class_cleanup_periodicity = reaction_class_cleanup_periodicity;
  98. res->species_cleanup_periodicity = species_cleanup_periodicity;
  99. res->molecules_order_random_shuffle_periodicity = molecules_order_random_shuffle_periodicity;
  100. res->sort_molecules = sort_molecules;
  101. res->memory_limit_gb = memory_limit_gb;
  102. res->initial_iteration = initial_iteration;
  103. res->initial_time = initial_time;
  104. res->initial_rng_state = is_set(initial_rng_state) ? initial_rng_state->deepcopy_rng_state() : nullptr;
  105. res->append_to_count_output_data = append_to_count_output_data;
  106. res->continue_after_sigalrm = continue_after_sigalrm;
  107. return res;
  108. }
  109. bool GenConfig::__eq__(const Config& other) const {
  110. return
  111. seed == other.seed &&
  112. time_step == other.time_step &&
  113. use_bng_units == other.use_bng_units &&
  114. surface_grid_density == other.surface_grid_density &&
  115. interaction_radius == other.interaction_radius &&
  116. intermembrane_interaction_radius == other.intermembrane_interaction_radius &&
  117. vacancy_search_distance == other.vacancy_search_distance &&
  118. center_molecules_on_grid == other.center_molecules_on_grid &&
  119. partition_dimension == other.partition_dimension &&
  120. initial_partition_origin == other.initial_partition_origin &&
  121. subpartition_dimension == other.subpartition_dimension &&
  122. total_iterations == other.total_iterations &&
  123. check_overlapped_walls == other.check_overlapped_walls &&
  124. reaction_class_cleanup_periodicity == other.reaction_class_cleanup_periodicity &&
  125. species_cleanup_periodicity == other.species_cleanup_periodicity &&
  126. molecules_order_random_shuffle_periodicity == other.molecules_order_random_shuffle_periodicity &&
  127. sort_molecules == other.sort_molecules &&
  128. memory_limit_gb == other.memory_limit_gb &&
  129. initial_iteration == other.initial_iteration &&
  130. initial_time == other.initial_time &&
  131. (
  132. (is_set(initial_rng_state)) ?
  133. (is_set(other.initial_rng_state) ?
  134. (initial_rng_state->__eq__(*other.initial_rng_state)) :
  135. false
  136. ) :
  137. (is_set(other.initial_rng_state) ?
  138. false :
  139. true
  140. )
  141. ) &&
  142. append_to_count_output_data == other.append_to_count_output_data &&
  143. continue_after_sigalrm == other.continue_after_sigalrm;
  144. }
  145. bool GenConfig::eq_nonarray_attributes(const Config& other, const bool ignore_name) const {
  146. return
  147. seed == other.seed &&
  148. time_step == other.time_step &&
  149. use_bng_units == other.use_bng_units &&
  150. surface_grid_density == other.surface_grid_density &&
  151. interaction_radius == other.interaction_radius &&
  152. intermembrane_interaction_radius == other.intermembrane_interaction_radius &&
  153. vacancy_search_distance == other.vacancy_search_distance &&
  154. center_molecules_on_grid == other.center_molecules_on_grid &&
  155. partition_dimension == other.partition_dimension &&
  156. true /*initial_partition_origin*/ &&
  157. subpartition_dimension == other.subpartition_dimension &&
  158. total_iterations == other.total_iterations &&
  159. check_overlapped_walls == other.check_overlapped_walls &&
  160. reaction_class_cleanup_periodicity == other.reaction_class_cleanup_periodicity &&
  161. species_cleanup_periodicity == other.species_cleanup_periodicity &&
  162. molecules_order_random_shuffle_periodicity == other.molecules_order_random_shuffle_periodicity &&
  163. sort_molecules == other.sort_molecules &&
  164. memory_limit_gb == other.memory_limit_gb &&
  165. initial_iteration == other.initial_iteration &&
  166. initial_time == other.initial_time &&
  167. (
  168. (is_set(initial_rng_state)) ?
  169. (is_set(other.initial_rng_state) ?
  170. (initial_rng_state->__eq__(*other.initial_rng_state)) :
  171. false
  172. ) :
  173. (is_set(other.initial_rng_state) ?
  174. false :
  175. true
  176. )
  177. ) &&
  178. append_to_count_output_data == other.append_to_count_output_data &&
  179. continue_after_sigalrm == other.continue_after_sigalrm;
  180. }
  181. std::string GenConfig::to_str(const bool all_details, const std::string ind) const {
  182. std::stringstream ss;
  183. ss << get_object_name() << ": " <<
  184. "seed=" << seed << ", " <<
  185. "time_step=" << time_step << ", " <<
  186. "use_bng_units=" << use_bng_units << ", " <<
  187. "surface_grid_density=" << surface_grid_density << ", " <<
  188. "interaction_radius=" << interaction_radius << ", " <<
  189. "intermembrane_interaction_radius=" << intermembrane_interaction_radius << ", " <<
  190. "vacancy_search_distance=" << vacancy_search_distance << ", " <<
  191. "center_molecules_on_grid=" << center_molecules_on_grid << ", " <<
  192. "partition_dimension=" << partition_dimension << ", " <<
  193. "initial_partition_origin=" << vec_nonptr_to_str(initial_partition_origin, all_details, ind + " ") << ", " <<
  194. "subpartition_dimension=" << subpartition_dimension << ", " <<
  195. "total_iterations=" << total_iterations << ", " <<
  196. "check_overlapped_walls=" << check_overlapped_walls << ", " <<
  197. "reaction_class_cleanup_periodicity=" << reaction_class_cleanup_periodicity << ", " <<
  198. "species_cleanup_periodicity=" << species_cleanup_periodicity << ", " <<
  199. "molecules_order_random_shuffle_periodicity=" << molecules_order_random_shuffle_periodicity << ", " <<
  200. "sort_molecules=" << sort_molecules << ", " <<
  201. "memory_limit_gb=" << memory_limit_gb << ", " <<
  202. "initial_iteration=" << initial_iteration << ", " <<
  203. "initial_time=" << initial_time << ", " <<
  204. "\n" << ind + " " << "initial_rng_state=" << "(" << ((initial_rng_state != nullptr) ? initial_rng_state->to_str(all_details, ind + " ") : "null" ) << ")" << ", " << "\n" << ind + " " <<
  205. "append_to_count_output_data=" << append_to_count_output_data << ", " <<
  206. "continue_after_sigalrm=" << continue_after_sigalrm;
  207. return ss.str();
  208. }
  209. py::class_<Config> define_pybinding_Config(py::module& m) {
  210. return py::class_<Config, std::shared_ptr<Config>>(m, "Config", "Class holds simulation configuration.")
  211. .def(
  212. py::init<
  213. const int,
  214. const double,
  215. const bool,
  216. const double,
  217. const double,
  218. const double,
  219. const double,
  220. const bool,
  221. const double,
  222. const std::vector<double>,
  223. const double,
  224. const double,
  225. const bool,
  226. const int,
  227. const int,
  228. const int,
  229. const bool,
  230. const int,
  231. const uint64_t,
  232. const double,
  233. std::shared_ptr<RngState>,
  234. const bool,
  235. const bool
  236. >(),
  237. py::arg("seed") = 1,
  238. py::arg("time_step") = 1e-6,
  239. py::arg("use_bng_units") = false,
  240. py::arg("surface_grid_density") = 10000,
  241. py::arg("interaction_radius") = FLT_UNSET,
  242. py::arg("intermembrane_interaction_radius") = FLT_UNSET,
  243. py::arg("vacancy_search_distance") = 10,
  244. py::arg("center_molecules_on_grid") = false,
  245. py::arg("partition_dimension") = 10,
  246. py::arg("initial_partition_origin") = std::vector<double>(),
  247. py::arg("subpartition_dimension") = 0.5,
  248. py::arg("total_iterations") = 1000000,
  249. py::arg("check_overlapped_walls") = true,
  250. py::arg("reaction_class_cleanup_periodicity") = 500,
  251. py::arg("species_cleanup_periodicity") = 10000,
  252. py::arg("molecules_order_random_shuffle_periodicity") = 10000,
  253. py::arg("sort_molecules") = false,
  254. py::arg("memory_limit_gb") = -1,
  255. py::arg("initial_iteration") = 0,
  256. py::arg("initial_time") = 0,
  257. py::arg("initial_rng_state") = nullptr,
  258. py::arg("append_to_count_output_data") = false,
  259. py::arg("continue_after_sigalrm") = false
  260. )
  261. .def("check_semantics", &Config::check_semantics)
  262. .def("__copy__", &Config::copy_config)
  263. .def("__deepcopy__", &Config::deepcopy_config, py::arg("memo"))
  264. .def("__str__", &Config::to_str, py::arg("all_details") = false, py::arg("ind") = std::string(""))
  265. .def("__eq__", &Config::__eq__, py::arg("other"))
  266. .def("dump", &Config::dump)
  267. .def_property("seed", &Config::get_seed, &Config::set_seed, "Random generator seed value.")
  268. .def_property("time_step", &Config::get_time_step, &Config::set_time_step, "Set the simulation time step to time_step seconds. 1e-6 (1us) is a common value. \nOne can set the time steps taken by individual molecules, but this \ntime step is still used as a default.\n")
  269. .def_property("use_bng_units", &Config::get_use_bng_units, &Config::set_use_bng_units, "When False (default), MCell uses traditional MCell units for bimolecular reaction rates are:\n * [M^-1*s^-1] for bimolecular reactions between either two volume molecules, a volume molecule \n and a surface (molecule), \n * [um^2*N^-1*s^-1] bimolecular reactions between two surface molecules on the same surface.\nWhen True, BioNetGen units for bimolecular reaction rates are:\n * [um^3*N^-1*s^-1] for any bimolecular reactions. Surface-surface reaction rate conversion assumes 10nm membrane thickness\nBioNetGen units are compatible with BioNetGen's ODE, SSA, and PLA solvers given that seed species \nis copy number (N), these units are not compatible with NFSim. \nNo other units are affected by this setting.\n")
  270. .def_property("surface_grid_density", &Config::get_surface_grid_density, &Config::set_surface_grid_density, "Tile all surfaces so that they can hold molecules at N different positions per square micron.")
  271. .def_property("interaction_radius", &Config::get_interaction_radius, &Config::set_interaction_radius, "Diffusing volume molecules will interact with each other when\nthey get within N microns of each other. The default is\n1/sqrt(PI * Sigma_s) where Sigma_s is the surface grid density \n(default or user-specified).\n")
  272. .def_property("intermembrane_interaction_radius", &Config::get_intermembrane_interaction_radius, &Config::set_intermembrane_interaction_radius, "Diffusing surface molecules will interact with surface molecules on other\nwalls when they get within N microns of each other. The default is\n1/sqrt(PI * Sigma_s) where Sigma_s is the surface grid density \n(default or user-specified). \nWhen unset, the default value is computed as: \n1.0 / sqrt_f(MY_PI * surface_grid_density).\n")
  273. .def_property("vacancy_search_distance", &Config::get_vacancy_search_distance, &Config::set_vacancy_search_distance, "Rather internal, there is usually no need to change this value.\nUsed in dynamic geometry (see Model.apply_vertex_moves()). \nWhen a wall moves or its dimensions change, this is the maximum search distance \nuse when looking onto which tiles place the molecules on this wall. \nIf no empty tile is found within this distance, simulation fails. \n \n")
  274. .def_property("center_molecules_on_grid", &Config::get_center_molecules_on_grid, &Config::set_center_molecules_on_grid, "If set to True, then all molecules on a surface will be\nlocated exactly at the center of their grid element. If False, the\nmolecules will be randomly located when placed, and reactions\nwill take place at the location of the target (or the site of impact\nin the case of 3D molecule/surface reactions). \n")
  275. .def_property("partition_dimension", &Config::get_partition_dimension, &Config::set_partition_dimension, "All the simulated 3d space is placed in a partition. The partition is a cube and \nthis partition_dimension specifies the length of its edge in um.\n")
  276. .def_property("initial_partition_origin", &Config::get_initial_partition_origin, &Config::set_initial_partition_origin, py::return_value_policy::reference, "Optional placement of the initial partition in um, specifies the left, lower front \npoint. If not set, value -partition_dimension/2 is used for each of the dimensions \nplacing the center of the partition to (0, 0, 0). \n")
  277. .def_property("subpartition_dimension", &Config::get_subpartition_dimension, &Config::set_subpartition_dimension, "Subpartition are spatial division of 3D space used to accelerate collision checking.\nIn general, partitions should be chosen to avoid having too many surfaces and molecules\nin one subpartition. \nIf there are few surfaces and/or molecules in a subvolume, it is advantageous to have the \nsubvolume as large as possible. Crossing partition boundaries takes a small amount of time, \nso it is rarely useful to have partitions more finely spaced than the average diffusion distance \nof the faster-moving molecules in the simulation.\n")
  278. .def_property("total_iterations", &Config::get_total_iterations, &Config::set_total_iterations, "Required for checkpointing so that the checkpointed model has information on\nthe intended total number of iterations. \nAlso used when generating visualization data files and also for other reporting uses. \nValue is truncated to an integer.\n")
  279. .def_property("check_overlapped_walls", &Config::get_check_overlapped_walls, &Config::set_check_overlapped_walls, "Enables check for overlapped walls. Overlapping walls can cause issues during \nsimulation such as a molecule escaping closed geometry when it hits two walls \nthat overlap. \n")
  280. .def_property("reaction_class_cleanup_periodicity", &Config::get_reaction_class_cleanup_periodicity, &Config::set_reaction_class_cleanup_periodicity, "Reaction class cleanup removes computed reaction classes for inactive species from memory.\nThis provides faster reaction lookup faster but when the same reaction class is \nneeded again, it must be recomputed.\n")
  281. .def_property("species_cleanup_periodicity", &Config::get_species_cleanup_periodicity, &Config::set_species_cleanup_periodicity, "Species cleanup removes inactive species from memory. It removes also all reaction classes \nthat reference it.\nThis provides faster addition of new species lookup faster but when the species is \nneeded again, it must be recomputed.\n")
  282. .def_property("molecules_order_random_shuffle_periodicity", &Config::get_molecules_order_random_shuffle_periodicity, &Config::set_molecules_order_random_shuffle_periodicity, "Randomly shuffle the order in which molecules are simulated.\nThis helps to overcome potential biases that may occur when \nmolecules are ordered e.g. by their species when simulation starts. \nThe first shuffling occurs at this iteration, i.e. no shuffle is done at iteration 0.\nSetting this parameter to 0 disables the shuffling. \n")
  283. .def_property("sort_molecules", &Config::get_sort_molecules, &Config::set_sort_molecules, "Enables sorting of molecules for diffusion, this may improve cache locality and provide \nslightly better performance. \nProduces different results for the same seed when enabled because molecules are simulated \nin a different order. \n")
  284. .def_property("memory_limit_gb", &Config::get_memory_limit_gb, &Config::set_memory_limit_gb, "Sets memory limit in GB for simulation run. \nWhen this limit is hit, all buffers are flushed and simulation is terminated with an error.\n")
  285. .def_property("initial_iteration", &Config::get_initial_iteration, &Config::set_initial_iteration, "Initial iteration, used when resuming a checkpoint.")
  286. .def_property("initial_time", &Config::get_initial_time, &Config::set_initial_time, "Initial time in us, used when resuming a checkpoint.\nWill be truncated to be a multiple of time step.\n")
  287. .def_property("initial_rng_state", &Config::get_initial_rng_state, &Config::set_initial_rng_state, "Used for checkpointing, may contain state of the random number generator to be set \nafter initialization right before the first event is started. \nWhen not set, the set 'seed' value is used to initialize the random number generator. \n")
  288. .def_property("append_to_count_output_data", &Config::get_append_to_count_output_data, &Config::set_append_to_count_output_data, "Used for checkpointing, instead of creating new files for Count observables data, \nnew values are appended to the existing files. If such files do not exist, new files are\ncreated.\n")
  289. .def_property("continue_after_sigalrm", &Config::get_continue_after_sigalrm, &Config::set_continue_after_sigalrm, "MCell registers a SIGALRM signal handler. When SIGALRM signal is received and \ncontinue_after_sigalrm is False, checkpoint is stored and simulation is terminated. \nWhen continue_after_sigalrm is True, checkpoint is stored and simulation continues.\nSIGALRM is not supported on Windows.\n")
  290. ;
  291. }
  292. std::string GenConfig::export_to_python(std::ostream& out, PythonExportContext& ctx) {
  293. if (!export_even_if_already_exported() && ctx.already_exported(this)) {
  294. return ctx.get_exported_name(this);
  295. }
  296. std::string exported_name = "config_" + std::to_string(ctx.postinc_counter("config"));
  297. if (!export_even_if_already_exported()) {
  298. ctx.add_exported(this, exported_name);
  299. }
  300. bool str_export = export_as_string_without_newlines();
  301. std::string nl = "";
  302. std::string ind = " ";
  303. std::stringstream ss;
  304. if (!str_export) {
  305. nl = "\n";
  306. ind = " ";
  307. ss << exported_name << " = ";
  308. }
  309. ss << "m.Config(" << nl;
  310. if (seed != 1) {
  311. ss << ind << "seed = " << seed << "," << nl;
  312. }
  313. if (time_step != 1e-6) {
  314. ss << ind << "time_step = " << f_to_str(time_step) << "," << nl;
  315. }
  316. if (use_bng_units != false) {
  317. ss << ind << "use_bng_units = " << use_bng_units << "," << nl;
  318. }
  319. if (surface_grid_density != 10000) {
  320. ss << ind << "surface_grid_density = " << f_to_str(surface_grid_density) << "," << nl;
  321. }
  322. if (interaction_radius != FLT_UNSET) {
  323. ss << ind << "interaction_radius = " << f_to_str(interaction_radius) << "," << nl;
  324. }
  325. if (intermembrane_interaction_radius != FLT_UNSET) {
  326. ss << ind << "intermembrane_interaction_radius = " << f_to_str(intermembrane_interaction_radius) << "," << nl;
  327. }
  328. if (vacancy_search_distance != 10) {
  329. ss << ind << "vacancy_search_distance = " << f_to_str(vacancy_search_distance) << "," << nl;
  330. }
  331. if (center_molecules_on_grid != false) {
  332. ss << ind << "center_molecules_on_grid = " << center_molecules_on_grid << "," << nl;
  333. }
  334. if (partition_dimension != 10) {
  335. ss << ind << "partition_dimension = " << f_to_str(partition_dimension) << "," << nl;
  336. }
  337. if (initial_partition_origin != std::vector<double>() && !skip_vectors_export()) {
  338. ss << ind << "initial_partition_origin = " << export_vec_initial_partition_origin(out, ctx, exported_name) << "," << nl;
  339. }
  340. if (subpartition_dimension != 0.5) {
  341. ss << ind << "subpartition_dimension = " << f_to_str(subpartition_dimension) << "," << nl;
  342. }
  343. if (total_iterations != 1000000) {
  344. ss << ind << "total_iterations = " << f_to_str(total_iterations) << "," << nl;
  345. }
  346. if (check_overlapped_walls != true) {
  347. ss << ind << "check_overlapped_walls = " << check_overlapped_walls << "," << nl;
  348. }
  349. if (reaction_class_cleanup_periodicity != 500) {
  350. ss << ind << "reaction_class_cleanup_periodicity = " << reaction_class_cleanup_periodicity << "," << nl;
  351. }
  352. if (species_cleanup_periodicity != 10000) {
  353. ss << ind << "species_cleanup_periodicity = " << species_cleanup_periodicity << "," << nl;
  354. }
  355. if (molecules_order_random_shuffle_periodicity != 10000) {
  356. ss << ind << "molecules_order_random_shuffle_periodicity = " << molecules_order_random_shuffle_periodicity << "," << nl;
  357. }
  358. if (sort_molecules != false) {
  359. ss << ind << "sort_molecules = " << sort_molecules << "," << nl;
  360. }
  361. if (memory_limit_gb != -1) {
  362. ss << ind << "memory_limit_gb = " << memory_limit_gb << "," << nl;
  363. }
  364. if (initial_iteration != 0) {
  365. ss << ind << "initial_iteration = " << initial_iteration << "," << nl;
  366. }
  367. if (initial_time != 0) {
  368. ss << ind << "initial_time = " << f_to_str(initial_time) << "," << nl;
  369. }
  370. if (is_set(initial_rng_state)) {
  371. ss << ind << "initial_rng_state = " << initial_rng_state->export_to_python(out, ctx) << "," << nl;
  372. }
  373. if (append_to_count_output_data != false) {
  374. ss << ind << "append_to_count_output_data = " << append_to_count_output_data << "," << nl;
  375. }
  376. if (continue_after_sigalrm != false) {
  377. ss << ind << "continue_after_sigalrm = " << continue_after_sigalrm << "," << nl;
  378. }
  379. ss << ")" << nl << nl;
  380. if (!str_export) {
  381. out << ss.str();
  382. return exported_name;
  383. }
  384. else {
  385. return ss.str();
  386. }
  387. }
  388. std::string GenConfig::export_vec_initial_partition_origin(std::ostream& out, PythonExportContext& ctx, const std::string& parent_name) {
  389. // does not print the array itself to 'out' and returns the whole list
  390. std::stringstream ss;
  391. ss << "[";
  392. for (size_t i = 0; i < initial_partition_origin.size(); i++) {
  393. const auto& item = initial_partition_origin[i];
  394. if (i == 0) {
  395. ss << " ";
  396. }
  397. else if (i % 16 == 0) {
  398. ss << "\n ";
  399. }
  400. ss << f_to_str(item) << ", ";
  401. }
  402. ss << "]";
  403. return ss.str();
  404. }
  405. } // namespace API
  406. } // namespace MCell