Repository navigation
Parsing DREAMM_V3_GROUPED
Note: Support for DREAMM_V3_GROUPED has been removed from the master branch.
If you want to generate large amounts of viz data for analysis purposes but don't want to deal with large numbers of files, you can set the MODE equal to DREAMM_V3_GROUPED in the VIZ_OUTPUT section of your mdl. Side note: DReAMM was the primary visualization tool for MCell simulations prior to CellBlender.
Below is an example of an MDL and python script which will illustrate how to parse DReAMM_V3_GROUPED output.
First, here is the mdl:
ITERATIONS = 1
TIME_STEP = 1e-6
DEFINE_MOLECULES
{
A
{
DIFFUSION_CONSTANT_3D = 1e-06
}
B
{
DIFFUSION_CONSTANT_2D = 1e-06
}
}
mybox BOX
{
CORNERS = [-0.5, -0.5, -0.5],[0.5, 0.5, 0.5]
}
INSTANTIATE Scene OBJECT
{
mybox OBJECT mybox{}
Release_Site RELEASE_SITE
{
SHAPE = Scene.mybox
MOLECULE = A
NUMBER_TO_RELEASE = 5
RELEASE_PROBABILITY = 1
}
Release_Site2 RELEASE_SITE
{
SHAPE = Scene.mybox
MOLECULE = B'
NUMBER_TO_RELEASE = 5
RELEASE_PROBABILITY = 1
}
}
sprintf(seed,"%05g",SEED)
VIZ_OUTPUT
{
MODE = DREAMM_V3_GROUPED
FILENAME = "./viz_data/seed_" & seed & "/Scene"
MOLECULES
{
NAME_LIST {ALL_MOLECULES}
ITERATION_NUMBERS {ALL_DATA @ ALL_ITERATIONS}
}
MESHES
{
NAME_LIST {ALL_MESHES}
ITERATION_NUMBERS {ALL_DATA @ ALL_ITERATIONS}
}
}
Now, here's the python script:
#!/usr/bin/env python
import struct
""" A toy script for parsing DREAMM_V3_GROUPED
This script is intended to illustrate how DReAMM_V3_GROUPED mode can be parsed
without using DReAMM. The ASCII dx file contains all the information about the
meshes and molecules (names, positions, orientations, connections, etc). The
main lines of interest look like this:
object 1 class array type float rank 1 shape 3 items 8 lsb binary data file
Scene.mesh_positions.bin,0 # Scene.mybox.positions #
rank refers to the dimensionality of the array (0 is 1D, 1 is 2D), shape to the
number of columns, items to the number of rows, lsb for small endian
formatting, mesh_positions.bin is the name of the file, mybox is the name of
the object, and positions is the type of data
In the example above, we are looking at a box made up of 8 vertices (i.e.
items). Each vertex is made up of an xyz coordinate (i.e. rank)
Note: This example does not show to parse the iteration_numbers.bin,
time_values.bin, or region_indices.bin.
"""
viz_dir = "./viz_data/seed_00001"
viz_prefix = "Scene"
with open("%s/%s.dx" % (viz_dir, viz_prefix), "r") as meshes_f:
lines = meshes_f.readlines()
mesh_bin = "%s/%s.mesh_positions.bin" % (viz_dir, viz_prefix)
mol_pos_bin = "%s/%s.molecule_positions.bin" % (viz_dir, viz_prefix)
mol_orient_bin = "%s/%s.molecule_orientations.bin" % (viz_dir, viz_prefix)
shape = 3
iteration = 0
with open(mesh_bin, 'rb') as mesh_f,\
open(mol_pos_bin, 'rb') as mol_pos_f,\
open(mol_orient_bin, 'rb') as mol_orient_f:
for line in lines:
# We are looking for lines like this:
# object 1 class array type float rank 1 shape 3 items 8 lsb binary
# data file Scene.mesh_positions.bin,0 # Scene.mybox.positions #
if "binary data" in line and line.endswith("#\n"):
line_split = line.split()
# This contains the name of the mesh/molecule as well as some
# descriptive info (orientations, positions, connections)
item_name = line_split[18]
print("\nName of item: %s" % item_name)
# If it is a constantarray (mainly used for volume molecule
# orientations), then we only scan one item.
item_nums = int(line_split[11]) if line_split[3] == "array" else 1
print("Number of items: %s" % item_nums)
unpack_type = line_split[5]
# Integer format is used for connections. Everything else
# (vertices, molecule locations, orientations) uses float
if unpack_type == "int":
unpack_format = "<iii"
else:
unpack_format = "<fff"
# Make sure we unpack from the right binary file
if "mesh_positions.bin" in line:
f = mesh_f
elif "molecule_positions.bin" in line:
f = mol_pos_f
elif "molecule_orientations.bin" in line:
f = mol_orient_f
for i in range(item_nums):
# The shape is three for all these examples but could be
# different (e.g. time_values.bin)
some_bytes = f.read(4*shape)
# These represent one of the following: mesh vertex, mesh
# connection, molecule xyz coordinate, or molecule orientation
item1, item2, item3 = struct.unpack(unpack_format, some_bytes)
print("%g %g %g" % (item1, item2, item3))
# A hackish way to check for the end of the iteration.
# The end of the iteration alway has something like this:
# "object 20 group"
elif len(line.split()) == 3 and line.split()[2] == "group":
print("\nENDING ITERATION: %s" % iteration)
iteration += 1
To see how this works, you first need to generate the viz data by running MCell on the mdl. Then, you will run the python script in the same directory as the viz data. The output of the script should look something like this:
Name of item: Scene.mybox.positions
Number of items: 8
-0.5 -0.5 -0.5
-0.5 0.5 -0.5
-0.5 -0.5 0.5
-0.5 0.5 0.5
0.5 -0.5 -0.5
0.5 0.5 -0.5
0.5 -0.5 0.5
0.5 0.5 0.5
Name of item: Scene.mybox.connections
Number of items: 12
0 2 1
3 1 2
4 5 6
7 6 5
0 4 2
6 2 4
1 3 5
7 5 3
0 1 4
5 4 1
2 6 3
7 3 6
Name of item: B.positions
Number of items: 5
0.322944 -0.336645 0.5
0.5 0.451294 -0.129677
-0.406163 -0.125827 0.5
0.5 0.465501 0.416085
-0.0718019 0.5 0.30419
Name of item: B.orientations
Number of items: 5
0 0 1
1 0 0
0 0 1
1 0 0
0 1 0
Name of item: A.positions
Number of items: 5
0.38133 0.291392 0.154809
0.291803 0.127609 0.31837
-0.0519496 -0.394685 0.432639
0.206934 0.0876586 -0.167383
0.0975908 -0.223076 0.33336
Name of item: A.orientations
Number of items: 1
0 0 1
ENDING ITERATION: 0
Name of item: Scene.mybox.positions
Number of items: 8
-0.5 -0.5 -0.5
-0.5 0.5 -0.5
-0.5 -0.5 0.5
-0.5 0.5 0.5
0.5 -0.5 -0.5
0.5 0.5 -0.5
0.5 -0.5 0.5
0.5 0.5 0.5
Name of item: Scene.mybox.connections
Number of items: 12
0 2 1
3 1 2
4 5 6
7 6 5
0 4 2
6 2 4
1 3 5
7 5 3
0 1 4
5 4 1
2 6 3
7 3 6
Name of item: B.positions
Number of items: 5
0.34267 -0.324638 0.5
0.5 0.478577 -0.120696
-0.377829 -0.11151 0.5
0.5 0.45991 0.428572
-0.077398 0.5 0.302083
Name of item: B.orientations
Number of items: 5
0 0 1
1 0 0
0 0 1
1 0 0
0 1 0
Name of item: A.positions
Number of items: 5
0.368494 0.308432 0.128818
0.294587 0.125268 0.30476
-0.0539362 -0.375936 0.439939
0.19843 0.0958858 -0.154272
0.0994184 -0.220274 0.348865
Name of item: A.orientations
Number of items: 1
0 0 1