file_formats.rst 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. ************
  2. File Formats
  3. ************
  4. This section describes some of the output file formats that MCell produces.
  5. Molecule Visualization Data
  6. ###########################
  7. MCell4 provides two output formats for molecule visualization.
  8. A textual and binary format.
  9. VizMode.ASCII mode selects a readable representation, VizMode.CELLBLENDER mode
  10. selects a binary representation that cannot be read using a text editor but
  11. is faster to generate and read.
  12. The code below shows an example of the VizOutput object with a selection of output
  13. file format.
  14. .. code-block:: python
  15. viz_output = m.VizOutput(
  16. mode = m.VizMode.ASCII, # or m.VizMode.CELLBLENDER or m.VizMode.CELLBLENDER_V1
  17. output_files_prefix = './viz_data/seed_' + str(SEED).zfill(5) + '/Scene'
  18. )
  19. model.add_viz_output(viz_output)
  20. Text Visualization Data
  21. ***********************
  22. The text format is composed of lines where each line contains data on one molecule
  23. in the following format:
  24. .. code-block:: text
  25. species id x y z nx ny nz
  26. Here, *species* is the string representation of the molecule species,
  27. *id* is a unique integer identifier of the molecule, *x* *y* *z*
  28. represent the 3D location of the molecule in um (micrometers), and *nx* *ny* *nz* is
  29. the normal vector. For volume molecules, the normal vector is always 0 0 0.
  30. For surface molecules, it corresponds to the normal of the wall where the molecule is
  31. located and can be either identical (when the molecule's orientation is UP), or
  32. negated (when the molecule's orientation is DOWN).
  33. Example:
  34. .. code-block:: text
  35. va@CP 1 0.0601783518 -0.0796582 -0.0180513811 0 0 0
  36. sb@PM 2 0.125 -0.115164035 0.066618027 1 0 0
  37. sc@PM 3 -0.113072306 0.00838499159 0.125 0 0 1
  38. Here we have three molecules, first is a volume molecule with species va\@CP
  39. (compartment is a part of molecule's species), then two surface molecules with
  40. species sb\@PM and sc\@PM with their normal vectors set.
  41. Binary Visualization Data V2
  42. ****************************
  43. The binary format has two versions with v2 being the most recent.
  44. All floating point-values (float) are encoded as 32-bit
  45. IEEE 745 single-precision floating-point format and the
  46. location uses the um (micrometer) unit. Values of indented addresses
  47. represent offset from the start of each block.
  48. It uses the following structure:
  49. .. code-block:: text
  50. 0x0: 2 (4 bytes, uint), constant, used to distinguish binary and ascii formats and to specify binary version
  51. 0x4: here start species blocks, each block contains:
  52. 0x0: name_len (4 byte, unsigned int)
  53. 0x4: name (sequence of 1-byte characters representing the species name without the terminating zero)
  54. name_len+4: species_type (1 byte, unsigned char), 0 for volume molecules and 1 for surface molecules
  55. name_len+5: num_mols (4 bytes, uint)
  56. name_len+9: molecule ids, repeated num_mols times
  57. 0x0: id (4 bytes, uint)
  58. name_len+9+num_mols*4: x,y,z triplets, repeated num_mols times
  59. 0x0: x (4 bytes, float)
  60. 0x4: y (4 bytes, float)
  61. 0x8: z (4 bytes, float)
  62. name_len+2+num_mols*12: if species_type is 1, on this address start nx,ny,nz triplets, otherwise empty (0 bytes)
  63. 0x0: nx (4 bytes, float)
  64. 0x4: ny (4 bytes, float)
  65. 0x8: nz (4 bytes, float)
  66. Example:
  67. .. code-block:: text
  68. 00000000 02 00 00 00 05 00 00 00 76 61 40 43 50 00 02 00 |........va@CP...|
  69. 00000010 00 00 00 00 00 00 01 00 00 00 37 67 95 3e 09 ac |..........7g.>..|
  70. 00000020 02 3e 5e 01 a3 3e 23 c9 54 bd 37 14 ca be d2 82 |.>^..>#.T.7.....|
  71. 00000030 dd 3e 05 00 00 00 73 62 40 50 4d 01 02 00 00 00 |.>....sb@PM.....|
  72. 00000040 02 00 00 00 03 00 00 00 00 00 00 3f 3b 32 3c bd |...........?;2<.|
  73. 00000050 ab 05 4b 3e f0 7d 77 3e 00 00 00 3f ea fa b8 bd |..K>.}w>...?....|
  74. 00000060 00 00 80 3f 00 00 00 00 00 00 00 00 00 00 00 80 |...?............|
  75. 00000070 00 00 80 3f 00 00 00 00 |...?....|
  76. 00000078
  77. This hex dump shows a binary representation of molecule positions equivalent to
  78. ASCII output shown here:
  79. .. code-block:: text
  80. va@CP 0 0.311161 0.145214365 0.32167688 0 0 0
  81. va@CP 1 -0.0498850037 -0.415475712 0.426996041 0 0 0
  82. sb@PM 2 0.5 -0.0639481536 0.170722492 1 0 0
  83. sb@PM 3 0.307013747 0.5 -0.174133457 -0 1 0
  84. In more detail, this is how the data is encoded:
  85. .. code-block:: text
  86. 00000000 02 00 00 00 - constant '2' (in little-endian representation)
  87. 00000004 05 00 00 00 - length of string 'va@CP' - 5
  88. 00000008 76 61 40 43 50 - characters of string 'va@CP'
  89. 0000000D 00 - '0' telling that these are volume molecules
  90. 0000000E 02 00 00 00 - 2 molecules
  91. 00000012 00 00 00 00 01 00 00 00 - IDs of molecules 0, 1
  92. 0000001A 7f 50 9f 3e 13 b3 14 3e d5 b2 a4 3e - xyz position of the first molecule
  93. 00000026 38 54 4c bd 3c b9 d4 be 3a 9f da 3e - xyz position of the second molecule
  94. 00000032 05 - length of string 'sb@PM'
  95. ... (species name, positions, and normals of sb@PM molecules follow)
  96. Binary Visualization Data V1
  97. ****************************
  98. Version 1 of the binary visualization data uses the following structure:
  99. .. code-block:: text
  100. 0x0: 1 (4 bytes, uint), constant, used to distinguish binary and ascii formats
  101. 0x4: here start species blocks, each block contains:
  102. 0x0: name_len (1 byte, unsigned char)
  103. 0x1: name (sequence of 1-byte characters representing the species name without the terminating zero)
  104. name_len+1: species_type (1 byte, unsigned char), 0 for volume molecules and 1 for surface molecules
  105. name_len+2: num_float_positions (4 bytes, uint)
  106. name_len+6: x,y,z triplets, repeated num_float_positions/3 times
  107. 0x0: x (4 bytes, float)
  108. 0x4: y (4 bytes, float)
  109. 0x8: z (4 bytes, float)
  110. name_len+2+num_float_positions*4: if species_type is 1, on this address start nx,ny,nz triplets, otherwise empty (0 bytes)
  111. 0x0: nx (4 bytes, float)
  112. 0x4: ny (4 bytes, float)
  113. 0x8: nz (4 bytes, float)
  114. The V1 format was changed to V2 by:
  115. 1) the first 4 bytes have value 2, 2) name_len is 4 bytes, and 3) num_float_positions was changed to num_mols
  116. having 3x lower value.