python_export_constants.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 LIBMCELL_API_PYTHON_EXPORT_CONSTANTS_H_
  12. #define LIBMCELL_API_PYTHON_EXPORT_CONSTANTS_H_
  13. #include "datamodel_defines.h"
  14. namespace MCell {
  15. namespace API {
  16. const int FLOAT_OUT_PRECISION = 15; // this is the precision that is used by mdl_to_data_model.py script
  17. const int MAX_SPECIES_NAME_LENGTH = 32;
  18. const char* const SHARED = "shared";
  19. const char* const PARAMETERS = "parameters";
  20. const char* const SUBSYSTEM = "subsystem";
  21. const char* const GEOMETRY = "geometry";
  22. const char* const INSTANTIATION = "instantiation";
  23. const char* const OBSERVABLES = "observables";
  24. const char* const SIMULATION_STATE = "simulation_state";
  25. const char* const MODEL = "model";
  26. #define CUSTOMIZATION "customization"
  27. const char* const CUSTOM_ARGPARSE_AND_PARAMETERS = "custom_argparse_and_parameters";
  28. const char* const CUSTOM_CONFIG = "custom_config";
  29. const char* const CUSTOM_INIT_AND_RUN = "custom_init_and_run";
  30. const char* const PARAMETER_OVERRIDES = "parameter_overrides";
  31. const char* const NOT_DEFINED = "not_defined";
  32. const char* const PY_EXT = ".py";
  33. const char* const BNGL_EXT = ".bngl";
  34. const char* const IMPORT = "import";
  35. const char* const MDOT = "m.";
  36. const char* const IND = " ";
  37. const char* const IND4 = " "; // this indent must be 4 chars because it is used as indentation in Python
  38. const char* const IND8 = " ";
  39. const char* const BLOCK_BEGIN1 = "# ---- ";
  40. const char* const BLOCK_BEGIN2 = " ----\n";
  41. const char* const BLOCK_END1 = "# ^^^^ ";
  42. const char* const BLOCK_END2 = " ^^^^\n\n";
  43. const char* const CTOR_END = ")\n\n";
  44. #define PARAM_SEED "SEED"
  45. const char* const PARAM_ITERATIONS = "ITERATIONS";
  46. const char* const PARAM_TIME_STEP = "TIME_STEP";
  47. const char* const PARAM_DUMP = "DUMP";
  48. const char* const PARAM_EXPORT_DATA_MODEL = "EXPORT_DATA_MODEL";
  49. const char* const SET_BNGL_MOLECULE_TYPES_INFO = "set_bngl_molecule_types_info";
  50. const char* const VAR_BNGL_PARAMS = "bngl_params";
  51. const char* const VEC3 = "Vec3";
  52. const char* const COMPONENT_PREFIX = "comp_";
  53. const char* const ELEMENTARY_MOLECULE_TYPE_PREFIX = "emt_";
  54. const char* const COUNT_PREFIX = "count_";
  55. const char* const COUNT_TERM_PREFIX = "cterm_";
  56. const char* const UNNAMED_REACTION_RULE_PREFIX = "unnamed_reaction_rule_";
  57. const char* const SURFACE_CLASS_PREFIX = "surface_class_";
  58. const char* const MOLECULE_LIST_PREFIX = "molecule_list_";
  59. const char* const VIZ_OUTPUT_NAME = "viz_output";
  60. const char* const DEFAULT_VIZ_OUTPUT_FILENAME_PREFIX = "./" VALUE_VIZ_DATA "/seed_' + str(" PARAM_SEED ").zfill(5) + '/Scene";
  61. const char* const DEFAULT_RXN_OUTPUT_FILENAME_PREFIX = "./" VALUE_REACT_DATA "/seed_' + str(" PARAM_SEED ").zfill(5) + '/";
  62. const char* const INTERPRETER = "#!/usr/bin/env python3\n\n";
  63. const char* const GENERATED_WARNING =
  64. "# WARNING: This is an automatically generated file and will be overwritten\n"
  65. "# by CellBlender on the next model export.\n";
  66. const char* const IMPORT_SYS_OS =
  67. "import sys\n"
  68. "import os\n"
  69. ;
  70. const char* const IMPORT_OS = "import os\n";
  71. const char* const IMPORT_MATH = "import math\n";
  72. const char* const IMPORT_SHARED = "import shared\n";
  73. #define MODEL_PATH "MODEL_PATH"
  74. const char* const MODEL_PATH_SETUP =
  75. MODEL_PATH " = os.path.dirname(os.path.abspath(__file__))\n"
  76. ;
  77. const char* const MCELL_PATH_SETUP =
  78. "\n# ---- import mcell module located in directory specified by system variable MCELL_PATH ----\n\n"
  79. "MCELL_PATH = os.environ.get('MCELL_PATH', '')\n"
  80. "if MCELL_PATH:\n"
  81. " lib_path = os.path.join(MCELL_PATH, 'lib')\n"
  82. " if os.path.exists(os.path.join(lib_path, 'mcell.so')) or \\\n"
  83. " os.path.exists(os.path.join(lib_path, 'mcell.pyd')):\n"
  84. " sys.path.append(lib_path)\n"
  85. " else:\n"
  86. " print(\"Error: Python module mcell.so or mcell.pyd was not found in \"\n"
  87. " \"directory '\" + lib_path + \"' constructed from system variable \"\n"
  88. " \"MCELL_PATH.\")\n"
  89. " sys.exit(1)\n"
  90. "else:\n"
  91. " print(\"Error: system variable MCELL_PATH that is used to find the mcell \"\n"
  92. " \"library was not set.\")\n"
  93. " sys.exit(1)\n"
  94. ;
  95. const char* const IMPORT_MCELL_AS_M = "import mcell as m\n\n";
  96. const char* const CHECKPOINT_ITERATION = "checkpoint_iteration";
  97. const char* const REGION_ALL_NAME = "ALL";
  98. const char* const REGION_ALL_SUFFIX = "[ALL]";
  99. const char* const NULL_PRODUCTS = "NULL";
  100. const char* const COUNT = "COUNT";
  101. const char* const WORLD = "WORLD";
  102. const char* const WORLD_FIRST_UPPER = "World";
  103. const char* const REV_RXN_SUFFIX = "_rev";
  104. std::string get_customization_import(const std::string& customization_module);
  105. std::string get_argparse_w_customization_begin(const std::string& customization_module);
  106. std::string get_argparse_checkpoint_iteration();
  107. std::string get_resume_from_checkpoint_code();
  108. std::string get_argparse_w_customization_end();
  109. std::string get_user_defined_configuration(const std::string& customization_module);
  110. std::string get_abs_path(const std::string file);
  111. std::string get_import(const std::string module);
  112. std::string get_import_star(const std::string module);
  113. const char* const TEMPLATE_CUSTOM_ARGPARSE_AND_PARAMETERS =
  114. "\"\"\"\n"
  115. "def custom_argparse_and_parameters():\n"
  116. " # When uncommented, this function is called to parse \n"
  117. " # custom commandline arguments.\n"
  118. " # It is executed before any of the automatically generated \n"
  119. " # parameter values are set so one can override the parameter \n"
  120. " # values here as well.\n"
  121. " # To override parameter values, add or overwrite an item in dictionary\n"
  122. " # shared.parameter_overrides, e.g. shared.parameter_overrides['SEED'] = 10\n"
  123. " pass\n"
  124. "\"\"\"\n"
  125. ;
  126. const char* const TEMPLATE_CUSTOM_CONFIG =
  127. "\"\"\"\n"
  128. "def custom_config(model):\n"
  129. " # When uncommented, this function is called to set custom\n"
  130. " # model configuration.\n"
  131. " # It is executed after basic parameter setup is done and \n"
  132. " # before any components are added to the model. \n"
  133. " pass\n"
  134. "\"\"\"\n"
  135. ;
  136. std::string get_template_custom_init_and_run(const std::string& parameters_module);
  137. } // namespace API
  138. } // namespace MCell
  139. #endif // LIBMCELL_API_PYTHON_EXPORT_CONSTANTS_H_