macromolecule.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. #ifndef INCLUDED_MACROMOLECULE_H
  2. #define INCLUDED_MACROMOLECULE_H
  3. #include "mcell_structs.h"
  4. /*
  5. * A subunit relation defines a particular semantic relation between
  6. * different subunits in a macromolecule (sucn as "dimer partner").
  7. *
  8. * Subunit relations are referred to by name in a few places, such as
  9. * cooperative rate rules. Each subunit relation must, given a
  10. * starting subunit, be able to identify the related subunit under the
  11. * mapping established by this relation.
  12. *
  13. * Currently, this mapping is a bijection, and forward and reverse
  14. * lookups may both be done by array lookup keyed on subunit index
  15. * within the complex.
  16. */
  17. struct subunit_relation
  18. {
  19. char const *name; /* Name of relation (used for reference in rule tables) */
  20. int const *target; /* Array of target subunit from each source subunit */
  21. int const *inverse; /* Inverse of 'target' mapping */
  22. };
  23. /*
  24. * A complex rate is an ordered table of rules, mapping states of a
  25. * macromolecule (that is, of the subunits of the macromolecule) onto
  26. * reaction rates for subunit reactions. In particular, the state
  27. * which may control reaction rate for a particular reaction for
  28. * subunit N are the species and orientations of all "related" subunits
  29. * (i.e. all subunits whose indices appear in the N-th slot in the
  30. * target array of any of the defined relations for the complex).
  31. *
  32. * The complex rate table will have one row for every rule in the
  33. * table, and will have as many columns as the complex has relations.
  34. * Surface macromolecules add one extra column in case we want to match
  35. * on the orientation of the complex itself. Note that many rate rules
  36. * may use only a subset of the available relations, but for
  37. * simplicity, each rate table includes columns for the full set of
  38. * relations.
  39. *
  40. * We move down the table from the first row to the last, accepting the
  41. * first rule we find that matches. This means that if the first rule
  42. * in the table is the "DEFAULT" rule, no other rules will ever be
  43. * matched.
  44. *
  45. * Semantically, each rule in the table consists of up to M clauses,
  46. * each of the form:
  47. *
  48. * RELATION == SPECIES
  49. * or:
  50. * RELATION != SPECIES
  51. *
  52. * where RELATION is a named subunit_relation defined for this
  53. * macromolecule, and SPECIES is a defined species with optional
  54. * orientation. No relation may appear in a rule more than once, and
  55. * the rule is matched if all clauses match. Any relation not
  56. * mentioned in a rule is automatically matched.
  57. *
  58. * The rows and columns of the table are stored in 4 arrays within the
  59. * rate. If there are M columns and N rows in the rule table, then:
  60. *
  61. * invert is an array of M*N integers, 0 if we're matching for
  62. * equality on this relation, 1 if we're matching for
  63. * inequality.
  64. *
  65. * neighbors is an array of M*N species, containing NULL if we don't
  66. * care about the species, (i.e. this relation is not
  67. * mentioned), or a pointer to the species to match.
  68. *
  69. * orientations is an array of M*N 8-bit signed integers, 1 if the
  70. * orientation being matched (or rejected) is the same as the
  71. * orientation of the reference subunit, -1 if the orientation
  72. * is opposite, and 0 if we don't care about the orientation.
  73. * orientations is NULL for volume macromolecules.
  74. *
  75. * rates is an array of N doubles, giving the reaction rate
  76. * associated with each rule.
  77. *
  78. * The DEFAULT rule, then, consists of all 0 for invert and
  79. * orientation, and all NULL for neighbors. Each rate table implicitly
  80. * ends with a DEFAULT rule and a rate of 0.0 if no DEFAULT rule is
  81. * specified in the MDL.
  82. */
  83. struct complex_rate
  84. {
  85. struct complex_rate *next; /* link to next rate table */
  86. char const *name; /* name of this rate rule table */
  87. int num_rules; /* count of rules in this table */
  88. int num_neighbors; /* count of clauses in each rule */
  89. struct species **neighbors; /* species for rate rule clauses */
  90. int *invert; /* invert flags for rate rule clauses */
  91. signed char *orientations; /* orients for rate rule clauses */
  92. double *rates; /* rates for each rule */
  93. };
  94. /*
  95. * A complex species is an extension of the base species used for most
  96. * molecules in MCell. It contains details of how to initialize the subunits
  97. * when placing a complex of this species. It also contains a table of
  98. * relations, a linked list of rate tables, and a linked list of counters.
  99. */
  100. struct complex_species
  101. {
  102. struct species base; /* base species */
  103. int num_subunits; /* num subunits */
  104. struct species **subunits; /* initial species for each subunit */
  105. signed char *orientations; /* initial orients for each subunit */
  106. struct vector3 *rel_locations; /* relative subunit locations */
  107. int num_relations; /* count of relations */
  108. struct subunit_relation const *relations; /* array of relations */
  109. struct complex_rate *rates; /* list of rate tables */
  110. struct complex_counters *counters; /* counters for this species, or NULL */
  111. };
  112. /*
  113. * A complex counter is used to count subunit state configurations in
  114. * macromolecules. Presently, it uses tables like the complex rate tables.
  115. *
  116. * subunit_to_rules_range is a hash table giving ranges of indices in the
  117. * tables, keyed by species.
  118. *
  119. */
  120. struct complex_counter
  121. {
  122. struct complex_counter *next; /* Link to next counter */
  123. struct pointer_hash subunit_to_rules_range; /* Map from subunit species to index */
  124. int *su_rules_indices; /* Array of indices into rules */
  125. struct species **neighbors; /* species for match rules */
  126. signed char *orientations; /* orients for match rules */
  127. int *invert; /* invert flag for match rules */
  128. int *counts; /* Counts for match rules */
  129. int this_orient; /* Complex orient for these counter */
  130. };
  131. /*
  132. * complex_counters is a collection of counters by region. in_world is the set
  133. * of complex counters for WORLD. region_to_counter is a map from region to
  134. * counters.
  135. */
  136. struct complex_counters
  137. {
  138. struct complex_counter in_world; /* WORLD counters */
  139. struct pointer_hash region_to_counter; /* counters by region */
  140. struct complex_counter *in_regions; /* All counters */
  141. int num_region_counters; /* Num counters */
  142. };
  143. /*
  144. * Relation state info -- used as intermediary representation before counting
  145. * is properly initialized. It is simply a digested form of the parsed
  146. * information. The relation is represented as an index into the
  147. * complex_species table of relations.
  148. */
  149. struct macro_relation_state
  150. {
  151. struct macro_relation_state *next; /* link to next */
  152. struct species *mol; /* species for clause */
  153. int relation; /* idx of relation */
  154. short invert; /* invert flag */
  155. short orient; /* orient for clause */
  156. };
  157. /*
  158. * Count request info -- used as intermediary representation before counting
  159. * is properly initialized. It ties together the expression tree for the
  160. * counter with the info needed to build the rule table.
  161. */
  162. struct macro_count_request
  163. {
  164. struct macro_count_request *next; /* link to next */
  165. struct output_expression *paired_expression; /* pointer to tied expression */
  166. struct complex_species *the_complex; /* pointer to complex owning this count */
  167. struct species *subunit_state; /* species of reference subunit */
  168. struct macro_relation_state *relation_states; /* list of relation states for this count */
  169. struct sym_table *location; /* "where" info for count */
  170. short master_orientation; /* macromol orientation for this count */
  171. short subunit_orientation; /* orient of reference subunit */
  172. };
  173. /* Given a macromolecule subunit, find its index within the complex. */
  174. int macro_subunit_index(struct abstract_molecule const *subunit);
  175. /* Lookup the (variable) reaction rate for a given molecule state */
  176. double macro_lookup_rate(struct complex_rate const *r,
  177. struct abstract_molecule const *subunit,
  178. double pb_factor);
  179. /* Find the highest reaction rate in a given rate table. */
  180. double macro_max_rate(struct complex_rate const *r,
  181. double pb_factor);
  182. /* Find a rule table by name. */
  183. struct complex_rate *macro_lookup_ruleset(struct complex_species const *cs,
  184. char const *name);
  185. /* Find a relation by name. */
  186. int macro_lookup_relation(struct complex_species *cs, char const *name);
  187. /* Place the subunits for a volume macromolecule. */
  188. int macro_place_subunits_volume(struct volume_molecule *master);
  189. /* Place a volume macromolecule at a particular location. */
  190. struct volume_molecule *macro_insert_molecule_volume(struct volume_molecule *templt,
  191. struct volume_molecule *guess);
  192. /* Place a grid macromolecule at a particular location. */
  193. struct grid_molecule *macro_insert_molecule_grid_2(struct species *spec,
  194. short orient,
  195. struct wall *surf,
  196. int grid_index,
  197. double event_time,
  198. struct region *rgn,
  199. struct release_region_data *rrd);
  200. /* Place a grid macromolecule at a particular (3-D) location. */
  201. struct grid_molecule *macro_insert_molecule_grid(struct species *spec,
  202. struct vector3 *pos,
  203. short orient,
  204. double diam,
  205. double event_time);
  206. /* Create a new complex species with a given number of subunits. */
  207. struct complex_species *new_complex_species(int num_subunits, int type);
  208. /* How many times does each subunit reference the target_subunit via a relation? */
  209. void macro_count_inverse_related_subunits(struct complex_species *spec,
  210. int *source_subunit_counts,
  211. int target_subunit);
  212. #endif