simulariumio/medyan/medyan_converter.py
def _get_trajectory_data(input_data: MedyanData) -> AgentData:
        """
        Parse a MEDYAN snapshot.traj output file to get agents
        """
        lines = input_data.snapshot_file.get_contents().split("\n")
        dimensions = MedyanConverter._parse_data_dimensions(lines, input_data)
        result = AgentData.from_dimensions(dimensions)
        time_index = -1
        at_frame_start = True
        parsing_object = False
        uids = {
            "filament": {},
            "linker": {},
            "motor": {},
        }
        last_uid = 0
        tids = {
            "filament": {},
            "linker": {},
            "motor": {},
        }
        last_tid = 0
        object_type = ""
        draw_endpoints = False
        for line in lines:
            if len(line) < 1:
                at_frame_start = True
                continue
            cols = line.split()
            if at_frame_start:
                # start of timestep
                time_index += 1
                agent_index = 0
                result.times[time_index] = float(cols[1])
                result.n_agents[time_index] = int(cols[2]) + int(cols[3]) + int(cols[4])
                at_frame_start = False
            if "FILAMENT" in line or "LINKER" in line or "MOTOR" in line:
                # start of object
                result.viz_types[time_index][agent_index] = VIZ_TYPE.FIBER
                if "FILAMENT" in line:
                    object_type = "filament"
                elif "LINKER" in line:
                    object_type = "linker"
                else:
                    object_type = "motor"
                draw_endpoints = MedyanConverter._draw_endpoints(
                    line, object_type, input_data
                )
                # unique instance ID
                raw_uid = int(cols[1])
                if raw_uid not in uids[object_type]:
                    uids[object_type][raw_uid] = last_uid
                    last_uid += 1 if not draw_endpoints else 3
                result.unique_ids[time_index][agent_index] = uids[object_type][raw_uid]
                # type ID
                raw_tid = int(cols[2])
                if raw_tid not in tids[object_type]:
                    tids[object_type][raw_tid] = last_tid
                    last_tid += 1
                # type name
                result.types[time_index].append(
                    MedyanConverter._get_output_type_name(line, object_type, input_data)
                )
                # radius
                radius = (
                    input_data.display_data[object_type][raw_tid].radius
                    if raw_tid in input_data.display_data[object_type]
                    and input_data.display_data[object_type][raw_tid].radius is not None
                    else 1.0
                )
                result.radii[time_index][agent_index] = (
                    input_data.meta_data.scale_factor * radius
                )
                if object_type == "filament":
                    result.n_subpoints[time_index][agent_index] = int(cols[3])
                else:
                    result.n_subpoints[time_index][agent_index] = 2
                # draw endpoints?
                if draw_endpoints:
                    for i in range(2):
                        result.viz_types[time_index][
                            agent_index + i + 1
                        ] = VIZ_TYPE.DEFAULT
                        result.unique_ids[time_index][agent_index + i + 1] = (
                            uids[object_type][raw_uid] + i + 1
                        )
                        result.types[time_index].append(
                            result.types[time_index][agent_index] + " End"
                        )
                        result.radii[time_index][agent_index + i + 1] = (
                            2 * input_data.meta_data.scale_factor * radius
                        )
                parsing_object = True
            elif parsing_object:
                # object coordinates
                for i in range(len(cols)):
                    subpoint_index = math.floor(i / 3)
                    d = i % 3
                    result.subpoints[time_index][agent_index][subpoint_index][
                        d
                    ] = input_data.meta_data.scale_factor * float(cols[i])
                    if draw_endpoints:
                        result.positions[time_index][agent_index + subpoint_index + 1][
                            d
                        ] = input_data.meta_data.scale_factor * float(cols[i])
                parsing_object = False
                agent_index += 1
                if draw_endpoints:
                    agent_index += 2
                    result.n_agents[time_index] += 2
        result.n_timesteps = time_index + 1
        return result

        Parse a MEDYAN snapshot.traj output file to get agents
        
Parse a MEDYAN snapshot.traj output file to get agents
Parse a MEDYAN snapshot . traj output file to get agents
def _get_trajectory_data(input_data: MedyanData) -> AgentData:
        lines = input_data.snapshot_file.get_contents().split("\n")
        dimensions = MedyanConverter._parse_data_dimensions(lines, input_data)
        result = AgentData.from_dimensions(dimensions)
        time_index = -1
        at_frame_start = True
        parsing_object = False
        uids = {
            "filament": {},
            "linker": {},
            "motor": {},
        }
        last_uid = 0
        tids = {
            "filament": {},
            "linker": {},
            "motor": {},
        }
        last_tid = 0
        object_type = ""
        draw_endpoints = False
        for line in lines:
            if len(line) < 1:
                at_frame_start = True
                continue
            cols = line.split()
            if at_frame_start:
                time_index += 1
                agent_index = 0
                result.times[time_index] = float(cols[1])
                result.n_agents[time_index] = int(cols[2]) + int(cols[3]) + int(cols[4])
                at_frame_start = False
            if "FILAMENT" in line or "LINKER" in line or "MOTOR" in line:
                result.viz_types[time_index][agent_index] = VIZ_TYPE.FIBER
                if "FILAMENT" in line:
                    object_type = "filament"
                elif "LINKER" in line:
                    object_type = "linker"
                else:
                    object_type = "motor"
                draw_endpoints = MedyanConverter._draw_endpoints(
                    line, object_type, input_data
                )
                raw_uid = int(cols[1])
                if raw_uid not in uids[object_type]:
                    uids[object_type][raw_uid] = last_uid
                    last_uid += 1 if not draw_endpoints else 3
                result.unique_ids[time_index][agent_index] = uids[object_type][raw_uid]
                raw_tid = int(cols[2])
                if raw_tid not in tids[object_type]:
                    tids[object_type][raw_tid] = last_tid
                    last_tid += 1
                result.types[time_index].append(
                    MedyanConverter._get_output_type_name(line, object_type, input_data)
                )
                radius = (
                    input_data.display_data[object_type][raw_tid].radius
                    if raw_tid in input_data.display_data[object_type]
                    and input_data.display_data[object_type][raw_tid].radius is not None
                    else 1.0
                )
                result.radii[time_index][agent_index] = (
                    input_data.meta_data.scale_factor * radius
                )
                if object_type == "filament":
                    result.n_subpoints[time_index][agent_index] = int(cols[3])
                else:
                    result.n_subpoints[time_index][agent_index] = 2
                if draw_endpoints:
                    for i in range(2):
                        result.viz_types[time_index][
                            agent_index + i + 1
                        ] = VIZ_TYPE.DEFAULT
                        result.unique_ids[time_index][agent_index + i + 1] = (
                            uids[object_type][raw_uid] + i + 1
                        )
                        result.types[time_index].append(
                            result.types[time_index][agent_index] + " End"
                        )
                        result.radii[time_index][agent_index + i + 1] = (
                            2 * input_data.meta_data.scale_factor * radius
                        )
                parsing_object = True
            elif parsing_object:
                for i in range(len(cols)):
                    subpoint_index = math.floor(i / 3)
                    d = i % 3
                    result.subpoints[time_index][agent_index][subpoint_index][
                        d
                    ] = input_data.meta_data.scale_factor * float(cols[i])
                    if draw_endpoints:
                        result.positions[time_index][agent_index + subpoint_index + 1][
                            d
                        ] = input_data.meta_data.scale_factor * float(cols[i])
                parsing_object = False
                agent_index += 1
                if draw_endpoints:
                    agent_index += 2
                    result.n_agents[time_index] += 2
        result.n_timesteps = time_index + 1
        return result
def _get_trajectory_data ( input_data : MedyanData ) -> AgentData : lines = input_data . snapshot_file . get_contents ( ) . split ( "\n" ) dimensions = MedyanConverter . _parse_data_dimensions ( lines , input_data ) result = AgentData . from_dimensions ( dimensions ) time_index = - 1 at_frame_start = True parsing_object = False uids = { "filament" : { } , "linker" : { } , "motor" : { } , } last_uid = 0 tids = { "filament" : { } , "linker" : { } , "motor" : { } , } last_tid = 0 object_type = "" draw_endpoints = False for line in lines : if len ( line ) < 1 : at_frame_start = True continue cols = line . split ( ) if at_frame_start : time_index += 1 agent_index = 0 result . times [ time_index ] = float ( cols [ 1 ] ) result . n_agents [ time_index ] = int ( cols [ 2 ] ) + int ( cols [ 3 ] ) + int ( cols [ 4 ] ) at_frame_start = False if "FILAMENT" in line or "LINKER" in line or "MOTOR" in line : result . viz_types [ time_index ] [ agent_index ] = VIZ_TYPE . FIBER if "FILAMENT" in line : object_type = "filament" elif "LINKER" in line : object_type = "linker" else : object_type = "motor" draw_endpoints = MedyanConverter . _draw_endpoints ( line , object_type , input_data ) raw_uid = int ( cols [ 1 ] ) if raw_uid not in uids [ object_type ] : uids [ object_type ] [ raw_uid ] = last_uid last_uid += 1 if not draw_endpoints else 3 result . unique_ids [ time_index ] [ agent_index ] = uids [ object_type ] [ raw_uid ] raw_tid = int ( cols [ 2 ] ) if raw_tid not in tids [ object_type ] : tids [ object_type ] [ raw_tid ] = last_tid last_tid += 1 result . types [ time_index ] . append ( MedyanConverter . _get_output_type_name ( line , object_type , input_data ) ) radius = ( input_data . display_data [ object_type ] [ raw_tid ] . radius if raw_tid in input_data . display_data [ object_type ] and input_data . display_data [ object_type ] [ raw_tid ] . radius is not None else 1.0 ) result . radii [ time_index ] [ agent_index ] = ( input_data . meta_data . scale_factor * radius ) if object_type == "filament" : result . n_subpoints [ time_index ] [ agent_index ] = int ( cols [ 3 ] ) else : result . n_subpoints [ time_index ] [ agent_index ] = 2 if draw_endpoints : for i in range ( 2 ) : result . viz_types [ time_index ] [ agent_index + i + 1 ] = VIZ_TYPE . DEFAULT result . unique_ids [ time_index ] [ agent_index + i + 1 ] = ( uids [ object_type ] [ raw_uid ] + i + 1 ) result . types [ time_index ] . append ( result . types [ time_index ] [ agent_index ] + " End" ) result . radii [ time_index ] [ agent_index + i + 1 ] = ( 2 * input_data . meta_data . scale_factor * radius ) parsing_object = True elif parsing_object : for i in range ( len ( cols ) ) : subpoint_index = math . floor ( i / 3 ) d = i % 3 result . subpoints [ time_index ] [ agent_index ] [ subpoint_index ] [ d ] = input_data . meta_data . scale_factor * float ( cols [ i ] ) if draw_endpoints : result . positions [ time_index ] [ agent_index + subpoint_index + 1 ] [ d ] = input_data . meta_data . scale_factor * float ( cols [ i ] ) parsing_object = False agent_index += 1 if draw_endpoints : agent_index += 2 result . n_agents [ time_index ] += 2 result . n_timesteps = time_index + 1 return result
Parse a MEDYAN snapshot.traj output file to get agents
Parse a MEDYAN snapshot . traj output file to get agents
"""
        Parse a MEDYAN snapshot.traj output file to get agents
        """ # start of timestep # start of object # unique instance ID # type ID # type name # radius # draw endpoints? # object coordinates
input_data
MedyanData