observables.yaml 12 KB

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