simulariumio/mcell/mcell_converter.py
def _read_binary_cellblender_viz_frame(
        file_name: str,
        time_index: int,
        molecule_info: Dict[str, Dict[str, Any]],
        input_data: McellData,
        result: AgentData,
    ) -> AgentData:
        """
        Read MCell binary visualization files

        code based on cellblender/cellblender_mol_viz.py function mol_viz_file_read
        """
        with open(file_name, "rb") as mol_file:
            # first 4 bytes must contain value '1'
            b = array.array("I")
            b.fromfile(mol_file, 1)
            assert b[0] == 1
            while True:
                try:
                    # get type name
                    n_chars_type_name = array.array("B")
                    n_chars_type_name.fromfile(mol_file, 1)
                    type_name_array = array.array("B")
                    type_name_array.fromfile(mol_file, n_chars_type_name[0])
                    type_name = type_name_array.tobytes().decode()
                    display_type_name = (
                        input_data.display_data[type_name].name
                        if type_name in input_data.display_data
                        else type_name
                    )
                    # get positions and rotations
                    is_surface_mol = array.array("B")
                    is_surface_mol.fromfile(mol_file, 1)
                    is_surface_mol = is_surface_mol[0] == 1
                    n_data = array.array("I")
                    n_data.fromfile(mol_file, 1)
                    n_data = n_data[0]
                    n_mols = int(n_data / 3.0)
                    positions = array.array("f")
                    positions.fromfile(mol_file, n_data)
                    positions = input_data.meta_data.scale_factor * np.array(positions)
                    positions = positions.reshape(n_mols, 3)
                    if is_surface_mol:
                        normals = array.array("f")
                        normals.fromfile(mol_file, n_data)
                        normals = np.array(normals)
                        normals = normals.reshape(n_mols, 3)
                        rotations = (
                            McellConverter._get_rotation_euler_angles_for_normals(
                                normals, input_data.surface_mol_rotation_angle
                            )
                        )
                        rotations = rotations.reshape(3 * n_mols)
                    else:
                        rotations = np.zeros_like(positions)
                    # save to AgentData
                    total_mols = int(result.n_agents[time_index])
                    # MCell binary format has no IDs, so use molecule index
                    result.unique_ids[time_index, total_mols : total_mols + n_mols] = (
                        np.arange(n_mols) + total_mols
                    )
                    result.types[time_index] += n_mols * [display_type_name]
                    result.positions[
                        time_index, total_mols : total_mols + n_mols, :
                    ] = positions
                    result.radii[time_index, total_mols : total_mols + n_mols] = (
                        input_data.meta_data.scale_factor
                        * BLENDER_GEOMETRY_SCALE_FACTOR
                        * (
                            input_data.display_data[type_name].radius
                            if type_name in input_data.display_data
                            and input_data.display_data[type_name].radius is not None
                            else molecule_info[type_name]["display"]["scale"]
                        )
                        * np.ones(n_mols)
                    )
                    result.rotations[
                        time_index, total_mols : total_mols + n_mols, :
                    ] = rotations
                    result.n_agents[time_index] += n_mols
                except EOFError:
                    mol_file.close()
                    break
        return result

        Read MCell binary visualization files

        code based on cellblender/cellblender_mol_viz.py function mol_viz_file_read
        
Read MCell binary visualization files
code based on cellblender/cellblender_mol_viz.py function mol_viz_file_read
Read MCell binary visualization files code based on cellblender / cellblender_mol_viz . py function mol_viz_file_read
def _read_binary_cellblender_viz_frame(
        file_name: str,
        time_index: int,
        molecule_info: Dict[str, Dict[str, Any]],
        input_data: McellData,
        result: AgentData,
    ) -> AgentData:
        with open(file_name, "rb") as mol_file:
            b = array.array("I")
            b.fromfile(mol_file, 1)
            assert b[0] == 1
            while True:
                try:
                    n_chars_type_name = array.array("B")
                    n_chars_type_name.fromfile(mol_file, 1)
                    type_name_array = array.array("B")
                    type_name_array.fromfile(mol_file, n_chars_type_name[0])
                    type_name = type_name_array.tobytes().decode()
                    display_type_name = (
                        input_data.display_data[type_name].name
                        if type_name in input_data.display_data
                        else type_name
                    )
                    is_surface_mol = array.array("B")
                    is_surface_mol.fromfile(mol_file, 1)
                    is_surface_mol = is_surface_mol[0] == 1
                    n_data = array.array("I")
                    n_data.fromfile(mol_file, 1)
                    n_data = n_data[0]
                    n_mols = int(n_data / 3.0)
                    positions = array.array("f")
                    positions.fromfile(mol_file, n_data)
                    positions = input_data.meta_data.scale_factor * np.array(positions)
                    positions = positions.reshape(n_mols, 3)
                    if is_surface_mol:
                        normals = array.array("f")
                        normals.fromfile(mol_file, n_data)
                        normals = np.array(normals)
                        normals = normals.reshape(n_mols, 3)
                        rotations = (
                            McellConverter._get_rotation_euler_angles_for_normals(
                                normals, input_data.surface_mol_rotation_angle
                            )
                        )
                        rotations = rotations.reshape(3 * n_mols)
                    else:
                        rotations = np.zeros_like(positions)
                    total_mols = int(result.n_agents[time_index])
                    result.unique_ids[time_index, total_mols : total_mols + n_mols] = (
                        np.arange(n_mols) + total_mols
                    )
                    result.types[time_index] += n_mols * [display_type_name]
                    result.positions[
                        time_index, total_mols : total_mols + n_mols, :
                    ] = positions
                    result.radii[time_index, total_mols : total_mols + n_mols] = (
                        input_data.meta_data.scale_factor
                        * BLENDER_GEOMETRY_SCALE_FACTOR
                        * (
                            input_data.display_data[type_name].radius
                            if type_name in input_data.display_data
                            and input_data.display_data[type_name].radius is not None
                            else molecule_info[type_name]["display"]["scale"]
                        )
                        * np.ones(n_mols)
                    )
                    result.rotations[
                        time_index, total_mols : total_mols + n_mols, :
                    ] = rotations
                    result.n_agents[time_index] += n_mols
                except EOFError:
                    mol_file.close()
                    break
        return result
def _read_binary_cellblender_viz_frame ( file_name : str , time_index : int , molecule_info : Dict [ str , Dict [ str , Any ] ] , input_data : McellData , result : AgentData , ) -> AgentData : with open ( file_name , "rb" ) as mol_file : b = array . array ( "I" ) b . fromfile ( mol_file , 1 ) assert b [ 0 ] == 1 while True : try : n_chars_type_name = array . array ( "B" ) n_chars_type_name . fromfile ( mol_file , 1 ) type_name_array = array . array ( "B" ) type_name_array . fromfile ( mol_file , n_chars_type_name [ 0 ] ) type_name = type_name_array . tobytes ( ) . decode ( ) display_type_name = ( input_data . display_data [ type_name ] . name if type_name in input_data . display_data else type_name ) is_surface_mol = array . array ( "B" ) is_surface_mol . fromfile ( mol_file , 1 ) is_surface_mol = is_surface_mol [ 0 ] == 1 n_data = array . array ( "I" ) n_data . fromfile ( mol_file , 1 ) n_data = n_data [ 0 ] n_mols = int ( n_data / 3.0 ) positions = array . array ( "f" ) positions . fromfile ( mol_file , n_data ) positions = input_data . meta_data . scale_factor * np . array ( positions ) positions = positions . reshape ( n_mols , 3 ) if is_surface_mol : normals = array . array ( "f" ) normals . fromfile ( mol_file , n_data ) normals = np . array ( normals ) normals = normals . reshape ( n_mols , 3 ) rotations = ( McellConverter . _get_rotation_euler_angles_for_normals ( normals , input_data . surface_mol_rotation_angle ) ) rotations = rotations . reshape ( 3 * n_mols ) else : rotations = np . zeros_like ( positions ) total_mols = int ( result . n_agents [ time_index ] ) result . unique_ids [ time_index , total_mols : total_mols + n_mols ] = ( np . arange ( n_mols ) + total_mols ) result . types [ time_index ] += n_mols * [ display_type_name ] result . positions [ time_index , total_mols : total_mols + n_mols , : ] = positions result . radii [ time_index , total_mols : total_mols + n_mols ] = ( input_data . meta_data . scale_factor * BLENDER_GEOMETRY_SCALE_FACTOR * ( input_data . display_data [ type_name ] . radius if type_name in input_data . display_data and input_data . display_data [ type_name ] . radius is not None else molecule_info [ type_name ] [ "display" ] [ "scale" ] ) * np . ones ( n_mols ) ) result . rotations [ time_index , total_mols : total_mols + n_mols , : ] = rotations result . n_agents [ time_index ] += n_mols except EOFError : mol_file . close ( ) break return result
Read MCell binary visualization files
code based on cellblender/cellblender_mol_viz.py function mol_viz_file_read
Read MCell binary visualization files code based on cellblender / cellblender_mol_viz . py function mol_viz_file_read
"""
        Read MCell binary visualization files

        code based on cellblender/cellblender_mol_viz.py function mol_viz_file_read
        """ # first 4 bytes must contain value '1' # get type name # get positions and rotations # save to AgentData # MCell binary format has no IDs, so use molecule index
file_name
str
time_index
int
molecule_info
Dict[str, Dict[str, Any]]
input_data
McellData
result
AgentData