bngl.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. **************************
  2. BioNetGen Language Support
  3. **************************
  4. MCell4 uses BioNetGen rule-based definition formalism to define species and reaction rules.
  5. Documentation on the BioNetGen language (BNGL) can be found on the official `BioNetGen website <http://bionetgen.org/>`_.
  6. This section contains a short overview of BNGL with described limitations and extensions.
  7. Loading a BNGL File
  8. ###################
  9. A file in BioNetGen language can be loaded directly from MCell4 Python model without any previous conversions like this:
  10. .. code-block:: python
  11. model = m.Model()
  12. ...
  13. # load our BNGL file and set directory for BNGL observables
  14. model.load_bngl('model.bngl', './react_data/seed_' + str(SEED).zfill(5) + '/')
  15. Calling *load_bngl* invokes a BNGL parser and the parsed data are converted internally into MCell4 classes.
  16. For more details see Model.load_bngl (that loads the full BNGL file), or methods that load only partial information:
  17. Subsystem.load_bngl_molecule_types_and_reaction_rules, Instatiation.load_bngl_compartments_and_seed_species,
  18. Observables.load_bngl_observables, and bngl_utils.load_bngl_parameters.
  19. Terminology
  20. ###########
  21. A *component type* is a template for components that defines name and all allowed states of a *component*.
  22. An *elementary molecule type* is a template for elementary molecules that defines name and all
  23. component types used by an *elementary molecule*.
  24. Example in BNGL:
  25. .. code-block:: text
  26. begin molecule types
  27. # simple elementary molecule type 'A' that has no components
  28. A
  29. # elementary molecule type 'B' that uses a single component type 'c' with no states
  30. B(c)
  31. # elementary molecule type 'C' that uses a single component type 'b' with states 'A' and 'B'
  32. C(b~A~B)
  33. end molecule types
  34. A BNGL *complex* is defined as a set of *elementary molecules* where each elementary molecule may contain *components*.
  35. These components may have *state* and *bond* declared. Through bonds, the elementary molecules are linked together.
  36. A complex is either a pattern where not all components need to be specified or a fully-specified complex
  37. where all contained elementary molecules contain all components for their type, and their states are set.
  38. .. code-block:: text
  39. # block seed species defines initial molecules in a simulation
  40. # all complexes used here must be fully-qualified
  41. begin seed species
  42. # complex with a single elementary molecule A, the initial count is 10
  43. A 10
  44. # complex with a single elementary molecule C with component b state set to A
  45. C(b~A)
  46. # complex composed of elem. molecules B and C bound through components
  47. B(c!1).C(b~A!1)
  48. end molecule types
  49. # block observables defines what patterns will be counted,
  50. # the complexes used here do not have to be fully-qualified
  51. begin observables
  52. # pattern with a single elementary molecule A, name of the observable is obs_A
  53. Molecules obs_A A
  54. # pattern matching a molecule C with any component state, bound or unbound
  55. Molecules obs_C C
  56. # pattern matching a molecule C with component's b state A, component b must be unbound
  57. Molecules obs_CbA C(b~A)
  58. # pattern matching a molecule that has both B and C with any component states
  59. # (in our example, the only complexes that match must be bound but the pattern does not require it)
  60. Molecules obs_CB B.C
  61. end observables
  62. What we call elementary molecule is in BNGL usually called just molecule, but we needed to be precise
  63. because in the MCell context, the term *molecule* is a single simulated agent.
  64. Each MCell molecule has a *species* assigned that defines its type.
  65. A species is represented by a fully-specified complex.
  66. Reaction Rules
  67. ##############
  68. Simple Reaction Rules
  69. *********************
  70. We will start with a simple example of a reversible bimolecular reaction.
  71. .. code-block:: text
  72. begin reaction rules
  73. A + B <-> C fwd_rate, rev_rate
  74. end reaction rules
  75. All reaction rules in MCell follow the law of mass action and
  76. this particular rule tells us that when molecule of species A hits a molecule of species B,
  77. then with a probability given by fwd_rate, a reaction can occur that transforms A and B into C.
  78. This is a reversible reaction rule, so also a unimolecular reaction is defined for C to split into
  79. A and B and the probability of this happening is given by rev_rate.
  80. Graph Transformations
  81. *********************
  82. A reaction rule in BNGL defines a graph transformation that creates or removes bonds, changes states, or
  83. adds or removes elementary molecules. We will demonstrate this graph transformation on an example:
  84. .. code-block:: text
  85. begin molecule types
  86. # A has two identical component types
  87. A(c0~R~S, c0~R~S)
  88. # B has two different component types (although their states are named identically)
  89. B(c2~U~V, c3~U~V)
  90. end molecule types
  91. begin reaction rules
  92. A(c0~R) + B(c2) -> A(c0~S!1).B(c2!1) rate
  93. end reaction rules
  94. The reaction rule makes a bond between A's component c0 with B's c2 and also changes the state of A's c0 from R to S
  95. as shown in the following image:
  96. .. image:: images/bngl_rule.png
  97. The way this transformation works is shown in the following image.
  98. Our inputs are reactants (2nd row). A mapping from each elementary molecules and each component
  99. from *reactant patterns* onto *reactants* is computed. All elementary molecules and components must be mapped otherwise
  100. the rule cannot be applied. There can be multiple mappings in general, but there is just one in our example.
  101. The next step is to compute a mapping of elementary molecules and components from the
  102. *reaction rule product pattern* onto reactant patterns.
  103. The difference between the reaction rule product pattern and the reactant patterns
  104. tells us what changes need to be made. In this instance, a bond between A's c0 with state R and B's c2
  105. is created,d the same A's component's c0 state is changed to S.
  106. Once we have our mappings, we can follow the arrows leading from the
  107. reaction rule product pattern to reactant patterns and then to reactants and do exactly these changes on the
  108. reactants, as shown in the row *reactants changed into products*.
  109. .. image:: images/bngl_rule_application.png
  110. Reaction Rates
  111. **************
  112. MCell and BioNetGen use different units for bimolecular kinetic rates.
  113. In MCell, a volume-volume reaction (reaction between two molecules
  114. that are free to diffuse in 3D space) is M\ :sup:`-1`\*s\ :sup:`-1`\ where
  115. M is the molar concentration (number of moles per liter).
  116. In BioNetGen, the user is not constricted to a specific unit but a usual unit
  117. is N\ :sup:`-1`\*s\ :sup:`-1`\ where N is a number of molecules per compartment
  118. and the default compartment volume if a compartment is not specified is 1fl (= 1 um\ :sup:`3`\).
  119. To convert from BioNetGen to MCell units, one needs to multiply the
  120. BioNetGen rate by NA * V where NA is Avogardro's constant and V is volume
  121. of the compartment is liters as derived here:
  122. 1/M = 1/(#moles/V) = 1/( (N/NA)/V) = NA * V * 1/N
  123. The unimolecular reaction rates in MCell and BioNetGen both use unit s\ :sup:`-1`\.
  124. MCell Parameter Prefixes
  125. ########################
  126. To simplify interoperability between BioNetGen and MCell, special parameters
  127. with reserved prefixes and names are used to provide the information needed by MCell such as diffusion constants.
  128. **MCELL_REDEFINE_** - allows a parameter to have a different value in MCell and for BioNetGen.
  129. Example:
  130. .. code-block:: text
  131. begin parameters
  132. NA_um3 6.022e8
  133. VOL_RXN 1
  134. # we will redefine the parameter VOL_RXN for MCell
  135. MCELL_REDEFINE_VOL_RXN NA_um3
  136. # the BioNetGen value of the parameter kp1 is 1 but for MCell
  137. # it is 6.022e8 * 1
  138. kp1 VOL_RXN * 1
  139. end parameters
  140. **MCELL_DIFFUSION_CONSTANT_3D_**, **MCELL_DIFFUSION_CONSTANT_2D_** - allows to specify a diffusion constant for a 3D (volume) or 2D (surface) elementary molecule
  141. type.
  142. .. code-block:: text
  143. begin parameters
  144. MCELL_DIFFUSION_CONSTANT_3D_V 1e-6
  145. MCELL_DIFFUSION_CONSTANT_2D_S 1e-7
  146. end parameters
  147. begin molecule types
  148. V
  149. S
  150. end molecule types
  151. All these parameter prefixes are ignored by the BioNetGen tools and are interpreted as
  152. any other parameter.
  153. Compartments and Orientations
  154. #############################
  155. BNGL compartments allow to define hierarchical volumes or surfaces where molecules are located.
  156. With compartments, one can define e.g. a transport reaction where a molecule that usually diffuses
  157. in volume is transported by a channel located in a membrane into another volume compartment.
  158. Let's say we need to define a reaction where a volume molecule A in a volume/3D compartment
  159. reacts with a surface molecule T (transporter) in a surface compartment as shown in Fig. X7.
  160. An example of compartments is shown in the following figure.
  161. EC is extracellular space, PM is plasma membrane, and CP is cytoplasm.
  162. A is a molecule that diffuses freely in 3D space, and T is located in a membrane.
  163. .. image:: images/bngl_compartments.png
  164. In BNGL, a reaction that defines transport of A from compartment EC into CP is represented like this:
  165. A\@EC + T\@PM -> A\@CP + T\@PM. An issue arises when one needs to model multiple instances of cells or organelles.
  166. A compartment is a specific object in the simulation. If we wanted to simulate multiple cells, we would need
  167. to repeat the definition of this reaction rule for
  168. each cell (with PM1, PM2, ...) e.g. like this: A\@EC + T\@PM1 -> A\@CP1 + T\@PM1, A\@EC + T\@PM2 -> A\@CP2 + T\@PM2, etc.
  169. To avoid the repetition of reaction rules for each compartment and to keep the BNG language consistent,
  170. an extension to the BNG language that uses compartment classes \@IN and \@OUT was introduced.
  171. The original BNG reaction with specific compartments is more generally represented as A\@OUT + T -> A\@IN + T.
  172. Only bimolecular reactions with one volume a one surface reactant may use \@IN or \@OUT compartment classes because
  173. the compartment of the surface reactant defines the meaning of the \@IN and \@OUT compartment class of the volume reactant.
  174. When this rule is applied to reactants A\@EC and T\@CP, we know that the compartment of T is PM, the compartment outside (parent)
  175. is EC, and inside is CP. So, we insert this information to the rule A\@OUT + T -> A\@IN + T and get A\@EC + T\@PM -> A\@CP + T\@PM
  176. (same as the example rule we started with).
  177. One more related case is the position of the reaction product. Let's have a reaction AT -> T + A.
  178. AT is a surface molecule that represents A bound to T. When it dissociates, A must be placed to the 'inside' or 'outside'
  179. compartment. When no compartment or compartment class is specified for the product volume molecule, the target compartment
  180. is selected randomly. A surface product molecule stays at the same surface compartment as the reactant.
  181. MCell3 used molecule orientations to limit which surface and volume reactions can occur.
  182. A surface molecule S could be released or created as a product in two different states S' (UP) and S, (DOWN).
  183. This behavior was deprecated in MCell4 and all surface molecules are by default created with orientation UP.
  184. If specific orientation is needed, one can use a component with state such as S(orient~UP~DOWN).
  185. Limitations
  186. ###########
  187. This section lists the limitations of the MCell4 BNGL support compared to the BioNetGen tools.
  188. - Section `functions` is not supported, and loading a file with BNGL functions will report an error.
  189. - The only reaction kinetics supported is the law of mass action, BNG supports others through keywords but
  190. the MCell4 parser will report an error.
  191. - Actions such as `generate_network` or `simulate` are silently ignored.