mcell_structs.h 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966
  1. #ifndef MCELL_STRUCTS
  2. #define MCELL_STRUCTS
  3. #include "config.h"
  4. #include <limits.h>
  5. #include <sys/types.h>
  6. #include <stdbool.h>
  7. #include <stdio.h>
  8. #include <time.h>
  9. #include <sys/time.h>
  10. #include "rng.h"
  11. #include "vector.h"
  12. #include "mem_util.h"
  13. #include "sched_util.h"
  14. #include "util.h"
  15. #include "binary_react_output_state.h"
  16. /*****************************************************/
  17. /** Brand new constants created for use in MCell3 **/
  18. /*****************************************************/
  19. /* these flags indicated what type of reaction data out
  20. * put was requested
  21. */
  22. #define ASCII_REACTION_OUTPUT 1
  23. #define BINARY_REACTION_OUTPUT 2
  24. #define ORIENT_NOT_SET SHRT_MIN
  25. /* Species flags */
  26. /* Surface classes have IS_SURFACE set, molecules do not. */
  27. /* Grid molecules have ON_GRID set */
  28. /* Volume molecules have NOT_FREE clear (i.e. flags&NOT_FREE==0) */
  29. /* Macromolecular complexes have IS_COMPLEX set */
  30. /* CAN_ flags specify what types of reactions this molecule can undergo */
  31. /* CANT_INITIATE means that this molecule may not trigger a reaction with another molecule */
  32. /* COUNT_TRIGGER means that someone wants to output a TRIGGER statement when something happens to this molecule */
  33. /* COUNT_CONTENTS is set if you're counting numbers of molecules in/on regions */
  34. /* COUNT_HITS is set if you're counting when the molecules hit regions */
  35. /* COUNT_RXNS is set if you're counting reactions involving this molecule */
  36. /* COUNT_ENCLOSED set if you count what happens inside closed region (vol molecules, or surface mols treated as if they were vol mols) */
  37. /* COUNT_SOME_MASK is a bitmask which is nonzero if any counting happens */
  38. /* CAN_REGION_BORDER is set when grid molecule can interact with region
  39. border that is declared REFLECTIVE/TRANSPARENT/ABSORPTIVE for that
  40. molecule */
  41. /* REGION_PRESENT set for the grid molecule when it is part of the
  42. SURFACE_CLASS definition and there are regions defined with
  43. this SURFACE_CLASS assigned */
  44. #define ON_GRID 0x01
  45. #define IS_SURFACE 0x02
  46. #define NOT_FREE 0x03
  47. #define TIME_VARY 0x04
  48. #define CAN_MOLMOLMOL 0x08
  49. #define CAN_MOLMOL 0x10
  50. #define CAN_MOLGRID 0x20
  51. #define CAN_MOLWALL 0x40
  52. #define CAN_GRIDGRID 0x80
  53. #define CAN_GRIDWALL 0x100
  54. #define CAN_MOLMOLGRID 0x200
  55. #define CANT_INITIATE 0x400
  56. #define COUNT_TRIGGER 0x0800
  57. #define COUNT_CONTENTS 0x1000
  58. #define COUNT_HITS 0x2000
  59. #define COUNT_RXNS 0x4000
  60. #define COUNT_ENCLOSED 0x8000
  61. #define COUNT_SOME_MASK 0xF800
  62. #define CAN_MOLGRIDGRID 0x10000
  63. #define CAN_GRIDGRIDGRID 0x20000
  64. #define IS_COMPLEX 0x40000
  65. #define SET_MAX_STEP_LENGTH 0x80000
  66. #define CAN_REGION_BORDER 0x100000
  67. #define REGION_PRESENT 0x200000
  68. /* Abstract Molecule Flags */
  69. /* RULES: only one of TYPE_GRID, TYPE_3D set. */
  70. /* ACT_NEWBIE beats ACT_INERT beats ACT_REACT */
  71. /* Can free up memory when nothing in IN_MASK */
  72. /* Molecule type--grid molecule, 3D molecule, or surface molecule */
  73. #define TYPE_GRID 0x001
  74. #define TYPE_3D 0x002
  75. #define TYPE_MASK 0x003
  76. /* If this flag is set, this mol is a subunit in a complex */
  77. #define COMPLEX_MEMBER 0x0004
  78. #define COMPLEX_MASTER 0x2000
  79. /* NEWBIE molecules get scheduled before anything else happens to them. */
  80. /* INERT molecules don't react. */
  81. /* ACT_REACT is set for molecules taking part in unimolecular reaction, or
  82. reaction with a surface */
  83. /* ACT_INERT represent molecules in a catalytic dead-time */
  84. /* CHANGE molecules have had their rate constant changed */
  85. /* DIFFUSE molecules diffuse (duh!) */
  86. /* CLAMPED molecules diffuse for part of a timestep and don't react with surfaces */
  87. #define ACT_DIFFUSE 0x008
  88. #define ACT_INERT 0x010
  89. #define ACT_REACT 0x020
  90. #define ACT_NEWBIE 0x040
  91. #define ACT_CHANGE 0x080
  92. #define ACT_CLAMPED 0x1000
  93. /* Flags telling us which linked lists the molecule appears in. */
  94. #define IN_SCHEDULE 0x100
  95. #define IN_SURFACE 0x200
  96. #define IN_VOLUME 0x400
  97. /* And a mask to pick off all three IN_ flags */
  98. #define IN_MASK 0x700
  99. /* Flags telling us what our counting status is */
  100. #define COUNT_ME 0x800
  101. /* Flag indicating that a molecule is old enough to take the maximum timestep */
  102. #define MATURE_MOLECULE 0x2000
  103. /* End of Abstract Molecule Flags. */
  104. /* Output Report Flags */
  105. /* rxn/mol/region counter report types */
  106. /* Do not set both WORLD and ENCLOSED flags; ENCLOSED applies only to regions */
  107. /* First set reports a single number */
  108. #define REPORT_NOTHING 0
  109. #define REPORT_CONTENTS 1
  110. #define REPORT_RXNS 2
  111. #define REPORT_FRONT_HITS 3
  112. #define REPORT_BACK_HITS 4
  113. #define REPORT_FRONT_CROSSINGS 5
  114. #define REPORT_BACK_CROSSINGS 6
  115. /* Anything >= REPORT_MULTIPLE reports some combination of the above */
  116. #define REPORT_MULTIPLE 7
  117. #define REPORT_ALL_HITS 8
  118. #define REPORT_ALL_CROSSINGS 9
  119. /* Concentration is kind of special. */
  120. #define REPORT_CONCENTRATION 10
  121. #define REPORT_ELAPSED_TIME 11
  122. /* All basic report types can be masked with this value */
  123. #define REPORT_TYPE_MASK 0x0F
  124. /* And finally we have some flags to say whether we're to count over */
  125. /* the entire world or the volume enclosed by a region (set only one) */
  126. #define REPORT_WORLD 0x20
  127. #define REPORT_ENCLOSED 0x40
  128. #define REPORT_TRIGGER 0x80
  129. /* rxn/mol/region counter flags */
  130. /* Only set one of MOL_COUNTER or RXN_COUNTER */
  131. /* Set ENCLOSING_COUNTER if the region is closed and counts inside itself */
  132. #define MOL_COUNTER 1
  133. #define RXN_COUNTER 2
  134. #define ENCLOSING_COUNTER 4
  135. #define TRIG_COUNTER 8
  136. /* Manifold Flags */
  137. enum manifold_flag_t
  138. {
  139. MANIFOLD_UNCHECKED, /* Manifold status is unknown */
  140. NOT_MANIFOLD, /* Known to be non-manifold */
  141. IS_MANIFOLD /* Known to be manifold */
  142. };
  143. /* Reaction flags */
  144. /* RX_ABSORB_REGION_BORDER signifies that a reaction is between a surface molecule and an ABSORPTIVE region border */
  145. /* RX_REFLEC signifies that a reaction is between a molecule and a REFLECTIVE wall */
  146. /* RX_TRANSP signifies that a reaction is between a molecule and a TRANSPARENT wall */
  147. /* Any value equal to or less than RX_SPECIAL refers to a special wall type */
  148. /* RX_BLOCKED signals a reaction that cannot take place because the grid is full */
  149. /* Any value equal to or less than RX_NO_RX indicates that a reaction did not take place */
  150. /* RX_FLIP signals that a molecule flips its orientation (crosses a wall if it's free) */
  151. /* RX_DESTROY signals that the molecule no longer exists (so don't try to keep using it) */
  152. /* RX_A_OK signals that all is OK with a reaction, proceed as normal (reflect if you're free) */
  153. #define RX_ABSORB_REGION_BORDER -5
  154. #define RX_REFLEC -4
  155. #define RX_TRANSP -3
  156. #define RX_SPECIAL -3
  157. #define RX_BLOCKED -2
  158. #define RX_NO_RX -2
  159. #define RX_FLIP -1
  160. #define RX_LEAST_VALID_PATHWAY 0
  161. #define RX_DESTROY 0
  162. #define RX_A_OK 1
  163. #define MAX_MATCHING_RXNS 64
  164. /* Pathway flags */
  165. /* TRANSPARENT means surface reaction between the molecule and TRANSPARENT wall */
  166. /* REFLECTIVE means surface reaction between the molecule and REFLECTIVE wall */
  167. /* CLAMP_CONC means surface reaction of CLAMP_CONCENTRATION type */
  168. #define PATHW_TRANSP 0x0001
  169. #define PATHW_REFLEC 0x0002
  170. #define PATHW_ABSORP 0x0004
  171. #define PATHW_CLAMP_CONC 0x0008
  172. /* BSP Flags */
  173. /* (Currently unused--these are for self-subdividing subvolumes.) */
  174. /* Flags for BSP trees to determine whether something is a node or a branch */
  175. /* Will either have BRANCH_XN through _ZP, or _L, _R, _X, _Y, _Z. */
  176. /* P is positive, N is negative. */
  177. #define BRANCH_XN 0x01
  178. #define BRANCH_XP 0x02
  179. #define BRANCH_YN 0x04
  180. #define BRANCH_YP 0x08
  181. #define BRANCH_ZN 0x10
  182. #define BRANCH_ZP 0x20
  183. #define BRANCH_L 0x01
  184. #define BRANCH_R 0x02
  185. #define BRANCH_X 0x04
  186. #define BRANCH_Y 0x08
  187. #define BRANCH_Z 0x10
  188. /* Direction Values */
  189. #define X_NEG 0
  190. #define X_POS 1
  191. #define Y_NEG 2
  192. #define Y_POS 3
  193. #define Z_NEG 4
  194. #define Z_POS 5
  195. #define NODIR 6
  196. /* Direction Bit Flags */
  197. #define X_NEG_BIT 0x01
  198. #define X_POS_BIT 0x02
  199. #define Y_NEG_BIT 0x04
  200. #define Y_POS_BIT 0x08
  201. #define Z_NEG_BIT 0x10
  202. #define Z_POS_BIT 0x20
  203. /* Collision types for rays striking surfaces */
  204. /* First a bunch of target types */
  205. /* REDO happens if you can't tell whether you hit or not (hit near an edge, for example */
  206. #define COLLIDE_REDO -1
  207. /* MISS means we hit nothing */
  208. #define COLLIDE_MISS 0
  209. /* FRONT and BACK are for surfaces */
  210. #define COLLIDE_FRONT 1
  211. #define COLLIDE_BACK 2
  212. /* MOL_M is collision with a volume molecule */
  213. #define COLLIDE_MOL_M 3
  214. /* SV_?? is for collisions with subvolumes (negative and positive for each coordinate axis */
  215. #define COLLIDE_SV_NX 4
  216. #define COLLIDE_SV_PX 5
  217. #define COLLIDE_SV_NY 6
  218. #define COLLIDE_SV_PY 7
  219. #define COLLIDE_SV_NZ 8
  220. #define COLLIDE_SV_PZ 9
  221. /* A mask to pick off all of the collision target types */
  222. #define COLLIDE_MASK 0x0F
  223. /* Bitmasks for each of the major types of collision */
  224. #define COLLIDE_WALL 0x10
  225. #define COLLIDE_MOL 0x20 /* collision between 2 volume molecules */
  226. #define COLLIDE_SUBVOL 0x40
  227. #define COLLIDE_MOL_MOL 0x80 /* collision between 3 volume molecules */
  228. #define COLLIDE_MOL_GRID 0x100 /* collision between 2 volume molecules
  229. and 1 grid molecule taken in the order
  230. mol-mol-grid */
  231. #define COLLIDE_GRID_GRID 0x200 /* collision between 1 volume molecule
  232. and 2 grid molecules */
  233. #define COLLIDE_GRID 0x400 /* bimolecular collision between moving
  234. volume_molecule and grid_molecule */
  235. /* Size constants */
  236. /* EPS_C is the fractional difference between two values that is considered meaningful */
  237. /* GIGANTIC is a distance that is larger than any possible simulation */
  238. /* FOREVER is a time that cannot be reached within one simulation (too many timesteps) */
  239. #define EPS_C 1e-12
  240. #define SQRT_EPS_C 1e-6
  241. #define GIGANTIC 1e140
  242. #define FOREVER 1e20
  243. /* How big will we let the reaction table get? */
  244. /* 0x400000 = 8 million */
  245. #define MAX_RX_HASH 0x400000
  246. /* How big will we let the count-by-region table get? */
  247. /* 0x10000 = 128K */
  248. #define MAX_COUNT_HASH 0x10000
  249. /* mask for count-by-region hash */
  250. #define COUNT_HASHMASK 0xffff
  251. /* What's the upper bound on the number of coarse partitions? */
  252. /* Not used for user-defined partitions */
  253. #define MAX_COARSE_PER_AXIS 16
  254. #define MIN_COARSE_PER_AXIS 6
  255. #define MAX_TARGET_TIMESTEP 1.0e6
  256. #define MIN_TARGET_TIMESTEP 10.0
  257. /* Release Shape Flags */
  258. enum release_shape_t
  259. {
  260. SHAPE_UNDEFINED = -1, /* Not specified */
  261. SHAPE_SPHERICAL, /* Volume enclosed by a sphere */
  262. SHAPE_CUBIC, /* Volume enclosed by a cube */
  263. SHAPE_ELLIPTIC, /* Volume enclosed by an ellipsoid */
  264. SHAPE_RECTANGULAR, /* Volume enclosed by a rect. solid */
  265. SHAPE_SPHERICAL_SHELL, /* Surface of a sphere */
  266. SHAPE_REGION, /* Inside/on the surface of an arbitrary region */
  267. SHAPE_LIST /* Individiaul mol. placement by list */
  268. };
  269. /* Region Expression Flags */
  270. /* Boolean set operations for releases on regions */
  271. /* Set only one of NO_OP, UNION, INTERSECTION, SUBTRACTION, INCLUSION */
  272. #define REXP_NO_OP 0x01
  273. #define REXP_UNION 0x02
  274. #define REXP_INTERSECTION 0x04
  275. #define REXP_SUBTRACTION 0x08
  276. #define REXP_INCLUSION 0x10
  277. #define REXP_MASK 0x1F
  278. #define REXP_LEFT_REGION 0x20
  279. #define REXP_RIGHT_REGION 0x40
  280. /* Distance in length units to search for a new site for a grid molecule */
  281. /* after checkpointing. Current site might be full, so a value >1 is */
  282. /* advisable. Being a little generous here. */
  283. #define CHKPT_GRID_TOLERANCE 2.0
  284. /* Constants for garbage collection of defunct molecules */
  285. /* (those that were consumed when hit by another molecule) */
  286. #define MIN_DEFUNCT_FOR_GC 1024
  287. #define MAX_DEFUNCT_FRAC 0.2
  288. /* Constants for notification levels */
  289. enum notify_level_t
  290. {
  291. NOTIFY_NONE, /* no output */
  292. NOTIFY_BRIEF, /* give a brief description (only used for a few types) */
  293. NOTIFY_FULL, /* give a (possibly verbose) description */
  294. };
  295. /* Constants for warning levels */
  296. enum warn_level_t
  297. {
  298. WARN_COPE, /* do something sensible and continue silently */
  299. WARN_WARN, /* do something sensible but emit a warning message */
  300. WARN_ERROR /* treat the warning and an error and stop */
  301. };
  302. /* Number of times to try diffusing on a surface before we give up (we might fail if the target grid is full) */
  303. #define SURFACE_DIFFUSION_RETRIES 10
  304. /* Overwrite Policy Flags */
  305. /* Flags for different types of file output */
  306. enum overwrite_policy_t
  307. {
  308. FILE_UNDEFINED, /* not specified */
  309. FILE_OVERWRITE, /* always overwrite, even after a checkpoint */
  310. FILE_SUBSTITUTE, /* DEFAULT: append to entries earlier in time than "now", but overwrite later entries */
  311. FILE_APPEND, /* always append to file, even on a new run */
  312. FILE_APPEND_HEADER, /* always append to file, including the header, even on a new run */
  313. FILE_CREATE, /* always create the file, or give an error if the file already exists (to prevent overwriting) */
  314. };
  315. /* Output Expression Flags */
  316. /* INT means that this expression is an integer */
  317. /* DBL means that this expression is a double */
  318. /* TRIG means that this expression will actually be handled by a triggering event */
  319. /* MASK lets us pick off the INT/DBL/TRIG flags */
  320. /* CONST means that this expression will not change during runtime (compute at parse time and store) */
  321. #define OEXPR_TYPE_UNDEF 0x0
  322. #define OEXPR_TYPE_INT 0x1
  323. #define OEXPR_TYPE_DBL 0x2
  324. #define OEXPR_TYPE_TRIG 0x3
  325. #define OEXPR_TYPE_MASK 0x7
  326. #define OEXPR_TYPE_CONST 0x8
  327. /* Same things for sub-expressions to the left, plus */
  328. /* REQUEST means that the expression contains a request for a count statement, not real count data yet (needs to be initialized) */
  329. /* OEXPR means that the expression is itself an expression that needs to be evaluated (not data) */
  330. #define OEXPR_LEFT_INT 0x10
  331. #define OEXPR_LEFT_DBL 0x20
  332. #define OEXPR_LEFT_TRIG 0x30
  333. #define OEXPR_LEFT_REQUEST 0x40
  334. #define OEXPR_LEFT_OEXPR 0x50
  335. #define OEXPR_LEFT_MACROREQUEST 0x60
  336. #define OEXPR_LEFT_MASK 0x70
  337. #define OEXPR_LEFT_CONST 0x80
  338. /* Same things again for sub-expressions to the right */
  339. #define OEXPR_RIGHT_INT 0x100
  340. #define OEXPR_RIGHT_DBL 0x200
  341. #define OEXPR_RIGHT_TRIG 0x300
  342. #define OEXPR_RIGHT_REQUEST 0x400
  343. #define OEXPR_RIGHT_OEXPR 0x500
  344. #define OEXPR_RIGHT_MACROREQUEST 0x600
  345. #define OEXPR_RIGHT_MASK 0x700
  346. #define OEXPR_RIGHT_CONST 0x800
  347. /* Magic value to indicate that a release pattern is actually a reaction */
  348. /* Should be some number not between 0 and 1 that is also not -1 */
  349. #define MAGIC_PATTERN_PROBABILITY 1.101001000100001
  350. /* Output Trigger Flags */
  351. /* Don't set both RXN and HIT flags */
  352. #define TRIG_IS_RXN 0x1
  353. #define TRIG_IS_HIT 0x2
  354. /* Range of molecule indices used to avoid self-reactions for 3D unbinding */
  355. #define DISSOCIATION_MAX -1000
  356. #define DISSOCIATION_MIN -1000000000
  357. /* Checkpoint related flags */
  358. enum checkpoint_request_type_t
  359. {
  360. CHKPT_NOT_REQUESTED, /* No CP requested */
  361. CHKPT_SIGNAL_CONT, /* CP requested via SIGUSR* signal, continue after CP */
  362. CHKPT_SIGNAL_EXIT, /* CP requested via SIGUSR* signal, exit after CP */
  363. CHKPT_ALARM_CONT, /* CP requested via "alarm" signal, continue after CP */
  364. CHKPT_ALARM_EXIT, /* CP requested via "alarm" signal, exit after CP */
  365. CHKPT_ITERATIONS_CONT, /* CP requested due to iteration count, continue after CP */
  366. CHKPT_ITERATIONS_EXIT, /* CP requested due to iteration count, exit after CP */
  367. };
  368. /*********************************************************/
  369. /** Constants used in MCell3 brought over from MCell2 **/
  370. /*********************************************************/
  371. /* 1/2^32 */
  372. #define R_UINT_MAX 2.3283064365386962890625e-10
  373. #define MY_PI 3.14159265358979323846
  374. #define N_AV 6.0221417930e23
  375. #define ROUND_UP 0.5
  376. /* Placement Type Flags */
  377. /* Place either a certain density or an exact number of surface molecules */
  378. #define EFFDENS 0
  379. #define EFFNUM 1
  380. /* Viz output options */
  381. #define VIZ_ALL_MOLECULES 0x01
  382. #define VIZ_MOLECULES_STATES 0x02
  383. #define VIZ_SURFACE_STATES 0x04
  384. /* the formats below are valid only for the DREAMM_V3_MODE */
  385. #define VIZ_MOLECULE_FORMAT_ASCII 0x08
  386. #define VIZ_MOLECULE_FORMAT_BINARY 0x10
  387. #define VIZ_MESH_FORMAT_ASCII 0x20
  388. #define VIZ_MESH_FORMAT_BINARY 0x40
  389. #define VIZ_ALL_MESHES 0x80
  390. /************************************************************/
  391. /** Old constants copied from MCell2, some may be broken **/
  392. /************************************************************/
  393. /* maximum allowed nesting level of INCLUDE_FILE statements in MDL */
  394. #define MAX_INCLUDE_DEPTH 16
  395. /* default size of output count buffers */
  396. #define COUNTBUFFERSIZE 10000
  397. /* Symbol types */
  398. /* Data types for items in MDL parser symbol tables. */
  399. enum symbol_type_t
  400. {
  401. RX, /* chemical reaction */
  402. RXPN, /* name of chemical reaction */
  403. MOL, /* molecule or surface class type (i.e. species) */
  404. OBJ, /* meta-object */
  405. RPAT, /* release pattern */
  406. REG, /* object region */
  407. DBL, /* double (numeric variable in MDL file) */
  408. STR, /* string (text variable in MDL file) */
  409. ARRAY, /* numeric array (array variable in MDL file) */
  410. FSTRM, /* file stream type for "C"-style file-io in MDL file */
  411. TMP, /* temporary place-holder type for assignment statements */
  412. VIZ_CHILD, /* viz_child structures (in viz_output_block sym tables) */
  413. };
  414. /* Count column data types */
  415. enum count_type_t
  416. {
  417. COUNT_UNSET=-1, /* no value specified */
  418. COUNT_DBL, /* double */
  419. COUNT_INT, /* integer type */
  420. COUNT_TRIG_STRUCT, /* trigger_struct data type (for TRIGGER statements) */
  421. };
  422. /* Object Type Flags */
  423. enum object_type_t
  424. {
  425. META_OBJ, /* Meta-object: aggregation of other objects */
  426. BOX_OBJ, /* Box object: Polygonalized cuboid */
  427. POLY_OBJ, /* Polygon list object: list of arbitrary triangles */
  428. REL_SITE_OBJ, /* Release site object */
  429. VOXEL_OBJ, /* Voxel object (so-far unused) */
  430. };
  431. /* Box sides */
  432. /* Note that there are two triangles per side, so we count up by two */
  433. #define TP 0
  434. #define BOT 2
  435. #define FRNT 4
  436. #define BCK 6
  437. #define LFT 8
  438. #define RT 10
  439. #define ALL_SIDES INT_MAX
  440. /* Viz state values */
  441. #define EXCLUDE_OBJ INT_MIN /*object is not visualized */
  442. #define INCLUDE_OBJ INT_MAX /*object is visualized but state value is not set*/
  443. /* Data Output Timing Type */
  444. /* Reaction and Viz data output timing */
  445. enum output_timer_type_t
  446. {
  447. OUTPUT_BY_STEP,
  448. OUTPUT_BY_TIME_LIST,
  449. OUTPUT_BY_ITERATION_LIST,
  450. };
  451. /* Visualization modes. */
  452. enum viz_mode_t
  453. {
  454. NO_VIZ_MODE,
  455. DX_MODE,
  456. DREAMM_V3_MODE,
  457. DREAMM_V3_GROUPED_MODE,
  458. RK_MODE,
  459. ASCII_MODE,
  460. CELLBLENDER_MODE,
  461. };
  462. /* Visualization Frame Data Type */
  463. /* Used to select type of data to include in viz output files */
  464. /* Will probably change significantly when we redesign DReAMM output format */
  465. enum viz_frame_type_t
  466. {
  467. ALL_FRAME_DATA,
  468. EFF_POS,
  469. EFF_STATES,
  470. MOL_POS,
  471. MOL_ORIENT,
  472. MOL_STATES,
  473. SURF_POS,
  474. SURF_STATES,
  475. MESH_GEOMETRY,
  476. REG_DATA,
  477. ALL_MOL_DATA,
  478. ALL_MESH_DATA,
  479. NUM_FRAME_TYPES,
  480. };
  481. /* Release Number Flags */
  482. enum release_number_type_t
  483. {
  484. CONSTNUM,
  485. GAUSSNUM,
  486. VOLNUM,
  487. CCNNUM,
  488. DENSITYNUM
  489. };
  490. /**********************************************/
  491. /** New/reworked structures used in MCell3 **/
  492. /**********************************************/
  493. typedef unsigned char byte;
  494. /* If you don't include sys/types.h, #define SYS_TYPES_NOT_LOADED so */
  495. /* you get the u_short/int/long set of types */
  496. #ifdef SYS_TYPES_NOT_LOADED
  497. typedef unsigned short u_short;
  498. typedef unsigned int u_int;
  499. typedef unsigned long u_long;
  500. #endif
  501. /* Linked list used to separate molecules by species */
  502. struct per_species_list
  503. {
  504. struct per_species_list *next; /* pointer to next p-s-l */
  505. struct species *properties; /* species for items in this bin */
  506. struct volume_molecule *head; /* linked list of mols */
  507. };
  508. /* Properties of one type of molecule or surface */
  509. struct species
  510. {
  511. u_int species_id; /* Unique ID for this species */
  512. u_int chkpt_species_id; /* Unique ID for this species from the
  513. checkpoint file */
  514. u_int hashval; /* Hash value (may be nonunique) */
  515. struct sym_table *sym; /* Symbol table entry (name) */
  516. struct eff_dat *eff_dat_head; /* If IS_SURFACE this points to head of
  517. effector data list associated with
  518. surface class */
  519. u_int population; /* How many of this species exist? */
  520. double D; /* Diffusion constant */
  521. double D_ref; /* Reference diffusion constant.
  522. For now - a placeholder for the future use */
  523. double space_step; /* Characteristic step length */
  524. double time_step; /* Minimum (maximum?) sensible timestep */
  525. double max_step_length; /* maximum allowed random walk step */
  526. u_int flags; /* Species Flags: Vol Molecule? Surface Molecule?
  527. Surface Class? Counting stuff, etc... */
  528. long long n_deceased; /* Total number that have been destroyed. */
  529. double cum_lifetime; /* Timesteps lived by now-destroyed molecules */
  530. int region_viz_value; /* Visualization state for surface class
  531. for output */
  532. /* if species s a surface_class (IS_SURFACE) below there are linked lists of molecule names/orientations that may be present in special reactions for this surface class */
  533. struct name_orient *refl_mols; /* names of the mols that REFLECT from surface */
  534. struct name_orient *transp_mols; /* names of the mols that are TRANSPARENT for surface */
  535. struct name_orient *absorb_mols; /* names of the mols that ABSORB at surface */
  536. struct name_orient *clamp_conc_mols; /* names of mols that CLAMP_CONC at surface */
  537. };
  538. /* All pathways leading away from a given intermediate */
  539. struct rxn
  540. {
  541. struct rxn *next; /* next node in the reaction linked list where
  542. each node contains only pathways with
  543. equivalent geometry */
  544. struct sym_table *sym; /* Ptr to symbol table entry for this rxn */
  545. u_int n_reactants; /* How many reactants? (At least 1.) */
  546. int n_pathways; /* How many pathways lead away?
  547. (Negative = special reaction, i.e. transparent etc...)*/
  548. double *cum_probs; /* Cumulative probabilities for (entering) all pathways */
  549. #if 0
  550. /* This is for Michaelis-Menten reaction kinetics, which are currently unimplemented. */
  551. double *cat_probs; /* Probabilities of leaving all pathways (<=0.0 is instant) */
  552. #endif
  553. struct complex_rate **rates; /* Rates for cooperative macromol subunit rxns */
  554. double max_fixed_p; /* Maximum 'p' for region of p-space for all non-cooperative pathways */
  555. double min_noreaction_p; /* Minimum 'p' for region of p-space which is always in the non-reacting "pathway". (note that cooperativity may mean that some values of p less than this still do not produce a reaction) */
  556. double pb_factor; /* Conversion factor from rxn rate to rxn probability (used for cooperativity) */
  557. u_int *product_idx; /* Index of 1st player for products of each pathway */
  558. struct species **players; /* Identities of reactants/products */
  559. short *geometries; /* Geometries of reactants/products */
  560. unsigned char *is_complex; /* Flags indicating which reactants/products are subunits of a complex. array is NULL if not a macro-rxn. */
  561. long long n_occurred; /* How many times has this reaction occurred? */
  562. double n_skipped; /* How many reactions were skipped due to probability overflow? */
  563. struct t_func *prob_t; /* List of probabilities changing over time, by pathway */
  564. struct pathway *pathway_head; /* List of pathways built at parse-time */
  565. struct pathway_info *info; /* Counts and names for each pathway */
  566. };
  567. /* User-defined name of a reaction pathway */
  568. struct rxn_pathname {
  569. struct sym_table *sym; /* Ptr to symbol table entry for this rxn name */
  570. u_int hashval; /* Hash value for counting named rxns on regions */
  571. u_int path_num; /* Pathway number in rxn */
  572. struct rxn *rx; /* The rxn associated with this name */
  573. struct magic_list *magic; /* A list of stuff that magically happens when the reaction happens */
  574. };
  575. /* Parse-time structure for reaction pathways */
  576. /* Everything except pathname can be deallocated after prepare_reactions */
  577. struct pathway {
  578. struct pathway *next; /* Next pathway for this reaction */
  579. struct rxn_pathname *pathname; /* Data for named reaction pathway or NULL */
  580. struct species *reactant1; /* First reactant in reaction pathway */
  581. struct species *reactant2; /* Second reactant (NULL if none) */
  582. struct species *reactant3; /* Third reactant (NULL if none) */
  583. unsigned char is_complex[3]; /* flag indicating whether each reactant must be a subunit in a complex */
  584. double km; /* Rate constant */
  585. char* km_filename; /* Filename for time-varying rates */
  586. struct complex_rate *km_complex; /* Rate "constant" for cooperative subunit rxns */
  587. short orientation1; /* Orientation of first reactant */
  588. short orientation2; /* Orientation of second reactant */
  589. short orientation3; /* Orientation of third reactant */
  590. struct product *product_head; /* Linked lists of species created */
  591. char *prod_signature; /* string created from the names of
  592. products put in alphabetical order */
  593. short flags; /* flags describing special reactions -
  594. REFLECTIVE, TRANSPARENT, CLAMP_CONCENTRATION */
  595. };
  596. /* Parse-time structure for products of reaction pathways */
  597. struct product {
  598. struct product *next;
  599. struct species *prod; /* Molecule type to be created */
  600. short orientation; /* Orientation to place molecule */
  601. unsigned char is_complex; /* flag indicating whether product is to be a subunit in a complex */
  602. };
  603. /* Run-time info for each pathway */
  604. /* Always do basic counts--do more sophisticated stuff if pathname!=NULL */
  605. struct pathway_info
  606. {
  607. double count; /* How many times the pathway has been taken */
  608. struct rxn_pathname *pathname; /* The name of the pathway or NULL */
  609. };
  610. /* Piecewise constant function for time-varying reaction rates */
  611. struct t_func
  612. {
  613. struct t_func *next;
  614. double time; /* Time to switch to next rate */
  615. double value; /* Current rate */
  616. int path; /* Which rxn pathway is this for? */
  617. };
  618. /* Abstract structure that starts all molecule structures */
  619. /* Used to make C structs act like C++ objects */
  620. struct abstract_molecule
  621. {
  622. struct abstract_molecule *next; /* Next molecule in scheduling queue */
  623. double t; /* Scheduling time. */
  624. double t2; /* Time of next unimolecular reaction */
  625. short flags; /* Abstract Molecule Flags: Who am I, what am I doing, etc. */
  626. struct species *properties; /* What type of molecule are we? */
  627. struct mem_helper *birthplace; /* What was I allocated from? */
  628. double birthday; /* Time at which this particle was born */
  629. u_long id; /* unique identifier of this molecule */
  630. struct abstract_molecule **cmplx; /* Other molecules forming this complex, if we're part of a complex (0: master, 1...n subunits) */
  631. };
  632. /* Volume molecules: freely diffusing or fixed in solution */
  633. struct volume_molecule
  634. {
  635. struct abstract_molecule *next;
  636. double t;
  637. double t2;
  638. short flags;
  639. struct species *properties;
  640. struct mem_helper *birthplace;
  641. double birthday;
  642. u_long id;
  643. struct volume_molecule **cmplx; /* Other molecules forming this complex, if we're part of a complex (0: master, 1...n subunits) */
  644. struct vector3 pos; /* Position in space */
  645. struct subvolume *subvol; /* Partition we are in */
  646. struct wall *previous_wall; /* Wall we were released from */
  647. int index; /* Index on that wall (don't rebind) */
  648. struct volume_molecule **prev_v; /* Previous molecule in this subvolume */
  649. struct volume_molecule *next_v; /* Next molecule in this subvolume */
  650. };
  651. /* Fixed molecule on a grid on a surface */
  652. struct grid_molecule
  653. {
  654. struct abstract_molecule *next;
  655. double t;
  656. double t2;
  657. short flags;
  658. struct species *properties;
  659. struct mem_helper *birthplace;
  660. double birthday;
  661. u_long id;
  662. struct grid_molecule **cmplx; /* Other molecules forming this complex, if we're part of a complex (0: master, 1...n subunits) */
  663. unsigned int grid_index; /* Which gridpoint do we occupy? */
  664. short orient; /* Which way do we point? */
  665. struct surface_grid *grid; /* Our grid (which tells us our surface) */
  666. struct vector2 s_pos; /* Where are we in surface coordinates? */
  667. };
  668. /* Used to transform coordinates of grid molecules diffusing between adjacent walls */
  669. struct edge
  670. {
  671. struct wall *forward; /* For which wall is this a forwards transform? */
  672. struct wall *backward; /* For which wall is this a reverse transform? */
  673. struct vector2 translate; /* Translation vector between coordinate systems */
  674. double cos_theta; /* Cosine of angle between coordinate systems */
  675. double sin_theta; /* Sine of angle between coordinate systems */
  676. double length; /* Length of the shared edge */
  677. double length_1; /* Reciprocal of length of shared edge */
  678. };
  679. struct wall
  680. {
  681. struct wall *next; /* Next wall in the universe */
  682. struct surf_class_list *surf_class_head; /* linked list of surface classes for this wall (multiple surface classes may come from the overlapping regions */
  683. int num_surf_classes; /* number of attached surface classes */
  684. int side; /* index of this wall in its parent object */
  685. struct vector3 *vert[3]; /* Array of pointers to vertices */
  686. double uv_vert1_u; /* Surface u-coord of 2nd corner (v=0) */
  687. struct vector2 uv_vert2; /* Surface coords of third corner */
  688. struct edge *edges[3]; /* Array of pointers to each edge. */
  689. struct wall *nb_walls[3]; /* Array of pointers to walls that share an edge*/
  690. double area; /* Area of this element */
  691. struct vector3 normal; /* Normal vector for this wall */
  692. struct vector3 unit_u; /* U basis vector for this wall */
  693. struct vector3 unit_v; /* V basis vector for this wall */
  694. double d; /* Distance to origin (point normal form) */
  695. struct surface_grid *grid; /* Grid of effectors for this wall */
  696. u_short flags; /* Count Flags: flags for whether and what we need to count */
  697. struct object *parent_object; /* The object we are a part of */
  698. struct storage *birthplace; /* Where we live in memory */
  699. struct region_list *counting_regions; /* Counted-on regions containing this wall */
  700. };
  701. /* Linked list of walls (for subvolumes) */
  702. struct wall_list
  703. {
  704. struct wall_list *next; /* The next entry in the list */
  705. struct wall *this_wall; /* The wall in this entry */
  706. };
  707. /* A linked list used to store the coordinates of vertices and the
  708. corresponding normal vectors */
  709. struct vertex_list
  710. {
  711. struct vector3 *vertex; /* pointer to one polygon vertex */
  712. struct vertex_list *next; /* pointer to next vertex list */
  713. };
  714. /* Grid over a surface containing grid_molecules */
  715. struct surface_grid
  716. {
  717. int n; /* Number of slots along each axis */
  718. double inv_strip_wid; /* Reciprocal of the width of one strip */
  719. double vert2_slope; /* Slope from vertex 0 to vertex 2 */
  720. double fullslope; /* Slope of full width of triangle */
  721. struct vector2 vert0; /* Projection of vertex zero onto unit_u and unit_v of wall */
  722. double binding_factor; /* Binding probability correction factor for surface area */
  723. u_int n_tiles; /* Number of tiles in effector grid (triangle: grid_size^2, rectangle: 2*grid_size^2) */
  724. u_int n_occupied; /* Number of tiles occupied by grid_molecules */
  725. struct grid_molecule **mol; /* Array of pointers to grid_molecule for each tile */
  726. struct subvolume *subvol;/* Best match for which subvolume we're in */
  727. struct wall *surface; /* The wall that we are in */
  728. };
  729. /* 3D vector of short integers */
  730. struct short3D
  731. {
  732. short x;
  733. short y;
  734. short z;
  735. };
  736. /* Point in space that will tell us which compartments we're in
  737. as determined by tracing from infinity */
  738. struct waypoint
  739. {
  740. struct vector3 loc; /* This is where the waypoint is */
  741. struct region_list *regions; /* We are inside these regions */
  742. struct region_list *antiregions; /* We are outside of (but hit) these regions */
  743. };
  744. /* Contains local memory and scheduler for molecules, walls, wall_lists, etc. */
  745. struct storage
  746. {
  747. struct mem_helper *list; /* Wall lists */
  748. struct mem_helper *mol; /* Molecules */
  749. struct mem_helper *gmol; /* Grid molecules */
  750. struct mem_helper *face; /* Walls */
  751. struct mem_helper *join; /* Edges */
  752. struct mem_helper *grids; /* Effector grids */
  753. struct mem_helper *coll; /* Collision list */
  754. struct mem_helper *sp_coll; /* Collision list - helps in trimolecular reactions*/
  755. struct mem_helper *tri_coll; /* Collision list for trimolecular collisions */
  756. struct mem_helper *regl; /* Region lists */
  757. struct mem_helper *exdv; /* Vertex lists for exact interaction disk area */
  758. struct mem_helper *pslv; /* Per-species-lists for vol mols */
  759. struct wall *wall_head; /* Locally stored walls */
  760. int wall_count; /* How many local walls? */
  761. int vert_count; /* How many vertices? */
  762. struct schedule_helper *timer; /* Local scheduler */
  763. double current_time; /* Local time */
  764. double max_timestep; /* Local maximum timestep */
  765. };
  766. /* Linked list of storage areas. */
  767. struct storage_list
  768. {
  769. struct storage_list *next;
  770. struct storage *store;
  771. };
  772. /* Walls and molecules in a spatial subvolume */
  773. struct subvolume
  774. {
  775. struct wall_list *wall_head; /* Head of linked list of intersecting walls */
  776. struct pointer_hash mol_by_species; /* table of species->molecule list */
  777. struct per_species_list *species_head;
  778. int mol_count; /* How many molecules are here? */
  779. struct short3D llf; /* Indices of left lower front corner */
  780. struct short3D urb; /* Indices of upper right back corner */
  781. short world_edge; /* Direction Bit Flags that are set for SSVs at edge of world */
  782. /* short is_bsp; */ /* Flags saying what the void pointers are */
  783. /* void *neighbor[6]; */ /* Subvolume or bsp_tree across each face */
  784. struct storage *local_storage; /* Local memory and scheduler */
  785. };
  786. /* Binary space partitioning tree for subvolume connections */
  787. /* Not used in the current release but may be useful in future. */
  788. /*
  789. struct bsp_tree
  790. {
  791. void *left; // The tree below the partition
  792. void *right; // The tree above the partition
  793. short partition; // The index of the partition
  794. short flags; // BSP Flags: coordinate that is split, plus terminal node flags
  795. };
  796. */
  797. /* Count data specific to named reaction pathways */
  798. struct rxn_counter_data
  799. {
  800. double n_rxn_at; /* # rxn occurrance on surface */
  801. double n_rxn_enclosed; /* # rxn occurrance inside closed region */
  802. };
  803. /* Count data specific to molecules */
  804. struct move_counter_data
  805. {
  806. double front_hits; /* # hits on front of region (normal up) */
  807. double back_hits; /* # hits on back of region */
  808. double front_to_back; /* # crossings from front to back */
  809. double back_to_front; /* # crossings from back to front */
  810. double scaled_hits; /* To determine integrated concentration */
  811. int n_at; /* # molecules on region surface */
  812. int n_enclosed; /* # molecules inside closed region */
  813. };
  814. /* Counter data specific to trigger events */
  815. struct trig_counter_data
  816. {
  817. double t_event; /* Event time (exact) */
  818. struct vector3 loc; /* Real position of event */
  819. short orient; /* For MOL_COUNTER: molecule orientation */
  820. struct trigger_request *listeners; /* Places waiting to be notified */
  821. };
  822. /* List of output items that need to know about this specific trigger event */
  823. struct trigger_request
  824. {
  825. struct trigger_request *next; /* Next request */
  826. struct output_request *ear; /* Who wants to hear about the trigger */
  827. };
  828. /* Shared memory for appropriate counts */
  829. union counter_data
  830. {
  831. struct rxn_counter_data rx;
  832. struct move_counter_data move;
  833. struct trig_counter_data trig;
  834. };
  835. /* Struct to count rxns or molecules within regions (where "within" includes */
  836. /* on the inside of a fully closed surface) */
  837. struct counter
  838. {
  839. struct counter *next;
  840. byte counter_type; /* Counter Type Flags (MOL_COUNTER etc.) */
  841. struct region *reg_type; /* Region we are counting on */
  842. void *target; /* Mol or rxn pathname we're counting (as indicated by counter_type) */
  843. short orientation; /* requested grid molecule orientation */
  844. union counter_data data; /* data for the count:
  845. reference data.move for move counter
  846. reference data.rx for rxn counter
  847. reference data.trig for trigger */
  848. };
  849. enum magic_types { magic_undefined,magic_release };
  850. struct magic_list
  851. {
  852. struct magic_list *next;
  853. void *data;
  854. enum magic_types type;
  855. };
  856. /* All data about the world */
  857. struct volume
  858. {
  859. /* Coarse partitions are input by the user */
  860. /* They may also be generated automagically */
  861. /* They mark the positions of initial partition boundaries */
  862. int nx_parts; /* Number of coarse X partition boundaries */
  863. int ny_parts; /* Number of coarse Y partition boundaries */
  864. int nz_parts; /* Number of coarse Z partition boundaries */
  865. double *x_partitions; /* Coarse X partition boundaries */
  866. double *y_partitions; /* Coarse Y partition boundaries */
  867. double *z_partitions; /* Coarse Z partition boundaries */
  868. int mem_part_x; /* Granularity of memory-partition binning for the X-axis */
  869. int mem_part_y; /* Granularity of memory-partition binning for the Y-axis */
  870. int mem_part_z; /* Granularity of memory-partition binning for the Z-axis */
  871. int mem_part_pool; /* Scaling factor for sizes of memory pools in each storage. */
  872. /* Fine partitions are intended to allow subdivision of coarse partitions */
  873. /* Subdivision is not yet implemented */
  874. int n_fineparts; /* Number of fine partition boundaries */
  875. double *x_fineparts; /* Fine X partition boundaries */
  876. double *y_fineparts; /* Fine Y partition boundaries */
  877. double *z_fineparts; /* Fine Z partition boundaries */
  878. int n_waypoints; /* How many waypoints (one per subvol) */
  879. struct waypoint *waypoints; /* Waypoints contain fully-closed region information */
  880. byte place_waypoints_flag; /* Used to save memory if waypoints not needed */
  881. int n_subvols; /* How many coarse subvolumes? */
  882. struct subvolume *subvol; /* Array containing all subvolumes */
  883. int n_walls; /* Total number of walls */
  884. int n_verts; /* Total number of vertices */
  885. struct vector3 *all_vertices; /* Central repository of vertices with a
  886. partial order imposed by natural ordering
  887. of "storages" */
  888. struct wall_list **walls_using_vertex; /* Array of linked lists of walls using a vertex (has the size of
  889. "all_vertices" array */
  890. int rx_hashsize; /* How many slots in our reaction hash table? */
  891. int n_reactions; /* How many reactions are there, total? */
  892. struct rxn **reaction_hash; /* A hash table of all reactions. */
  893. struct mem_helper *tv_rxn_mem; /* Memory to store time-varying reactions */
  894. int count_hashmask; /* Mask for looking up count hash table */
  895. struct counter **count_hash; /* Count hash table */
  896. struct schedule_helper *count_scheduler; /* When to generate reaction output */
  897. struct schedule_helper *volume_output_scheduler; /* When to generate volume output */
  898. int n_species; /* How many different species (molecules)? */
  899. struct species **species_list; /* Array of all species (molecules). */
  900. struct schedule_helper *releaser; /* Scheduler for release events */
  901. struct mem_helper *storage_allocator; /* Memory for storage list */
  902. struct storage_list *storage_head; /* Linked list of all local memory/schedulers */
  903. u_long current_mol_id; /* next unique molecule id to use*/
  904. double speed_limit; /* How far can the fastest particle get in one timestep? */
  905. struct sym_table_head *fstream_sym_table; /* Global MDL file stream symbol hash table */
  906. struct sym_table_head *var_sym_table; /* Global MDL variables symbol hash table */
  907. struct sym_table_head *rxn_sym_table; /* RXN symbol hash table */
  908. struct sym_table_head *obj_sym_table; /* Objects symbol hash table */
  909. struct sym_table_head *reg_sym_table; /* Regions symbol hash table */
  910. struct sym_table_head *mol_sym_table; /* Molecule type symbol hash table */
  911. struct sym_table_head *rpat_sym_table; /* Release pattern hash table */
  912. struct sym_table_head *rxpn_sym_table; /* Named reaction pathway hash table */
  913. struct object *root_object; /* Root of the object template tree */
  914. struct object *root_instance; /* Root of the instantiated object tree */
  915. struct release_pattern *default_release_pattern; /* release once at t=0 */
  916. struct volume_output_item *volume_output_head; /* List of all volume data output items */
  917. struct macro_count_request *macro_count_request_head;
  918. struct output_block *output_block_head; /* Global list of reaction data output blocks */
  919. struct output_request *output_request_head; /* Global list linking COUNT statements to internal variables */
  920. struct mem_helper *oexpr_mem; /* Memory to store output_expressions */
  921. struct mem_helper *outp_request_mem; /* Memory to store output_requests */
  922. struct mem_helper *counter_mem; /* Memory to store counters (for counting molecules/reactions on regions) */
  923. struct mem_helper *trig_request_mem; /* Memory to store listeners for trigger events */
  924. struct mem_helper *magic_mem; /* Memory used to store magic lists for reaction-triggered releases and such */
  925. double elapsed_time; /* Used for concentration measurement */
  926. /* Visualization state */
  927. struct viz_output_block *viz_blocks; /* VIZ_OUTPUT blocks from file */
  928. struct species *all_mols; /* Refers to ALL_MOLECULES keyword */
  929. struct species *all_volume_mols; /* Refers to ALL_VOLUME_MOLECULES keyword */
  930. struct species *all_surface_mols; /* Refers to ALL_SURFACE_MOLECULES keyword */
  931. double time_unit; /* Duration of one global time step in real time */
  932. /* Used to convert between real time and internal time */
  933. double time_step_max; /* Maximum internal time that a molecule may diffuse */
  934. double grid_density; /* Density of grid for surface molecules, number per um^2 */
  935. double length_unit; /* Internal unit of distance, 1/sqrt(grid_density), in microns */
  936. double r_length_unit; /* Reciprocal of length_unit to avoid division */
  937. double rx_radius_3d; /* Interaction radius for reactions between volume molecules */
  938. double space_step; /* User-supplied desired average diffusion distance for volume molecules */
  939. double *r_step; /* Lookup table of 3D diffusion step lengths */
  940. double *d_step; /* Lookup table of 3D diffusion direction vectors */
  941. double *r_step_surface; /* Lookup table of 2D diffusion step lengths */
  942. double *r_step_release; /* Lookup table of diffusion lengths for 3D release */
  943. u_int radial_subdivisions; /* Size of 2D and 3D step length lookup tables */
  944. u_int radial_directions; /* Requested size of 3D direction lookup table */
  945. u_int num_directions; /* Actual size of 3D direction lookup table */
  946. int directions_mask; /* Mask to obtain RNG bits for direction lookup */
  947. int fully_random; /* If set, generate directions with trig functions instead of lookup table */
  948. int dissociation_index; /* Used to keep 3D products from reacting with each other too soon */
  949. int complex_placement_attempts; /* How many times will we try to place each complex before giving up? */
  950. long long chkpt_iterations; /* Number of iterations to advance before checkpointing */
  951. u_int chkpt_init; /* Set if this is the initial run of a simulation with no previous checkpoints */
  952. u_int chkpt_flag; /* Set if there are any CHECKPOINT statements in "mdl" file */
  953. u_int chkpt_seq_num; /* Number of current run in checkpoint sequence */
  954. char *chkpt_infile; /* Name of checkpoint file to read from */
  955. char *chkpt_outfile; /* Name of checkpoint file to write to */
  956. u_int chkpt_byte_order_mismatch; /* Flag that defines whether mismatch
  957. in byte order exists between the saved
  958. checkpoint file and the machine reading it */
  959. double chkpt_elapsed_real_time; /* elapsed simulation time (in sec) for new checkpoint */
  960. double chkpt_elapsed_real_time_start; /* start of the simulation time (in sec) for new checkpoint */
  961. double current_real_time; /* current simulation time in seconds */
  962. double current_start_real_time; /* simulation start time (in seconds) */
  963. long long diffusion_number; /* Total number of times molecules have had their positions updated */
  964. double diffusion_cumtime; /* Total time spent diffusing by all molecules */
  965. long long ray_voxel_tests; /* How many ray-subvolume intersection tests have we performed */
  966. long long ray_polygon_tests; /* How many ray-polygon intersection tests have we performed */
  967. long long ray_polygon_colls; /* How many ray-polygon intersections have occured */
  968. /* below "mol" means volume molecule, "grid" means surface molecule */
  969. long long mol_mol_colls; /* How many mol-mol collisions have occured */
  970. long long mol_grid_colls; /* How many mol-grid collisions have occured */
  971. long long grid_grid_colls; /* How many grid-grid collisions have occured */
  972. long long mol_wall_colls; /* How many mol-wall collisions have occured */
  973. long long mol_mol_mol_colls; /* How many mol-mol-mol collisions have occured */
  974. long long mol_mol_grid_colls; /* How many mol-mol-grid collisions have occured */
  975. long long mol_grid_grid_colls; /* How many mol-grid-grid collisions have occured */
  976. long long grid_grid_grid_colls; /* How many grid-grid-grid collisions have occured */
  977. struct vector3 bb_llf; /* llf corner of world bounding box */
  978. struct vector3 bb_urb; /* urb corner of world bounding box */
  979. struct rng_state *rng; /* State of the random number generator (currently isaac64) */
  980. u_int init_seed; /* Initial seed value for random number generator */
  981. long long it_time; /* How many iterations have been run so far */
  982. long long start_time; /* Starting iteration number for the current run */
  983. int procnum; /* Processor number for a parallel run */
  984. int quiet_flag; /* Quiet mode */
  985. int with_checks_flag; /* Check geometry for overlapped walls? */
  986. struct mem_helper *coll_mem; /* Collision list */
  987. struct mem_helper *sp_coll_mem; /* Collision list (trimol) */
  988. struct mem_helper *tri_coll_mem; /* Collision list (trimol) */
  989. struct mem_helper *exdv_mem; /* Vertex lists for exact interaction disk area */
  990. char const *mcell_version; /* Current version number.
  991. Format is "3.XX.YY" where XX is major release number (for new features)
  992. and YY is minor release number (for patches) */
  993. int use_expanded_list; /* If set, check neighboring subvolumes for mol-mol interactions */
  994. int randomize_gmol_pos; /* If set, always place surface molecule at random location instead of center of grid */
  995. double vacancy_search_dist2; /* Square of distance to search for free grid location to place surface product */
  996. byte surface_reversibility; /* If set, match unbinding diffusion distribution to binding distribution at surface */
  997. byte volume_reversibility; /* If set, match unbinding diffusion distribution to binding distribution in volume */
  998. /* MCell startup command line arguments */
  999. u_int seed_seq; /* Seed for random number generator */
  1000. long long iterations; /* How many iterations to run */
  1001. unsigned long log_freq; /* Interval between simulation progress reports, default scales as sqrt(iterations) */
  1002. char *mdl_infile_name; /* Name of MDL file specified on command line */
  1003. char const *curr_file; /* Name of MDL file currently being parsed */
  1004. /* XXX: Why do we allocate this on the heap rather than including it inline? */
  1005. struct notifications *notify; /* Notification/warning/output flags */
  1006. struct ccn_clamp_data *clamp_list; /* List of objects at which volume molecule concentrations should be clamped */
  1007. /* Flags for asynchronously-triggered checkpoints */
  1008. enum checkpoint_request_type_t checkpoint_requested; /* Flag indicating whether a checkpoint has been requested. */
  1009. unsigned int checkpoint_alarm_time; /* number of seconds between checkpoints */
  1010. int continue_after_checkpoint; /* 0: exit after chkpt, 1: continue after chkpt */
  1011. long long last_checkpoint_iteration; /* Last iteration when chkpt was created */
  1012. time_t begin_timestamp; /* Time since epoch at beginning of 'main' */
  1013. char *initialization_state; /* NULL after initialization completes */
  1014. /* flags that tells whether reactions of certain types are present
  1015. in the simulation (used for the molecule collision report, also see above
  1016. the corresponding counters) */
  1017. int mol_mol_reaction_flag;
  1018. int mol_grid_reaction_flag;
  1019. int grid_grid_reaction_flag;
  1020. int mol_wall_reaction_flag;
  1021. int mol_mol_mol_reaction_flag;
  1022. int mol_mol_grid_reaction_flag;
  1023. int mol_grid_grid_reaction_flag;
  1024. int grid_grid_grid_reaction_flag;
  1025. /* shared walls information per mesh vertex is created when there are
  1026. reactions present with more than one surface reactant
  1027. or more than one surface product */
  1028. int create_shared_walls_info_flag;
  1029. /* resource usage during initialization */
  1030. struct timeval u_init_time; /* user time */
  1031. struct timeval s_init_time; /* system time */
  1032. time_t t_start; /* global start time */
  1033. byte reaction_prob_limit_flag; /* checks whether there is at least one
  1034. reaction with probability greater
  1035. than 1 including variable rate reactions */
  1036. };
  1037. /* Data structure to store information about collisions. */
  1038. struct collision
  1039. {
  1040. struct collision *next;
  1041. double t; /* Time of collision (may be slightly early) */
  1042. void *target; /* Thing that we hit: wall, molecule, subvol etc */
  1043. int what; /* Target-type Flags: what kind of thing did we hit? */
  1044. struct rxn *intermediate; /* Reaction that told us we could hit it */
  1045. struct vector3 loc; /* Location of impact */
  1046. };
  1047. /* Special type of collision - used when moving molecule
  1048. can engage in tri-molecular collisions */
  1049. struct sp_collision
  1050. {
  1051. struct sp_collision *next;
  1052. double t; /* Time of collision (may be slightly early) */
  1053. double t_start; /* Start time of random walk */
  1054. struct vector3 pos_start; /* Start position of random walk */
  1055. struct subvolume *sv_start; /* Start subvolume */
  1056. struct species *moving; /* Species of the moving molecule */
  1057. void *target; /* Thing that we hit: wall, molecule, subvol etc */
  1058. int what; /* Target-type Flags: what kind of thing did we hit? */
  1059. struct vector3 disp; /* Random walk displacement for the moving molecule */
  1060. struct vector3 loc; /* Location of impact */
  1061. };
  1062. /* Data structure to store information about trimolecular and bimolecular
  1063. collisions. */
  1064. struct tri_collision
  1065. {
  1066. struct tri_collision *next;
  1067. double t; /* Time of collision (may be slightly early) */
  1068. void *target1; /* First thing that we hit: wall, molecule, subvol etc */
  1069. void *target2; /* Second thing that we hit: wall, molecule, subvol etc - always the furthest from the moving molecule */
  1070. short orient; /* orientation of the moving volume_molecule
  1071. when it hits the surface_molecule */
  1072. int what; /* Target-type Flags: what kind of thing did we hit? */
  1073. struct rxn *intermediate; /* Reaction that told us we could hit target1 and/or target2 */
  1074. struct vector3 loc; /* Assumed location of impact */
  1075. struct vector3 loc1; /* Location of impact with first target */
  1076. struct vector3 loc2; /* Location of impact with second target */
  1077. struct vector3 last_walk_from; /* Location of mol. before last step before final collision */
  1078. double factor; /* Result of "exact_disk()" with both targets
  1079. or scaling coef. for MOL_WALL interaction */
  1080. double local_prob_factor; /* coefficient depending on the number of
  1081. nearest neighbors for MOL_GRID_GRID
  1082. interaction */
  1083. struct wall *wall; /* pointer to the wall in the collision if
  1084. such exists */
  1085. };
  1086. /* Data structures to store information about exact interaction disk geometry */
  1087. struct exd_vertex
  1088. {
  1089. struct exd_vertex *next;
  1090. double u,v; /* x,y style coordinates */
  1091. double r2,zeta; /* r,theta style coordinates */
  1092. struct exd_vertex *e; /* Edge to next vertex */
  1093. struct exd_vertex *span; /* List of edges spanning this point */
  1094. int role; /* Exact Disk Flags: Head, tail, whatever */
  1095. };
  1096. /* Data structures to describe release events */
  1097. struct release_event_queue {
  1098. struct release_event_queue *next;
  1099. double event_time; /* Time of the release */
  1100. struct release_site_obj *release_site; /* What to release, where to release it, etc */
  1101. double t_matrix[4][4]; /* transformation matrix for location of release site */
  1102. int train_counter; /* counts executed trains */
  1103. double train_high_time; /* time of the train's start */
  1104. };
  1105. /* Release site information */
  1106. struct release_site_obj {
  1107. struct vector3 *location; /* location of release site */
  1108. struct species *mol_type; /* species to be released */
  1109. byte release_number_method; /* Release Number Flags: controls how release_number is used (enum release_number_type_t) */
  1110. int8_t release_shape; /* Release Shape Flags: controls shape over which to release (enum release_shape_t) */
  1111. short orientation; /* Orientation of released surface molecules */
  1112. double release_number; /* Number to release */
  1113. double mean_diameter; /* Diameter for symmetric releases */
  1114. double concentration; /* Concentration of molecules to release.
  1115. Units are Molar for volume molecules, and number per um^2 for surface molecules. */
  1116. double standard_deviation; /* Standard deviation of release_number for GAUSSNUM,
  1117. or of mean_diameter for VOLNUM */
  1118. struct vector3 *diameter; /* x,y,z diameter for geometrical release shapes */
  1119. struct release_region_data *region_data; /* Information related to release on regions */
  1120. struct release_single_molecule *mol_list; /* Information related to release by list */
  1121. double release_prob; /* Probability of releasing at scheduled time */
  1122. struct release_pattern *pattern; /* Timing of releases by virtual function generator */
  1123. char *name; /* Fully referenced name of the instantiated release_site */
  1124. };
  1125. /* Timing pattern for molecule release from a release site. */
  1126. struct release_pattern {
  1127. struct sym_table *sym; /* Symbol hash table entry for the pattern */
  1128. double delay; /* Delay between time 0 and first release event. */
  1129. double release_interval; /* Time between release events within a train. */
  1130. double train_interval; /* Time from the start of one train to the start of the next one. */
  1131. double train_duration; /* Length of the train. */
  1132. int number_of_trains; /* How many trains are produced. */
  1133. };
  1134. /* Extended data for complex releases on regions,
  1135. including boolean combinations of regions.
  1136. Not all fields are used for all release types. */
  1137. struct release_region_data
  1138. {
  1139. struct vector3 llf; /* One corner of bounding box for release volume */
  1140. struct vector3 urb; /* Opposite corner */
  1141. int n_walls_included; /* How many walls total */
  1142. double *cum_area_list; /* Cumulative area of all walls */
  1143. int *wall_index; /* Indices of each wall (by object) */
  1144. int *obj_index; /* Indices for objects (in owners array) */
  1145. int n_objects; /* How many objects are there total */
  1146. struct object **owners; /* Array of pointers to each object */
  1147. struct bit_array **in_release; /* Array of bit arrays; each bit array says which walls are in release for an object */
  1148. int refinement; /* Number of volume-inclusion checks to do (2d releases only) */
  1149. int *walls_per_obj; /* Number of walls in release for each object */
  1150. struct object *self; /* A pointer to our own release site object */
  1151. struct release_evaluator *expression; /* A set-construction expression combining regions to form this release site */
  1152. };
  1153. /* Data structure used to build boolean combinations of regions */
  1154. struct release_evaluator
  1155. {
  1156. byte op; /* Region Expression Flags: the operation used */
  1157. void *left; /* The left side of the expression--another evaluator or a region object depending on bitmask of op */
  1158. void *right; /* The right side--same thing */
  1159. };
  1160. /* Data structure used to store LIST releases */
  1161. struct release_single_molecule
  1162. {
  1163. struct release_single_molecule *next;
  1164. struct species *mol_type; /* Species to release */
  1165. struct vector3 loc; /* Position to release it */
  1166. short orient; /* Orientation (for 2D species) */
  1167. };
  1168. /* Holds information about a box with rectangular patches on it. */
  1169. struct subdivided_box
  1170. {
  1171. int nx; /* number of subdivisions including box corners in X-direction */
  1172. int ny; /* number of subdivisions including box corners in Y-direction */
  1173. int nz; /* number of subdivisions including box corners in Z-direction */
  1174. double *x; /* array of X-coordinates of subdivisions */
  1175. double *y; /* array of Y-coordinates of subdivisions */
  1176. double *z; /* array of Z-coordinates of subdivisions */
  1177. };
  1178. /* Holds information about what we want dumped to the screen */
  1179. struct notifications
  1180. {
  1181. /* Informational stuff, most possible values NOTIFY_FULL or NOTIFY_NONE */
  1182. /* see corresponding keywords */
  1183. enum notify_level_t progress_report; /* PROGRESS_REPORT */
  1184. enum notify_level_t diffusion_constants; /* DIFFUSION_CONSTANT_REPORT */
  1185. enum notify_level_t reaction_probabilities; /* PROBABILITY_REPORT */
  1186. enum notify_level_t time_varying_reactions; /* VARYING_PROBABILITY_REPORT */
  1187. double reaction_prob_notify; /* PROBABILITY_REPORT_THRESHOLD */
  1188. enum notify_level_t partition_location; /* PARTITION_LOCATION_REPORT */
  1189. enum notify_level_t box_triangulation; /* BOX_TRIANGULATION_REPORT */
  1190. enum notify_level_t iteration_report; /* ITERATION_REPORT */
  1191. long long custom_iteration_value; /* ITERATION_REPORT */
  1192. enum notify_level_t throughput_report; /* THROUGHPUT_REPORT */
  1193. enum notify_level_t checkpoint_report; /* CHECKPOINT_REPORT */
  1194. enum notify_level_t release_events; /* RELEASE_EVENT_REPORT */
  1195. enum notify_level_t file_writes; /* FILE_OUTPUT_REPORT */
  1196. enum notify_level_t final_summary; /* FINAL_SUMMARY */
  1197. enum notify_level_t reaction_output_report; /* REACTION_OUTPUT_REPORT */
  1198. enum notify_level_t volume_output_report; /* VOLUME_OUTPUT_REPORT */
  1199. enum notify_level_t viz_output_report; /* VIZ_OUTPUT_REPORT */
  1200. enum notify_level_t molecule_collision_report; /* MOLECULE_COLLISION_REPORT */
  1201. /* Warning stuff, possible values IGNORED, WARNING, ERROR */
  1202. /* see corresponding keywords */
  1203. enum warn_level_t neg_diffusion; /* NEGATIVE_DIFFUSION_CONSTANT */
  1204. enum warn_level_t neg_reaction; /* NEGATIVE_REACTION_RATE */
  1205. enum warn_level_t high_reaction_prob; /* HIGH_REACTION_PROBABILITY */
  1206. double reaction_prob_warn; /* HIGH_PROBABILITY_THRESHOLD */
  1207. enum warn_level_t close_partitions; /* CLOSE_PARTITION_SPACING */
  1208. enum warn_level_t degenerate_polys; /* DEGENERATE_POLYGONS */
  1209. enum warn_level_t overwritten_file; /* OVERWRITTEN_OUTPUT_FILE */
  1210. enum warn_level_t short_lifetime; /* LIFETIME_TOO_SHORT */
  1211. long long short_lifetime_value; /* LIFETIME_THRESHOLD */
  1212. enum warn_level_t missed_reactions; /* MISSED_REACTIONS */
  1213. double missed_reaction_value; /* MISSED_REACTION_THRESHOLD */
  1214. enum warn_level_t missed_surf_orient; /* MISSING_SURFACE_ORIENTATION */
  1215. enum warn_level_t useless_vol_orient; /* USELESS_VOLUME_ORIENTATION */
  1216. enum warn_level_t complex_placement_failure; /* COMPLEX_PLACEMENT_FAILURE */
  1217. long long complex_placement_failure_threshold; /* COMPLEX_PLACEMENT_FAILURE_THRESHOLD */
  1218. enum warn_level_t mol_placement_failure; /* MOLECULE_PLACEMENT_FAILURE */
  1219. enum warn_level_t invalid_output_step_time; /* INVALID_OUTPUT_STEP_TIME */
  1220. };
  1221. /* Information related to concentration clamp surfaces, by object */
  1222. struct ccn_clamp_data
  1223. {
  1224. struct ccn_clamp_data *next; /* The next concentration clamp, by surface class */
  1225. struct species *surf_class; /* Which surface class clamps? */
  1226. struct species *mol; /* Which molecule does it clamp? */
  1227. double concentration; /* At which concentration? */
  1228. short orient; /* On which side? */
  1229. struct object *objp; /* Which object are we clamping? */
  1230. struct bit_array *sides; /* Which walls in that object? */
  1231. int n_sides; /* How many walls? */
  1232. int *side_idx; /* Indices of the walls that are clamped */
  1233. double *cum_area; /* Cumulative area of all the clamped walls */
  1234. double scaling_factor; /* Used to predict #mols/timestep */
  1235. struct ccn_clamp_data *next_mol; /* Next clamp, by molecule, for this class */
  1236. struct ccn_clamp_data *next_obj; /* Next clamp, by object, for this class */
  1237. };
  1238. /* Structure for a VOLUME_DATA_OUTPUT item */
  1239. struct volume_output_item
  1240. {
  1241. /* Do not move or reorder these 2 items. scheduler depends upon them */
  1242. struct volume_output_item *next;
  1243. double t;
  1244. char *filename_prefix;
  1245. /* what? */
  1246. int num_molecules;
  1247. struct species **molecules; /* sorted by address */
  1248. /* where? */
  1249. struct vector3 location;
  1250. struct vector3 voxel_size;
  1251. int nvoxels_x;
  1252. int nvoxels_y;
  1253. int nvoxels_z;
  1254. /* when? */
  1255. enum output_timer_type_t timer_type;
  1256. double step_time;
  1257. int num_times;
  1258. double *times; /* in numeric order */
  1259. double *next_time; /* points into times */
  1260. };
  1261. /* Data for a single REACTION_DATA_OUTPUT block */
  1262. struct output_block
  1263. {
  1264. struct output_block *next; /* Next in world or scheduler */
  1265. double t; /* Scheduled time to update counters */
  1266. enum output_timer_type_t timer_type; /* Data Output Timing Type (OUTPUT_BY_STEP, etc) */
  1267. double step_time; /* Output interval (seconds) */
  1268. struct num_expr_list *time_list_head; /* List of output times/iteration numbers */
  1269. struct num_expr_list *time_now; /* Current entry in list */
  1270. u_int buffersize; /* Size of output buffer */
  1271. u_int trig_bufsize; /* Size of output buffer for triggers */
  1272. u_int buf_index; /* Index into buffer (for non-triggers) */
  1273. double *time_array; /* Array of output times (for non-triggers) */
  1274. struct output_set *data_set_head; /* Linked list of data sets (separate files) */
  1275. int reaction_data_output_type; /* type of reaction data output; */
  1276. struct binary_output *binary_out; /* struct containing binary output info */
  1277. };
  1278. /* Data that controls what output is written to a single file */
  1279. struct output_set
  1280. {
  1281. struct output_set *next; /* Next data set in this block */
  1282. struct output_block *block; /* Which block do we belong to? */
  1283. char *outfile_name; /* Filename */
  1284. enum overwrite_policy_t file_flags; /* Overwrite Policy Flags: tells us how to handle existing files */
  1285. u_int chunk_count; /* Number of buffered output chunks processed */
  1286. char *header_comment; /* Comment character(s) for header */
  1287. int exact_time_flag; /* Boolean value; nonzero means print exact time in TRIGGER statements */
  1288. struct output_column *column_head; /* Data for one output column */
  1289. };
  1290. /* Data that controls what data is written to one column of output file */
  1291. struct output_column
  1292. {
  1293. struct output_column *next; /* Next column in this set */
  1294. struct output_set *set; /* Which set do we belong to? */
  1295. enum count_type_t data_type; /* Type of data in this column. */
  1296. double initial_value; /* To continue existing cumulative counts--not implemented yet--and keep track of triggered data */
  1297. void *buffer; /* Output buffer array (cast based on data_type) */
  1298. struct output_expression *expr; /* Evaluate this to calculate our value (NULL if trigger) */
  1299. };
  1300. /* Expression evaluation tree to compute output value for one column */
  1301. struct output_expression
  1302. {
  1303. struct output_column *column; /* Which column are we going to? */
  1304. int expr_flags; /* Output Expression Flags: what are we and what is left and right? */
  1305. struct output_expression *up; /* Parent output expression */
  1306. void *left; /* Item on the left */
  1307. void *right; /* Item on the right */
  1308. char oper; /* Operation to apply to items */
  1309. double value; /* Resulting value from operation */
  1310. char *title; /* String describing this expression for user */
  1311. };
  1312. /* Information about a requested COUNT or TRIGGER statement */
  1313. /* Used during initialization to link output expressions with appropriate target,
  1314. and instruct MCell3 to collect appropriate statistics at the target. */
  1315. struct output_request
  1316. {
  1317. struct output_request *next; /* Next request in global list */
  1318. struct output_expression *requester; /* Expression in which we appear */
  1319. struct sym_table *count_target; /* Mol/rxn we're supposed to count */
  1320. short count_orientation; /* orientation of the molecule
  1321. we are supposed to count */
  1322. struct sym_table *count_location; /* Object or region on which we're supposed to count it */
  1323. byte report_type; /* Output Report Flags telling us how to count */
  1324. };
  1325. /* Data stored when a trigger event happens */
  1326. struct output_trigger_data
  1327. {
  1328. double t_iteration; /* Iteration time of the triggering event (in sec) */
  1329. double event_time; /* Exact time of the event */
  1330. struct vector3 loc; /* Position of event */
  1331. int how_many; /* Number of events */
  1332. short orient; /* Orientation information */
  1333. short flags; /* Output Trigger Flags */
  1334. char *name; /* Name to give event */
  1335. };
  1336. /******************************************************************/
  1337. /** Everything below this line has been copied from MCell 2.69 **/
  1338. /******************************************************************/
  1339. /* A polygon list object, part of a surface. */
  1340. struct polygon_object {
  1341. int n_verts; /* Number of vertices in polyhedron */
  1342. struct vertex_list *parsed_vertices; /* Temporary linked list */
  1343. int n_walls; /* Number of triangles in polyhedron */
  1344. struct element_data *element; /* Array specifying the vertex connectivity of each triangle */
  1345. struct subdivided_box *sb; /* Holds corners of box if necessary */
  1346. struct bit_array *side_removed; /* Bit array; if bit is set, side is removed */
  1347. };
  1348. /* Data structure used to build one triangular polygon
  1349. according to the connectivity in the MDL file. */
  1350. struct element_data {
  1351. int vertex_index[3]; /* Array of vertex indices forming a triangle */
  1352. };
  1353. /* A voxel list object, part of a volume */
  1354. struct voxel_object
  1355. {
  1356. struct vector3 *vertex; /* Array of tetrahedron vertices */
  1357. struct tet_element_data *element; /* Array tet_element_data data structures */
  1358. struct tet_neighbors_data *neighbor; /* Array tet_neighbors_data data structures */
  1359. int n_verts; /* Number of vertices in polyhedron */
  1360. int n_voxels; /* Number of voxels in polyhedron */
  1361. };
  1362. /**
  1363. * Data structure used to build one tetrahedron.
  1364. * This data structure is used to store the data from the MDL file
  1365. * and to contruct each tetrahedron of a voxel object.
  1366. */
  1367. struct tet_element_data
  1368. {
  1369. int vertex_index[4]; /* Array of vertex indices forming a tetrahedron. */
  1370. };
  1371. /**
  1372. * This data structure is used to store the data about neighbors
  1373. * of each tetrahedron of a voxel object.
  1374. */
  1375. struct tet_neighbors_data
  1376. {
  1377. int neighbors_index[4]; /* Array of indices pointing to the neighbors of tetrahedron. */
  1378. };
  1379. /* Surface molecule placement data */
  1380. struct eff_dat {
  1381. struct eff_dat *next;
  1382. struct species *eff; /* Species to place on surface */
  1383. byte quantity_type; /* Placement Type Flags: either EFFDENS or EFFNUM */
  1384. double quantity; /* Amount of surface molecules to place by density or number */
  1385. short orientation; /* Orientation of molecules to place */
  1386. };
  1387. /* Linked list of wall index ranges for regions */
  1388. struct element_list {
  1389. struct element_list *next;
  1390. u_int begin; /* First number in the range */
  1391. u_int end; /* Last number in the range */
  1392. struct element_special *special; /* Pre-existing region or patch on box */
  1393. };
  1394. /* Elements can be patches on boxes or pre-existing regions */
  1395. struct element_special
  1396. {
  1397. struct vector3 corner1; /* Corner of patch on box */
  1398. struct vector3 corner2; /* Opposite corner of patch on box */
  1399. struct region *referent; /* Points to pre-existing region on object */
  1400. byte exclude; /* If set, remove elements rather than include them */
  1401. };
  1402. /* Region of an object */
  1403. /* If region is a manifold then it can be used as both a volume and surface region.
  1404. Otherwise it can only be used as a surface region. */
  1405. struct region {
  1406. struct sym_table *sym; /* Symbol hash table entry for this region */
  1407. u_int hashval; /* Hash value for counter hash table */
  1408. char *region_last_name; /* Name of region without prepended object name */
  1409. struct object *parent; /* Parent of this region */
  1410. struct element_list *element_list_head; /* List of element ranges comprising this region (used at parse time) */
  1411. struct bit_array *membership; /* Each bit indicates whether the corresponding wall is in the region */
  1412. struct eff_dat *eff_dat_head; /* List of surface molecules to add to region */
  1413. struct species *surf_class; /* Surface class of this region */
  1414. struct vector3 *bbox; /* Array of length 2 to hold corners of region bounding box
  1415. (used for release in region) */
  1416. int region_viz_value; /* Used for visualization */
  1417. double area; /* Area of region */
  1418. u_short flags; /* Counting subset of Species Flags */
  1419. byte manifold_flag; /* Manifold Flags: If IS_MANIFOLD, region is a closed manifold and thus defines a volume */
  1420. struct pointer_hash *boundaries; /* hash table of edges that constitute
  1421. external boundary of the region */
  1422. int region_has_all_elements; /* flag that tells whether the region
  1423. contains ALL_ELEMENTS (effectively
  1424. comprises the whole object) */
  1425. };
  1426. /* A list of regions */
  1427. struct region_list {
  1428. struct region_list *next;
  1429. struct region *reg; /* A region */
  1430. };
  1431. /* Container data structure for all physical objects */
  1432. struct object {
  1433. struct object *next; /* Next sibling object */
  1434. struct object *parent; /* Parent meta object */
  1435. struct object *first_child; /* First child object */
  1436. struct object *last_child; /* Last child object */
  1437. struct sym_table *sym; /* Symbol hash table entry for this object */
  1438. char *last_name; /* Name of object without pre-pended parent object name */
  1439. enum object_type_t object_type; /* Object Type Flags */
  1440. void *contents; /* Actual physical object, cast according to object_type */
  1441. u_int num_regions; /* Number of regions defined on object */
  1442. struct region_list *regions; /* List of regions for this object */
  1443. int n_walls; /* Total number of walls in object */
  1444. int n_walls_actual; /* Number of non-null walls in object */
  1445. struct wall *walls; /* Array of walls in object */
  1446. struct wall **wall_p; /* Array of ptrs to walls in object (used at run-time) */
  1447. int n_verts; /* Total number of vertices in object */
  1448. struct vector3 **vertices; /* Array of pointers to vertices
  1449. (linked to "all_vertices" array) */
  1450. double total_area; /* Area of object in length units */
  1451. u_int n_tiles; /* Number of surface grid tiles on object */
  1452. u_int n_occupied_tiles; /* Number of occupied tiles on object */
  1453. double t_matrix[4][4]; /* Transformation matrix for object */
  1454. };
  1455. /* Doubly linked list of object names */
  1456. struct name_list {
  1457. struct name_list *next;
  1458. struct name_list *prev;
  1459. char *name; /* An object name */
  1460. };
  1461. /* Linked list of names-orientations. Used in printing special reactions report
  1462. for surface classes */
  1463. struct name_orient{
  1464. struct name_orient *next;
  1465. char *name; /* molecule name */
  1466. int orient; /* molecule orientation */
  1467. };
  1468. /* Visualization objects */
  1469. struct viz_dx_obj
  1470. {
  1471. struct viz_dx_obj *next;
  1472. char *name; /* Name taken from OBJECT_FILE_PREFIXES
  1473. or FILENAME_PREFIXES or FILENAME assignment */
  1474. char *full_name; /* Full name of the object, like A.B.C */
  1475. struct object *obj; /* The object being visualized */
  1476. struct viz_child *viz_child_head; /* List of child objects to visualize */
  1477. struct viz_output_block *parent; /* Parent block to whom we belong */
  1478. struct viz_child **actual_objects; /* Pointers to actual objects to visualize */
  1479. int n_actual_objects; /* Number of actual objects to visualize */
  1480. };
  1481. /* Tree of pointers to objects (mirrors standard geometry hierarchy). */
  1482. /* Contains child polygon or box objects to be visualized. */
  1483. struct viz_child
  1484. {
  1485. struct viz_child *next;
  1486. struct viz_child *parent;
  1487. struct viz_child *children;
  1488. struct object *obj; /* An object to visualize*/
  1489. int *viz_state; /* Array of viz state values, one for each element of object. */
  1490. };
  1491. struct visualization_state
  1492. {
  1493. /* Iteration numbers */
  1494. long long last_meshes_iteration;
  1495. long long last_mols_iteration;
  1496. /* Tokenized filename prefix */
  1497. char *filename_prefix_basename;
  1498. char *filename_prefix_dirname;
  1499. /* All visualized volume molecule species */
  1500. int n_vol_species;
  1501. struct species **vol_species;
  1502. /* All visualized grid molecule species */
  1503. int n_grid_species;
  1504. struct species **grid_species;
  1505. /* Iteration numbers and times of outputs */
  1506. struct iteration_counter output_times;
  1507. struct iteration_counter mesh_output_iterations;
  1508. struct iteration_counter vol_mol_output_iterations;
  1509. struct iteration_counter grid_mol_output_iterations;
  1510. /* For DREAMM V3 Grouped output, combined group member strings */
  1511. struct string_buffer combined_group_members;
  1512. /* For DREAMM V3 Grouped output, the current object number */
  1513. int dx_main_object_index;
  1514. /* For DREAMM V3 Grouped output, the last iteration for certain outputs */
  1515. long long dreamm_last_iteration_meshes;
  1516. long long dreamm_last_iteration_vol_mols;
  1517. long long dreamm_last_iteration_surf_mols;
  1518. /* For DREAMM V3 Ungrouped output, path of 'frame data dir' and iter dir */
  1519. char *frame_data_dir;
  1520. char *iteration_number_dir;
  1521. };
  1522. struct viz_output_block
  1523. {
  1524. struct viz_output_block *next; /* Link to next block */
  1525. struct frame_data_list *frame_data_head; /* head of the linked list of viz frames to output */
  1526. struct visualization_state viz_state_info; /* miscellaneous state for viz_output code */
  1527. enum viz_mode_t viz_mode;
  1528. char *molecule_prefix_name;
  1529. char *file_prefix_name;
  1530. u_short viz_output_flag; /* Takes VIZ_ALL_MOLECULES, VIZ_MOLECULES_STATES, etc. */
  1531. int *species_viz_states;
  1532. int default_mesh_state; /* Only set if (viz_output_flag & VIZ_ALL_MESHES) */
  1533. int default_mol_state; /* Only set if (viz_output_flag & VIZ_ALL_MOLECULES) */
  1534. /* DREAMM-mode only. */
  1535. struct viz_child **dreamm_object_info; /* Pointers to actual objects to visualize */
  1536. struct object **dreamm_objects;
  1537. int n_dreamm_objects; /* Number of actual objects to visualize */
  1538. /* DX-mode only: head of linked list of OBJECT_FILE_PREFIXES. */
  1539. struct viz_dx_obj *dx_obj_head;
  1540. /* RK-mode only. */
  1541. struct rk_mode_data *rk_mode_var;
  1542. /* Parse-time only: Tables to hold temporary information. */
  1543. struct sym_table_head *viz_children;
  1544. struct pointer_hash parser_species_viz_states;
  1545. };
  1546. /* Geometric transformation data for a physical object */
  1547. struct transformation {
  1548. struct vector3 translate; /* X,Y,Z translation vector */
  1549. struct vector3 scale; /* X,Y,Z scaling factors */
  1550. struct vector3 rot_axis; /* Vector defining an axis of rotation */
  1551. double rot_angle; /* Rotation angle in degrees */
  1552. };
  1553. /* Linked list of viz data to be output */
  1554. struct frame_data_list
  1555. {
  1556. struct frame_data_list *next;
  1557. enum output_timer_type_t list_type; /* Data Output Timing Type (OUTPUT_BY_TIME_LIST, etc) */
  1558. enum viz_frame_type_t type; /* Visualization Frame Data Type (ALL_FRAME_DATA, etc) */
  1559. long long viz_iteration; /* Value of the current iteration step. */
  1560. long long n_viz_iterations; /* Number of iterations in the iteration_list. */
  1561. struct num_expr_list *iteration_list; /* Linked list of iteration steps values */
  1562. struct num_expr_list *curr_viz_iteration; /* Points to the current iteration in the linked list */
  1563. };
  1564. /* A pointer to filehandle and its real name */
  1565. /* Used for user defined file IO operations */
  1566. struct file_stream {
  1567. char *name; /* File name */
  1568. FILE *stream; /* File handle structure */
  1569. };
  1570. /* Symbol hash table */
  1571. /* Used to parse and store user defined symbols from the MDL input file */
  1572. struct sym_table_head {
  1573. struct sym_table **entries;
  1574. int n_entries;
  1575. int n_bins;
  1576. };
  1577. /* Symbol hash table entry */
  1578. /* Used to parse and store user defined symbols from the MDL input file */
  1579. /* XXX: This is a poorly named structure. Maybe "sym_entry" or even just "symbol"? */
  1580. struct sym_table {
  1581. struct sym_table *next; /* Chain to next symbol in this bin of the hash */
  1582. int sym_type; /* Symbol Type */
  1583. char *name; /* Name of symbol*/
  1584. void *value; /* Stored value, cast by sym_type */
  1585. };
  1586. /* Linked list of symbols */
  1587. /* Used to parse and retrieve user defined symbols having wildcards from the MDL input file */
  1588. struct sym_table_list {
  1589. struct sym_table_list *next;
  1590. struct sym_table *node; /* Symbol table entry matching a user input wildcard string */
  1591. };
  1592. /* Linked list of numerical expressions */
  1593. /* Used for parsing MDL input file arithmetic expressions */
  1594. struct num_expr_list {
  1595. struct num_expr_list *next;
  1596. double value; /* Value of one element of the expression */
  1597. };
  1598. /* Histogram visualization output mode used by Rex */
  1599. struct rk_mode_data
  1600. {
  1601. int n_bins;
  1602. int* bins;
  1603. double *parts;
  1604. struct vector3 *direction;
  1605. int n_written;
  1606. };
  1607. /* Linked list of surface classes */
  1608. struct surf_class_list {
  1609. struct surf_class_list *next;
  1610. struct species *surf_class;
  1611. };
  1612. /* Linked list of edges - used for REGION borders */
  1613. struct edge_list
  1614. {
  1615. struct edge_list *next;
  1616. struct edge *ed;
  1617. };
  1618. /* Data about hits/crossing on the region border */
  1619. struct hit_data
  1620. {
  1621. struct hit_data *next;
  1622. struct region_list *count_regions; /* list of regions we counting on */
  1623. int direction; /* 1 - INSIDE_OUT, 0 - OUTSIDE_IN */
  1624. int crossed; /* 1 - if crossed, 0 - if not */
  1625. short orientation; /* orientation of the grid molecule */
  1626. struct vector3 loc; /* location of the hit */
  1627. double t; /* time of the hit */
  1628. };
  1629. #endif