observables.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. .. _api-observables:
  2. ***********
  3. Observables
  4. ***********
  5. Count
  6. =====
  7. Represents a molecule or reaction count observable.
  8. What is counted is defined through a CounTerm tree and a reference to
  9. the root of this tree is stored into attribute expression.
  10. This tree usually contains just one node.
  11. Example: `1500_region_release_must_set_compartment/model.py <https://github.com/mcellteam/mcell_tests/blob/master/tests/pymcell4/1500_region_release_must_set_compartment/model.py>`_
  12. Attributes:
  13. ***********
  14. .. _Count__name:
  15. name: str
  16. ---------
  17. | Name of a count may be specified when one needs to search for them later.
  18. | When the count is created when a BNGL file is loaded, its name is set, for instance
  19. | when the following BNGL code is loaded\:
  20. |
  21. | begin observables
  22. | Molecules Acount A
  23. | end observables
  24. |
  25. | the name is set to Acount.
  26. | - default argument value in constructor: None
  27. .. _Count__file_name:
  28. file_name: str
  29. --------------
  30. | File name where this observable values will be stored.
  31. | File extension or setting explicit output_format determines the output format.
  32. | A) When not set, the value is set using seed during model initialization as follows:
  33. | file_name = './react_data/seed_' + str(model.config.seed).zfill(5) + '/' + name + '.dat'
  34. | and the output format is set to CountOutputFormat.DAT in the constructor.
  35. | B) When the file_name is set explicitly by the user and the extension is .dat such as here:
  36. | file_name = './react_data/seed_' + str(SEED).zfill(5) + '/' + name + '.dat'
  37. | and the output format is set to CountOutputFormat.DAT in the constructor.
  38. | File names for individual Counts must be different.
  39. | C) When the file_name is set explicitly by the user and the extension is .gdat such as here:
  40. | file_name = './react_data/seed_' + str(SEED).zfill(5) + '/counts.gdat'
  41. | and the output format is set to CountOutputFormat.GDAT in the constructor.
  42. | The file name is usually the same for all counts but one can
  43. | create multiple gdat files with different observables.
  44. | All observables that are stored into a single .gdat file must have the same
  45. | periodicity specified by attribute every_n_timesteps.
  46. | Must be set.
  47. | - default argument value in constructor: None
  48. .. _Count__expression:
  49. expression: CountTerm
  50. ---------------------
  51. | The expression must be set to a root of an expression tree composed of CountTerms.
  52. | In the usual cases, there is just one CountTerm in this expression tree and its
  53. | node_type is ExprNodeType.LEAF.
  54. | The count expression tree defines CountTerm objects that are added or subtracted
  55. | from each other.
  56. | - default argument value in constructor: None
  57. .. _Count__multiplier:
  58. multiplier: float
  59. -----------------
  60. | In some cases it might be useful to multiply the whole count by a constant to get
  61. | for instance concentration. The expression tree allows only addition and subtraction
  62. | of count terms so such multiplication can be done through this attribute.
  63. | It can be also used to divide the resulting count by passing an inverse of the divisor (1/d).
  64. | - default argument value in constructor: 1
  65. .. _Count__every_n_timesteps:
  66. every_n_timesteps: float
  67. ------------------------
  68. | Specifies periodicity of this count's output.
  69. | Value is truncated (floored) to an integer.
  70. | If value is set to 0, this Count is used only on-demand through calls to its
  71. | get_current_value method.
  72. | - default argument value in constructor: 1
  73. .. _Count__output_format:
  74. output_format: CountOutputFormat
  75. --------------------------------
  76. | Listed as the last attribute because the automatic default value
  77. | is sufficient in most cases.
  78. | Selection of output format. Default setting uses file extension
  79. | from attribute file_name.
  80. | When set to CountOutputFormat.AUTOMATIC_FROM_EXTENSION,
  81. | this output_format is set automatically only in the Count's constructor.
  82. | - default argument value in constructor: CountOutputFormat.AUTOMATIC_FROM_EXTENSION
  83. Methods:
  84. *********
  85. .. _Count__get_current_value:
  86. get_current_value () -> float
  87. -----------------------------
  88. | Returns the current value for this count. Can be used to count both molecules and reactions.
  89. | Reaction counting starts at the beginning of the simulation.
  90. | The model must be initialized with this Count present as one of the observables.
  91. | Examples: `2600_get_current_mol_count/model.py <https://github.com/mcellteam/mcell_tests/blob/master/tests/pymcell4_positive/2600_get_current_mol_count/model.py>`_ `2650_get_current_rxn_count/model.py <https://github.com/mcellteam/mcell_tests/blob/master/tests/pymcell4_positive/2650_get_current_rxn_count/model.py>`_
  92. CountTerm
  93. =========
  94. A count observable can be defined as an expression composed of addition
  95. or subtraction individual count terms. This class represents one count term
  96. in this expression.
  97. Attributes:
  98. ***********
  99. .. _CountTerm__species_pattern:
  100. species_pattern: Complex
  101. ------------------------
  102. | Count the number of molecules that match the given complex instance pattern.
  103. | This corresponds to the BNGL 'Species' specifier in the BNGL seed species section.
  104. | Counts each molecule exactly once.
  105. | If the pattern has a compartment set, this specifies the counted region.
  106. | Exactly one of species_pattern, molecules_pattern, and reaction_rule must be set.
  107. | - default argument value in constructor: None
  108. .. _CountTerm__molecules_pattern:
  109. molecules_pattern: Complex
  110. --------------------------
  111. | Count the number of matches of the given pattern on molecules.
  112. | This corresponds to the BNGL 'Molecules' specifier in the BNGL seed species section.
  113. | The observable will increment the count every time the pattern matches the molecule.
  114. | For instance, pattern A will match a complex A(a!1).B(a!1,a!2).A(b!2) twice.
  115. | When the pattern is symmetric, e.g. as in A(a!1).A(a!1) then a
  116. | molecule A(b.a!1).A(a!1,b!2).B(a!2) will be counted twice because the
  117. | pattern may match in two different ways.
  118. | If the pattern has a compartment set, the compartment is used to filter out the molecules.
  119. | Exactly one of species_pattern, molecules_pattern, and reaction_rule must be set.
  120. | - default argument value in constructor: None
  121. .. _CountTerm__reaction_rule:
  122. reaction_rule: ReactionRule
  123. ---------------------------
  124. | Count the number of applications of this specific reactions that occurred since the
  125. | start of the simulation.
  126. | Exactly one of species_pattern, molecules_pattern, and reaction_rule must be set.
  127. | - default argument value in constructor: None
  128. .. _CountTerm__region:
  129. region: Region
  130. --------------
  131. | Only a GeometryObject or SurfaceRegion can be passed as the region argument,
  132. | compound regions (created with +, -, \*) are not supproted yet.
  133. | Can be combined with a compartment specified in the species_pattern or molecules_pattern.
  134. | If compartment in species_pattern or molecules_pattern is not specified and
  135. | region is left unset, counting is done in the whole world.
  136. | - default argument value in constructor: None
  137. .. _CountTerm__node_type:
  138. node_type: ExprNodeType
  139. -----------------------
  140. | Internal, used to specify what type of count expression node this object represents.
  141. | - default argument value in constructor: ExprNodeType.LEAF
  142. .. _CountTerm__left_node:
  143. left_node: CountTerm
  144. --------------------
  145. | Internal, when node_type is not Leaf, this is the left operand.
  146. | - default argument value in constructor: None
  147. .. _CountTerm__right_node:
  148. right_node: CountTerm
  149. ---------------------
  150. | Internal, when node_type is not Leaf, this is the right operand.
  151. | - default argument value in constructor: None
  152. .. _CountTerm__initial_reactions_count:
  153. initial_reactions_count: int
  154. ----------------------------
  155. | Used for checkpointing, allows to set initial count of reactions that occurred.
  156. | Ignored when molecules are counted.
  157. | - default argument value in constructor: 0
  158. Methods:
  159. *********
  160. .. _CountTerm____add__:
  161. __add__ (op2: CountTerm) -> CountTerm
  162. -------------------------------------
  163. | Create a new CountTerm that represents addition of two count terms.
  164. | Usually used through operator '+' such as in ct1 + ct2.
  165. * | op2: CountTerm
  166. .. _CountTerm____sub__:
  167. __sub__ (op2: CountTerm) -> CountTerm
  168. -------------------------------------
  169. | Create a new CountTerm that represents subtraction of two count terms.
  170. | Usually used through operator '-' such as in ct1 - ct2.
  171. * | op2: CountTerm
  172. Observables
  173. ===========
  174. Container used to hold observables-related model data.
  175. Observables are the measured values of the system.
  176. This class also includes information on visualization of simulation.
  177. Example: `2600_get_current_mol_count/observables.py <https://github.com/mcellteam/mcell_tests/blob/master/tests/pymcell4_positive/2600_get_current_mol_count/observables.py>`_
  178. Attributes:
  179. ***********
  180. .. _Observables__viz_outputs:
  181. viz_outputs: List[VizOutput]
  182. ----------------------------
  183. | List of visualization outputs to be included in the model.
  184. | There is usually just one VizOutput object.
  185. | - default argument value in constructor: None
  186. .. _Observables__counts:
  187. counts: List[Count]
  188. -------------------
  189. | List of counts to be included in the model.
  190. | - default argument value in constructor: None
  191. Methods:
  192. *********
  193. .. _Observables__add_viz_output:
  194. add_viz_output (viz_output: VizOutput)
  195. --------------------------------------
  196. | Adds a reference to the viz_output object to the list of visualization output specifications.
  197. * | viz_output: VizOutput
  198. .. _Observables__add_count:
  199. add_count (count: Count)
  200. ------------------------
  201. | Adds a reference to the count object to the list of count specifications.
  202. * | count: Count
  203. .. _Observables__find_count:
  204. find_count (name: str) -> Count
  205. -------------------------------
  206. | Finds a count object by its name, returns None if no such count is present.
  207. * | name: str
  208. .. _Observables__load_bngl_observables:
  209. load_bngl_observables (file_name: str, observables_path_or_file: str=None, parameter_overrides: Dict[str, float]=None, observables_output_format: CountOutputFormat=CountOutputFormat.AUTOMATIC_FROM_EXTENSION)
  210. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  211. | Loads section observables from a BNGL file and creates Count objects according to it.
  212. | All elementary molecule types used in the seed species section must be defined in subsystem.
  213. * | file_name: str
  214. | Path to the BNGL file.
  215. * | observables_path_or_file: str = None
  216. | Directory prefix or file name where observable values will be stored.
  217. | If a directory such as './react_data/seed_' + str(SEED).zfill(5) + '/' or an empty
  218. | string/unset is used, each observable gets its own file and the output file format for created Count
  219. | objects is CountOutputFormat.DAT.
  220. | When not set, this path is used: './react_data/seed_' + str(model.config.seed).zfill(5) + '/'.
  221. | If a file has a .gdat extension such as
  222. | './react_data/seed_' + str(SEED).zfill(5) + '/counts.gdat', all observable are stored in this
  223. | file and the output file format for created Count objects is CountOutputFormat.GDAT.
  224. | Must not be empty when observables_output_format is explicitly set to CountOutputFormat.GDAT.
  225. * | parameter_overrides: Dict[str, float] = None
  226. | For each key k in the parameter_overrides, if it is defined in the BNGL's parameters section,
  227. | its value is ignored and instead value parameter_overrides[k] is used.
  228. * | observables_output_format: CountOutputFormat = CountOutputFormat.AUTOMATIC_FROM_EXTENSION
  229. | Selection of output format. Default setting uses automatic detection
  230. | based on contents of the 'observables_path_or_file' attribute.
  231. | Example: `2100_gradual_bngl_load/model.py <https://github.com/mcellteam/mcell_tests/blob/master/tests/pymcell4/2100_gradual_bngl_load/model.py>`_
  232. VizOutput
  233. =========
  234. Defines a visualization output with locations of molecules
  235. that can be then loaded by CellBlender.
  236. Example: `1100_point_release/model.py <https://github.com/mcellteam/mcell_tests/blob/master/tests/pymcell4/1100_point_release/model.py>`_
  237. Attributes:
  238. ***********
  239. .. _VizOutput__output_files_prefix:
  240. output_files_prefix: str
  241. ------------------------
  242. | Prefix for the viz output files.
  243. | When not set, the default prefix value is computed from the simulation seed
  244. | when the model is initialized to\:
  245. | './viz_data/seed_' + str(seed).zfill(5) + '/Scene'.
  246. | - default argument value in constructor: None
  247. .. _VizOutput__species_list:
  248. species_list: List[Species]
  249. ---------------------------
  250. | Specifies a list of species to be visualized, when empty, all_species will be generated.
  251. | - default argument value in constructor: None
  252. .. _VizOutput__mode:
  253. mode: VizMode
  254. -------------
  255. | Specified the output format of the visualization files.
  256. | VizMode.ASCII is a readable representation, VizMode.CELLBLENDER is a binary representation
  257. | that cannot be read using a text editor but is faster to generate.
  258. | - default argument value in constructor: VizMode.ASCII
  259. .. _VizOutput__every_n_timesteps:
  260. every_n_timesteps: float
  261. ------------------------
  262. | Specifies periodicity of visualization output.
  263. | Value is truncated (floored) to an integer.
  264. | Value 0 means that the viz output is ran only once at iteration 0.
  265. | - default argument value in constructor: 1