From 203ef4ad5d2fbd63a33514031d674ba35e2f092a Mon Sep 17 00:00:00 2001 From: Alli <111383930+ascibisz@users.noreply.github.com> Date: Thu, 10 Nov 2022 15:27:00 -0800 Subject: [PATCH] Merge pull request #119 from simularium/fix/update-trajectory-tests Rewrite Trajectory Converter Tests --- simulariumio/md/md_converter.py | 7 +- simulariumio/readdy/readdy_converter.py | 1 + simulariumio/tests/conftest.py | 230 +- .../converters/test_cytosim_converter.py | 1546 ++-------- .../tests/converters/test_mcell_converter.py | 451 +-- .../tests/converters/test_md_converter.py | 685 +++-- .../tests/converters/test_medyan_converter.py | 1383 +++------ .../converters/test_physicell_converter.py | 2191 +++++--------- .../tests/converters/test_readdy_converter.py | 637 +++-- .../converters/test_smoldyn_converter.py | 847 +++--- .../converters/test_springsalad_converter.py | 926 +++--- .../converters/test_trajectory_converter.py | 2509 +++++++++-------- .../data/cytosim/3_fibers_3_frames/test.txt | 38 + simulariumio/tests/data/medyan/test.traj | 18 + .../tests/data/smoldyn/example_data.txt | 4 + simulariumio/tests/data/springsalad/test.txt | 22 + 16 files changed, 4857 insertions(+), 6638 deletions(-) create mode 100644 simulariumio/tests/data/cytosim/3_fibers_3_frames/test.txt create mode 100644 simulariumio/tests/data/medyan/test.traj create mode 100644 simulariumio/tests/data/smoldyn/example_data.txt create mode 100644 simulariumio/tests/data/springsalad/test.txt diff --git a/simulariumio/md/md_converter.py b/simulariumio/md/md_converter.py index 4623bc8a..fec67d53 100644 --- a/simulariumio/md/md_converter.py +++ b/simulariumio/md/md_converter.py @@ -12,7 +12,7 @@ from ..trajectory_converter import TrajectoryConverter from ..data_objects import TrajectoryData, AgentData, DimensionData, DisplayData -from ..constants import JMOL_COLORS +from ..constants import DISPLAY_TYPE, JMOL_COLORS from .md_data import MdData ############################################################################### @@ -115,7 +115,10 @@ def _get_display_data_for_type( display_data = copy.copy(input_data.display_data[element_type]) display_data.name = type_name else: - display_data = DisplayData(name=type_name) + display_data = DisplayData( + name=type_name, + display_type=DISPLAY_TYPE.SPHERE + ) if display_data.color: return display_data display_data.color = color diff --git a/simulariumio/readdy/readdy_converter.py b/simulariumio/readdy/readdy_converter.py index 6788433d..8a8b2131 100644 --- a/simulariumio/readdy/readdy_converter.py +++ b/simulariumio/readdy/readdy_converter.py @@ -89,6 +89,7 @@ def _get_agent_data( agent_index ] result.types[time_index].append(display_data.name) + result.display_data[display_data.name] = display_data result.positions[time_index][new_agent_index] = ( input_data.meta_data.scale_factor * positions[time_index][agent_index] diff --git a/simulariumio/tests/conftest.py b/simulariumio/tests/conftest.py index e5e7877c..e3c60f53 100644 --- a/simulariumio/tests/conftest.py +++ b/simulariumio/tests/conftest.py @@ -76,6 +76,53 @@ def default_agents_type_mapping() -> Dict[str, Any]: } +def minimal_custom_type_mappings() -> Dict[str, Any]: + return { + "0": { + "name": "C", + "geometry": { + "displayType": "SPHERE", + }, + }, + "1": { + "name": "U", + "geometry": { + "displayType": "SPHERE", + }, + }, + "2": { + "name": "L", + "geometry": { + "displayType": "SPHERE", + }, + }, + "3": { + "name": "S", + "geometry": { + "displayType": "SPHERE", + }, + }, + "4": { + "name": "O", + "geometry": { + "displayType": "SPHERE", + }, + }, + "5": { + "name": "Y", + "geometry": { + "displayType": "SPHERE", + }, + }, + "6": { + "name": "W", + "geometry": { + "displayType": "SPHERE", + }, + }, + } + + def three_default_agents() -> TrajectoryData: return TrajectoryData( meta_data=MetaData( @@ -173,6 +220,75 @@ def three_default_agents() -> TrajectoryData: ) +def minimal_custom_data() -> TrajectoryData: + return TrajectoryData( + meta_data=MetaData(), + agent_data=AgentData( + times=0.5 * np.array(list(range(3))), + n_agents=np.array(3 * [3]), + viz_types=np.array(3 * [3 * [1000.0]]), + unique_ids=np.array([[0.0, 1.0, 2.0], [0.0, 1.0, 2.0], [0.0, 1.0, 2.0]]), + types=[["C", "U", "C"], ["U", "L", "S"], ["O", "Y", "W"]], + display_data={ + "C": DisplayData( + name="C", + display_type=DISPLAY_TYPE.SPHERE, + ), + "W": DisplayData( + name="W", + display_type=DISPLAY_TYPE.SPHERE, + ), + "S": DisplayData( + name="S", + display_type=DISPLAY_TYPE.SPHERE, + ), + "Y": DisplayData( + name="Y", + display_type=DISPLAY_TYPE.SPHERE, + ), + "L": DisplayData( + name="L", + display_type=DISPLAY_TYPE.SPHERE, + ), + "U": DisplayData( + name="U", + display_type=DISPLAY_TYPE.SPHERE, + ), + "O": DisplayData( + name="O", + display_type=DISPLAY_TYPE.SPHERE, + ), + }, + positions=np.array( + [ + [ + [4.89610492, -29.81564851, 40.77254057], + [43.43048197, 48.00424379, -36.02881338], + [29.84924588, -38.02769707, 2.46644825], + ], + [ + [-43.37181102, -13.41127423, -17.31316927], + [9.62132397, 13.4774314, -20.30846039], + [41.41039848, -45.85543786, 49.06208485], + ], + [ + [-24.91450698, -44.79360525, 13.32273796], + [4.10861266, 43.86451151, 21.93697483], + [-7.16740679, -13.06491594, 44.97026158], + ], + ] + ), + radii=np.array( + [ + [8.38656327, 6.18568039, 6.61459206], + [5.26366739, 6.69209780, 9.88033853], + [8.91022619, 9.01379396, 8.39880154], + ] + ), + ), + ) + + def test_scatter_plot() -> ScatterPlotData: return ScatterPlotData( title="Test Scatterplot 1", @@ -286,6 +402,47 @@ def full_default_buffer() -> AgentData: ) +def fiber_agents_type_mapping() -> Dict[str, Any]: + return { + "0": { + "name": "H", + "geometry": { + "displayType": "FIBER", + }, + }, + "1": { + "name": "A", + "geometry": { + "displayType": "FIBER", + }, + }, + "2": { + "name": "C", + "geometry": { + "displayType": "FIBER", + }, + }, + "3": { + "name": "L", + "geometry": { + "displayType": "FIBER", + }, + }, + "4": { + "name": "D", + "geometry": { + "displayType": "FIBER", + }, + }, + "5": { + "name": "K", + "geometry": { + "displayType": "FIBER", + }, + }, + } + + def fiber_agents() -> TrajectoryData: return TrajectoryData( meta_data=MetaData( @@ -474,6 +631,77 @@ def fiber_agents() -> TrajectoryData: ) +def mixed_agents_type_mapping() -> Dict[str, Any]: + return { + "0": { + "name": "H", + "geometry": { + "displayType": "SPHERE", + }, + }, + "1": { + "name": "A", + "geometry": { + "displayType": "FIBER", + }, + }, + "2": { + "name": "C", + "geometry": { + "displayType": "FIBER", + }, + }, + "3": { + "name": "X", + "geometry": { + "displayType": "SPHERE", + }, + }, + "4": { + "name": "J", + "geometry": { + "displayType": "FIBER", + }, + }, + "5": { + "name": "L", + "geometry": { + "displayType": "FIBER", + }, + }, + "6": { + "name": "D", + "geometry": { + "displayType": "SPHERE", + }, + }, + "7": { + "name": "U", + "geometry": { + "displayType": "FIBER", + }, + }, + "8": { + "name": "E", + "geometry": { + "displayType": "SPHERE", + }, + }, + "9": { + "name": "Q", + "geometry": { + "displayType": "SPHERE", + }, + }, + "10": { + "name": "K", + "geometry": { + "displayType": "FIBER", + }, + }, + } + + def mixed_agents() -> TrajectoryData: return TrajectoryData( meta_data=MetaData( @@ -818,7 +1046,7 @@ def mixed_agents() -> TrajectoryData: ), }, ), - time_units=UnitData("s"), + time_units=UnitData("s", 2.0), spatial_units=UnitData("um"), plots=["plot data goes here"], ) diff --git a/simulariumio/tests/converters/test_cytosim_converter.py b/simulariumio/tests/converters/test_cytosim_converter.py index 7e95b9f2..3d9ec105 100644 --- a/simulariumio/tests/converters/test_cytosim_converter.py +++ b/simulariumio/tests/converters/test_cytosim_converter.py @@ -12,1265 +12,329 @@ ) from simulariumio import MetaData, DisplayData, InputFileData from simulariumio.constants import ( - DEFAULT_CAMERA_SETTINGS, - CURRENT_VERSION, DISPLAY_TYPE, + DEFAULT_BOX_SIZE, + VIZ_TYPE, ) +data = CytosimData( + object_info={ + "fibers": CytosimObjectInfo( + cytosim_file=InputFileData( + file_path=( + "simulariumio/tests/data/cytosim/3_fibers_3_frames/test.txt" + ), + ), + ) + }, +) +converter = CytosimConverter(data) +results = JsonWriter.format_trajectory_data(converter._data) + +# test box data default @pytest.mark.parametrize( - "trajectory, expected_data", + "box_size, expected_box_size", [ - # 3 fiber agents ( - CytosimData( - meta_data=MetaData( - box_size=np.array([0.5, 0.5, 0.5]), - scale_factor=1e3, - ), - object_info={ - "fibers": CytosimObjectInfo( - cytosim_file=InputFileData( - file_path=( - "simulariumio/tests/data/cytosim" - "/3_fibers_3_frames/fiber_points.txt" - ), - ), - display_data={ - 0: DisplayData( - name="fiber", - radius=0.001, - display_type=DISPLAY_TYPE.FIBER, - color="#d71f5f", - ) - }, - ) - }, - ), + results["trajectoryInfo"]["size"], { - "trajectoryInfo": { - "version": CURRENT_VERSION.TRAJECTORY_INFO, - "timeUnits": { - "magnitude": 1.0, - "name": "s", - }, - "timeStepSize": 0.1, - "totalSteps": 3, - "spatialUnits": { - "magnitude": 1.0, - "name": "nm", - }, - "size": {"x": 500.0, "y": 500.0, "z": 500.0}, - "cameraDefault": { - "position": { - "x": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[2], - }, - "lookAtPosition": { - "x": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[2], - }, - "upVector": { - "x": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[0], - "y": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[1], - "z": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[2], - }, - "fovDegrees": DEFAULT_CAMERA_SETTINGS.FOV_DEGREES, - }, - "typeMapping": { - "0": { - "name": "fiber", - "geometry": { - "displayType": "FIBER", - "color": "#d71f5f", - }, - }, + "x": DEFAULT_BOX_SIZE[0], + "y": DEFAULT_BOX_SIZE[1], + "z": DEFAULT_BOX_SIZE[2], + }, + ) + ], +) +def test_box_size_default(box_size, expected_box_size): + assert box_size == expected_box_size + + +# test type mapping default +@pytest.mark.parametrize( + "typeMapping, expected_typeMapping", + [ + ( + results["trajectoryInfo"]["typeMapping"], + { + "0": { + "name": "fiber0", + "geometry": { + "displayType": "FIBER", }, }, - "spatialData": { - "version": CURRENT_VERSION.SPATIAL_DATA, - "msgType": 1, - "bundleStart": 0, - "bundleSize": 3, - "bundleData": [ - { - "frameNumber": 0, - "time": 0.1, - "data": [ - 1001.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 9.0, - -3.70929, - 110.164, - -400.052, - -009.70537, - 110.184, - -391.947, - -15.7378, - 110.304, - -383.87, - 1001.0, - 2.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 18.0, - 39.440000000000005, - -60.4351, - -344.994, - 37.8824, - -50.56, - -347.361, - 36.3195, - -40.6802, - -349.704, - 34.7773, - -30.804000000000002, - -352.077, - 33.265, - -20.9349, - -354.497, - 31.8441, - -11.0556, - -356.932, - 1001.0, - 3.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 12.0, - 42.215700000000005, - -93.7993, - -349.962, - 40.2307, - -101.867, - -346.47499999999997, - 38.2648, - -109.90700000000001, - -342.916, - 36.3465, - -117.922, - -339.274, - ], - }, - { - "frameNumber": 1, - "time": 0.2, - "data": [ - 1001.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 9.0, - -5.69782, - 129.971, - -393.00800000000004, - -15.290700000000001, - 127.437, - -394.796, - -24.8686, - 124.766, - -396.463, - 1001.0, - 2.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 18.0, - 19.0975, - -44.6282, - -345.032, - 028.7449, - -41.2174, - -345.948, - 38.4093, - -37.8622, - -346.891, - 48.0874, - -34.5692, - -347.90900000000005, - 57.7825, - -31.335799999999995, - -348.95599999999996, - 67.48859999999999, - -28.145300000000002, - -350.03299999999996, - 1001.0, - 3.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 12.0, - -2.25528, - -76.97500000000001, - -390.275, - 2.86711, - -71.30789999999999, - -385.498, - 7.987640000000001, - -65.6548, - -380.702, - 13.1339, - -59.9998, - -375.936, - ], - }, - { - "frameNumber": 2, - "time": 0.3, - "data": [ - 1001.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 9.0, - 8.850850000000001, - 142.58399999999997, - -381.975, - -0.66752, - 141.898, - -378.722, - -10.1991, - 141.17499999999998, - -375.517, - 1001.0, - 2.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 18.0, - -53.0708, - -112.578, - -323.72499999999997, - -48.829299999999996, - -106.16799999999999, - -330.54200000000003, - -44.5379, - -99.7703, - -337.339, - -40.219199999999994, - -93.4137, - -344.157, - -35.9216, - -87.07, - -351.00100000000003, - -31.5842, - -80.7395, - -357.831, - 1001.0, - 3.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 12.0, - 33.213300000000004, - -102.894, - -367.733, - 26.529799999999998, - -98.4461, - -363.644, - 19.8645, - -93.94890000000001, - -359.57800000000003, - 13.2555, - -89.3484, - -355.537, - ], - }, - ], - }, - "plotData": {"version": CURRENT_VERSION.PLOT_DATA, "data": []}, }, - ), - # aster_pull3D example with couples, actin fibers, and solids added + ) + ], +) +def test_typeMapping_default(typeMapping, expected_typeMapping): + assert expected_typeMapping == typeMapping + + +# xyz dimensions represented as array +box_x = 0.5 +box_y = 0.3 +box_z = 0.4 +scale_factor = 1000 +data_with_metadata = CytosimData( + meta_data=MetaData( + box_size=np.array([box_x, box_y, box_z]), + scale_factor=scale_factor, + ), + object_info={ + "fibers": CytosimObjectInfo( + cytosim_file=InputFileData( + file_path=( + "simulariumio/tests/data/cytosim/3_fibers_3_frames/test.txt" + ), + ), + ) + }, +) +converter_meta_data = CytosimConverter(data_with_metadata) +results_meta_data = JsonWriter.format_trajectory_data(converter_meta_data._data) + + +# test box data provided +@pytest.mark.parametrize( + "box_size, expected_box_size", + [ ( - CytosimData( - meta_data=MetaData( - box_size=np.array([2.0, 2.0, 2.0]), - scale_factor=100.0, + results_meta_data["trajectoryInfo"]["size"], + { + "x": box_x * scale_factor, + "y": box_y * scale_factor, + "z": box_z * scale_factor, + }, + ) + ], +) +def test_box_size_provided(box_size, expected_box_size): + assert box_size == expected_box_size + + +name_0 = "fiber" +radius_0 = 0.001 +color_0 = "#d71f5f" +data_with_display_data = CytosimData( + meta_data=MetaData( + box_size=np.array([box_x, box_y, box_z]), + scale_factor=scale_factor, + ), + object_info={ + "fibers": CytosimObjectInfo( + cytosim_file=InputFileData( + file_path=( + "simulariumio/tests/data/cytosim/3_fibers_3_frames/test.txt" ), - object_info={ - "fibers": CytosimObjectInfo( - cytosim_file=InputFileData( - file_path=( - "simulariumio/tests/data/cytosim/aster_pull3D" - "_couples_actin_solid_3_frames/fiber_points.txt" - ), - ), - display_data={ - 2: DisplayData( - name="actin", - display_type=DISPLAY_TYPE.FIBER, - radius=0.01, - color="#ffc100", - ), - }, - ), - "solids": CytosimObjectInfo( - cytosim_file=InputFileData( - file_path=( - "simulariumio/tests/data/cytosim/" - "aster_pull3D_couples_actin_solid_3_frames/solids.txt" - ), - ), - display_data={ - 1: DisplayData( - name="aster", - display_type=DISPLAY_TYPE.SPHERE, - ), - 2: DisplayData( - name="vesicle", - display_type=DISPLAY_TYPE.SPHERE, - radius=0.1, - ), - }, - ), - "singles": CytosimObjectInfo( - cytosim_file=InputFileData( - file_path=( - "simulariumio/tests/data/cytosim/" - "aster_pull3D_couples_actin_solid_3_frames/singles.txt" - ), - ), - display_data={ - 1: DisplayData( - name="dynein", - display_type=DISPLAY_TYPE.SPHERE, - radius=0.01, - ), - 2: DisplayData( - name="kinesin", - radius=0.01, - display_type=DISPLAY_TYPE.PDB, - url="https://files.rcsb.org/download/3KIN.pdb", - color="#0080ff", - ), - }, - ), - "couples": CytosimObjectInfo( - cytosim_file=InputFileData( - file_path=( - "simulariumio/tests/data/cytosim/" - "aster_pull3D_couples_actin_solid_3_frames/couples.txt" - ), - ), - display_data={ - 1: DisplayData( - name="motor complex", - display_type=DISPLAY_TYPE.SPHERE, - radius=0.02, - ) - }, - position_indices=[3, 4, 5], - ), - }, ), + display_data={ + 0: DisplayData( + name=name_0, + radius=radius_0, + display_type=DISPLAY_TYPE.FIBER, + color=color_0, + ) + }, + ) + }, +) +converter_display_data = CytosimConverter(data_with_display_data) +results_display_data = JsonWriter.format_trajectory_data(converter_display_data._data) + + +# test type mapping provided +@pytest.mark.parametrize( + "typeMapping, expected_typeMapping", + [ + ( + results_display_data["trajectoryInfo"]["typeMapping"], { - "trajectoryInfo": { - "version": CURRENT_VERSION.TRAJECTORY_INFO, - "timeUnits": { - "magnitude": 1.0, - "name": "s", - }, - "timeStepSize": 0.05, - "totalSteps": 3, - "spatialUnits": { - "magnitude": 10.0, - "name": "nm", - }, - "size": {"x": 200.0, "y": 200.0, "z": 200.0}, - "cameraDefault": { - "position": { - "x": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[2], - }, - "lookAtPosition": { - "x": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[2], - }, - "upVector": { - "x": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[0], - "y": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[1], - "z": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[2], - }, - "fovDegrees": DEFAULT_CAMERA_SETTINGS.FOV_DEGREES, - }, - "typeMapping": { - "0": { - "name": "fiber1", - "geometry": { - "displayType": "FIBER", - }, - }, - "1": { - "name": "actin", - "geometry": { - "displayType": "FIBER", - "color": "#ffc100", - }, - }, - "2": { - "name": "aster", - "geometry": { - "displayType": "SPHERE", - }, - }, - "3": { - "name": "vesicle", - "geometry": { - "displayType": "SPHERE", - }, - }, - "4": { - "name": "kinesin", - "geometry": { - "displayType": "PDB", - "url": "https://files.rcsb.org/download/3KIN.pdb", - "color": "#0080ff", - }, - }, - "5": { - "name": "dynein", - "geometry": { - "displayType": "SPHERE", - }, - }, - "6": { - "name": "motor complex", - "geometry": { - "displayType": "SPHERE", - }, - }, + "0": { + "name": name_0, + "geometry": { + "displayType": "FIBER", + "color": color_0, }, }, - "spatialData": { - "version": CURRENT_VERSION.SPATIAL_DATA, - "msgType": 1, - "bundleStart": 0, - "bundleSize": 3, - "bundleData": [ - { - "frameNumber": 0, - "time": 0.0, - "data": [ - 1001.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 100.0, - 15.0, - 36.93, - 36.80, - 16.78, - 30.55, - 43.87, - 19.84, - 24.169999999999998, - 50.93, - 22.900000000000002, - 17.78, - 57.99999999999999, - 25.95, - 11.40, - 65.07, - 29.01, - 1001.0, - 2.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 100.0, - 12.0, - 36.93, - 36.80, - 16.78, - 37.20, - 27.11, - 19.220000000000002, - 37.46, - 17.41, - 21.66, - 37.730000000000004, - 7.720000000000001, - 24.099999999999998, - 1001.0, - 3.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 100.0, - 15.0, - 36.93, - 36.80, - 16.78, - 40.71, - 30.86, - 23.880000000000003, - 44.50, - 24.92, - 30.98, - 48.28, - 18.970000000000002, - 38.07, - 52.07000000000001, - 13.03, - 45.17, - 1001.0, - 13.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 12.0, - 46.08, - -104.85, - -2.10, - 45.67, - -104.54, - -1.90, - 45.26, - -104.23, - -1.7000000000000002, - 44.85, - -103.91999999999999, - -1.50, - 1001.0, - 14.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 9.0, - 53.690000000000005, - 79.28, - -3.09, - 53.60, - 78.83, - -3.39, - 53.50, - 78.39, - -3.6999999999999997, - 1000.0, - 4.0, - 2.0, - 36.93, - 36.80, - 16.78, - 0.0, - 0.0, - 0.0, - 100.0, - 0.0, - 1000.0, - 5.0, - 3.0, - 78.60000000000001, - -28.799999999999997, - 18.04, - 0.0, - 0.0, - 0.0, - 10.0, - 0.0, - 1000.0, - 6.0, - 3.0, - -55.089999999999996, - -33.42, - -61.85000000000001, - 0.0, - 0.0, - 0.0, - 10.0, - 0.0, - 1000.0, - 7.0, - 4.0, - 20.61, - -39.910000000000004, - 89.35, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 8.0, - 4.0, - 92.82000000000001, - 32.269999999999996, - 18.55, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 9.0, - 4.0, - 37.56, - -80.46, - -46.00, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 101.0, - 5.0, - -74.11999999999999, - 30.31, - -59.89, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 102.0, - 5.0, - -61.739999999999995, - -55.269999999999996, - -55.98, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 103.0, - 5.0, - -19.37, - -9.379999999999999, - 97.66, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 10.0, - 6.0, - 32.629999999999995, - 38.550000000000004, - 57.120000000000005, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1000.0, - 11.0, - 6.0, - 4.42, - 20.200000000000003, - -62.88, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1000.0, - 12.0, - 6.0, - -73.80, - -25.20, - -43.89, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - ], - }, - { - "frameNumber": 1, - "time": 0.05, - "data": [ - 1001.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 100.0, - 18.0, - 44.55, - 33.97, - 8.86, - 36.63, - 38.269999999999996, - 4.51, - 28.96, - 43.28, - 0.50, - 21.83, - 49.61, - -2.52, - 16.00, - 57.66, - -3.58, - 12.85, - 66.92, - -1.47, - 1001.0, - 2.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 100.0, - 9.0, - 44.230000000000004, - 33.56, - 9.04, - 42.02, - 24.04, - 6.92, - 40.52, - 14.330000000000002, - 5.050000000000001, - 1001.0, - 3.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 100.0, - 15.0, - 44.22, - 33.18, - 8.89, - 40.660000000000004, - 24.060000000000002, - 10.94, - 37.22, - 15.10, - 13.750000000000002, - 34.00, - 6.74, - 18.20, - 31.369999999999997, - -0.06999999999999999, - 25.03, - 1001.0, - 13.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 15.0, - 51.480000000000004, - -85.75, - 5.3100000000000005, - 51.00, - -85.78, - 5.59, - 50.529999999999994, - -85.82, - 5.87, - 50.06, - -85.86, - 6.15, - 49.58, - -85.90, - 6.419999999999999, - 1001.0, - 14.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 9.0, - 47.00, - 81.69999999999999, - -9.139999999999999, - 47.099999999999994, - 81.22, - -9.39, - 47.21, - 80.74, - -9.64, - 1000.0, - 4.0, - 2.0, - 44.86, - 34.239999999999995, - 9.36, - 0.0, - 0.0, - 0.0, - 100.0, - 0.0, - 1000.0, - 5.0, - 3.0, - 77.18, - -36.65, - 21.90, - 0.0, - 0.0, - 0.0, - 10.0, - 0.0, - 1000.0, - 6.0, - 3.0, - -59.67, - -29.659999999999997, - -65.88000000000001, - 0.0, - 0.0, - 0.0, - 10.0, - 0.0, - 1000.0, - 7.0, - 4.0, - 20.61, - -39.910000000000004, - 89.35, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 8.0, - 4.0, - 92.82000000000001, - 32.269999999999996, - 18.55, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 9.0, - 4.0, - 37.56, - -80.46, - -46.00, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 101.0, - 5.0, - -74.11999999999999, - 30.31, - -59.89, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 102.0, - 5.0, - -61.739999999999995, - -55.269999999999996, - -55.98, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 103.0, - 5.0, - -19.37, - -9.379999999999999, - 97.66, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 10.0, - 6.0, - 33.96, - 13.309999999999999, - 50.29, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1000.0, - 11.0, - 6.0, - 19.189999999999998, - 17.69, - -76.94, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1000.0, - 12.0, - 6.0, - -72.52, - -21.90, - -43.59, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - ], - }, - { - "frameNumber": 2, - "time": 0.1, - "data": [ - 1001.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 100.0, - 15.0, - 44.55, - 33.97, - 8.86, - 36.63, - 38.269999999999996, - 4.51, - 28.96, - 43.28, - 0.50, - 21.83, - 49.61, - -2.52, - 16.00, - 57.66, - -3.58, - 1001.0, - 2.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 100.0, - 6.0, - 44.230000000000004, - 33.56, - 9.04, - 42.02, - 24.04, - 6.92, - 1001.0, - 3.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 100.0, - 12.0, - 44.22, - 33.18, - 8.89, - 40.660000000000004, - 24.060000000000002, - 10.94, - 37.22, - 15.10, - 13.750000000000002, - 34.00, - 6.74, - 18.20, - 1001.0, - 13.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - 51.480000000000004, - -85.75, - 5.3100000000000005, - 51.00, - -85.78, - 5.59, - 1001.0, - 14.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 12.0, - 47.00, - 81.69999999999999, - -9.139999999999999, - 47.099999999999994, - 81.22, - -9.39, - 47.21, - 80.74, - -9.64, - 47.31, - 80.25999999999999, - -9.89, - 1000.0, - 4.0, - 2.0, - 44.86, - 34.239999999999995, - 9.36, - 0.0, - 0.0, - 0.0, - 100.0, - 0.0, - 1000.0, - 5.0, - 3.0, - 77.18, - -36.65, - 21.90, - 0.0, - 0.0, - 0.0, - 10.0, - 0.0, - 1000.0, - 6.0, - 3.0, - -59.67, - -29.659999999999997, - -65.88000000000001, - 0.0, - 0.0, - 0.0, - 10.0, - 0.0, - 1000.0, - 7.0, - 4.0, - 20.61, - -39.910000000000004, - 89.35, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 8.0, - 4.0, - 92.82000000000001, - 32.269999999999996, - 18.55, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 9.0, - 4.0, - 37.56, - -80.46, - -46.00, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 101.0, - 5.0, - -74.11999999999999, - 30.31, - -59.89, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 102.0, - 5.0, - -61.739999999999995, - -55.269999999999996, - -55.98, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 103.0, - 5.0, - -19.37, - -9.379999999999999, - 97.66, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 10.0, - 6.0, - 33.96, - 13.309999999999999, - 50.29, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1000.0, - 11.0, - 6.0, - 19.189999999999998, - 17.69, - -76.94, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1000.0, - 12.0, - 6.0, - -72.52, - -21.90, - -43.59, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - ], - }, - ], - }, - "plotData": {"version": CURRENT_VERSION.PLOT_DATA, "data": []}, }, + ) + ], +) +def test_typeMapping_provided(typeMapping, expected_typeMapping): + assert expected_typeMapping == typeMapping + + +@pytest.mark.parametrize( + "bundleData, expected_bundleData", + [ + ( + results_display_data["spatialData"]["bundleData"][0], + [ + VIZ_TYPE.FIBER, # agent 1 + 1.0, # id + 0.0, # type + 0.0, # x + 0.0, # y + 0.0, # z + 0.0, # x rotation + 0.0, # y rotation + 0.0, # z rotation + radius_0 * scale_factor, # radius + 9.0, # subpoints + -3.70929, + 110.164, + -400.052, + -009.70537, + 110.184, + -391.947, + -15.7378, + 110.304, + -383.87, + VIZ_TYPE.FIBER, # agent 2 + 2.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + radius_0 * scale_factor, + 18.0, + 39.440000000000005, + -60.4351, + -344.994, + 37.8824, + -50.56, + -347.361, + 36.3195, + -40.6802, + -349.704, + 34.7773, + -30.804000000000002, + -352.077, + 33.265, + -20.9349, + -354.497, + 31.8441, + -11.0556, + -356.932, + ], + ), + ( + results_display_data["spatialData"]["bundleData"][1], + [ + VIZ_TYPE.FIBER, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + radius_0 * scale_factor, + 9.0, + -5.69782, + 129.971, + -393.00800000000004, + -15.290700000000001, + 127.437, + -394.796, + -24.8686, + 124.766, + -396.463, + VIZ_TYPE.FIBER, + 2.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + radius_0 * scale_factor, + 18.0, + 19.0975, + -44.6282, + -345.032, + 028.7449, + -41.2174, + -345.948, + 38.4093, + -37.8622, + -346.891, + 48.0874, + -34.5692, + -347.90900000000005, + 57.7825, + -31.335799999999995, + -348.95599999999996, + 67.48859999999999, + -28.145300000000002, + -350.03299999999996, + ], ), ], ) -def test_cytosim_converter(trajectory, expected_data): - converter = CytosimConverter(trajectory) - buffer_data = JsonWriter.format_trajectory_data(converter._data) - assert expected_data == buffer_data - assert JsonWriter._check_agent_ids_are_unique_per_frame(buffer_data) +def test_bundleData(bundleData, expected_bundleData): + assert expected_bundleData == bundleData["data"] + + +def test_agent_ids(): + assert JsonWriter._check_agent_ids_are_unique_per_frame(results_display_data) + + +# test data extraction from aster_pull3D example +aster_pull3D_objects = CytosimData( + object_info={ + "fibers": CytosimObjectInfo( + cytosim_file=InputFileData( + file_path=( + "simulariumio/tests/data/cytosim/aster_pull3D" + "_couples_actin_solid_3_frames/fiber_points.txt" + ), + ), + ), + "solids": CytosimObjectInfo( + cytosim_file=InputFileData( + file_path=( + "simulariumio/tests/data/cytosim/" + "aster_pull3D_couples_actin_solid_3_frames/solids.txt" + ), + ), + ), + "singles": CytosimObjectInfo( + cytosim_file=InputFileData( + file_path=( + "simulariumio/tests/data/cytosim/" + "aster_pull3D_couples_actin_solid_3_frames/singles.txt" + ), + ), + ), + "couples": CytosimObjectInfo( + cytosim_file=InputFileData( + file_path=( + "simulariumio/tests/data/cytosim/" + "aster_pull3D_couples_actin_solid_3_frames/couples.txt" + ), + ), + ), + }, +) +# load the data from Cytosim output .txt files +cytosim_data = {} +for object_type in aster_pull3D_objects.object_info: + cytosim_data[object_type] = ( + aster_pull3D_objects.object_info[object_type] + .cytosim_file.get_contents() + .split("\n") + ) + + +def test_parse_dimensions(): + dimension_data = CytosimConverter._parse_dimensions(cytosim_data) + assert dimension_data.total_steps == 3 + assert dimension_data.max_agents == 19 + assert dimension_data.max_subpoints == 18 diff --git a/simulariumio/tests/converters/test_mcell_converter.py b/simulariumio/tests/converters/test_mcell_converter.py index ebe0f8c2..274ea58b 100644 --- a/simulariumio/tests/converters/test_mcell_converter.py +++ b/simulariumio/tests/converters/test_mcell_converter.py @@ -9,226 +9,265 @@ from simulariumio import DisplayData, MetaData, JsonWriter from simulariumio.constants import ( DEFAULT_CAMERA_SETTINGS, - CURRENT_VERSION, DISPLAY_TYPE, + VIZ_TYPE, ) +data = McellData( + path_to_data_model_json="simulariumio/tests/data/mcell/" + "organelle_model_viz_output/Scene.data_model.00.json", + path_to_binary_files="simulariumio/tests/data/mcell/" "organelle_model_viz_output", +) +converter = McellConverter(data) +results = JsonWriter.format_trajectory_data(converter._data) + @pytest.mark.parametrize( - "trajectory, expected_data", + "typeMapping, expected_typeMapping", [ - # truncated data from organelle model example ( - McellData( - path_to_data_model_json="simulariumio/tests/data/mcell/" - "organelle_model_viz_output/Scene.data_model.00.json", - path_to_binary_files="simulariumio/tests/data/mcell/" - "organelle_model_viz_output", - meta_data=MetaData(box_size=np.array([50.0, 50.0, 50.0])), - display_data={ - "a": DisplayData( - name="Kinesin", - radius=0.03, - display_type=DISPLAY_TYPE.PDB, - url="https://files.rcsb.org/download/3KIN.pdb", - color="#0080ff", - ), - "t2": DisplayData( - name="Transporter", - display_type=DISPLAY_TYPE.SPHERE, - color="#ff1493", - ), - }, - surface_mol_rotation_angle=0.0, - ), + results["trajectoryInfo"]["typeMapping"], { - "trajectoryInfo": { - "version": CURRENT_VERSION.TRAJECTORY_INFO, - "timeUnits": { - "magnitude": 1.0, - "name": "µs", + "0": { + "name": "b", + "geometry": { + "displayType": "SPHERE", }, - "timeStepSize": 1.0, - "totalSteps": 3, - "spatialUnits": { - "magnitude": 1.0, - "name": "µm", - }, - "size": {"x": 50.0, "y": 50.0, "z": 50.0}, - "cameraDefault": { - "position": { - "x": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[2], - }, - "lookAtPosition": { - "x": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[2], - }, - "upVector": { - "x": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[0], - "y": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[1], - "z": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[2], - }, - "fovDegrees": DEFAULT_CAMERA_SETTINGS.FOV_DEGREES, + }, + "1": { + "name": "t2", + "geometry": { + "displayType": "SPHERE", }, - "typeMapping": { - "0": { - "name": "b", - "geometry": { - "displayType": "SPHERE", - }, - }, - "1": { - "name": "Transporter", - "geometry": { - "displayType": "SPHERE", - "color": "#ff1493", - }, - }, - "2": { - "name": "Kinesin", - "geometry": { - "displayType": "PDB", - "url": "https://files.rcsb.org/download/3KIN.pdb", - "color": "#0080ff", - }, - }, + }, + "2": { + "name": "a", + "geometry": { + "displayType": "SPHERE", }, }, - "spatialData": { - "version": CURRENT_VERSION.SPATIAL_DATA, - "msgType": 1, - "bundleStart": 0, - "bundleSize": 3, - "bundleData": [ - { - "frameNumber": 0, - "time": 0.0, - "data": [ - 1000.0, - 0.0, - 0.0, - 0.12416012585163116, - -0.1974048614501953, - -0.10042950510978699, - 0.0, - 0.0, - 0.0, - 0.005, - 0.0, - 1000.0, - 1.0, - 1.0, - -0.027653440833091736, - 0.1265464723110199, - -0.07352104783058167, - -160.8765121025542, - 0.0, - -9.231996800714258, - 0.005, - 0.0, - 1000.0, - 2.0, - 2.0, - 0.3647538423538208, - 0.1595117300748825, - 0.3979622721672058, - 0.0, - 0.0, - 0.0, - 0.00015, - 0.0, - ], - }, - { - "frameNumber": 1, - "time": 1.0, - "data": [ - 1000.0, - 0.0, - 0.0, - 0.10336990654468536, - -0.20304752886295319, - -0.08513453602790833, - 0.0, - 0.0, - 0.0, - 0.005, - 0.0, - 1000.0, - 1.0, - 1.0, - -0.0269027017056942, - 0.12665313482284546, - -0.07417202740907669, - -160.8765121025542, - 0.0, - -9.231996800714258, - 0.005, - 0.0, - 1000.0, - 2.0, - 2.0, - 0.38411179184913635, - 0.17711672186851501, - 0.4012693464756012, - 0.0, - 0.0, - 0.0, - 0.00015, - 0.0, - ], - }, - { - "frameNumber": 2, - "time": 2.0, - "data": [ - 1000.0, - 0.0, - 0.0, - 0.11451153457164764, - -0.1880205273628235, - -0.08175600320100784, - 0.0, - 0.0, - 0.0, - 0.005, - 0.0, - 1000.0, - 1.0, - 1.0, - -0.024035021662712097, - 0.12565766274929047, - -0.07266511768102646, - -160.8765121025542, - 0.0, - -9.231996800714258, - 0.005, - 0.0, - 1000.0, - 2.0, - 2.0, - 0.39510709047317505, - 0.17876243591308594, - 0.3935079276561737, - 0.0, - 0.0, - 0.0, - 0.00015, - 0.0, - ], - }, - ], + }, + ) + ], +) +def test_typeMapping_default(typeMapping, expected_typeMapping): + assert expected_typeMapping == typeMapping + + +@pytest.mark.parametrize( + "camera_settings, expected_camera_settings", + [ + ( + results["trajectoryInfo"]["cameraDefault"], + { + "position": { + "x": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[0], + "y": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[1], + "z": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[2], + }, + "lookAtPosition": { + "x": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[0], + "y": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[1], + "z": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[2], + }, + "upVector": { + "x": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[0], + "y": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[1], + "z": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[2], }, - "plotData": {"version": CURRENT_VERSION.PLOT_DATA, "data": []}, + "fovDegrees": DEFAULT_CAMERA_SETTINGS.FOV_DEGREES, }, + ) + ], +) +def test_camera_setting_default(camera_settings, expected_camera_settings): + assert camera_settings == expected_camera_settings + + +@pytest.mark.parametrize( + "box_size, expected_box_size", + [(results["trajectoryInfo"]["size"], {"x": 1.28, "y": 1.28, "z": 1.28})], +) +def test_box_size_default(box_size, expected_box_size): + assert box_size == expected_box_size + + +box_size = 50.0 +a_name = "Kinesin" +a_radius = 0.03 +a_url = "https://files.rcsb.org/download/3KIN.pdb" +a_color = "#0080ff" +t2_name = "Transporter" +t2_color = "#ff1493" +data_with_display_data = McellData( + path_to_data_model_json="simulariumio/tests/data/mcell/" + "organelle_model_viz_output/Scene.data_model.00.json", + path_to_binary_files="simulariumio/tests/data/mcell/" "organelle_model_viz_output", + meta_data=MetaData(box_size=np.array([box_size, box_size, box_size])), + display_data={ + "a": DisplayData( + name=a_name, + radius=a_radius, + display_type=DISPLAY_TYPE.PDB, + url=a_url, + color=a_color, ), + "t2": DisplayData( + name=t2_name, + display_type=DISPLAY_TYPE.SPHERE, + color=t2_color, + ), + }, + surface_mol_rotation_angle=0.0, +) + +converter_display_data = McellConverter(data_with_display_data) +results_display_data = JsonWriter.format_trajectory_data(converter_display_data._data) + + +@pytest.mark.parametrize( + "typeMapping, expected_typeMapping", + [ + ( + results_display_data["trajectoryInfo"]["typeMapping"], + { + "0": { + "name": "b", + "geometry": { + "displayType": "SPHERE", + }, + }, + "1": { + "name": t2_name, + "geometry": { + "displayType": "SPHERE", + "color": t2_color, + }, + }, + "2": { + "name": a_name, + "geometry": { + "displayType": "PDB", + "url": a_url, + "color": a_color, + }, + }, + }, + ) + ], +) +def test_typeMapping(typeMapping, expected_typeMapping): + assert expected_typeMapping == typeMapping + + +@pytest.mark.parametrize( + "box_size, expected_box_size", + [ + ( + results_display_data["trajectoryInfo"]["size"], + {"x": box_size, "y": box_size, "z": box_size}, + ) + ], +) +def test_box_size_provided(box_size, expected_box_size): + # if a box size is provided, we should use it + assert box_size == expected_box_size + + +@pytest.mark.parametrize( + "bundleData, expected_bundleData", + [ + ( + # just testing the first frame + results_display_data["spatialData"]["bundleData"][0], + [ + VIZ_TYPE.DEFAULT, # first agent + 0.0, # id + 0.0, # type + 0.12416012585163116, # x + -0.1974048614501953, # y + -0.10042950510978699, # z + 0.0, # x rotation + 0.0, # y rotation + 0.0, # z rotation + 0.005, # radius + 0.0, # number of subpoints + VIZ_TYPE.DEFAULT, # second agent + 1.0, + 1.0, + -0.027653440833091736, + 0.1265464723110199, + -0.07352104783058167, + -160.8765121025542, + 0.0, + -9.231996800714258, + 0.005, + 0.0, + VIZ_TYPE.DEFAULT, # third agent + 2.0, + 2.0, + 0.3647538423538208, + 0.1595117300748825, + 0.3979622721672058, + 0.0, + 0.0, + 0.0, + 0.00015, + 0.0, + ], + ) + ], +) +def test_bundleData(bundleData, expected_bundleData): + assert expected_bundleData == bundleData["data"] + + +def test_agent_ids(): + assert JsonWriter._check_agent_ids_are_unique_per_frame(results_display_data) + + +@pytest.mark.parametrize( + "v, expected_perpendicular", + [ + ( + [0.0, 0.0, 1.0], + [0.0, 1.0, 0.0], + ) + ], +) +def test_perp_vector(v, expected_perpendicular): + mcell_perpendicular = McellConverter._get_perpendicular_vector(v, 0.0) + assert (expected_perpendicular == mcell_perpendicular).all() + + +@pytest.mark.parametrize( + "v1, v2, expected_result", + [ + ( + [0.0, 0.0, 1.0], + [0.0, 1.0, 0.0], + [ + [0.0, 0.0, 1.0], + [1.0, 0.0, 0.0], + [0.0, 1.0, 0.0], + ], + ) + ], +) +def test_rotation_matrix(v1, v2, expected_result): + rotation_matrix = McellConverter._get_rotation_matrix(v1, v2) + assert (rotation_matrix == expected_result).all() + + +@pytest.mark.parametrize( + "v1, expected_result", + [ + ( + [0.0, 0.0, 1.0], + [90.0, 0.0, 90.0], + ) ], ) -def test_mcell_converter(trajectory, expected_data): - converter = McellConverter(trajectory) - buffer_data = JsonWriter.format_trajectory_data(converter._data) - assert expected_data == buffer_data - assert JsonWriter._check_agent_ids_are_unique_per_frame(buffer_data) +def test_get_euler_angles(v1, expected_result): + euler_angles = McellConverter._get_euler_angles(v1, 45) + assert (euler_angles == expected_result).all() diff --git a/simulariumio/tests/converters/test_md_converter.py b/simulariumio/tests/converters/test_md_converter.py index b6b85bd8..943f0e69 100644 --- a/simulariumio/tests/converters/test_md_converter.py +++ b/simulariumio/tests/converters/test_md_converter.py @@ -9,378 +9,361 @@ MdConverter, MdData, ) -from simulariumio import MetaData, UnitData, DisplayData, JsonWriter, DISPLAY_TYPE +from simulariumio import MetaData, UnitData, DisplayData, JsonWriter from simulariumio.constants import ( DEFAULT_CAMERA_SETTINGS, - CURRENT_VERSION, + DEFAULT_BOX_SIZE, + VIZ_TYPE, + DISPLAY_TYPE ) +data = MdData(md_universe=Universe("simulariumio/tests/data/md/example.xyz")) +converter = MdConverter(data) +results = JsonWriter.format_trajectory_data(converter._data) + +# test box data default @pytest.mark.parametrize( - "trajectory, expected_data", + "box_size, expected_box_size", [ - # visualize every frame ( - MdData( - md_universe=Universe("simulariumio/tests/data/md/example.xyz"), - meta_data=MetaData( - box_size=np.array([200.0, 200.0, 200.0]), - ), - display_data={ - "type_27": DisplayData( - name="A", - display_type=DISPLAY_TYPE.SPHERE, - radius=2.0, - color="#dfdacd", - ), - "H": DisplayData( - name="Hydrogen", - display_type=DISPLAY_TYPE.SPHERE, - ), + results["trajectoryInfo"]["size"], + { + "x": DEFAULT_BOX_SIZE[0], + "y": DEFAULT_BOX_SIZE[1], + "z": DEFAULT_BOX_SIZE[2], + }, + ) + ], +) +def test_box_size_default(box_size, expected_box_size): + assert box_size == expected_box_size + + +# test default camera settings +@pytest.mark.parametrize( + "camera_settings, expected_camera_settings", + [ + ( + results["trajectoryInfo"]["cameraDefault"], + { + "position": { + "x": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[0], + "y": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[1], + "z": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[2], + }, + "lookAtPosition": { + "x": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[0], + "y": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[1], + "z": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[2], + }, + "upVector": { + "x": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[0], + "y": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[1], + "z": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[2], }, - spatial_units=UnitData("nm"), - ), + "fovDegrees": DEFAULT_CAMERA_SETTINGS.FOV_DEGREES, + }, + ) + ], +) +def test_camera_setting_default(camera_settings, expected_camera_settings): + assert camera_settings == expected_camera_settings + + +# test time units default +@pytest.mark.parametrize( + "timeUnits, expected_timeUnits", + [ + ( + results["trajectoryInfo"]["timeUnits"], { - "trajectoryInfo": { - "version": CURRENT_VERSION.TRAJECTORY_INFO, - "timeUnits": { - "magnitude": 1.0, - "name": "s", - }, - "timeStepSize": 1.0, - "totalSteps": 3, - "spatialUnits": { - "magnitude": 1, - "name": "nm", - }, - "size": {"x": 200.0, "y": 200.0, "z": 200.0}, - "cameraDefault": { - "position": { - "x": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[2], - }, - "lookAtPosition": { - "x": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[2], - }, - "upVector": { - "x": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[0], - "y": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[1], - "z": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[2], - }, - "fovDegrees": DEFAULT_CAMERA_SETTINGS.FOV_DEGREES, - }, - "typeMapping": { - "0": { - "name": "A", - "geometry": { - "displayType": "SPHERE", - "color": "#dfdacd", - }, - }, - "1": { - "name": "Hydrogen", - "geometry": { - "displayType": "SPHERE", - "color": "#FFFFFF", - }, - }, + "magnitude": 1.0, + "name": "s", + }, + ) + ], +) +def test_timeUnits_default(timeUnits, expected_timeUnits): + assert timeUnits == expected_timeUnits + + +# test spatial units default +@pytest.mark.parametrize( + "spatialUnits, expected_spatialUnits", + [ + ( + results["trajectoryInfo"]["spatialUnits"], + { + "magnitude": 1.0, + "name": "m", + }, + ) + ], +) +def test_spatialUnits_default(spatialUnits, expected_spatialUnits): + assert spatialUnits == expected_spatialUnits + + +# test type mapping default +@pytest.mark.parametrize( + "typeMapping, expected_typeMapping", + [ + ( + results["trajectoryInfo"]["typeMapping"], + { + "0": { + "name": "T#type_27", + "geometry": { + "displayType": "SPHERE", }, }, - "spatialData": { - "version": CURRENT_VERSION.SPATIAL_DATA, - "msgType": 1, - "bundleStart": 0, - "bundleSize": 3, - "bundleData": [ - { - "frameNumber": 0, - "time": 0.0, - "data": [ - 1000.0, - 0.0, - 0.0, - 42.51536560058594, - -22.60795783996582, - 61.29037857055664, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1000.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1000.0, - 2.0, - 1.0, - -50.82551574707031, - 74.92604064941406, - 15.793620109558105, - 0.0, - 0.0, - 0.0, - 1.1, - 0.0, - ], - }, - { - "frameNumber": 1, - "time": 1.0, - "data": [ - 1000.0, - 0.0, - 0.0, - 46.06970977783203, - -23.434326171875, - 62.29541015625, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1000.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1000.0, - 2.0, - 1.0, - -53.94221115112305, - 77.53073120117188, - 15.477828979492188, - 0.0, - 0.0, - 0.0, - 1.1, - 0.0, - ], - }, - { - "frameNumber": 2, - "time": 2.0, - "data": [ - 1000.0, - 0.0, - 0.0, - 46.473079681396484, - -19.95725440979004, - 62.311668395996094, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1000.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1000.0, - 2.0, - 1.0, - -21.319805145263672, - -76.14720153808594, - -13.58427906036377, - 0.0, - 0.0, - 0.0, - 1.1, - 0.0, - ], - }, - ], + "1": { + "name": "H#H", + "geometry": { + "displayType": "SPHERE", + "color": "#FFFFFF", + }, }, - "plotData": {"version": CURRENT_VERSION.PLOT_DATA, "data": []}, }, + ) + ], +) +def test_typeMapping_default(typeMapping, expected_typeMapping): + assert expected_typeMapping == typeMapping + + +time_unit_name = "ms" +time_unit_value = 2.0 +spatial_unit_name = "nm" +spatial_unit_value = 1.0 +data_with_unit_data = MdData( + md_universe=Universe("simulariumio/tests/data/md/example.xyz"), + time_units=UnitData(time_unit_name, time_unit_value), + spatial_units=UnitData(spatial_unit_name, spatial_unit_value), +) +converter_unit_data = MdConverter(data_with_unit_data) +results_unit_data = JsonWriter.format_trajectory_data(converter_unit_data._data) + + +# test time units provided +@pytest.mark.parametrize( + "timeUnits, expected_timeUnits", + [ + ( + results_unit_data["trajectoryInfo"]["timeUnits"], + { + "magnitude": time_unit_value, + "name": time_unit_name, + }, + ) + ], +) +def test_timeUnits_provided(timeUnits, expected_timeUnits): + assert timeUnits == expected_timeUnits + + +# test spatial units provided +@pytest.mark.parametrize( + "spatialUnits, expected_spatialUnits", + [ + ( + results_unit_data["trajectoryInfo"]["spatialUnits"], + { + "magnitude": spatial_unit_value, + "name": spatial_unit_name, + }, + ) + ], +) +def test_spatialUnits_provided(spatialUnits, expected_spatialUnits): + assert spatialUnits == expected_spatialUnits + + +size_x = 200.0 +size_y = 200.0 +size_z = 100.0 +data_with_meta_data = MdData( + md_universe=Universe("simulariumio/tests/data/md/example.xyz"), + meta_data=MetaData(box_size=np.array([size_x, size_y, size_z])), +) +converter_meta_data = MdConverter(data_with_meta_data) +results_meta_data = JsonWriter.format_trajectory_data(converter_meta_data._data) + + +# test box data provided +@pytest.mark.parametrize( + "box_size, expected_box_size", + [ + ( + results_meta_data["trajectoryInfo"]["size"], + {"x": size_x, "y": size_y, "z": size_z}, + ) + ], +) +def test_box_size_provided(box_size, expected_box_size): + assert box_size == expected_box_size + + +type_27_name = "A" +type_27_radius = 2.0 +type_27_color = "#dfdacd" +h_name = "Hydrogen" +data_with_display_data = MdData( + md_universe=Universe("simulariumio/tests/data/md/example.xyz"), + display_data={ + "type_27": DisplayData( + name=type_27_name, + display_type=DISPLAY_TYPE.SPHERE, + radius=type_27_radius, + color=type_27_color, ), - # visualize every other frame + "H": DisplayData( + name=h_name, + display_type=DISPLAY_TYPE.SPHERE, + ), + }, +) +converter_display_data = MdConverter(data_with_display_data) +results_display_data = JsonWriter.format_trajectory_data(converter_display_data._data) + + +# test type mapping provided +@pytest.mark.parametrize( + "typeMapping, expected_typeMapping", + [ ( - MdData( - md_universe=Universe("simulariumio/tests/data/md/example.xyz"), - nth_timestep_to_read=2, - meta_data=MetaData( - box_size=np.array([200.0, 200.0, 200.0]), - ), - display_data={ - "type_27": DisplayData( - name="A", - display_type=DISPLAY_TYPE.SPHERE, - radius=2.0, - color="#dfdacd", - ), - "H": DisplayData( - name="Hydrogen", - display_type=DISPLAY_TYPE.SPHERE, - ), - }, - spatial_units=UnitData("nm"), - ), + results_display_data["trajectoryInfo"]["typeMapping"], { - "trajectoryInfo": { - "version": CURRENT_VERSION.TRAJECTORY_INFO, - "timeUnits": { - "magnitude": 1.0, - "name": "s", - }, - "timeStepSize": 2.0, - "totalSteps": 2, - "spatialUnits": { - "magnitude": 1, - "name": "nm", - }, - "size": {"x": 200.0, "y": 200.0, "z": 200.0}, - "cameraDefault": { - "position": { - "x": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[2], - }, - "lookAtPosition": { - "x": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[2], - }, - "upVector": { - "x": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[0], - "y": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[1], - "z": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[2], - }, - "fovDegrees": DEFAULT_CAMERA_SETTINGS.FOV_DEGREES, - }, - "typeMapping": { - "0": { - "name": "A", - "geometry": { - "displayType": "SPHERE", - "color": "#dfdacd", - }, - }, - "1": { - "name": "Hydrogen", - "geometry": { - "displayType": "SPHERE", - "color": "#FFFFFF", - }, - }, + "0": { + "name": type_27_name, + "geometry": { + "displayType": "SPHERE", + "color": type_27_color, }, }, - "spatialData": { - "version": CURRENT_VERSION.SPATIAL_DATA, - "msgType": 1, - "bundleStart": 0, - "bundleSize": 2, - "bundleData": [ - { - "frameNumber": 0, - "time": 0.0, - "data": [ - 1000.0, - 0.0, - 0.0, - 42.51536560058594, - -22.60795783996582, - 61.29037857055664, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1000.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1000.0, - 2.0, - 1.0, - -50.82551574707031, - 74.92604064941406, - 15.793620109558105, - 0.0, - 0.0, - 0.0, - 1.1, - 0.0, - ], - }, - { - "frameNumber": 1, - "time": 2.0, - "data": [ - 1000.0, - 0.0, - 0.0, - 46.473079681396484, - -19.95725440979004, - 62.311668395996094, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1000.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1000.0, - 2.0, - 1.0, - -21.319805145263672, - -76.14720153808594, - -13.58427906036377, - 0.0, - 0.0, - 0.0, - 1.1, - 0.0, - ], - }, - ], + "1": { + "name": h_name, + "geometry": { + "displayType": "SPHERE", + "color": "#FFFFFF", + }, }, - "plotData": {"version": CURRENT_VERSION.PLOT_DATA, "data": []}, }, + ) + ], +) +def test_typeMapping_provided(typeMapping, expected_typeMapping): + assert expected_typeMapping == typeMapping + + +# same display data as above, except only displaying every other timestep +data_nth_timestep = MdData( + md_universe=Universe("simulariumio/tests/data/md/example.xyz"), + nth_timestep_to_read=2, + display_data={ + "type_27": DisplayData( + name=type_27_name, + display_type=DISPLAY_TYPE.SPHERE, + radius=type_27_radius, + color=type_27_color, + ), + "H": DisplayData( + name=h_name, + display_type=DISPLAY_TYPE.SPHERE, ), + }, +) +converter_nth_timestep = MdConverter(data_nth_timestep) +results_nth_timestep = JsonWriter.format_trajectory_data(converter_nth_timestep._data) + +first_frame_data = [ + VIZ_TYPE.DEFAULT, # agent 1 + 0.0, # id + 0.0, # type + 42.51536560058594, # x + -22.60795783996582, # y + 61.29037857055664, # z + 0.0, # x rotation + 0.0, # y rotation + 0.0, # z rotation + type_27_radius, # radius + 0.0, # subpoints + VIZ_TYPE.DEFAULT, # agent 2 + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + type_27_radius, + 0.0, + VIZ_TYPE.DEFAULT, # agent 3 + 2.0, + 1.0, + -50.82551574707031, + 74.92604064941406, + 15.793620109558105, + 0.0, + 0.0, + 0.0, + 1.1, + 0.0, +] + +third_frame_data = [ + VIZ_TYPE.DEFAULT, # first agent + 0.0, # id + 0.0, # type + 46.473079681396484, # x + -19.95725440979004, # y + 62.311668395996094, # z + 0.0, # x rotation + 0.0, # y rotation + 0.0, # z rotation + type_27_radius, # radius + 0.0, # subpoints + VIZ_TYPE.DEFAULT, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + type_27_radius, + 0.0, + VIZ_TYPE.DEFAULT, + 2.0, + 1.0, + -21.319805145263672, + -76.14720153808594, + -13.58427906036377, + 0.0, + 0.0, + 0.0, + 1.1, + 0.0, +] + + +@pytest.mark.parametrize( + "bundleData, expected_bundleData", + [ + (results_display_data["spatialData"]["bundleData"][0], first_frame_data), + (results_display_data["spatialData"]["bundleData"][2], third_frame_data), + # test every nth timestep (n = 2) + (results_nth_timestep["spatialData"]["bundleData"][0], first_frame_data), + (results_nth_timestep["spatialData"]["bundleData"][1], third_frame_data), ], ) -def test_md_converter(trajectory, expected_data): - converter = MdConverter(trajectory) - buffer_data = JsonWriter.format_trajectory_data(converter._data) - assert expected_data == buffer_data - assert JsonWriter._check_agent_ids_are_unique_per_frame(buffer_data) +def test_bundleData(bundleData, expected_bundleData): + assert expected_bundleData == bundleData["data"] + + +def test_agent_ids(): + assert JsonWriter._check_agent_ids_are_unique_per_frame(results_display_data) + assert JsonWriter._check_agent_ids_are_unique_per_frame(results_nth_timestep) diff --git a/simulariumio/tests/converters/test_medyan_converter.py b/simulariumio/tests/converters/test_medyan_converter.py index bfd15baf..4994a11b 100644 --- a/simulariumio/tests/converters/test_medyan_converter.py +++ b/simulariumio/tests/converters/test_medyan_converter.py @@ -5,965 +5,478 @@ import pytest from simulariumio.medyan import MedyanConverter, MedyanData -from simulariumio import MetaData, DisplayData, InputFileData, JsonWriter, DISPLAY_TYPE -from simulariumio.constants import DEFAULT_CAMERA_SETTINGS, CURRENT_VERSION +from simulariumio import MetaData, DisplayData, InputFileData, JsonWriter +from simulariumio.constants import ( + DEFAULT_BOX_SIZE, + DEFAULT_CAMERA_SETTINGS, + VIZ_TYPE, + DISPLAY_TYPE +) + +data = MedyanData( + snapshot_file=InputFileData(file_path="simulariumio/tests/data/medyan/test.traj"), +) +converter = MedyanConverter(data) +results = JsonWriter.format_trajectory_data(converter._data) +# test box data default @pytest.mark.parametrize( - "trajectory, expected_data", + "box_size, expected_box_size", [ - # truncated data from 50filaments_motor_linker example ( - MedyanData( - meta_data=MetaData( - box_size=np.array([1000.0, 1000.0, 500.0]), - ), - snapshot_file=InputFileData( - file_path="simulariumio/tests/data/medyan/snapshot.traj" - ), - filament_display_data={ - 0: DisplayData( - name="Actin", - display_type=DISPLAY_TYPE.FIBER, - radius=2, - color="#d71f5f", - ), - }, - linker_display_data={ - 1: DisplayData( - name="Xlink", - display_type=DISPLAY_TYPE.FIBER, - radius=0.5, - color="#0080ff", - ), - }, - ), + results["trajectoryInfo"]["size"], { - "trajectoryInfo": { - "version": CURRENT_VERSION.TRAJECTORY_INFO, - "timeUnits": { - "magnitude": 1.0, - "name": "s", + "x": DEFAULT_BOX_SIZE[0], + "y": DEFAULT_BOX_SIZE[1], + "z": DEFAULT_BOX_SIZE[2], + }, + ) + ], +) +def test_box_size_default(box_size, expected_box_size): + assert box_size == expected_box_size + + +# test type mapping default +@pytest.mark.parametrize( + "typeMapping, expected_typeMapping", + [ + ( + results["trajectoryInfo"]["typeMapping"], + { + "0": { + "name": "filament0", + "geometry": { + "displayType": "FIBER", }, - "timeStepSize": 1.0, - "totalSteps": 3, - "spatialUnits": { - "magnitude": 1.0, - "name": "nm", + }, + "1": { + "name": "linker0", + "geometry": { + "displayType": "FIBER", }, - "size": {"x": 1000.0, "y": 1000.0, "z": 500.0}, - "cameraDefault": { - "position": { - "x": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[2], - }, - "lookAtPosition": { - "x": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[2], - }, - "upVector": { - "x": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[0], - "y": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[1], - "z": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[2], - }, - "fovDegrees": DEFAULT_CAMERA_SETTINGS.FOV_DEGREES, + }, + "2": { + "name": "linker1", + "geometry": { + "displayType": "FIBER", }, - "typeMapping": { - "0": { - "name": "Actin", - "geometry": { - "displayType": "FIBER", - "color": "#d71f5f", - }, - }, - "1": { - "name": "linker0", - "geometry": { - "displayType": "FIBER", - }, - }, - "2": { - "name": "Xlink", - "geometry": { - "displayType": "FIBER", - "color": "#0080ff", - }, - }, - "3": { - "name": "linker2", - "geometry": { - "displayType": "FIBER", - }, - }, - "4": { - "name": "motor1", - "geometry": { - "displayType": "FIBER", - }, - }, + }, + "3": { + "name": "motor1", + "geometry": { + "displayType": "FIBER", }, }, - "spatialData": { - "version": CURRENT_VERSION.SPATIAL_DATA, - "msgType": 1, - "bundleStart": 0, - "bundleSize": 3, - "bundleData": [ - { - "frameNumber": 0, - "time": 0.0, - "data": [ - 1001.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 2.0, - 6.0, - 454.3434234, - 363.439226, - 265.4405349, - 519.7377041, - 351.5737487, - 180.312405, - 1001.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 2.0, - 6.0, - 547.5943503, - 280.3075619, - 307.4127023, - 535.194707, - 173.0325428, - 308.9355694, - ], - }, - { - "frameNumber": 1, - "time": 1.000038293, - "data": [ - 1001.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 2.0, - 18.0, - 443.3162276, - 369.8644852, - 293.1521372, - 458.4600122, - 366.5425284, - 274.4414626, - 525.5102849, - 351.3129172, - 191.1648549, - 595.4174881, - 336.6403217, - 110.1741389, - 672.5234407, - 322.3132598, - 35.94250437, - 678.3129825, - 321.2378855, - 30.3779709, - 1001.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 2.0, - 15.0, - 549.7619454, - 310.7627687, - 302.0296124, - 547.773019, - 286.5808386, - 303.3456815, - 537.9496947, - 179.2424416, - 309.5407552, - 518.8214547, - 73.12680239, - 314.8723733, - 509.9893907, - 28.15495189, - 317.0372613, - 1001.0, - 2.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - 216.8006048, - 854.8097767, - 302.9108981, - 191.2656514, - 867.5975965, - 281.4725825, - 1001.0, - 3.0, - 2.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.5, - 6.0, - 657.3317212, - 421.4935263, - 212.7250047, - 662.1669685, - 436.2944039, - 182.6128889, - 1001.0, - 4.0, - 3.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - 639.8034428, - 430.9883592, - 162.5605615, - 670.9326577, - 411.1640706, - 178.0690934, - 1001.0, - 5.0, - 4.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - 541.3878582, - 216.8108805, - 307.3724794, - 584.5992533, - 412.7637236, - 381.2579975, - ], - }, - { - "frameNumber": 2, - "time": 2.000139228, - "data": [ - 1001.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 2.0, - 18.0, - 419.3626297, - 381.10638, - 315.8483744, - 446.7371319, - 375.818468, - 282.8508029, - 516.3105843, - 361.2676189, - 201.5443633, - 592.9597694, - 344.2612152, - 127.3963243, - 679.1547838, - 328.7033152, - 64.22840104, - 728.0327863, - 320.5202629, - 31.49161861, - 1001.0, - 2.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - 219.5947346, - 861.7155242, - 300.8401219, - 190.1993603, - 868.6151397, - 282.8074954, - 1001.0, - 3.0, - 2.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.5, - 6.0, - 655.5447164, - 417.8251525, - 217.1708231, - 669.7077335, - 432.941762, - 190.7921575, - 1001.0, - 6.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - 748.6131058, - 312.0532071, - 295.8168199, - 713.2424309, - 307.8785764, - 295.6282915, - 1001.0, - 7.0, - 3.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - 543.4687581, - 148.8799083, - 277.8911145, - 529.893394, - 146.6094325, - 312.4195341, - 1001.0, - 5.0, - 4.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - 610.406461, - 152.6068272, - 304.3073239, - 432.9961836, - 229.7552013, - 191.6383788, - 1001.0, - 8.0, - 4.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - 668.8368056, - 523.9037131, - 357.0977571, - 721.9538022, - 345.9688898, - 427.5226707, - ], - }, - ], + }, + ) + ], +) +def test_typeMapping_default(typeMapping, expected_typeMapping): + assert expected_typeMapping == typeMapping + + +# test default camera settings +@pytest.mark.parametrize( + "camera_settings, expected_camera_settings", + [ + ( + results["trajectoryInfo"]["cameraDefault"], + { + "position": { + "x": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[0], + "y": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[1], + "z": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[2], + }, + "lookAtPosition": { + "x": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[0], + "y": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[1], + "z": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[2], + }, + "upVector": { + "x": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[0], + "y": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[1], + "z": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[2], }, - "plotData": {"version": CURRENT_VERSION.PLOT_DATA, "data": []}, + "fovDegrees": DEFAULT_CAMERA_SETTINGS.FOV_DEGREES, }, + ) + ], +) +def test_camera_setting_default(camera_settings, expected_camera_settings): + assert camera_settings == expected_camera_settings + + +x_size = 1000.0 +y_size = 1000.0 +z_size = 500.0 +data_with_meta_data = MedyanData( + meta_data=MetaData( + box_size=np.array([x_size, y_size, z_size]), + ), + snapshot_file=InputFileData(file_path="simulariumio/tests/data/medyan/test.traj"), +) +converter_meta_data = MedyanConverter(data_with_meta_data) +results_meta_data = JsonWriter.format_trajectory_data(converter_meta_data._data) + + +# test box data provided +@pytest.mark.parametrize( + "box_size, expected_box_size", + [ + ( + results_meta_data["trajectoryInfo"]["size"], + {"x": x_size, "y": y_size, "z": z_size}, + ) + ], +) +def test_box_size_provided(box_size, expected_box_size): + assert box_size == expected_box_size + + +actin_radius = 2.0 +actin_color = "#d71f5f" +linker_radius = 0.5 +linker_color = "#0080ff" +data_with_display_data = MedyanData( + meta_data=MetaData( + box_size=np.array([x_size, y_size, z_size]), + ), + snapshot_file=InputFileData(file_path="simulariumio/tests/data/medyan/test.traj"), + filament_display_data={ + 0: DisplayData( + name="Actin", + display_type=DISPLAY_TYPE.FIBER, + radius=actin_radius, + color=actin_color, + ), + }, + linker_display_data={ + 1: DisplayData( + name="Xlink", + display_type=DISPLAY_TYPE.FIBER, + radius=linker_radius, + color=linker_color, ), - # same data but add drawing endpoints + }, +) +converter_display_data = MedyanConverter(data_with_display_data) +results_display_data = JsonWriter.format_trajectory_data(converter_display_data._data) + + +# test type mapping with display data provided +@pytest.mark.parametrize( + "typeMapping, expected_typeMapping", + [ ( - MedyanData( - meta_data=MetaData( - box_size=np.array([1000.0, 1000.0, 500.0]), - ), - snapshot_file=InputFileData( - file_path="simulariumio/tests/data/medyan/snapshot.traj" - ), - filament_display_data={ - 0: DisplayData( - name="Actin", - display_type=DISPLAY_TYPE.FIBER, - radius=2, - color="#ff1493", - ), + results_display_data["trajectoryInfo"]["typeMapping"], + { + "0": { + "name": "Actin", + "geometry": { + "displayType": "FIBER", + "color": actin_color, + }, + }, + "1": { + "name": "linker0", + "geometry": { + "displayType": "FIBER", + }, }, - linker_display_data={ - 0: DisplayData( - name="Xlink0", - display_type=DISPLAY_TYPE.FIBER, - radius=1.0, - color="#0080ff", - ), - 1: DisplayData( - name="Xlink1", - display_type=DISPLAY_TYPE.FIBER, - radius=0.5, - ), + "2": { + "name": "Xlink", + "geometry": { + "displayType": "FIBER", + "color": linker_color, + }, + }, + "3": { + "name": "motor1", + "geometry": { + "displayType": "FIBER", + }, }, - agents_with_endpoints=["Xlink0", "Xlink1"], - ), + }, + ) + ], +) +def test_typeMapping_with_display_data(typeMapping, expected_typeMapping): + assert typeMapping == expected_typeMapping + + +@pytest.mark.parametrize( + "bundleData, expected_bundleData", + [ + ( + # just testing the first frame + results_display_data["spatialData"]["bundleData"][0], + [ + VIZ_TYPE.FIBER, # first agent + 0.0, # id + 0.0, # type + 0.0, # x + 0.0, # y + 0.0, # z + 0.0, # x rotation + 0.0, # y rotation + 0.0, # z rotation + actin_radius, # radius + 6.0, # number of subpoints + 454.3434234, + 363.439226, + 265.4405349, + 519.7377041, + 351.5737487, + 180.312405, + VIZ_TYPE.FIBER, # second agent + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + actin_radius, + 6.0, + 547.5943503, + 280.3075619, + 307.4127023, + 535.194707, + 173.0325428, + 308.9355694, + ], + ) + ], +) +def test_bundleData(bundleData, expected_bundleData): + assert expected_bundleData == bundleData["data"] + + +def test_agent_ids(): + assert JsonWriter._check_agent_ids_are_unique_per_frame(results_display_data) + + +# add in drawing endpoints +data_with_drawing_endpoints = MedyanData( + meta_data=MetaData( + box_size=np.array([x_size, y_size, z_size]), + ), + snapshot_file=InputFileData(file_path="simulariumio/tests/data/medyan/test.traj"), + filament_display_data={ + 0: DisplayData( + name="Actin", + display_type=DISPLAY_TYPE.FIBER, + radius=actin_radius, + color=actin_color, + ), + }, + linker_display_data={ + 1: DisplayData( + name="Xlink", + display_type=DISPLAY_TYPE.FIBER, + radius=linker_radius, + color=linker_color, + ), + }, + agents_with_endpoints=["Xlink"], +) +converter_drawing_endpoints = MedyanConverter(data_with_drawing_endpoints) +results_drawing_endpoints = JsonWriter.format_trajectory_data( + converter_drawing_endpoints._data +) + + +@pytest.mark.parametrize( + "typeMapping, expected_typeMapping", + [ + ( + results_drawing_endpoints["trajectoryInfo"]["typeMapping"], { - "trajectoryInfo": { - "version": CURRENT_VERSION.TRAJECTORY_INFO, - "timeUnits": { - "magnitude": 1.0, - "name": "s", + "0": { + "name": "Actin", + "geometry": { + "displayType": "FIBER", + "color": actin_color, }, - "timeStepSize": 1.0, - "totalSteps": 3, - "spatialUnits": { - "magnitude": 1.0, - "name": "nm", + }, + "1": { + "name": "linker0", + "geometry": { + "displayType": "FIBER", }, - "size": {"x": 1000.0, "y": 1000.0, "z": 500.0}, - "cameraDefault": { - "position": { - "x": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[2], - }, - "lookAtPosition": { - "x": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[2], - }, - "upVector": { - "x": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[0], - "y": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[1], - "z": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[2], - }, - "fovDegrees": DEFAULT_CAMERA_SETTINGS.FOV_DEGREES, + }, + "2": { + "name": "Xlink", + "geometry": { + "displayType": "FIBER", + "color": linker_color, }, - "typeMapping": { - "0": { - "name": "Actin", - "geometry": { - "displayType": "FIBER", - "color": "#ff1493", - }, - }, - "1": { - "name": "Xlink0", - "geometry": { - "displayType": "FIBER", - "color": "#0080ff", - }, - }, - "2": { - "name": "Xlink0 End", - "geometry": { - "displayType": "SPHERE", - }, - }, - "3": { - "name": "Xlink1", - "geometry": { - "displayType": "FIBER", - }, - }, - "4": { - "name": "Xlink1 End", - "geometry": { - "displayType": "SPHERE", - }, - }, - "5": { - "name": "linker2", - "geometry": { - "displayType": "FIBER", - }, - }, - "6": { - "name": "motor1", - "geometry": { - "displayType": "FIBER", - }, - }, + }, + "3": { + "name": "Xlink End", + "geometry": { + "displayType": "SPHERE", }, }, - "spatialData": { - "version": CURRENT_VERSION.SPATIAL_DATA, - "msgType": 1, - "bundleStart": 0, - "bundleSize": 3, - "bundleData": [ - { - "frameNumber": 0, - "time": 0.0, - "data": [ - 1001.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 2.0, - 6.0, - 454.3434234, - 363.439226, - 265.4405349, - 519.7377041, - 351.5737487, - 180.312405, - 1001.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 2.0, - 6.0, - 547.5943503, - 280.3075619, - 307.4127023, - 535.194707, - 173.0325428, - 308.9355694, - ], - }, - { - "frameNumber": 1, - "time": 1.000038293, - "data": [ - 1001.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 2.0, - 18.0, - 443.3162276, - 369.8644852, - 293.1521372, - 458.4600122, - 366.5425284, - 274.4414626, - 525.5102849, - 351.3129172, - 191.1648549, - 595.4174881, - 336.6403217, - 110.1741389, - 672.5234407, - 322.3132598, - 35.94250437, - 678.3129825, - 321.2378855, - 30.3779709, - 1001.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 2.0, - 15.0, - 549.7619454, - 310.7627687, - 302.0296124, - 547.773019, - 286.5808386, - 303.3456815, - 537.9496947, - 179.2424416, - 309.5407552, - 518.8214547, - 73.12680239, - 314.8723733, - 509.9893907, - 28.15495189, - 317.0372613, - 1001.0, - 2.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - 216.8006048, - 854.8097767, - 302.9108981, - 191.2656514, - 867.5975965, - 281.4725825, - 1000.0, - 3.0, - 2.0, - 216.8006048, - 854.8097767, - 302.9108981, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1000.0, - 4.0, - 2.0, - 191.2656514, - 867.5975965, - 281.4725825, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1001.0, - 5.0, - 3.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.5, - 6.0, - 657.3317212, - 421.4935263, - 212.7250047, - 662.1669685, - 436.2944039, - 182.6128889, - 1000.0, - 6.0, - 4.0, - 657.3317212, - 421.4935263, - 212.7250047, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 7.0, - 4.0, - 662.1669685, - 436.2944039, - 182.6128889, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1001.0, - 8.0, - 5.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - 639.8034428, - 430.9883592, - 162.5605615, - 670.9326577, - 411.1640706, - 178.0690934, - 1001.0, - 9.0, - 6.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - 541.3878582, - 216.8108805, - 307.3724794, - 584.5992533, - 412.7637236, - 381.2579975, - ], - }, - { - "frameNumber": 2, - "time": 2.000139228, - "data": [ - 1001.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 2.0, - 18.0, - 419.3626297, - 381.10638, - 315.8483744, - 446.7371319, - 375.818468, - 282.8508029, - 516.3105843, - 361.2676189, - 201.5443633, - 592.9597694, - 344.2612152, - 127.3963243, - 679.1547838, - 328.7033152, - 64.22840104, - 728.0327863, - 320.5202629, - 31.49161861, - 1001.0, - 2.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - 219.5947346, - 861.7155242, - 300.8401219, - 190.1993603, - 868.6151397, - 282.8074954, - 1000.0, - 3.0, - 2.0, - 219.5947346, - 861.7155242, - 300.8401219, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1000.0, - 4.0, - 2.0, - 190.1993603, - 868.6151397, - 282.8074954, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1001.0, - 5.0, - 3.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.5, - 6.0, - 655.5447164, - 417.8251525, - 217.1708231, - 669.7077335, - 432.941762, - 190.7921575, - 1000.0, - 6.0, - 4.0, - 655.5447164, - 417.8251525, - 217.1708231, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 7.0, - 4.0, - 669.7077335, - 432.941762, - 190.7921575, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1001.0, - 10.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - 748.6131058, - 312.0532071, - 295.8168199, - 713.2424309, - 307.8785764, - 295.6282915, - 1000.0, - 11.0, - 2.0, - 748.6131058, - 312.0532071, - 295.8168199, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1000.0, - 12.0, - 2.0, - 713.2424309, - 307.8785764, - 295.6282915, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1001.0, - 13.0, - 5.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - 543.4687581, - 148.8799083, - 277.8911145, - 529.893394, - 146.6094325, - 312.4195341, - 1001.0, - 9.0, - 6.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - 610.406461, - 152.6068272, - 304.3073239, - 432.9961836, - 229.7552013, - 191.6383788, - 1001.0, - 14.0, - 6.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - 668.8368056, - 523.9037131, - 357.0977571, - 721.9538022, - 345.9688898, - 427.5226707, - ], - }, - ], + "4": { + "name": "motor1", + "geometry": { + "displayType": "FIBER", + }, }, - "plotData": {"version": CURRENT_VERSION.PLOT_DATA, "data": []}, }, - ), + ) ], ) -def test_medyan_converter(trajectory, expected_data): - converter = MedyanConverter(trajectory) - buffer_data = JsonWriter.format_trajectory_data(converter._data) - assert expected_data == buffer_data - assert JsonWriter._check_agent_ids_are_unique_per_frame(buffer_data) +def test_typeMapping_with_drawing_endpoints(typeMapping, expected_typeMapping): + assert typeMapping == expected_typeMapping + + +@pytest.mark.parametrize( + "bundleData, expected_bundleData", + [ + ( + # just testing the first frame + results_drawing_endpoints["spatialData"]["bundleData"][1], + [ + VIZ_TYPE.FIBER, # first agent + 0.0, # id + 0.0, # type - Actin + 0.0, # x + 0.0, # y + 0.0, # z + 0.0, # x rotation + 0.0, # y rotation + 0.0, # z rotation + actin_radius, # radius + 18.0, # number of subpoints (18) + 443.3162276, # subpoint 1 x + 369.8644852, # subpoint 1 y + 293.1521372, # subpoint 1 z + 458.4600122, # subpoint 2 x + 366.5425284, # ... + 274.4414626, + 525.5102849, + 351.3129172, + 191.1648549, + 595.4174881, + 336.6403217, + 110.1741389, + 672.5234407, + 322.3132598, + 35.94250437, + 678.3129825, + 321.2378855, + 30.3779709, + VIZ_TYPE.FIBER, # second agent + 1.0, # id + 0.0, # type - Actin + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + actin_radius, + 15.0, # 15 subpoints + 549.7619454, + 310.7627687, + 302.0296124, + 547.773019, + 286.5808386, + 303.3456815, + 537.9496947, + 179.2424416, + 309.5407552, + 518.8214547, + 73.12680239, + 314.8723733, + 509.9893907, + 28.15495189, + 317.0372613, + VIZ_TYPE.FIBER, # third agent + 2.0, # id + 1.0, # type - linker0 + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, # default radius + 6.0, # 6 subpoints + 216.8006048, + 854.8097767, + 302.9108981, + 191.2656514, + 867.5975965, + 281.4725825, + VIZ_TYPE.FIBER, # 4th agent + 3.0, # id + 2.0, # type - Xlink + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + linker_radius, + 6.0, + 657.3317212, + 421.4935263, + 212.7250047, + 662.1669685, + 436.2944039, + 182.6128889, + VIZ_TYPE.DEFAULT, # 5th agent + 4.0, # id + 3.0, # type - Xlink End + 657.3317212, + 421.4935263, + 212.7250047, + 0.0, + 0.0, + 0.0, + 1.0, # default radius + 0.0, + VIZ_TYPE.DEFAULT, # 6th agent + 5.0, # id + 3.0, # type - Xlink End + 662.1669685, + 436.2944039, + 182.6128889, + 0.0, + 0.0, + 0.0, + 1.0, # default radius + 0.0, + VIZ_TYPE.FIBER, # 7th agent + 6.0, # id + 4.0, # motor1 + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, # default radius + 6.0, + 541.3878582, + 216.8108805, + 307.3724794, + 584.5992533, + 412.7637236, + 381.2579975, + ], + ) + ], +) +def test_bundleData_drawing_endpoints(bundleData, expected_bundleData): + assert expected_bundleData == bundleData["data"] + + +def test_agent_ids_drawing_endpoints(): + assert JsonWriter._check_agent_ids_are_unique_per_frame(results_drawing_endpoints) diff --git a/simulariumio/tests/converters/test_physicell_converter.py b/simulariumio/tests/converters/test_physicell_converter.py index 416a26c1..0b136af7 100644 --- a/simulariumio/tests/converters/test_physicell_converter.py +++ b/simulariumio/tests/converters/test_physicell_converter.py @@ -5,371 +5,697 @@ import pytest from simulariumio.physicell import PhysicellConverter, PhysicellData -from simulariumio import MetaData, DisplayData, JsonWriter, DISPLAY_TYPE, UnitData +from simulariumio import MetaData, DisplayData, JsonWriter, UnitData from simulariumio.constants import ( - DEFAULT_CAMERA_SETTINGS, - CURRENT_VERSION, + DEFAULT_BOX_SIZE, DEFAULT_COLORS, + DISPLAY_TYPE, + VIZ_TYPE ) -from simulariumio.tests.conftest import assert_buffers_equal + +data = PhysicellData( + timestep=360.0, + path_to_output_dir="simulariumio/tests/data/physicell/default_output/", +) +converter = PhysicellConverter(data) +results = JsonWriter.format_trajectory_data(converter._data) +# test box data default @pytest.mark.parametrize( - "trajectory, expected_data", + "box_size, expected_box_size", [ - # 3 cells 3 frames ( - PhysicellData( - meta_data=MetaData( - box_size=np.array([1000.0, 1000.0, 100.0]), - scale_factor=0.01, - ), - timestep=360.0, - path_to_output_dir="simulariumio/tests/data/physicell/default_output/", - display_data={ - 0: DisplayData( - name="Cancer cell", - display_type=DISPLAY_TYPE.SPHERE, - radius=30.0, - color="#0080ff", - ), - }, - phase_names={1: {4: "interphase"}}, - ), + results["trajectoryInfo"]["size"], { - "trajectoryInfo": { - "version": CURRENT_VERSION.TRAJECTORY_INFO, - "timeUnits": { - "magnitude": 1.0, - "name": "s", - }, - "timeStepSize": 360.0, - "totalSteps": 3, - "spatialUnits": { - "magnitude": 100.0, - "name": "µm", + "x": DEFAULT_BOX_SIZE[0], + "y": DEFAULT_BOX_SIZE[1], + "z": DEFAULT_BOX_SIZE[2], + }, + ) + ], +) +def test_box_size_default(box_size, expected_box_size): + assert box_size == expected_box_size + + +# test type mapping default +@pytest.mark.parametrize( + "typeMapping, expected_typeMapping", + [ + ( + results["trajectoryInfo"]["typeMapping"], + { + "0": { + "name": "cell1#phase4", + "geometry": { + "displayType": "SPHERE", }, - "size": {"x": 10.0, "y": 10.0, "z": 1.0}, - "cameraDefault": { - "position": { - "x": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[2], - }, - "lookAtPosition": { - "x": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[2], - }, - "upVector": { - "x": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[0], - "y": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[1], - "z": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[2], - }, - "fovDegrees": DEFAULT_CAMERA_SETTINGS.FOV_DEGREES, + }, + "1": { + "name": "cell0#phase4", + "geometry": { + "displayType": "SPHERE", }, - "typeMapping": { - "0": { - "name": "cell1#interphase", - "geometry": { - "displayType": "SPHERE", - }, - }, - "1": { - "name": "Cancer cell#phase4", - "geometry": { - "displayType": "SPHERE", - "color": "#0080ff", - }, - }, + }, + }, + ) + ], +) +def test_typeMapping_default(typeMapping, expected_typeMapping): + assert expected_typeMapping == typeMapping + + +# test time units default +@pytest.mark.parametrize( + "timeUnits, expected_timeUnits", + [ + ( + results["trajectoryInfo"]["timeUnits"], + { + "magnitude": 1.0, + "name": "s", + }, + ) + ], +) +def test_timeUnits_default(timeUnits, expected_timeUnits): + assert timeUnits == expected_timeUnits + + +size_x = 1000.0 +size_y = 1000.0 +size_z = 100.0 +scale_factor = 0.01 +time_unit = "ms" +data_with_meta_data = PhysicellData( + meta_data=MetaData( + box_size=np.array([size_x, size_y, size_z]), + scale_factor=scale_factor, + ), + timestep=360.0, + path_to_output_dir="simulariumio/tests/data/physicell/default_output/", + time_units=UnitData( + name=time_unit, + ), +) +converter_meta_data = PhysicellConverter(data_with_meta_data) +results_meta_data = JsonWriter.format_trajectory_data(converter_meta_data._data) + + +# test box data provided +@pytest.mark.parametrize( + "box_size, expected_box_size", + [ + ( + results_meta_data["trajectoryInfo"]["size"], + { + "x": size_x * scale_factor, + "y": size_y * scale_factor, + "z": size_z * scale_factor, + }, + ) + ], +) +def test_box_size_provided(box_size, expected_box_size): + assert box_size == expected_box_size + + +# test time units provided +@pytest.mark.parametrize( + "timeUnits, expected_timeUnits", + [ + ( + results_meta_data["trajectoryInfo"]["timeUnits"], + { + "magnitude": 1.0, + "name": time_unit, + }, + ) + ], +) +def test_timeUnits_provided(timeUnits, expected_timeUnits): + assert timeUnits == expected_timeUnits + + +test_name = "Sample name" +test_radius = 30.0 +test_color = "#0080ff" +test_phase = "interphase" + +data_with_display_data = PhysicellData( + meta_data=MetaData( + box_size=np.array([size_x, size_y, size_z]), + scale_factor=scale_factor, + ), + timestep=360.0, + path_to_output_dir="simulariumio/tests/data/physicell/default_output/", + display_data={ + 0: DisplayData( + name=test_name, + display_type=DISPLAY_TYPE.SPHERE, + radius=test_radius, + color=test_color, + ), + }, + phase_names={1: {4: test_phase}}, +) +converter_display_data = PhysicellConverter(data_with_display_data) +results_display_data = JsonWriter.format_trajectory_data(converter_display_data._data) + + +# test type mapping provided +@pytest.mark.parametrize( + "typeMapping, expected_typeMapping", + [ + ( + results_display_data["trajectoryInfo"]["typeMapping"], + { + "0": { + "name": f"cell1#{test_phase}", + "geometry": { + "displayType": "SPHERE", }, }, - "spatialData": { - "version": CURRENT_VERSION.SPATIAL_DATA, - "msgType": 1, - "bundleStart": 0, - "bundleSize": 3, - "bundleData": [ - { - "frameNumber": 0, - "time": 0.0, - "data": [ - 1000.0, - 0.0, - 0.0, - -4.2700000000000005, - -2.5100000000000002, - 0.0, - 0.0, - 0.0, - 0.0, - 0.08412710547954229, - 0.0, - 1000.0, - 1.0, - 1.0, - -2.2800000000000002, - 4.3, - 0.0, - 0.0, - 0.0, - 0.0, - 0.3, - 0.0, - 1000.0, - 2.0, - 1.0, - 4.23, - 3.7800000000000002, - 0.0, - 0.0, - 0.0, - 0.0, - 0.3, - 0.0, - ], - }, - { - "frameNumber": 1, - "time": 360.0, - "data": [ - 1000.0, - 0.0, - 0.0, - -4.247925822013689, - -2.386576945662163, - 0.0, - 0.0, - 0.0, - 0.0, - 0.08412710547954229, - 0.0, - 1000.0, - 1.0, - 1.0, - -2.2800000000000002, - 4.3, - 0.0, - 0.0, - 0.0, - 0.0, - 0.3, - 0.0, - 1000.0, - 2.0, - 1.0, - 4.23, - 3.7800000000000002, - 0.0, - 0.0, - 0.0, - 0.0, - 0.3, - 0.0, - ], - }, - { - "frameNumber": 2, - "time": 720.0, - "data": [ - 1000.0, - 0.0, - 0.0, - -3.993800168730208, - -2.5387508185531873, - 0.0, - 0.0, - 0.0, - 0.0, - 0.08412710547954229, - 0.0, - 1000.0, - 1.0, - 1.0, - -2.2800000000000002, - 4.3, - 0.0, - 0.0, - 0.0, - 0.0, - 0.3, - 0.0, - 1000.0, - 2.0, - 1.0, - 4.23, - 3.7800000000000002, - 0.0, - 0.0, - 0.0, - 0.0, - 0.3, - 0.0, - ], - }, - ], + "1": { + "name": f"{test_name}#phase4", + "geometry": { + "displayType": "SPHERE", + "color": test_color, + }, }, - "plotData": {"version": CURRENT_VERSION.PLOT_DATA, "data": []}, }, + ) + ], +) +def test_typeMapping_provided(typeMapping, expected_typeMapping): + assert expected_typeMapping == typeMapping + + +# sphere groups for owner cells and subcells +substrate_name = "Substrate" +substrate_color = "#d0c5c8" +owner_cell_name = "Stem cell" +data_subcells = PhysicellData( + meta_data=MetaData( + box_size=np.array([960.0, 640.0, 300.0]), + scale_factor=scale_factor, + ), + timestep=36.0, + path_to_output_dir="simulariumio/tests/data/physicell/subcell_output/", + display_data={ + 0: DisplayData( + name=substrate_name, + display_type=DISPLAY_TYPE.SPHERE, + color=substrate_color, ), - # 3 cells 1 frame + }, + phase_names={0: {18: "fixed"}}, + max_owner_cells=10000, + owner_cell_display_name=owner_cell_name, + time_units=UnitData("min"), +) +converter_subcells = PhysicellConverter(data_subcells) +results_subcells = JsonWriter.format_trajectory_data(converter_subcells._data) + + +# test type mapping provided +@pytest.mark.parametrize( + "typeMapping, expected_typeMapping", + [ ( - PhysicellData( - timestep=360.0, - path_to_output_dir="simulariumio/tests/data/physicell/default_output/", - meta_data=MetaData( - box_size=np.array([1000.0, 1000.0, 100.0]), - scale_factor=0.01, - ), - nth_timestep_to_read=2, - display_data={ - 0: DisplayData( - name="Cancer cell", - display_type=DISPLAY_TYPE.SPHERE, - radius=30.0, - color="#0080ff", - ), - }, - phase_names={1: {4: "interphase"}}, - ), + results_subcells["trajectoryInfo"]["typeMapping"], { - "trajectoryInfo": { - "version": CURRENT_VERSION.TRAJECTORY_INFO, - "timeUnits": { - "magnitude": 1.0, - "name": "s", + "0": { + "name": f"{substrate_name}#fixed", + "geometry": { + "displayType": "SPHERE", + "color": substrate_color, }, - "timeStepSize": 720.0, - "totalSteps": 2, - "spatialUnits": { - "magnitude": 100.0, - "name": "µm", + }, + "1": { + "name": f"{owner_cell_name}#8", + "geometry": { + "displayType": "SPHERE_GROUP", + "color": DEFAULT_COLORS[0], }, - "size": {"x": 10.0, "y": 10.0, "z": 1.0}, - "cameraDefault": { - "position": { - "x": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[2], - }, - "lookAtPosition": { - "x": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[2], - }, - "upVector": { - "x": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[0], - "y": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[1], - "z": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[2], - }, - "fovDegrees": DEFAULT_CAMERA_SETTINGS.FOV_DEGREES, + }, + "2": { + "name": f"{owner_cell_name}#14", + "geometry": { + "displayType": "SPHERE_GROUP", + "color": DEFAULT_COLORS[1], }, - "typeMapping": { - "0": { - "name": "cell1#interphase", - "geometry": { - "displayType": "SPHERE", - }, - }, - "1": { - "name": "Cancer cell#phase4", - "geometry": { - "displayType": "SPHERE", - "color": "#0080ff", - }, - }, + }, + "3": { + "name": f"{owner_cell_name}#25", + "geometry": { + "displayType": "SPHERE_GROUP", + "color": DEFAULT_COLORS[2], }, }, - "spatialData": { - "version": CURRENT_VERSION.SPATIAL_DATA, - "msgType": 1, - "bundleStart": 0, - "bundleSize": 2, - "bundleData": [ - { - "frameNumber": 0, - "time": 0.0, - "data": [ - 1000.0, - 0.0, - 0.0, - -4.2700000000000005, - -2.5100000000000002, - 0.0, - 0.0, - 0.0, - 0.0, - 0.08412710547954229, - 0.0, - 1000.0, - 1.0, - 1.0, - -2.2800000000000002, - 4.3, - 0.0, - 0.0, - 0.0, - 0.0, - 0.3, - 0.0, - 1000.0, - 2.0, - 1.0, - 4.23, - 3.7800000000000002, - 0.0, - 0.0, - 0.0, - 0.0, - 0.3, - 0.0, - ], - }, - { - "frameNumber": 1, - "time": 720.0, - "data": [ - 1000.0, - 0.0, - 0.0, - -3.993800168730208, - -2.5387508185531873, - 0.0, - 0.0, - 0.0, - 0.0, - 0.08412710547954229, - 0.0, - 1000.0, - 1.0, - 1.0, - -2.2800000000000002, - 4.3, - 0.0, - 0.0, - 0.0, - 0.0, - 0.3, - 0.0, - 1000.0, - 2.0, - 1.0, - 4.23, - 3.7800000000000002, - 0.0, - 0.0, - 0.0, - 0.0, - 0.3, - 0.0, - ], - }, - ], + "4": { + "name": f"{owner_cell_name}#2", + "geometry": { + "displayType": "SPHERE_GROUP", + "color": DEFAULT_COLORS[3], + }, }, - "plotData": {"version": CURRENT_VERSION.PLOT_DATA, "data": []}, }, + ) + ], +) +def test_typeMapping_subcells(typeMapping, expected_typeMapping): + assert expected_typeMapping == typeMapping + + +@pytest.mark.parametrize( + "bundleData, expected_bundleData", + [ + ( + results_display_data["spatialData"]["bundleData"][0], + [ + VIZ_TYPE.DEFAULT, # first agent + 0.0, # id + 0.0, # type + -4.2700000000000005, # x + -2.5100000000000002, # y + 0.0, # z + 0.0, # x rotation + 0.0, # y rotation + 0.0, # z rotation + 0.08412710547954229, + 0.0, + VIZ_TYPE.DEFAULT, + 1.0, + 1.0, + -2.2800000000000002, + 4.3, + 0.0, + 0.0, + 0.0, + 0.0, + test_radius * scale_factor, + 0.0, + VIZ_TYPE.DEFAULT, + 2.0, + 1.0, + 4.23, + 3.7800000000000002, + 0.0, + 0.0, + 0.0, + 0.0, + test_radius * scale_factor, + 0.0, + ], ), - # path_to_output_dir is incorrect + ( + results_subcells["spatialData"]["bundleData"][0], + [ + VIZ_TYPE.DEFAULT, # first agent + 35, # id + 0, # type + 4.3983198, # x + 2.7733247999999997, # y + 0.16099999999999998, # z + 0, # x rotation + 0, # y rotation + 0, # z rotation + 0.18837494593627718, # radius + 0, # number of subpoints + VIZ_TYPE.DEFAULT, # second agent + 36, + 0, + 4.701652200000001, + 2.7733247999999997, + 0.16099999999999998, + 0, + 0, + 0, + 0.18837494593627718, + 0, + VIZ_TYPE.DEFAULT, + 37, + 0, + 5.0049846, + 2.7733247999999997, + 0.16099999999999998, + 0, + 0, + 0, + 0.18837494593627718, + 0, + VIZ_TYPE.DEFAULT, + 38, + 0, + 5.308317000000001, + 2.7733247999999997, + 0.16099999999999998, + 0, + 0, + 0, + 0.18837494593627718, + 0, + VIZ_TYPE.DEFAULT, + 39, + 0, + 4.2466536, + 3.0441573, + 0.16099999999999998, + 0, + 0, + 0, + 0.18837494593627718, + 0, + VIZ_TYPE.DEFAULT, + 40, + 0, + 4.5499860000000005, + 3.0441573, + 0.16099999999999998, + 0, + 0, + 0, + 0.18837494593627718, + 0, + VIZ_TYPE.DEFAULT, + 41, + 0, + 4.8533184, + 3.0441573, + 0.16099999999999998, + 0, + 0, + 0, + 0.18837494593627718, + 0, + VIZ_TYPE.DEFAULT, + 42, + 0, + 5.1566508, + 3.0441573, + 0.16099999999999998, + 0, + 0, + 0, + 0.18837494593627718, + 0, + VIZ_TYPE.DEFAULT, + 43, + 0, + 4.3983198, + 3.3041565, + 0.16099999999999998, + 0, + 0, + 0, + 0.18837494593627718, + 0, + VIZ_TYPE.DEFAULT, + 44, + 0, + 4.701652200000001, + 3.3041565, + 0.16099999999999998, + 0, + 0, + 0, + 0.18837494593627718, + 0, + VIZ_TYPE.DEFAULT, + 45, + 0, + 5.0049846, + 3.3041565, + 0.16099999999999998, + 0, + 0, + 0, + 0.18837494593627718, + 0, + VIZ_TYPE.DEFAULT, + 46, + 0, + 5.308317000000001, + 3.3041565, + 0.16099999999999998, + 0, + 0, + 0, + 0.18837494593627718, + 0, + VIZ_TYPE.DEFAULT, + 47, + 0, + 4.2466536, + 3.5641557, + 0.16099999999999998, + 0, + 0, + 0, + 0.18837494593627718, + 0, + VIZ_TYPE.DEFAULT, + 48, + 0, + 4.5499860000000005, + 3.5641557, + 0.16099999999999998, + 0, + 0, + 0, + 0.18837494593627718, + 0, + VIZ_TYPE.DEFAULT, + 49, + 0, + 4.8533184, + 3.5641557, + 0.16099999999999998, + 0, + 0, + 0, + 0.18837494593627718, + 0, + VIZ_TYPE.DEFAULT, + 50, + 0, + 5.1566508, + 3.5641557, + 0.16099999999999998, + 0, + 0, + 0, + 0.18837494593627718, + 0, + VIZ_TYPE.DEFAULT, + 10008, + 1, + 4.756803545454546, + 2.750673354545455, + 0.5169090909090909, + 0, + 0, + 0, + 1.0, + 44, + -0.510149945454546, + -0.1290147545454552, + -0.09490909090909089, + 0.1869798113091103, + -0.20681754545454556, + -0.1290147545454552, + -0.09490909090909089, + 0.1869798113091103, + 0.09651485454545394, + -0.1290147545454552, + -0.09490909090909089, + 0.1869798113091103, + 0.39984725454545433, + -0.1290147545454552, + -0.09490909090909089, + 0.1869798113091103, + -0.35848374545454575, + 0.14181774545454484, + -0.09490909090909089, + 0.1869798113091103, + -0.055151345454545364, + 0.14181774545454484, + -0.09490909090909089, + 0.1869798113091103, + 0.24818105454545414, + 0.14181774545454484, + -0.09490909090909089, + 0.1869798113091103, + -0.35848374545454575, + 0.02265144545454456, + 0.16609090909090907, + 0.1869798113091103, + -0.055151345454545364, + 0.02265144545454456, + 0.16609090909090907, + 0.1869798113091103, + 0.24818105454545414, + 0.02265144545454456, + 0.16609090909090907, + 0.1869798113091103, + 0.5515134545454545, + 0.02265144545454456, + 0.16609090909090907, + 0.1869798113091103, + VIZ_TYPE.DEFAULT, + 10014, + 2, + 4.774188208695653, + 3.3719823782608698, + 0.5468260869565217, + 0, + 0, + 0, + 1.0, + 92, + -0.5275346086956532, + -0.21949207826086958, + -0.1248260869565217, + 0.1869798113091103, + -0.22420220869565277, + -0.21949207826086958, + -0.1248260869565217, + 0.1869798113091103, + 0.07913019130434673, + -0.21949207826086958, + -0.1248260869565217, + 0.1869798113091103, + 0.3824625913043471, + -0.21949207826086958, + -0.1248260869565217, + 0.1869798113091103, + -0.37586840869565297, + 0.040507121739130625, + -0.1248260869565217, + 0.1869798113091103, + -0.07253600869565258, + 0.040507121739130625, + -0.1248260869565217, + 0.1869798113091103, + 0.23079639130434693, + 0.040507121739130625, + -0.1248260869565217, + 0.1869798113091103, + 0.5341287913043473, + 0.040507121739130625, + -0.1248260869565217, + 0.1869798113091103, + -0.5275346086956532, + 0.3005063217391304, + -0.1248260869565217, + 0.1869798113091103, + -0.22420220869565277, + 0.3005063217391304, + -0.1248260869565217, + 0.1869798113091103, + 0.07913019130434673, + 0.3005063217391304, + -0.1248260869565217, + 0.1869798113091103, + 0.3824625913043471, + 0.3005063217391304, + -0.1248260869565217, + 0.1869798113091103, + -0.22420220869565277, + -0.3278250782608696, + 0.13617391304347826, + 0.1869798113091103, + 0.07913019130434673, + -0.3278250782608696, + 0.13617391304347826, + 0.1869798113091103, + 0.3824625913043471, + -0.3278250782608696, + 0.13617391304347826, + 0.1869798113091103, + -0.37586840869565297, + -0.06782587826086983, + 0.13617391304347826, + 0.1869798113091103, + -0.07253600869565258, + -0.06782587826086983, + 0.13617391304347826, + 0.1869798113091103, + 0.23079639130434693, + -0.06782587826086983, + 0.13617391304347826, + 0.1869798113091103, + 0.5341287913043473, + -0.06782587826086983, + 0.13617391304347826, + 0.1869798113091103, + -0.5275346086956532, + 0.19217332173913038, + 0.13617391304347826, + 0.1869798113091103, + -0.22420220869565277, + 0.19217332173913038, + 0.13617391304347826, + 0.1869798113091103, + 0.07913019130434673, + 0.19217332173913038, + 0.13617391304347826, + 0.1869798113091103, + 0.3824625913043471, + 0.19217332173913038, + 0.13617391304347826, + 0.1869798113091103, + VIZ_TYPE.DEFAULT, + 10025, + 3, + 4.2466536, + 3.0441573, + 0.6829999999999999, + 0, + 0, + 0, + 1.0, + 4, + 0, + 0, + 0, + 0.1869798113091103, + VIZ_TYPE.DEFAULT, + 10002, + 4, + 0, + 0, + 0, + 0, + 0, + 0, + 1.0, + 4, + 0, + 0, + 0, + 0, + ] + ) + ], +) +def test_bundleData(bundleData, expected_bundleData): + assert False not in np.isclose( + np.array(expected_bundleData), + np.array(bundleData["data"]), + ) + + +def test_agent_ids(): + assert JsonWriter._check_agent_ids_are_unique_per_frame(results_display_data) + + +# path_to_output_dir is incorrect +@pytest.mark.parametrize( + "trajectory, expected_data", + [ pytest.param( { "meta_data": MetaData( @@ -382,1192 +708,9 @@ {}, marks=pytest.mark.raises(exception=AttributeError), ), - # sphere groups for owner cells and subcells - ( - PhysicellData( - meta_data=MetaData( - box_size=np.array([960.0, 640.0, 300.0]), - scale_factor=0.01, - ), - timestep=36.0, - path_to_output_dir="simulariumio/tests/data/physicell/subcell_output/", - display_data={ - 0: DisplayData( - name="Substrate", - display_type=DISPLAY_TYPE.SPHERE, - color="#d0c5c8", - ), - }, - phase_names={0: {18: "fixed"}}, - max_owner_cells=10000, - owner_cell_display_name="Stem cell", - time_units=UnitData("min"), - ), - { - "trajectoryInfo": { - "version": CURRENT_VERSION.TRAJECTORY_INFO, - "timeUnits": { - "magnitude": 1.0, - "name": "min", - }, - "timeStepSize": 36.0, - "totalSteps": 3, - "spatialUnits": { - "magnitude": 100.0, - "name": "µm", - }, - "size": {"x": 9.6, "y": 6.4, "z": 3.0}, - "cameraDefault": { - "position": { - "x": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[2], - }, - "lookAtPosition": { - "x": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[2], - }, - "upVector": { - "x": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[0], - "y": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[1], - "z": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[2], - }, - "fovDegrees": DEFAULT_CAMERA_SETTINGS.FOV_DEGREES, - }, - "typeMapping": { - "0": { - "name": "Substrate#fixed", - "geometry": { - "displayType": "SPHERE", - "color": "#d0c5c8", - }, - }, - "1": { - "name": "Stem cell#8", - "geometry": { - "displayType": "SPHERE_GROUP", - "color": DEFAULT_COLORS[0], - }, - }, - "2": { - "name": "Stem cell#14", - "geometry": { - "displayType": "SPHERE_GROUP", - "color": DEFAULT_COLORS[1], - }, - }, - "3": { - "name": "Stem cell#25", - "geometry": { - "displayType": "SPHERE_GROUP", - "color": DEFAULT_COLORS[2], - }, - }, - "4": { - "name": "Stem cell#2", - "geometry": { - "displayType": "SPHERE_GROUP", - "color": DEFAULT_COLORS[3], - }, - }, - }, - }, - "spatialData": { - "version": CURRENT_VERSION.SPATIAL_DATA, - "msgType": 1, - "bundleStart": 0, - "bundleSize": 3, - "bundleData": [ - { - "frameNumber": 0, - "time": 0.0, - "data": [ - 1000, - 35, - 0, - 4.3983198, - 2.7733247999999997, - 0.16099999999999998, - 0, - 0, - 0, - 0.18837494593627718, - 0, - 1000, - 36, - 0, - 4.701652200000001, - 2.7733247999999997, - 0.16099999999999998, - 0, - 0, - 0, - 0.18837494593627718, - 0, - 1000, - 37, - 0, - 5.0049846, - 2.7733247999999997, - 0.16099999999999998, - 0, - 0, - 0, - 0.18837494593627718, - 0, - 1000, - 38, - 0, - 5.308317000000001, - 2.7733247999999997, - 0.16099999999999998, - 0, - 0, - 0, - 0.18837494593627718, - 0, - 1000, - 39, - 0, - 4.2466536, - 3.0441573, - 0.16099999999999998, - 0, - 0, - 0, - 0.18837494593627718, - 0, - 1000, - 40, - 0, - 4.5499860000000005, - 3.0441573, - 0.16099999999999998, - 0, - 0, - 0, - 0.18837494593627718, - 0, - 1000, - 41, - 0, - 4.8533184, - 3.0441573, - 0.16099999999999998, - 0, - 0, - 0, - 0.18837494593627718, - 0, - 1000, - 42, - 0, - 5.1566508, - 3.0441573, - 0.16099999999999998, - 0, - 0, - 0, - 0.18837494593627718, - 0, - 1000, - 43, - 0, - 4.3983198, - 3.3041565, - 0.16099999999999998, - 0, - 0, - 0, - 0.18837494593627718, - 0, - 1000, - 44, - 0, - 4.701652200000001, - 3.3041565, - 0.16099999999999998, - 0, - 0, - 0, - 0.18837494593627718, - 0, - 1000, - 45, - 0, - 5.0049846, - 3.3041565, - 0.16099999999999998, - 0, - 0, - 0, - 0.18837494593627718, - 0, - 1000, - 46, - 0, - 5.308317000000001, - 3.3041565, - 0.16099999999999998, - 0, - 0, - 0, - 0.18837494593627718, - 0, - 1000, - 47, - 0, - 4.2466536, - 3.5641557, - 0.16099999999999998, - 0, - 0, - 0, - 0.18837494593627718, - 0, - 1000, - 48, - 0, - 4.5499860000000005, - 3.5641557, - 0.16099999999999998, - 0, - 0, - 0, - 0.18837494593627718, - 0, - 1000, - 49, - 0, - 4.8533184, - 3.5641557, - 0.16099999999999998, - 0, - 0, - 0, - 0.18837494593627718, - 0, - 1000, - 50, - 0, - 5.1566508, - 3.5641557, - 0.16099999999999998, - 0, - 0, - 0, - 0.18837494593627718, - 0, - 1000, - 10008, - 1, - 4.756803545454546, - 2.750673354545455, - 0.5169090909090909, - 0, - 0, - 0, - 1.0, - 44, - -0.510149945454546, - -0.1290147545454552, - -0.09490909090909089, - 0.18697981, - -0.20681754545454645, - -0.1290147545454552, - -0.09490909090909089, - 0.18697981, - 0.09651485454545394, - -0.1290147545454552, - -0.09490909090909089, - 0.18697981, - 0.39984725454545433, - -0.1290147545454552, - -0.09490909090909089, - 0.18697981, - -0.35848374545454575, - 0.14181774545454484, - -0.09490909090909089, - 0.18697981, - -0.05515134545454625, - 0.14181774545454484, - -0.09490909090909089, - 0.18697981, - 0.24818105454545414, - 0.14181774545454484, - -0.09490909090909089, - 0.18697981, - -0.35848374545454575, - 0.022651445454545005, - 0.16609090909090918, - 0.18697981, - -0.05515134545454625, - 0.022651445454545005, - 0.16609090909090918, - 0.18697981, - 0.24818105454545414, - 0.022651445454545005, - 0.16609090909090918, - 0.18697981, - 0.5515134545454536, - 0.022651445454545005, - 0.16609090909090918, - 0.18697981, - 1000, - 10014, - 2, - 4.774188208695653, - 3.3719823782608698, - 0.5468260869565217, - 0, - 0, - 0, - 1.0, - 92, - -0.5275346086956532, - -0.21949207826086958, - -0.1248260869565217, - 0.18697981, - -0.22420220869565366, - -0.21949207826086958, - -0.1248260869565217, - 0.18697981, - 0.07913019130434673, - -0.21949207826086958, - -0.1248260869565217, - 0.18697981, - 0.3824625913043471, - -0.21949207826086958, - -0.1248260869565217, - 0.18697981, - -0.37586840869565297, - 0.04050712173913018, - -0.1248260869565217, - 0.18697981, - -0.07253600869565346, - 0.04050712173913018, - -0.1248260869565217, - 0.18697981, - 0.23079639130434693, - 0.04050712173913018, - -0.1248260869565217, - 0.18697981, - 0.5341287913043464, - 0.04050712173913018, - -0.1248260869565217, - 0.18697981, - -0.5275346086956532, - 0.3005063217391304, - -0.1248260869565217, - 0.18697981, - -0.22420220869565366, - 0.3005063217391304, - -0.1248260869565217, - 0.18697981, - 0.07913019130434673, - 0.3005063217391304, - -0.1248260869565217, - 0.18697981, - 0.3824625913043471, - 0.3005063217391304, - -0.1248260869565217, - 0.18697981, - -0.22420220869565366, - -0.3278250782608696, - 0.13617391304347837, - 0.18697981, - 0.07913019130434673, - -0.3278250782608696, - 0.13617391304347837, - 0.18697981, - 0.3824625913043471, - -0.3278250782608696, - 0.13617391304347837, - 0.18697981, - -0.37586840869565297, - -0.06782587826086983, - 0.13617391304347837, - 0.18697981, - -0.07253600869565346, - -0.06782587826086983, - 0.13617391304347837, - 0.18697981, - 0.23079639130434693, - -0.06782587826086983, - 0.13617391304347837, - 0.18697981, - 0.5341287913043464, - -0.06782587826086983, - 0.13617391304347837, - 0.18697981, - -0.5275346086956532, - 0.19217332173913038, - 0.13617391304347837, - 0.18697981, - -0.22420220869565366, - 0.19217332173913038, - 0.13617391304347837, - 0.18697981, - 0.07913019130434673, - 0.19217332173913038, - 0.13617391304347837, - 0.18697981, - 0.3824625913043471, - 0.19217332173913038, - 0.13617391304347837, - 0.18697981, - 1000, - 10025, - 3, - 4.2466536, - 3.0441573, - 0.6829999999999999, - 0, - 0, - 0, - 1.0, - 4, - 0, - 0, - 0, - 0.18697981, - 1000, - 10002, - 4, - 0, - 0, - 0, - 0, - 0, - 0, - 1.0, - 4, - 0, - 0, - 0, - 0, - ], - }, - { - "frameNumber": 1, - "time": 36.0, - "data": [ - 1000.0, - 35.0, - 0.0, - 4.3983198, - 2.7733247999999997, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 36.0, - 0.0, - 4.701652200000001, - 2.7733247999999997, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 37.0, - 0.0, - 5.0049846, - 2.7733247999999997, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 38.0, - 0.0, - 5.308317000000001, - 2.7733247999999997, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 39.0, - 0.0, - 4.2466536, - 3.0441573, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 40.0, - 0.0, - 4.5499860000000005, - 3.0441573, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 41.0, - 0.0, - 4.8533184, - 3.0441573, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 42.0, - 0.0, - 5.1566508, - 3.0441573, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 43.0, - 0.0, - 4.3983198, - 3.3041565, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 44.0, - 0.0, - 4.701652200000001, - 3.3041565, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 45.0, - 0.0, - 5.0049846, - 3.3041565, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 46.0, - 0.0, - 5.308317000000001, - 3.3041565, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 47.0, - 0.0, - 4.2466536, - 3.5641557, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 48.0, - 0.0, - 4.5499860000000005, - 3.5641557, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 49.0, - 0.0, - 4.8533184, - 3.5641557, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 50.0, - 0.0, - 5.1566508, - 3.5641557, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000, - 10008, - 1, - 4.755333955318625, - 2.7263123028751712, - 0.5118600096509627, - 0, - 0, - 0, - 1.0, - 44, - -0.4959798053186253, - -0.12955481287517134, - -0.04334475965096268, - 0.18809803, - -0.21201424531862578, - -0.12054490287517128, - -0.07022550965096269, - 0.18809803, - 0.09862539468137488, - -0.11994588287517116, - -0.0811813196509627, - 0.18809803, - 0.4090256446813747, - -0.1424338528751714, - -0.10038918965096266, - 0.18809803, - -0.3904194053186254, - 0.13664715712482867, - -0.0934313996509627, - 0.18809803, - -0.03716005531862532, - 0.15572271712482877, - -0.05236797965096268, - 0.18809803, - 0.24952956468137444, - 0.1316427271248286, - -0.10930103965096266, - 0.18809803, - -0.3613665653186251, - 0.044857907124828955, - 0.15314911034903733, - 0.18809803, - -0.05202583531862537, - 0.0014580971248285834, - 0.16008046034903733, - 0.18809803, - 0.23570780468137453, - 0.013413907124828928, - 0.1552170003490373, - 0.18809803, - 0.5560774946813742, - 0.02873694712482866, - 0.08179463034903733, - 0.18809803, - 1000, - 10014, - 2, - 4.787495886715849, - 3.3723325732242633, - 0.5563642249839672, - 0, - 0, - 0, - 1.0, - 92, - -0.5367313367158486, - -0.20701431322426345, - -0.1412322049839672, - 0.18809803, - -0.2396973667158493, - -0.20510443322426308, - -0.1285622249839672, - 0.18809803, - 0.07795058328415116, - -0.23166254322426338, - -0.1047843749839672, - 0.18809803, - 0.4093069432841512, - -0.22665159322426343, - -0.1575157649839672, - 0.18809803, - -0.3862019367158487, - 0.03138807677573663, - -0.1268679149839672, - 0.18809803, - -0.06616328671584881, - 0.047444736775736907, - -0.10716412498396721, - 0.18809803, - 0.23537127328415064, - 0.013505556775736505, - -0.08235354498396719, - 0.18809803, - 0.5126489832841505, - 0.022758846775736696, - -0.13971390498396719, - 0.18809803, - -0.5223376567158491, - 0.32723837677573675, - -0.1357459049839672, - 0.18809803, - -0.23545405671584874, - 0.3079699767757367, - -0.10008217498396721, - 0.18809803, - 0.08444176328415054, - 0.3216982267757369, - -0.08471171498396718, - 0.18809803, - 0.3990678832841512, - 0.2869947167757365, - -0.1207413649839672, - 0.18809803, - -0.20334275671584923, - -0.3396434432242632, - 0.15648543501603285, - 0.18809803, - 0.09657458328415114, - -0.3126436832242634, - 0.14390809501603274, - 0.18809803, - 0.3571919932841512, - -0.3383341332242633, - 0.10837355501603274, - 0.18809803, - -0.3874341067158493, - -0.08011545322426317, - 0.13722801501603277, - 0.18809803, - -0.06898875671584914, - -0.07576772322426306, - 0.12396819501603284, - 0.18809803, - 0.22660273328415137, - -0.06838381322426335, - 0.1435910850160328, - 0.18809803, - 0.5389750432841511, - -0.02890919322426333, - 0.08743777501603278, - 0.18809803, - -0.5165171167158489, - 0.18988593677573684, - 0.09521577501603284, - 0.18809803, - -0.23180985671584864, - 0.18211605677573672, - 0.1354257050160328, - 0.18809803, - 0.07829122328415128, - 0.18818234677573686, - 0.13913436501603282, - 0.18809803, - 0.37825523328415134, - 0.19504745677573654, - 0.1587072150160328, - 0.18809803, - 1000, - 10025, - 3, - 4.22797133, - 3.03325335, - 0.74915296, - 0, - 0, - 0, - 1.0, - 4, - 0, - 0, - 0, - 0.18809803, - ], - }, - { - "frameNumber": 2, - "time": 72.0, - "data": [ - 1000.0, - 35.0, - 0.0, - 4.3983198, - 2.7733247999999997, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 36.0, - 0.0, - 4.701652200000001, - 2.7733247999999997, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 37.0, - 0.0, - 5.0049846, - 2.7733247999999997, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 38.0, - 0.0, - 5.308317000000001, - 2.7733247999999997, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 39.0, - 0.0, - 4.2466536, - 3.0441573, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 40.0, - 0.0, - 4.5499860000000005, - 3.0441573, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 41.0, - 0.0, - 4.8533184, - 3.0441573, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 42.0, - 0.0, - 5.1566508, - 3.0441573, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 43.0, - 0.0, - 4.3983198, - 3.3041565, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 44.0, - 0.0, - 4.701652200000001, - 3.3041565, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 45.0, - 0.0, - 5.0049846, - 3.3041565, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 46.0, - 0.0, - 5.308317000000001, - 3.3041565, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 47.0, - 0.0, - 4.2466536, - 3.5641557, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 48.0, - 0.0, - 4.5499860000000005, - 3.5641557, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 49.0, - 0.0, - 4.8533184, - 3.5641557, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000.0, - 50.0, - 0.0, - 5.1566508, - 3.5641557, - 0.16099999999999998, - 0.0, - 0.0, - 0.0, - 0.18837494593627718, - 0.0, - 1000, - 10008, - 1, - 4.759469007632346, - 2.710022734301882, - 0.5138546602365159, - 0, - 0, - 0, - 1.0, - 44, - -0.4892159776323455, - -0.16233177430188173, - -0.04762399023651592, - 0.1882706, - -0.20889030763234562, - -0.07935174430188185, - -0.07516356023651594, - 0.1882706, - 0.10049580236765454, - -0.11598376430188173, - -0.06342552023651593, - 0.1882706, - 0.3872237123676543, - -0.15806030430188178, - -0.11942286023651594, - 0.1882706, - -0.41538527763234523, - 0.13516008569811788, - -0.11975010023651594, - 0.1882706, - -0.043588517632345614, - 0.163524915698118, - -0.06511044023651591, - 0.1882706, - 0.28690280236765453, - 0.1280923356981183, - -0.11666178023651591, - 0.1882706, - -0.3625914376323456, - 0.048042645698118225, - 0.14084408976348406, - 0.1882706, - -0.06956299763234597, - -0.028331944301881684, - 0.22592579976348404, - 0.1882706, - 0.26824600236765406, - 0.009221915698117922, - 0.15063988976348408, - 0.1882706, - 0.5463661923676542, - 0.060017645698118294, - 0.0897484797634841, - 0.1882706, - 1000, - 10014, - 2, - 4.806285799240596, - 3.3726477958587093, - 0.556993326654809, - 0, - 0, - 0, - 1.0, - 92, - -0.5483939792405961, - -0.22849490585870935, - -0.15044518665480905, - 0.1882706, - -0.23449975924059618, - -0.19845061585870916, - -0.15421609665480907, - 0.1882706, - 0.0883125807594034, - -0.2025261158587095, - -0.13493780665480903, - 0.1882706, - 0.3962429207594038, - -0.20040478585870947, - -0.17250750665480907, - 0.1882706, - -0.40610481924059627, - 0.04188281414129058, - -0.11978112665480906, - 0.1882706, - -0.0931149592405962, - 0.053624694141290785, - -0.08776491665480907, - 0.1882706, - 0.2079964107594039, - 0.018425334141290772, - -0.08373766665480903, - 0.1882706, - 0.5050494907594034, - 0.03805642414129062, - -0.11822585665480906, - 0.1882706, - -0.5298164492405961, - 0.3523820141412908, - -0.14853099665480907, - 0.1882706, - -0.2079924792405965, - 0.31751330414129075, - -0.10667933665480905, - 0.1882706, - 0.10422041075940403, - 0.3167185341412906, - -0.12523858665480903, - 0.1882706, - 0.41850705075940375, - 0.2939729841412908, - -0.07831207665480905, - 0.1882706, - -0.2239699592405966, - -0.34936758585870953, - 0.133708233345191, - 0.1882706, - 0.08982416075940414, - -0.30619373585870946, - 0.12200107334519095, - 0.1882706, - 0.3608457507594034, - -0.3351345458587094, - 0.153759533345191, - 0.1882706, - -0.39592128924059633, - -0.12325413585870937, - 0.14518854334519093, - 0.1882706, - -0.054375799240596656, - -0.05610295585870917, - 0.14127757334519098, - 0.1882706, - 0.23853449075940336, - -0.07756553585870929, - 0.14562730334519092, - 0.1882706, - 0.5361469007594035, - -0.07129567585870955, - 0.08391924334519096, - 0.1882706, - -0.5219094992405964, - 0.16691234414129053, - 0.11812568334519091, - 0.1882706, - -0.22127055924059658, - 0.1524363041412906, - 0.15388547334519098, - 0.1882706, - 0.09807903075940327, - 0.20389651414129073, - 0.12309504334519095, - 0.1882706, - 0.3936103607594035, - 0.19296930414129054, - 0.15978946334519095, - 0.1882706, - 1000, - 10025, - 3, - 4.21487647, - 3.04925178, - 0.7672043, - 0, - 0, - 0, - 1.0, - 4, - 0, - 0, - 0, - 0.1882706, - ], - }, - ], - }, - "plotData": {"version": CURRENT_VERSION.PLOT_DATA, "data": []}, - }, - ), ], ) -def test_physicell_converter(trajectory, expected_data): +def test_bad_path_to_output_dir(trajectory, expected_data): converter = PhysicellConverter(trajectory) buffer_data = JsonWriter.format_trajectory_data(converter._data) - assert_buffers_equal(buffer_data, expected_data) - assert JsonWriter._check_agent_ids_are_unique_per_frame(buffer_data) + assert expected_data == buffer_data diff --git a/simulariumio/tests/converters/test_readdy_converter.py b/simulariumio/tests/converters/test_readdy_converter.py index c613dd9d..1a9b2767 100644 --- a/simulariumio/tests/converters/test_readdy_converter.py +++ b/simulariumio/tests/converters/test_readdy_converter.py @@ -8,262 +8,419 @@ from simulariumio import UnitData, MetaData, DisplayData, JsonWriter from simulariumio.constants import ( DEFAULT_CAMERA_SETTINGS, - CURRENT_VERSION, DISPLAY_TYPE, + DEFAULT_BOX_SIZE, + VIZ_TYPE, ) +data = ReaddyData( + timestep=0.1, + path_to_readdy_h5="simulariumio/tests/data/readdy/test.h5", +) +converter = ReaddyConverter(data) +results = JsonWriter.format_trajectory_data(converter._data) + + +# test box data default @pytest.mark.parametrize( - "trajectory, expected_data", + "box_size, expected_box_size", [ - # 4 particles 3 frames ( - ReaddyData( - meta_data=MetaData( - box_size=np.array([20.0, 20.0, 20.0]), - ), - timestep=0.1, - path_to_readdy_h5="simulariumio/tests/data/readdy/test.h5", - display_data={ - "A": DisplayData( - name="C", - display_type=DISPLAY_TYPE.SPHERE, - radius=3.0, - color="#0080ff", - ), - "B": DisplayData( - name="B", - radius=2.0, - display_type=DISPLAY_TYPE.OBJ, - url="c.obj", - color="#dfdacd", - ), - "D": DisplayData( - name="C", - display_type=DISPLAY_TYPE.SPHERE, - radius=3.0, - color="#0080ff", - ), + results["trajectoryInfo"]["size"], + { + "x": DEFAULT_BOX_SIZE[0], + "y": DEFAULT_BOX_SIZE[1], + "z": DEFAULT_BOX_SIZE[2], + }, + ) + ], +) +def test_box_size_default(box_size, expected_box_size): + assert box_size == expected_box_size + + +# test default camera settings +@pytest.mark.parametrize( + "camera_settings, expected_camera_settings", + [ + ( + results["trajectoryInfo"]["cameraDefault"], + { + "position": { + "x": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[0], + "y": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[1], + "z": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[2], + }, + "lookAtPosition": { + "x": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[0], + "y": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[1], + "z": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[2], }, - ignore_types=["E"], - time_units=UnitData("ms", 1e-6), - spatial_units=UnitData("nm"), - ), + "upVector": { + "x": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[0], + "y": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[1], + "z": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[2], + }, + "fovDegrees": DEFAULT_CAMERA_SETTINGS.FOV_DEGREES, + }, + ) + ], +) +def test_camera_setting_default(camera_settings, expected_camera_settings): + assert camera_settings == expected_camera_settings + + +# test time units default +@pytest.mark.parametrize( + "timeUnits, expected_timeUnits", + [ + ( + results["trajectoryInfo"]["timeUnits"], { - "trajectoryInfo": { - "version": CURRENT_VERSION.TRAJECTORY_INFO, - "timeUnits": { - "magnitude": 1.0, - "name": "ns", + "magnitude": 1.0, + "name": "s", + }, + ) + ], +) +def test_timeUnits_default(timeUnits, expected_timeUnits): + assert timeUnits == expected_timeUnits + + +# test spatial units default +@pytest.mark.parametrize( + "spatialUnits, expected_spatialUnits", + [ + ( + results["trajectoryInfo"]["spatialUnits"], + { + "magnitude": 1.0, + "name": "m", + }, + ) + ], +) +def test_spatialUnits_default(spatialUnits, expected_spatialUnits): + assert spatialUnits == expected_spatialUnits + + +# test type mapping default +@pytest.mark.parametrize( + "typeMapping, expected_typeMapping", + [ + ( + results["trajectoryInfo"]["typeMapping"], + { + "0": { + "name": "A", + "geometry": { + "displayType": "SPHERE", }, - "timeStepSize": 0.1, - "totalSteps": 3, - "spatialUnits": { - "magnitude": 1.0, - "name": "nm", + }, + "1": { + "name": "B", + "geometry": { + "displayType": "SPHERE", }, - "size": {"x": 20.0, "y": 20.0, "z": 20.0}, - "cameraDefault": { - "position": { - "x": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[2], - }, - "lookAtPosition": { - "x": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[2], - }, - "upVector": { - "x": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[0], - "y": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[1], - "z": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[2], - }, - "fovDegrees": DEFAULT_CAMERA_SETTINGS.FOV_DEGREES, + }, + }, + ) + ], +) +def test_typeMapping_default(typeMapping, expected_typeMapping): + assert expected_typeMapping == typeMapping + + +time_unit_name = "ns" +time_unit_value = 1.0 +spatial_unit_name = "nm" +data_with_unit_data = ReaddyData( + timestep=0.1, + path_to_readdy_h5="simulariumio/tests/data/readdy/test.h5", + time_units=UnitData(time_unit_name, time_unit_value), + spatial_units=UnitData(spatial_unit_name), +) +converter_unit_data = ReaddyConverter(data_with_unit_data) +results_unit_data = JsonWriter.format_trajectory_data(converter_unit_data._data) + + +# test time units provided +@pytest.mark.parametrize( + "timeUnits, expected_timeUnits", + [ + ( + results_unit_data["trajectoryInfo"]["timeUnits"], + { + "magnitude": time_unit_value, + "name": time_unit_name, + }, + ) + ], +) +def test_timeUnits_provided(timeUnits, expected_timeUnits): + assert timeUnits == expected_timeUnits + + +# test spatial units provided +@pytest.mark.parametrize( + "spatialUnits, expected_spatialUnits", + [ + ( + results_unit_data["trajectoryInfo"]["spatialUnits"], + { + "magnitude": 1.0, + "name": spatial_unit_name, + }, + ) + ], +) +def test_spatialUnits_provided(spatialUnits, expected_spatialUnits): + assert spatialUnits == expected_spatialUnits + + +size_x = 20.0 +size_y = 20.0 +size_z = 10.0 +data_with_meta_data = ReaddyData( + meta_data=MetaData( + box_size=np.array([size_x, size_y, size_z]), + ), + timestep=0.1, + path_to_readdy_h5="simulariumio/tests/data/readdy/test.h5", +) +converter_meta_data = ReaddyConverter(data_with_meta_data) +results_meta_data = JsonWriter.format_trajectory_data(converter_meta_data._data) + + +# test box data provided +@pytest.mark.parametrize( + "box_size, expected_box_size", + [ + ( + results_meta_data["trajectoryInfo"]["size"], + {"x": size_x, "y": size_y, "z": size_z}, + ) + ], +) +def test_box_size_provided(box_size, expected_box_size): + assert box_size == expected_box_size + + +radius_0 = 3.0 +radius_1 = 2.0 +name_0 = "C" +name_1 = "B" +color_0 = "#0080ff" +color_1 = "#dfdacd" +data_with_display_data = ReaddyData( + timestep=0.1, + path_to_readdy_h5="simulariumio/tests/data/readdy/test.h5", + display_data={ + "A": DisplayData( + name=name_0, + display_type=DISPLAY_TYPE.SPHERE, + radius=radius_0, + color=color_0, + ), + "B": DisplayData( + name=name_1, + radius=radius_1, + display_type=DISPLAY_TYPE.OBJ, + url="c.obj", + color=color_1, + ), + "D": DisplayData( + name=name_0, + display_type=DISPLAY_TYPE.SPHERE, + radius=radius_0, + color=color_0, + ), + }, +) +converter_display_data = ReaddyConverter(data_with_display_data) +results_display_data = JsonWriter.format_trajectory_data(converter_display_data._data) + + +# test type mapping provided +@pytest.mark.parametrize( + "typeMapping, expected_typeMapping", + [ + ( + results_display_data["trajectoryInfo"]["typeMapping"], + { + "0": { + "name": name_0, + "geometry": { + "displayType": "SPHERE", + "color": color_0, }, - "typeMapping": { - "0": { - "name": "C", - "geometry": { - "displayType": "SPHERE", - "color": "#0080ff", - }, - }, - "1": { - "name": "B", - "geometry": { - "displayType": "OBJ", - "url": "c.obj", - "color": "#dfdacd", - }, - }, + }, + "1": { + "name": name_1, + "geometry": { + "displayType": "OBJ", + "url": "c.obj", + "color": color_1, }, }, - "spatialData": { - "version": CURRENT_VERSION.SPATIAL_DATA, - "msgType": 1, - "bundleStart": 0, - "bundleSize": 3, - "bundleData": [ - { - "frameNumber": 0, - "time": 0.0, - "data": [ - 1000.0, - 0.0, - 0.0, - -4.076107488021348, - 3.9849372168961708, - 7.892235671222785, - 0.0, - 0.0, - 0.0, - 3.0, - 0.0, - 1000.0, - 1.0, - 1.0, - -2.780407911074236, - 4.762366216929244, - 9.202490133610398, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1000.0, - 2.0, - 0.0, - 8.19869797660185, - 1.4425866729829266, - 6.215047907498356, - 0.0, - 0.0, - 0.0, - 3.0, - 0.0, - 1000.0, - 3.0, - 1.0, - 8.66544980756901, - 1.97558947182814, - 8.08535556794141, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - ], - }, - { - "frameNumber": 1, - "time": 0.1, - "data": [ - 1000.0, - 0.0, - 0.0, - -3.600301271046627, - 4.360124409946104, - 6.956371030429721, - 0.0, - 0.0, - 0.0, - 3.0, - 0.0, - 1000.0, - 1.0, - 1.0, - -2.761977374836856, - 4.835017769931593, - 9.136878226258032, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1000.0, - 2.0, - 0.0, - 7.755862317430045, - 1.3102736549734222, - 6.862906605118455, - 0.0, - 0.0, - 0.0, - 3.0, - 0.0, - 1000.0, - 3.0, - 1.0, - 8.704102749692902, - 1.8166930930965905, - 7.8727242890809475, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - ], - }, - { - "frameNumber": 2, - "time": 0.2, - "data": [ - 1000.0, - 0.0, - 0.0, - -2.5613935239104135, - 5.2768511678362575, - -9.666619435197141, - 0.0, - 0.0, - 0.0, - 3.0, - 0.0, - 1000.0, - 1.0, - 1.0, - -4.252869632733068, - 4.420710058343225, - 6.427577234992345, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1000.0, - 2.0, - 0.0, - 4.230292288749659, - 0.2170518151763472, - 3.88903614029613, - 0.0, - 0.0, - 0.0, - 3.0, - 0.0, - 1000.0, - 3.0, - 1.0, - -8.417490965010238, - 4.002378907710486, - -9.198614964227042, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - ], - }, - ], + }, + ) + ], +) +def test_typeMapping_provided(typeMapping, expected_typeMapping): + assert expected_typeMapping == typeMapping + + +data_with_ignore_type = ReaddyData( + timestep=0.1, + path_to_readdy_h5="simulariumio/tests/data/readdy/test.h5", + display_data={ + "A": DisplayData( + name=name_0, + display_type=DISPLAY_TYPE.SPHERE, + radius=radius_0, + color=color_0, + ), + "B": DisplayData( + name=name_1, + radius=radius_1, + display_type=DISPLAY_TYPE.OBJ, + url="c.obj", + color=color_1, + ), + "D": DisplayData( + name=name_0, + display_type=DISPLAY_TYPE.SPHERE, + radius=radius_0, + color=color_0, + ), + }, + ignore_types=[name_1], +) +converter_ignore_type = ReaddyConverter(data_with_ignore_type) +results_ignore_types = JsonWriter.format_trajectory_data(converter_ignore_type._data) + + +@pytest.mark.parametrize( + "bundleData, expected_bundleData", + [ + ( + results_display_data["spatialData"]["bundleData"][0], + [ + VIZ_TYPE.DEFAULT, # first agent + 0.0, # id + 0.0, # type + -4.076107488021348, # x + 3.9849372168961708, # y + 7.892235671222785, # z + 0.0, # x rotation + 0.0, # y rotation + 0.0, # z rotation + radius_0, # radius + 0.0, # subpoints + VIZ_TYPE.DEFAULT, + 1.0, + 1.0, + -2.780407911074236, + 4.762366216929244, + 9.202490133610398, + 0.0, + 0.0, + 0.0, + radius_1, + 0.0, + VIZ_TYPE.DEFAULT, + 2.0, + 0.0, + 8.19869797660185, + 1.4425866729829266, + 6.215047907498356, + 0.0, + 0.0, + 0.0, + radius_0, + 0.0, + VIZ_TYPE.DEFAULT, + 3.0, + 1.0, + 8.66544980756901, + 1.97558947182814, + 8.08535556794141, + 0.0, + 0.0, + 0.0, + radius_1, + 0.0, + ], + ) + ], +) +def test_bundleData(bundleData, expected_bundleData): + assert expected_bundleData == bundleData["data"] + + +def test_agent_ids(): + assert JsonWriter._check_agent_ids_are_unique_per_frame(results_display_data) + + +# test type mapping with ignore types +@pytest.mark.parametrize( + "typeMapping, expected_typeMapping", + [ + ( + results_ignore_types["trajectoryInfo"]["typeMapping"], + { + "0": { + "name": name_0, + "geometry": { + "displayType": "SPHERE", + "color": color_0, + }, }, - "plotData": {"version": CURRENT_VERSION.PLOT_DATA, "data": []}, }, ) ], ) -def test_readdy_converter(trajectory, expected_data): - converter = ReaddyConverter(trajectory) - buffer_data = JsonWriter.format_trajectory_data(converter._data) - assert expected_data == buffer_data - assert JsonWriter._check_agent_ids_are_unique_per_frame(buffer_data) +def test_typeMapping_ignore_types(typeMapping, expected_typeMapping): + assert expected_typeMapping == typeMapping + + +@pytest.mark.parametrize( + "bundleData, expected_bundleData", + [ + ( + results_ignore_types["spatialData"]["bundleData"][0], + [ + VIZ_TYPE.DEFAULT, # first agent + 0.0, # id + 0.0, # type + -4.076107488021348, # x + 3.9849372168961708, # y + 7.892235671222785, # z + 0.0, # x rotation + 0.0, # y rotation + 0.0, # z rotation + radius_0, # radius + 0.0, # subpoints + VIZ_TYPE.DEFAULT, + 2.0, + 0.0, + 8.19869797660185, + 1.4425866729829266, + 6.215047907498356, + 0.0, + 0.0, + 0.0, + radius_0, + 0.0, + ], + ) + ], +) +def test_bundleData_ignored_types(bundleData, expected_bundleData): + assert expected_bundleData == bundleData["data"] + + +def test_agent_ids_ignored_types(): + assert JsonWriter._check_agent_ids_are_unique_per_frame(results_display_data) diff --git a/simulariumio/tests/converters/test_smoldyn_converter.py b/simulariumio/tests/converters/test_smoldyn_converter.py index c86c8247..d87878b9 100644 --- a/simulariumio/tests/converters/test_smoldyn_converter.py +++ b/simulariumio/tests/converters/test_smoldyn_converter.py @@ -10,453 +10,454 @@ ) from simulariumio import MetaData, UnitData, DisplayData, InputFileData, JsonWriter from simulariumio.constants import ( + DEFAULT_BOX_SIZE, DEFAULT_CAMERA_SETTINGS, - CURRENT_VERSION, DISPLAY_TYPE, + VIZ_TYPE, ) +data = SmoldynData( + smoldyn_file=InputFileData( + file_path="simulariumio/tests/data/smoldyn/example_data.txt" + ) +) +converter = SmoldynConverter(data) +results = JsonWriter.format_trajectory_data(converter._data) + +# test box data default @pytest.mark.parametrize( - "trajectory, expected_data", + "box_size, expected_box_size", [ - # 2D ( - SmoldynData( - meta_data=MetaData( - box_size=np.array([2.0, 2.0, 0.1]), - scale_factor=100, - ), - smoldyn_file=InputFileData( - file_path="simulariumio/tests/data/smoldyn/example_2D.txt" - ), - display_data={ - "S(solution)": DisplayData( - name="S", - radius=0.01, - display_type=DISPLAY_TYPE.OBJ, - url="s.obj", - color="#dfdacd", - ), - "E(front)": DisplayData( - name="E", - display_type=DISPLAY_TYPE.SPHERE, - radius=0.1, - color="#0080ff", - ), - "ES(front)": DisplayData( - name="ES", - display_type=DISPLAY_TYPE.SPHERE, - ), - }, - ), + results["trajectoryInfo"]["size"], { - "trajectoryInfo": { - "version": CURRENT_VERSION.TRAJECTORY_INFO, - "timeUnits": { - "magnitude": 1.0, - "name": "s", - }, - "timeStepSize": 0.01, - "totalSteps": 3, - "spatialUnits": { - "magnitude": 10, - "name": "mm", + "x": DEFAULT_BOX_SIZE[0], + "y": DEFAULT_BOX_SIZE[1], + "z": DEFAULT_BOX_SIZE[2], + }, + ) + ], +) +def test_box_size_default(box_size, expected_box_size): + assert box_size == expected_box_size + + +# test type mapping default +@pytest.mark.parametrize( + "typeMapping, expected_typeMapping", + [ + ( + results["trajectoryInfo"]["typeMapping"], + { + "0": { + "name": "S(solution)", + "geometry": { + "displayType": "SPHERE", }, - "size": {"x": 200.0, "y": 200.0, "z": 10.0}, - "cameraDefault": { - "position": { - "x": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[2], - }, - "lookAtPosition": { - "x": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[2], - }, - "upVector": { - "x": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[0], - "y": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[1], - "z": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[2], - }, - "fovDegrees": DEFAULT_CAMERA_SETTINGS.FOV_DEGREES, + }, + "1": { + "name": "E(front)", + "geometry": { + "displayType": "SPHERE", }, - "typeMapping": { - "0": { - "name": "S", - "geometry": { - "displayType": "OBJ", - "url": "s.obj", - "color": "#dfdacd", - }, - }, - "1": { - "name": "E", - "geometry": { - "displayType": "SPHERE", - "color": "#0080ff", - }, - }, - "2": { - "name": "ES", - "geometry": { - "displayType": "SPHERE", - }, - }, + }, + "2": { + "name": "ES(front)", + "geometry": { + "displayType": "SPHERE", }, }, - "spatialData": { - "version": CURRENT_VERSION.SPATIAL_DATA, - "msgType": 1, - "bundleStart": 0, - "bundleSize": 3, - "bundleData": [ - { - "frameNumber": 0, - "time": 0.0, - "data": [ - 1000.0, - 500.0, - 0.0, - -87.48, - -45.101200000000006, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 499.0, - 0.0, - 63.683, - 44.5285, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 600.0, - 1.0, - 84.49889999999999, - -53.4784, - 0.0, - 0.0, - 0.0, - 0.0, - 10.0, - 0.0, - ], - }, - { - "frameNumber": 1, - "time": 0.01, - "data": [ - 1000.0, - 500.0, - 0.0, - -81.3601, - -46.5024, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 499.0, - 0.0, - 68.1931, - 26.2768, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 600.0, - 1.0, - 84.49889999999999, - -53.4784, - 0.0, - 0.0, - 0.0, - 0.0, - 10.0, - 0.0, - 1000.0, - 606.0, - 2.0, - 66.6775, - 74.52590000000001, - 0.0, - 0.0, - 0.0, - 0.0, - 100.0, - 0.0, - ], - }, - { - "frameNumber": 2, - "time": 0.02, - "data": [ - 1000.0, - 500.0, - 0.0, - -82.8472, - -51.7215, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 600.0, - 1.0, - 84.49889999999999, - -53.4784, - 0.0, - 0.0, - 0.0, - 0.0, - 10.0, - 0.0, - 1000.0, - 602.0, - 2.0, - 26.263199999999998, - -96.4896, - 0.0, - 0.0, - 0.0, - 0.0, - 100.0, - 0.0, - ], - }, - ], + }, + ) + ], +) +def test_typeMapping_default(typeMapping, expected_typeMapping): + assert expected_typeMapping == typeMapping + + +# test default camera settings +@pytest.mark.parametrize( + "camera_settings, expected_camera_settings", + [ + ( + results["trajectoryInfo"]["cameraDefault"], + { + "position": { + "x": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[0], + "y": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[1], + "z": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[2], }, - "plotData": {"version": CURRENT_VERSION.PLOT_DATA, "data": []}, + "lookAtPosition": { + "x": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[0], + "y": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[1], + "z": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[2], + }, + "upVector": { + "x": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[0], + "y": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[1], + "z": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[2], + }, + "fovDegrees": DEFAULT_CAMERA_SETTINGS.FOV_DEGREES, + }, + ) + ], +) +def test_camera_setting_default(camera_settings, expected_camera_settings): + assert camera_settings == expected_camera_settings + + +# test time units default +@pytest.mark.parametrize( + "timeUnits, expected_timeUnits", + [ + ( + results["trajectoryInfo"]["timeUnits"], + { + "magnitude": 1.0, + "name": "s", + }, + ) + ], +) +def test_timeUnits_default(timeUnits, expected_timeUnits): + assert timeUnits == expected_timeUnits + + +# test spatial units default +@pytest.mark.parametrize( + "spatialUnits, expected_spatialUnits", + [ + ( + results["trajectoryInfo"]["spatialUnits"], + { + "magnitude": 1.0, + "name": "m", }, + ) + ], +) +def test_spatialUnits_default(spatialUnits, expected_spatialUnits): + assert spatialUnits == expected_spatialUnits + + +x_size = 2.0 +y_size = 2.0 +z_size = 0.1 +scale_factor = 100 +data_with_meta_data = SmoldynData( + meta_data=MetaData( + box_size=np.array([x_size, y_size, z_size]), + scale_factor=scale_factor, + ), + smoldyn_file=InputFileData( + file_path="simulariumio/tests/data/smoldyn/example_data.txt" + ), +) +converter_meta_data = SmoldynConverter(data_with_meta_data) +results_meta_data = JsonWriter.format_trajectory_data(converter_meta_data._data) + + +# test box size provided +@pytest.mark.parametrize( + "box_size, expected_box_size", + [ + ( + results_meta_data["trajectoryInfo"]["size"], + { + "x": x_size * scale_factor, + "y": y_size * scale_factor, + "z": z_size * scale_factor, + }, + ) + ], +) +def test_box_size_provided(box_size, expected_box_size): + # if a box size is provided, we should use it + assert box_size == expected_box_size + + +time_unit_name = "ns" +time_unit_value = 1.0 +spatial_unit_name = "nm" +data_with_unit_data = SmoldynData( + time_units=UnitData(time_unit_name, time_unit_value), + spatial_units=UnitData(spatial_unit_name), + smoldyn_file=InputFileData( + file_path="simulariumio/tests/data/smoldyn/example_data.txt" + ), +) +converter_unit_data = SmoldynConverter(data_with_unit_data) +results_unit_data = JsonWriter.format_trajectory_data(converter_unit_data._data) + + +# test time units provided +@pytest.mark.parametrize( + "timeUnits, expected_timeUnits", + [ + ( + results_unit_data["trajectoryInfo"]["timeUnits"], + { + "magnitude": time_unit_value, + "name": time_unit_name, + }, + ) + ], +) +def test_timeUnits_provided(timeUnits, expected_timeUnits): + assert timeUnits == expected_timeUnits + + +# test spatial units provided +@pytest.mark.parametrize( + "spatialUnits, expected_spatialUnits", + [ + ( + results_unit_data["trajectoryInfo"]["spatialUnits"], + { + "magnitude": 1.0, + "name": spatial_unit_name, + }, + ) + ], +) +def test_spatialUnits_provided(spatialUnits, expected_spatialUnits): + assert spatialUnits == expected_spatialUnits + + +s_radius = 0.01 +s_url = "s.obj" +s_color = "#dfdacd" +e_radius = 0.1 +e_color = "#0080ff" +data_with_display_data = SmoldynData( + meta_data=MetaData( + box_size=np.array([x_size, y_size, z_size]), + scale_factor=scale_factor, + ), + smoldyn_file=InputFileData( + file_path="simulariumio/tests/data/smoldyn/example_data.txt" + ), + display_data={ + "S(solution)": DisplayData( + name="S", + radius=s_radius, + display_type=DISPLAY_TYPE.OBJ, + url=s_url, + color=s_color, + ), + "E(front)": DisplayData( + name="E", + display_type=DISPLAY_TYPE.SPHERE, + radius=e_radius, + color=e_color, ), - # 3D + "ES(front)": DisplayData( + name="ES", + display_type=DISPLAY_TYPE.SPHERE, + ), + }, +) +converter_display_data = SmoldynConverter(data_with_display_data) +results_display_data = JsonWriter.format_trajectory_data(converter_display_data._data) + + +# test type mapping with display data provided +@pytest.mark.parametrize( + "typeMapping, expected_typeMapping", + [ ( - SmoldynData( - meta_data=MetaData( - box_size=np.array([100.0, 100.0, 100.0]), - ), - smoldyn_file=InputFileData( - file_contents=( - "0 0\n" - "green(solution) 23.4545 49.2404 12.29 130\n" - "green(solution) 83.9871 56.5501 33.9238 129\n" - "red(solution) 20 30 20 100\n" - "red(solution) 20 30 20 99\n" - "0.01 0\n" - "green(solution) 23.4969 49.2821 12.5752 130\n" - "red(solution) 20.0684 30.3008 20.2782 100\n" - "red(solution) 20.2498 29.916 19.949 99\n" - "0.02 0\n" - "green(solution) 23.5342 49.3372 12.6891 130\n" - "red(solution) 20.5348 30.1101 19.7543 100\n" - "\n" - ), - ), - display_data={ - "green(solution)": DisplayData( - name="Green", - display_type=DISPLAY_TYPE.SPHERE, - radius=2.0, - color="#dfdacd", - ), - }, - spatial_units=UnitData("m"), - ), + results_display_data["trajectoryInfo"]["typeMapping"], { - "trajectoryInfo": { - "version": CURRENT_VERSION.TRAJECTORY_INFO, - "timeUnits": { - "magnitude": 1.0, - "name": "s", + "0": { + "name": "S", + "geometry": { + "displayType": "OBJ", + "url": s_url, + "color": s_color, }, - "timeStepSize": 0.01, - "totalSteps": 3, - "spatialUnits": { - "magnitude": 1, - "name": "m", + }, + "1": { + "name": "E", + "geometry": { + "displayType": "SPHERE", + "color": e_color, }, - "size": {"x": 100.0, "y": 100.0, "z": 100.0}, - "cameraDefault": { - "position": { - "x": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[2], - }, - "lookAtPosition": { - "x": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[2], - }, - "upVector": { - "x": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[0], - "y": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[1], - "z": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[2], - }, - "fovDegrees": DEFAULT_CAMERA_SETTINGS.FOV_DEGREES, + }, + "2": { + "name": "ES", + "geometry": { + "displayType": "SPHERE", }, - "typeMapping": { - "0": { - "name": "Green", - "geometry": { - "displayType": "SPHERE", - "color": "#dfdacd", - }, - }, - "1": { - "name": "red(solution)", - "geometry": { - "displayType": "SPHERE", - }, - }, + }, + }, + ) + ], +) +def test_typeMapping_with_display_data(typeMapping, expected_typeMapping): + assert expected_typeMapping == typeMapping + + +@pytest.mark.parametrize( + "bundleData, expected_bundleData", + [ + ( + # just testing the first frame + results_display_data["spatialData"]["bundleData"][0], + [ + VIZ_TYPE.DEFAULT, # first agent + 500.0, # id + 0.0, # type + -87.48, # x + -45.101200000000006, # y + 0.0, # z + 0.0, # x rotation + 0.0, # y rotation + 0.0, # z rotation + s_radius * scale_factor, # radius + 0.0, # number of subpoints + VIZ_TYPE.DEFAULT, # second agent + 600.0, + 1.0, + 84.49889999999999, + -53.4784, + 0.0, + 0.0, + 0.0, + 0.0, + e_radius * scale_factor, + 0.0, + VIZ_TYPE.DEFAULT, # third agent + 606.0, + 2.0, + 66.6775, + 74.52590000000001, + 0.0, + 0.0, + 0.0, + 0.0, + scale_factor, # default radius = 1.0 + 0.0, + ], + ) + ], +) +def test_bundleData(bundleData, expected_bundleData): + assert expected_bundleData == bundleData["data"] + + +def test_agent_ids(): + assert JsonWriter._check_agent_ids_are_unique_per_frame(results_display_data) + + +# test 3D data +size = 100.0 +green_name = "Green" +green_radius = 2.0 +green_color = "#dfdacd" +data_3D = SmoldynData( + meta_data=MetaData( + box_size=np.array([size, size, size]), + ), + smoldyn_file=InputFileData( + file_path="simulariumio/tests/data/smoldyn/example_3D.txt" + ), + display_data={ + "green(solution)": DisplayData( + name=green_name, + display_type=DISPLAY_TYPE.SPHERE, + radius=green_radius, + color=green_color, + ), + }, + spatial_units=UnitData("m"), +) +converter_3D_data = SmoldynConverter(data_3D) +results_3D_data = JsonWriter.format_trajectory_data(converter_3D_data._data) + + +# test type mapping with display data provided +@pytest.mark.parametrize( + "typeMapping, expected_typeMapping", + [ + ( + results_3D_data["trajectoryInfo"]["typeMapping"], + { + "0": { + "name": green_name, + "geometry": { + "displayType": "SPHERE", + "color": green_color, }, }, - "spatialData": { - "version": CURRENT_VERSION.SPATIAL_DATA, - "msgType": 1, - "bundleStart": 0, - "bundleSize": 3, - "bundleData": [ - { - "frameNumber": 0, - "time": 0.0, - "data": [ - 1000.0, - 130.0, - 0.0, - 23.4545, - 49.2404, - 12.29, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1000.0, - 129.0, - 0.0, - 83.9871, - 56.5501, - 33.9238, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1000.0, - 100.0, - 1.0, - 20, - 30, - 20, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 99.0, - 1.0, - 20, - 30, - 20, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - ], - }, - { - "frameNumber": 1, - "time": 0.01, - "data": [ - 1000.0, - 130.0, - 0.0, - 23.4969, - 49.2821, - 12.5752, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1000.0, - 100.0, - 1.0, - 20.0684, - 30.3008, - 20.2782, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 99.0, - 1.0, - 20.2498, - 29.916, - 19.949, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - ], - }, - { - "frameNumber": 2, - "time": 0.02, - "data": [ - 1000.0, - 130.0, - 0.0, - 23.5342, - 49.3372, - 12.6891, - 0.0, - 0.0, - 0.0, - 2.0, - 0.0, - 1000.0, - 100.0, - 1.0, - 20.5348, - 30.1101, - 19.7543, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - ], - }, - ], + "1": { + "name": "red(solution)", + "geometry": { + "displayType": "SPHERE", + }, }, - "plotData": {"version": CURRENT_VERSION.PLOT_DATA, "data": []}, }, - ), + ) + ], +) +def test_typeMapping_with_3D_data(typeMapping, expected_typeMapping): + assert expected_typeMapping == typeMapping + + +@pytest.mark.parametrize( + "bundleData, expected_bundleData", + [ + ( + # just testing the first frame + results_3D_data["spatialData"]["bundleData"][0], + [ + VIZ_TYPE.DEFAULT, # first agent + 130.0, # id + 0.0, # type + 23.4545, # x + 49.2404, # y + 12.29, # z + 0.0, # x rotation + 0.0, # y rotation + 0.0, # z rotation + green_radius, # radius + 0.0, # subpoints + VIZ_TYPE.DEFAULT, # second agent + 129.0, + 0.0, + 83.9871, + 56.5501, + 33.9238, + 0.0, + 0.0, + 0.0, + green_radius, + 0.0, + VIZ_TYPE.DEFAULT, # third agent + 100.0, + 1.0, + 20, + 30, + 20, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + VIZ_TYPE.DEFAULT, # fourth agent + 99.0, + 1.0, + 20, + 30, + 20, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + ], + ) ], ) -def test_smoldyn_converter(trajectory, expected_data): - converter = SmoldynConverter(trajectory) - buffer_data = JsonWriter.format_trajectory_data(converter._data) - assert expected_data == buffer_data - assert JsonWriter._check_agent_ids_are_unique_per_frame(buffer_data) +def test_bundleData_3D(bundleData, expected_bundleData): + assert expected_bundleData == bundleData["data"] diff --git a/simulariumio/tests/converters/test_springsalad_converter.py b/simulariumio/tests/converters/test_springsalad_converter.py index c97600c3..d1b95a28 100644 --- a/simulariumio/tests/converters/test_springsalad_converter.py +++ b/simulariumio/tests/converters/test_springsalad_converter.py @@ -1,577 +1,421 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +import numpy as np import pytest from simulariumio.springsalad import SpringsaladConverter, SpringsaladData from simulariumio import DisplayData, MetaData, InputFileData, JsonWriter from simulariumio.constants import ( DEFAULT_CAMERA_SETTINGS, - CURRENT_VERSION, DISPLAY_TYPE, + DEFAULT_BOX_SIZE, + VIZ_TYPE, ) +data = SpringsaladData( + sim_view_txt_file=InputFileData( + file_path=("simulariumio/tests/data/springsalad/test.txt"), + ), + draw_bonds=False, +) +converter = SpringsaladConverter(data) +results = JsonWriter.format_trajectory_data(converter._data) + + +# test box data default +@pytest.mark.parametrize( + "box_size, expected_box_size", + [ + ( + results["trajectoryInfo"]["size"], + { + "x": DEFAULT_BOX_SIZE[0], + "y": DEFAULT_BOX_SIZE[1], + "z": DEFAULT_BOX_SIZE[2], + }, + ) + ], +) +def test_box_size_default(box_size, expected_box_size): + assert box_size == expected_box_size + + +# test default camera settings @pytest.mark.parametrize( - "trajectory, expected_data", + "camera_settings, expected_camera_settings", [ - # truncated data from tutorial example ( - SpringsaladData( - sim_view_txt_file=InputFileData( - file_path=( - "simulariumio/tests/data/springsalad/" - "Simulation0_SIM_VIEW_Run0.txt" - ), - ), - meta_data=MetaData( - scale_factor=0.1, - ), - display_data={ - "GREEN": DisplayData( - name="A", - radius=10.0, - display_type=DISPLAY_TYPE.OBJ, - url="a.obj", - color="#dfdacd", - ), - "RED": DisplayData( - name="B", - display_type=DISPLAY_TYPE.SPHERE, - color="#0080ff", - ), + results["trajectoryInfo"]["cameraDefault"], + { + "position": { + "x": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[0], + "y": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[1], + "z": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[2], + }, + "lookAtPosition": { + "x": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[0], + "y": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[1], + "z": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[2], + }, + "upVector": { + "x": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[0], + "y": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[1], + "z": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[2], }, - draw_bonds=False, - ), + "fovDegrees": DEFAULT_CAMERA_SETTINGS.FOV_DEGREES, + }, + ) + ], +) +def test_camera_setting_default(camera_settings, expected_camera_settings): + assert camera_settings == expected_camera_settings + + +# test type mapping default +@pytest.mark.parametrize( + "typeMapping, expected_typeMapping", + [ + ( + results["trajectoryInfo"]["typeMapping"], { - "trajectoryInfo": { - "version": CURRENT_VERSION.TRAJECTORY_INFO, - "timeUnits": { - "magnitude": 1.0, - "name": "s", + "0": { + "name": "GREEN", + "geometry": { + "displayType": "SPHERE", }, - "timeStepSize": 0.1, - "totalSteps": 2, - "spatialUnits": { - "magnitude": 10.0, - "name": "nm", + }, + "1": { + "name": "RED", + "geometry": { + "displayType": "SPHERE", }, - "size": {"x": 10.0, "y": 10.0, "z": 20.0}, - "cameraDefault": { - "position": { - "x": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[2], - }, - "lookAtPosition": { - "x": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[2], - }, - "upVector": { - "x": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[0], - "y": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[1], - "z": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[2], - }, - "fovDegrees": DEFAULT_CAMERA_SETTINGS.FOV_DEGREES, + }, + "2": { + "name": "GRAY", + "geometry": { + "displayType": "SPHERE", }, - "typeMapping": { - "0": { - "name": "A", - "geometry": { - "displayType": "OBJ", - "url": "a.obj", - "color": "#dfdacd", - }, - }, - "1": { - "name": "B", - "geometry": { - "displayType": "SPHERE", - "color": "#0080ff", - }, - }, - "2": { - "name": "GRAY", - "geometry": { - "displayType": "SPHERE", - }, - }, - "3": { - "name": "CYAN", - "geometry": { - "displayType": "SPHERE", - }, - }, - "4": { - "name": "BLUE", - "geometry": { - "displayType": "SPHERE", - }, - }, + }, + }, + ) + ], +) +def test_typeMapping_default(typeMapping, expected_typeMapping): + assert expected_typeMapping == typeMapping + + +scale_factor = 0.1 +size_x = 100.0 +size_y = 100.0 +size_z = 10.0 +data_with_metadata = SpringsaladData( + sim_view_txt_file=InputFileData( + file_path=("simulariumio/tests/data/springsalad/" "test.txt"), + ), + meta_data=MetaData( + scale_factor=scale_factor, + box_size=np.array([size_x, size_y, size_z]), + ), +) +converter_metadata = SpringsaladConverter(data_with_metadata) +results_metadata = JsonWriter.format_trajectory_data(converter_metadata._data) + + +# test box data provided +@pytest.mark.parametrize( + "box_size, expected_box_size", + [ + ( + results_metadata["trajectoryInfo"]["size"], + { + "x": size_x * scale_factor, + "y": size_y * scale_factor, + "z": size_z * scale_factor, + }, + ) + ], +) +def test_box_size_provided(box_size, expected_box_size): + assert box_size == expected_box_size + + +radius_0 = 10.0 +name_0 = "A" +name_1 = "B" +color_0 = "#dfdacd" +color_1 = "#0080ff" +url_0 = "a.obj" +data_with_display_data = SpringsaladData( + sim_view_txt_file=InputFileData( + file_path=("simulariumio/tests/data/springsalad/" "test.txt"), + ), + meta_data=MetaData( + scale_factor=scale_factor, + box_size=np.array([size_x, size_y, size_z]), + ), + display_data={ + "GREEN": DisplayData( + name=name_0, + radius=radius_0, + display_type=DISPLAY_TYPE.OBJ, + url=url_0, + color=color_0, + ), + "RED": DisplayData( + name=name_1, + display_type=DISPLAY_TYPE.SPHERE, + color=color_1, + ), + }, + draw_bonds=False, +) +converter_display_data = SpringsaladConverter(data_with_display_data) +results_display_data = JsonWriter.format_trajectory_data(converter_display_data._data) + + +# test type mapping provided +@pytest.mark.parametrize( + "typeMapping, expected_typeMapping", + [ + ( + results_display_data["trajectoryInfo"]["typeMapping"], + { + "0": { + "name": name_0, + "geometry": { + "displayType": "OBJ", + "url": url_0, + "color": color_0, }, }, - "spatialData": { - "version": CURRENT_VERSION.SPATIAL_DATA, - "msgType": 1, - "bundleStart": 0, - "bundleSize": 2, - "bundleData": [ - { - "frameNumber": 0, - "time": 0.0, - "data": [ - 1000.0, - 100000000.0, - 0.0, - -2.3515194000000004, - 4.1677663, - -0.2872943, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 100010000.0, - 0.0, - -1.1726563, - 3.7363461000000004, - -0.47181300000000004, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 100200001.0, - 1.0, - -0.3749313, - 0.6674895000000001, - -0.5000000, - 0.0, - 0.0, - 0.0, - 0.2, - 0.0, - 1000.0, - 100200000.0, - 2.0, - -0.3749313, - 0.6674895000000001, - 0.000000, - 0.0, - 0.0, - 0.0, - 0.2, - 0.0, - 1000.0, - 100200002.0, - 3.0, - -0.3749313, - 0.6674895000000001, - 0.5000000, - 0.0, - 0.0, - 0.0, - 0.2, - 0.0, - 1000.0, - 100300000.0, - 4.0, - -2.9673074, - 0.5123882000000001, - 5.0633669, - 0.0, - 0.0, - 0.0, - 0.1, - 0.0, - ], - }, - { - "frameNumber": 1, - "time": 0.10000000998802996, - "data": [ - 1000.0, - 100200001.0, - 1.0, - 3.8385084999999997, - -2.5307899000000003, - -0.5000000, - 0.0, - 0.0, - 0.0, - 0.2, - 0.0, - 1000.0, - 100200000.0, - 2.0, - 3.7610036000000004, - -2.4899603, - 0.000000, - 0.0, - 0.0, - 0.0, - 0.2, - 0.0, - 1000.0, - 100200002.0, - 3.0, - 3.6784268, - -2.5100304, - 0.5000000, - 0.0, - 0.0, - 0.0, - 0.2, - 0.0, - 1000.0, - 100210001.0, - 1.0, - 0.9422604, - 1.1849763, - -0.5000000, - 0.0, - 0.0, - 0.0, - 0.2, - 0.0, - 1000.0, - 100300000.0, - 4.0, - 1.7784686, - 0.8480382000000001, - 1.8389947, - 0.0, - 0.0, - 0.0, - 0.1, - 0.0, - ], - }, - ], + "1": { + "name": name_1, + "geometry": { + "displayType": "SPHERE", + "color": color_1, + }, + }, + "2": { + "name": "GRAY", + "geometry": { + "displayType": "SPHERE", + }, }, - "plotData": {"version": CURRENT_VERSION.PLOT_DATA, "data": []}, }, + ) + ], +) +def test_typeMapping_provided(typeMapping, expected_typeMapping): + assert expected_typeMapping == typeMapping + + +@pytest.mark.parametrize( + "bundleData, expected_bundleData", + [ + ( + results_display_data["spatialData"]["bundleData"][0], + [ + VIZ_TYPE.DEFAULT, # first agent + 100000000.0, # id + 0.0, # type index + -2.3515194000000004, # x + 4.1677663, # y + -0.2872943, # z + 0.0, # x rotation + 0.0, # y rotation + 0.0, # z rotation + radius_0 * scale_factor, # radius + 0.0, # subpoints + VIZ_TYPE.DEFAULT, # second agent + 100010000.0, + 0.0, + -1.1726563, + 3.7363461000000004, + -0.47181300000000004, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + VIZ_TYPE.DEFAULT, # third agent + 100200001.0, + 1.0, + -0.3749313, + 0.6674895000000001, + -0.5000000, + 0.0, + 0.0, + 0.0, + 0.2, + 0.0, + VIZ_TYPE.DEFAULT, # fourth agent + 100200000.0, + 2.0, + -0.3749313, + 0.6674895000000001, + 0.000000, + 0.0, + 0.0, + 0.0, + 0.2, + 0.0, + ], + ) + ], +) +def test_bundleData(bundleData, expected_bundleData): + assert expected_bundleData == bundleData["data"] + + +def test_agent_ids(): + assert JsonWriter._check_agent_ids_are_unique_per_frame(results_display_data) + + +data_draw_bonds = SpringsaladData( + sim_view_txt_file=InputFileData( + file_path=("simulariumio/tests/data/springsalad/" "test.txt"), + ), + meta_data=MetaData( + scale_factor=scale_factor, + box_size=np.array([size_x, size_y, size_z]), + ), + display_data={ + "GREEN": DisplayData( + name=name_0, + radius=radius_0, + display_type=DISPLAY_TYPE.OBJ, + url=url_0, + color=color_0, + ), + "RED": DisplayData( + name=name_1, + display_type=DISPLAY_TYPE.SPHERE, + color=color_1, ), - # truncated data from tutorial example (and draw bonds) + }, +) +converter_draw_bonds = SpringsaladConverter(data_draw_bonds) +results_draw_bonds = JsonWriter.format_trajectory_data(converter_draw_bonds._data) + + +# test type mapping drawing bonds +@pytest.mark.parametrize( + "typeMapping, expected_typeMapping", + [ ( - SpringsaladData( - sim_view_txt_file=InputFileData( - file_path=( - "simulariumio/tests/data/springsalad/" - "Simulation0_SIM_VIEW_Run0.txt" - ), - ), - meta_data=MetaData( - scale_factor=0.1, - ), - display_data={ - "GREEN": DisplayData( - name="A", - radius=10.0, - display_type=DISPLAY_TYPE.OBJ, - url="a.obj", - color="#dfdacd", - ), - "RED": DisplayData( - name="B", - display_type=DISPLAY_TYPE.SPHERE, - color="#0080ff", - ), - }, - ), + results_draw_bonds["trajectoryInfo"]["typeMapping"], { - "trajectoryInfo": { - "version": CURRENT_VERSION.TRAJECTORY_INFO, - "timeUnits": { - "magnitude": 1.0, - "name": "s", - }, - "timeStepSize": 0.1, - "totalSteps": 2, - "spatialUnits": { - "magnitude": 10.0, - "name": "nm", + "0": { + "name": name_0, + "geometry": { + "displayType": "OBJ", + "url": url_0, + "color": color_0, }, - "size": {"x": 10.0, "y": 10.0, "z": 20.0}, - "cameraDefault": { - "position": { - "x": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[2], - }, - "lookAtPosition": { - "x": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[2], - }, - "upVector": { - "x": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[0], - "y": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[1], - "z": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[2], - }, - "fovDegrees": DEFAULT_CAMERA_SETTINGS.FOV_DEGREES, + }, + "1": { + "name": name_1, + "geometry": { + "displayType": "SPHERE", + "color": color_1, }, - "typeMapping": { - "0": { - "name": "A", - "geometry": { - "displayType": "OBJ", - "url": "a.obj", - "color": "#dfdacd", - }, - }, - "1": { - "name": "B", - "geometry": { - "displayType": "SPHERE", - "color": "#0080ff", - }, - }, - "2": { - "name": "GRAY", - "geometry": { - "displayType": "SPHERE", - }, - }, - "3": { - "name": "CYAN", - "geometry": { - "displayType": "SPHERE", - }, - }, - "4": { - "name": "BLUE", - "geometry": { - "displayType": "SPHERE", - }, - }, - "5": { - "name": "Link", - "geometry": { - "displayType": "FIBER", - }, - }, + }, + "2": { + "name": "GRAY", + "geometry": { + "displayType": "SPHERE", }, }, - "spatialData": { - "version": CURRENT_VERSION.SPATIAL_DATA, - "msgType": 1, - "bundleStart": 0, - "bundleSize": 2, - "bundleData": [ - { - "frameNumber": 0, - "time": 0.0, - "data": [ - 1000.0, - 100000000.0, - 0.0, - -2.3515194000000004, - 4.1677663, - -0.2872943, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 100010000.0, - 0.0, - -1.1726563, - 3.7363461000000004, - -0.47181300000000004, - 0.0, - 0.0, - 0.0, - 1.0, - 0.0, - 1000.0, - 100200001.0, - 1.0, - -0.3749313, - 0.6674895000000001, - -0.5000000, - 0.0, - 0.0, - 0.0, - 0.2, - 0.0, - 1000.0, - 100200000.0, - 2.0, - -0.3749313, - 0.6674895000000001, - 0.000000, - 0.0, - 0.0, - 0.0, - 0.2, - 0.0, - 1000.0, - 100200002.0, - 3.0, - -0.3749313, - 0.6674895000000001, - 0.5000000, - 0.0, - 0.0, - 0.0, - 0.2, - 0.0, - 1000.0, - 100300000.0, - 4.0, - -2.9673074, - 0.5123882000000001, - 5.0633669, - 0.0, - 0.0, - 0.0, - 0.1, - 0.0, - 1001.0, - 0.0, - 5.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - -0.3749313, - 0.6674895000000001, - 0.000000, - -0.3749313, - 0.6674895000000001, - -0.5000000, - 1001.0, - 1.0, - 5.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - -0.3749313, - 0.6674895000000001, - 0.000000, - -0.3749313, - 0.6674895000000001, - 0.5000000, - ], - }, - { - "frameNumber": 1, - "time": 0.10000000998802996, - "data": [ - 1000.0, - 100200001.0, - 1.0, - 3.8385084999999997, - -2.5307899000000003, - -0.5000000, - 0.0, - 0.0, - 0.0, - 0.2, - 0.0, - 1000.0, - 100200000.0, - 2.0, - 3.7610036000000004, - -2.4899603, - 0.000000, - 0.0, - 0.0, - 0.0, - 0.2, - 0.0, - 1000.0, - 100200002.0, - 3.0, - 3.6784268, - -2.5100304, - 0.5000000, - 0.0, - 0.0, - 0.0, - 0.2, - 0.0, - 1000.0, - 100210001.0, - 1.0, - 0.9422604, - 1.1849763, - -0.5000000, - 0.0, - 0.0, - 0.0, - 0.2, - 0.0, - 1000.0, - 100300000.0, - 4.0, - 1.7784686, - 0.8480382000000001, - 1.8389947, - 0.0, - 0.0, - 0.0, - 0.1, - 0.0, - 1001.0, - 0.0, - 5.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - 3.7610036000000004, - -2.4899603, - 0.000000, - 3.8385084999999997, - -2.5307899000000003, - -0.5000000, - 1001.0, - 1.0, - 5.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - 3.7610036000000004, - -2.4899603, - 0.000000, - 3.6784268, - -2.5100304, - 0.5000000, - ], - }, - ], + "3": { + "name": "Link", + "geometry": { + "displayType": "FIBER", + }, }, - "plotData": {"version": CURRENT_VERSION.PLOT_DATA, "data": []}, }, - ), + ) ], ) -def test_springsalad_converter(trajectory, expected_data): - converter = SpringsaladConverter(trajectory) - buffer_data = JsonWriter.format_trajectory_data(converter._data) - assert expected_data == buffer_data - assert JsonWriter._check_agent_ids_are_unique_per_frame(buffer_data) +def test_typeMapping_bonds(typeMapping, expected_typeMapping): + assert expected_typeMapping == typeMapping + + +@pytest.mark.parametrize( + "bundleData, expected_bundleData", + [ + ( + results_draw_bonds["spatialData"]["bundleData"][0], + [ + VIZ_TYPE.DEFAULT, # first agent + 100000000.0, # id + 0.0, # type index + -2.3515194000000004, # x + 4.1677663, # y + -0.2872943, # z + 0.0, # x rotation + 0.0, # y rotation + 0.0, # z rotation + radius_0 * scale_factor, # radius + 0.0, # subpoints + VIZ_TYPE.DEFAULT, # second agent + 100010000.0, + 0.0, + -1.1726563, + 3.7363461000000004, + -0.47181300000000004, + 0.0, + 0.0, + 0.0, + 1.0, + 0.0, + VIZ_TYPE.DEFAULT, # third agent + 100200001.0, + 1.0, + -0.3749313, + 0.6674895000000001, + -0.5000000, + 0.0, + 0.0, + 0.0, + 0.2, + 0.0, + VIZ_TYPE.DEFAULT, # fourth agent + 100200000.0, + 2.0, + -0.3749313, + 0.6674895000000001, + 0.000000, + 0.0, + 0.0, + 0.0, + 0.2, + 0.0, + VIZ_TYPE.FIBER, # fifth agent (fiber) + 0.0, + 3.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 6.0, + -0.3749313, + 0.6674895000000001, + 0.000000, + -0.3749313, + 0.6674895000000001, + -0.5000000, + ], + ) + ], +) +def test_bundleData_bonds(bundleData, expected_bundleData): + assert expected_bundleData == bundleData["data"] + + +def test_agent_ids_bonds(): + assert JsonWriter._check_agent_ids_are_unique_per_frame(results_display_data) diff --git a/simulariumio/tests/converters/test_trajectory_converter.py b/simulariumio/tests/converters/test_trajectory_converter.py index 39e8de15..4dcd1168 100644 --- a/simulariumio/tests/converters/test_trajectory_converter.py +++ b/simulariumio/tests/converters/test_trajectory_converter.py @@ -5,1225 +5,1387 @@ from simulariumio import TrajectoryConverter, JsonWriter from simulariumio.tests.conftest import ( - three_default_agents, + fiber_agents_type_mapping, + minimal_custom_data, + mixed_agents_type_mapping, mixed_agents, fiber_agents, + minimal_custom_type_mappings, sphere_group_agents, - default_agents_type_mapping, ) from simulariumio.constants import ( + DEFAULT_BOX_SIZE, DEFAULT_CAMERA_SETTINGS, CURRENT_VERSION, + VIZ_TYPE, MAX_AGENT_ID, ) + from simulariumio.exceptions import DataError def mixed_agents_invalid_agent_id(): + # Agent IDs are larger than a 32 bit int can represent result = mixed_agents() result.agent_data.unique_ids[0][0] = MAX_AGENT_ID + 1 return result +# 3 default agents (radius 5-10) with all optional trajectory +# parameters left blank +default_agents_trajectory = minimal_custom_data() +default_agents_trajectory.meta_data._set_box_size() +default_agents_converter = TrajectoryConverter(default_agents_trajectory) +default_agents_data = JsonWriter.format_trajectory_data(default_agents_converter._data) + +# 2 default agents (radius 5-10) and 3 fiber agents +# at given positions for 3 frames, no plots +mixed_agents_trajectory = mixed_agents() +mixed_agents_converter = TrajectoryConverter(mixed_agents_trajectory) +mixed_agents_data = JsonWriter.format_trajectory_data(mixed_agents_converter._data) + +# 3 fiber agents with points drawn +# at given positions for 3 frames, no plots +fiber_agents_trajectory = fiber_agents() +fiber_agents_converter = TrajectoryConverter(fiber_agents_trajectory) +fiber_agents_data = JsonWriter.format_trajectory_data(fiber_agents_converter._data) + +# 2 sphere group agents with 3 spheres each for 3 frames +sphere_group_trajectory = sphere_group_agents() +sphere_group_converter = TrajectoryConverter(sphere_group_trajectory) +sphere_group_data = JsonWriter.format_trajectory_data(sphere_group_converter._data) + + +# test trajectory info @pytest.mark.parametrize( - "trajectory, expected_data", + "trajectory_version, expected_version", [ - # 3 default agents (radius 5-10) at given positions for 3 frames ( - three_default_agents(), + default_agents_data["trajectoryInfo"]["version"], + CURRENT_VERSION.TRAJECTORY_INFO, + ), + ( + mixed_agents_data["trajectoryInfo"]["version"], + CURRENT_VERSION.TRAJECTORY_INFO, + ), + ( + fiber_agents_data["trajectoryInfo"]["version"], + CURRENT_VERSION.TRAJECTORY_INFO, + ), + ( + sphere_group_data["trajectoryInfo"]["version"], + CURRENT_VERSION.TRAJECTORY_INFO, + ) + ], +) +def test_versions_trajectory(trajectory_version, expected_version): + assert trajectory_version == expected_version + + +# test time units +@pytest.mark.parametrize( + "timeUnits, expected_timeUnits", + [ + ( + # default time units: 1.0 sec + default_agents_data["trajectoryInfo"]["timeUnits"], + {"magnitude": 1.0, "name": "s"}, + ), + ( + mixed_agents_data["trajectoryInfo"]["timeUnits"], + {"magnitude": 2.0, "name": "s"}, + ), + ( + fiber_agents_data["trajectoryInfo"]["timeUnits"], + {"magnitude": 1.0, "name": "µs"}, + ), + ( + sphere_group_data["trajectoryInfo"]["timeUnits"], + {"magnitude": 1.0, "name": "s"}, + ), + ], +) +def test_timeUnits(timeUnits, expected_timeUnits): + assert timeUnits == expected_timeUnits + + +# test spatial units +@pytest.mark.parametrize( + "spatialUnits, expected_spatialUnits", + [ + ( + # default spatial units: 1.0 m + default_agents_data["trajectoryInfo"]["spatialUnits"], + {"magnitude": 1.0, "name": "m"}, + ), + ( + mixed_agents_data["trajectoryInfo"]["spatialUnits"], + {"magnitude": 1.0, "name": "µm"}, + ), + ( + fiber_agents_data["trajectoryInfo"]["spatialUnits"], + {"magnitude": 10.0, "name": "m"}, + ), + ( + sphere_group_data["trajectoryInfo"]["spatialUnits"], + {"magnitude": 1.0, "name": "m"}, + ), + ], +) +def test_spatialUnits(spatialUnits, expected_spatialUnits): + assert spatialUnits == expected_spatialUnits + + +# test box size +@pytest.mark.parametrize( + "size, expected_size", + [ + ( + default_agents_data["trajectoryInfo"]["size"], { - "trajectoryInfo": { - "version": CURRENT_VERSION.TRAJECTORY_INFO, - "timeUnits": { - "magnitude": 1.0, - "name": "ns", - }, - "timeStepSize": 0.5, - "totalSteps": 3, - "spatialUnits": { - "magnitude": 1.0, - "name": "nm", - }, - "size": {"x": 100.0, "y": 100.0, "z": 100.0}, - "cameraDefault": { - "position": { - "x": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[2], - }, - "lookAtPosition": { - "x": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[2], - }, - "upVector": { - "x": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[0], - "y": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[1], - "z": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[2], - }, - "fovDegrees": DEFAULT_CAMERA_SETTINGS.FOV_DEGREES, - }, - "typeMapping": default_agents_type_mapping(), + "x": DEFAULT_BOX_SIZE[0], + "y": DEFAULT_BOX_SIZE[1], + "z": DEFAULT_BOX_SIZE[2], + }, + ), + ( + mixed_agents_data["trajectoryInfo"]["size"], + { + "x": DEFAULT_BOX_SIZE[0] * 10, + "y": DEFAULT_BOX_SIZE[1] * 10, + "z": DEFAULT_BOX_SIZE[2] * 10, + }, + ), + ( + fiber_agents_data["trajectoryInfo"]["size"], + { + "x": DEFAULT_BOX_SIZE[0] * 10, + "y": DEFAULT_BOX_SIZE[1] * 10, + "z": DEFAULT_BOX_SIZE[2] * 10, + }, + ), + ( + sphere_group_data["trajectoryInfo"]["size"], + { + "x": DEFAULT_BOX_SIZE[0], + "y": DEFAULT_BOX_SIZE[1], + "z": DEFAULT_BOX_SIZE[2], + }, + ), + ], +) +def test_box_size(size, expected_size): + assert size == expected_size + + +# test camera +@pytest.mark.parametrize( + "camera, expected_camera", + [ + ( + default_agents_data["trajectoryInfo"]["cameraDefault"], + { + "position": { + "x": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[0], + "y": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[1], + "z": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[2], }, - "spatialData": { - "version": CURRENT_VERSION.SPATIAL_DATA, - "msgType": 1, - "bundleStart": 0, - "bundleSize": 3, - "bundleData": [ - { - "frameNumber": 0, - "time": 0.0, - "data": [ - 1000.0, - 0.0, - 0.0, - 4.89610492, - -29.81564851, - 40.77254057, - 40.77254057, - -29.81564851, - 4.89610492, - 8.38656327, - 0.0, - 1000.0, - 1.0, - 1.0, - 43.43048197, - 48.00424379, - -36.02881338, - -36.02881338, - 48.00424379, - 43.43048197, - 6.18568039, - 0.0, - 1000.0, - 2.0, - 0.0, - 29.84924588, - -38.02769707, - 2.46644825, - 2.46644825, - -38.02769707, - 29.84924588, - 6.61459206, - 0.0, - ], - }, - { - "frameNumber": 1, - "time": 0.5, - "data": [ - 1000.0, - 0.0, - 1.0, - -43.37181102, - -13.41127423, - -17.31316927, - -17.31316927, - -13.41127423, - -43.37181102, - 5.26366739, - 0.0, - 1000.0, - 1.0, - 2.0, - 9.62132397, - 13.4774314, - -20.30846039, - -20.30846039, - 13.4774314, - 9.62132397, - 6.69209780, - 0.0, - 1000.0, - 2.0, - 3.0, - 41.41039848, - -45.85543786, - 49.06208485, - 49.06208485, - -45.85543786, - 41.41039848, - 9.88033853, - 0.0, - ], - }, - { - "frameNumber": 2, - "time": 1.0, - "data": [ - 1000.0, - 0.0, - 4.0, - -24.91450698, - -44.79360525, - 13.32273796, - 13.32273796, - -44.79360525, - -24.91450698, - 8.91022619, - 0.0, - 1000.0, - 1.0, - 5.0, - 4.10861266, - 43.86451151, - 21.93697483, - 21.93697483, - 43.86451151, - 4.10861266, - 9.01379396, - 0.0, - 1000.0, - 2.0, - 6.0, - -7.16740679, - -13.06491594, - 44.97026158, - 44.97026158, - -13.06491594, - -7.16740679, - 8.39880154, - 0.0, - ], - }, - ], + "lookAtPosition": { + "x": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[0], + "y": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[1], + "z": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[2], }, - "plotData": {"version": CURRENT_VERSION.PLOT_DATA, "data": []}, + "upVector": { + "x": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[0], + "y": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[1], + "z": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[2], + }, + "fovDegrees": DEFAULT_CAMERA_SETTINGS.FOV_DEGREES, }, ), - # 2 default agents (radius 5-10) and 3 fiber agents - # at given positions for 3 frames ( - mixed_agents(), + mixed_agents_data["trajectoryInfo"]["cameraDefault"], { - "trajectoryInfo": { - "version": CURRENT_VERSION.TRAJECTORY_INFO, - "trajectoryTitle": "low concentrations", - "modelInfo": { - "title": "Some agent-based model", - "version": "8.1", - "authors": "A Modeler", - "description": ( - "An agent-based model started with " - "low agent concentrations" - ), - "doi": "10.7554/eLife.49840", - "inputDataUrl": "https://allencell.org", - }, - "timeUnits": { - "magnitude": 1.0, - "name": "s", - }, - "timeStepSize": 1.0, - "totalSteps": 3, - "spatialUnits": { - "magnitude": 1.0, - "name": "µm", - }, - "size": {"x": 1000.0, "y": 1000.0, "z": 1000.0}, - "cameraDefault": { - "position": {"x": 0, "y": 120, "z": 0}, - "lookAtPosition": {"x": 10, "y": 0, "z": 0}, - "upVector": {"x": 0, "y": 0, "z": 1}, - "fovDegrees": 60.0, - }, - "typeMapping": { - "0": { - "name": "H", - "geometry": { - "displayType": "SPHERE", - }, - }, - "1": { - "name": "A", - "geometry": { - "displayType": "FIBER", - }, - }, - "2": { - "name": "C", - "geometry": { - "displayType": "FIBER", - }, - }, - "3": { - "name": "X", - "geometry": { - "displayType": "SPHERE", - }, - }, - "4": { - "name": "J", - "geometry": { - "displayType": "FIBER", - }, - }, - "5": { - "name": "L", - "geometry": { - "displayType": "FIBER", - }, - }, - "6": { - "name": "D", - "geometry": { - "displayType": "SPHERE", - }, - }, - "7": { - "name": "U", - "geometry": { - "displayType": "FIBER", - }, - }, - "8": { - "name": "E", - "geometry": { - "displayType": "SPHERE", - }, - }, - "9": { - "name": "Q", - "geometry": { - "displayType": "SPHERE", - }, - }, - "10": { - "name": "K", - "geometry": { - "displayType": "FIBER", - }, - }, - }, + "position": { + "x": 0.0, + "y": 120.0, + "z": 0.0, }, - "spatialData": { - "version": CURRENT_VERSION.SPATIAL_DATA, - "msgType": 1, - "bundleStart": 0, - "bundleSize": 3, - "bundleData": [ - { - "frameNumber": 0, - "time": 0.0, - "data": [ - 1000.0, - 0.0, - 0.0, - 4.89610492, - -29.81564851, - 40.77254057, - 0.0, - 0.0, - 0.0, - 8.38656327, - 0.0, - 1001.0, - 1.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 9.0, - -243.14059805, - 207.75566987, - -95.33921063, - -20.54663446, - 475.97201603, - 14.43506311, - -76.45581828, - -97.31170699, - -144.30184731, - 1001.0, - 2.0, - 2.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 12.0, - 108.28447939, - 175.55049775, - -274.34792273, - 13.44237701, - 258.21483663, - -65.05452787, - 224.55922362, - -455.56482869, - -351.23389958, - -286.95502659, - 330.12683064, - 183.79420473, - 1000.0, - 3.0, - 3.0, - 43.43048197, - 48.00424379, - -36.02881338, - 0.0, - 0.0, - 0.0, - 6.18568039, - 0.0, - 1001.0, - 4.0, - 4.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - 49.76236816, - -353.11708296, - 226.84570983, - -234.5462914, - 105.46507228, - 17.16552317, - ], - }, - { - "frameNumber": 1, - "time": 1.0, - "data": [ - 1001.0, - 0.0, - 5.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 9.0, - -442.27202981, - 202.83568625, - -262.13407113, - -372.23130078, - 217.21997368, - 404.88561338, - 171.37918011, - 205.80515525, - -65.95336727, - 1000.0, - 1.0, - 6.0, - -43.37181102, - -13.41127423, - -17.31316927, - 0.0, - 0.0, - 0.0, - 6.69209780, - 0.0, - 1001.0, - 2.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 9.0, - 245.9111405, - 372.15936027, - -261.94702214, - 3.50037066, - 441.92904046, - 321.75701298, - 146.23928574, - -315.3241668, - 82.00405173, - 1001.0, - 3.0, - 7.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - 104.82606074, - -413.76671598, - 366.66127719, - 136.7228888, - -210.69313998, - -465.59967482, - 1000.0, - 4.0, - 6.0, - 9.62132397, - 13.4774314, - -20.30846039, - 0.0, - 0.0, - 0.0, - 9.88033853, - 0.0, - ], - }, - { - "frameNumber": 2, - "time": 2.0, - "data": [ - 1000.0, - 0.0, - 8.0, - -24.91450698, - -44.79360525, - 13.32273796, - 0.0, - 0.0, - 0.0, - 8.91022619, - 0.0, - 1000.0, - 1.0, - 9.0, - 4.10861266, - 43.86451151, - 21.93697483, - 0.0, - 0.0, - 0.0, - 9.01379396, - 0.0, - 1001.0, - 2.0, - 10.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 9.0, - -148.70447678, - 225.27562348, - -273.51318785, - -5.32043612, - -55.97783429, - 413.32948686, - 165.64239994, - 322.63703294, - -2.2348818, - 1001.0, - 3.0, - 10.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - -317.48515644, - -237.70246887, - 238.69661676, - 94.56942257, - 346.13786088, - -7.93209392, - 1001.0, - 4.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - 7.77508859, - 260.16762947, - -171.02427873, - -20.46326319, - 179.43194042, - 485.07810635, - ], - }, - ], + "lookAtPosition": { + "x": 10.0, + "y": 0.0, + "z": 0.0, }, - "plotData": { - "version": CURRENT_VERSION.PLOT_DATA, - "data": ["plot data goes here"], + "upVector": { + "x": 0.0, + "y": 0.0, + "z": 1.0, }, + "fovDegrees": 60.0, }, ), - # 3 fiber agents with points drawn - # at given positions for 3 frames ( - fiber_agents(), + fiber_agents_data["trajectoryInfo"]["cameraDefault"], { - "trajectoryInfo": { - "version": CURRENT_VERSION.TRAJECTORY_INFO, - "modelInfo": { - "title": "Some fibers", - "authors": "A Modeler", - }, - "timeUnits": { - "magnitude": 1.0, - "name": "µs", - }, - "timeStepSize": 1.0, - "totalSteps": 3, - "spatialUnits": { - "magnitude": 10.0, - "name": "m", - }, - "size": {"x": 1000.0, "y": 1000.0, "z": 1000.0}, - "cameraDefault": { - "position": { - "x": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[2], - }, - "lookAtPosition": { - "x": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[2], - }, - "upVector": { - "x": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[0], - "y": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[1], - "z": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[2], - }, - "fovDegrees": DEFAULT_CAMERA_SETTINGS.FOV_DEGREES, - }, - "typeMapping": { - "0": { - "name": "H", - "geometry": { - "displayType": "FIBER", - }, - }, - "1": { - "name": "A", - "geometry": { - "displayType": "FIBER", - }, - }, - "2": { - "name": "C", - "geometry": { - "displayType": "FIBER", - }, - }, - "3": { - "name": "L", - "geometry": { - "displayType": "FIBER", - }, - }, - "4": { - "name": "D", - "geometry": { - "displayType": "FIBER", - }, - }, - "5": { - "name": "K", - "geometry": { - "displayType": "FIBER", - }, - }, - }, + "position": { + "x": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[0], + "y": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[1], + "z": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[2], }, - "spatialData": { - "version": CURRENT_VERSION.SPATIAL_DATA, - "msgType": 1, - "bundleStart": 0, - "bundleSize": 3, - "bundleData": [ - { - "frameNumber": 0, - "time": 0.0, - "data": [ - 1001.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 9.0, - -243.14059805, - 207.75566987, - -95.33921063, - -20.54663446, - 475.97201603, - 14.43506311, - -76.45581828, - -97.31170699, - -144.30184731, - 1000.0, - 200.0, - 0.0, - -243.14059805, - 207.75566987, - -95.33921063, - 0.0, - 0.0, - 0.0, - 0.5, - 0.0, - 1000.0, - 202.0, - 0.0, - -76.45581828, - -97.31170699, - -144.30184731, - 0.0, - 0.0, - 0.0, - 0.5, - 0.0, - 1001.0, - 2.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 12.0, - 108.28447939, - 175.55049775, - -274.34792273, - 13.44237701, - 258.21483663, - -65.05452787, - 224.55922362, - -455.56482869, - -351.23389958, - -286.95502659, - 330.12683064, - 183.79420473, - 1000.0, - 300.0, - 1.0, - 108.28447939, - 175.55049775, - -274.34792273, - 0.0, - 0.0, - 0.0, - 0.5, - 0.0, - 1000.0, - 302.0, - 1.0, - 224.55922362, - -455.56482869, - -351.23389958, - 0.0, - 0.0, - 0.0, - 0.5, - 0.0, - 1001.0, - 3.0, - 2.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - 49.76236816, - -353.11708296, - 226.84570983, - -234.5462914, - 105.46507228, - 17.16552317, - 1000.0, - 400.0, - 2.0, - 49.76236816, - -353.11708296, - 226.84570983, - 0.0, - 0.0, - 0.0, - 0.5, - 0.0, - ], - }, - { - "frameNumber": 1, - "time": 1.00001, - "data": [ - 1001.0, - 1.0, - 3.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 9.0, - -442.27202981, - 202.83568625, - -262.13407113, - -372.23130078, - 217.21997368, - 404.88561338, - 171.37918011, - 205.80515525, - -65.95336727, - 1000.0, - 200.0, - 3.0, - -442.27202981, - 202.83568625, - -262.13407113, - 0.0, - 0.0, - 0.0, - 0.5, - 0.0, - 1000.0, - 202.0, - 3.0, - 171.37918011, - 205.80515525, - -65.95336727, - 0.0, - 0.0, - 0.0, - 0.5, - 0.0, - 1001.0, - 2.0, - 4.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 9.0, - 245.9111405, - 372.15936027, - -261.94702214, - 3.50037066, - 441.92904046, - 321.75701298, - 146.23928574, - -315.3241668, - 82.00405173, - 1000.0, - 300.0, - 4.0, - 245.9111405, - 372.15936027, - -261.94702214, - 0.0, - 0.0, - 0.0, - 0.5, - 0.0, - 1000.0, - 302.0, - 4.0, - 146.23928574, - -315.3241668, - 82.00405173, - 0.0, - 0.0, - 0.0, - 0.5, - 0.0, - 1001.0, - 3.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - 104.82606074, - -413.76671598, - 366.66127719, - 136.7228888, - -210.69313998, - -465.59967482, - 1000.0, - 400.0, - 1.0, - 104.82606074, - -413.76671598, - 366.66127719, - 0.0, - 0.0, - 0.0, - 0.5, - 0.0, - ], - }, - { - "frameNumber": 2, - "time": 2.00001, - "data": [ - 1001.0, - 1.0, - 5.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 9.0, - -148.70447678, - 225.27562348, - -273.51318785, - -5.32043612, - -55.97783429, - 413.32948686, - 165.64239994, - 322.63703294, - -2.2348818, - 1000.0, - 200.0, - 5.0, - -148.70447678, - 225.27562348, - -273.51318785, - 0.0, - 0.0, - 0.0, - 0.5, - 0.0, - 1000.0, - 202.0, - 5.0, - 165.64239994, - 322.63703294, - -2.2348818, - 0.0, - 0.0, - 0.0, - 0.5, - 0.0, - 1001.0, - 2.0, - 5.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - -317.48515644, - -237.70246887, - 238.69661676, - 94.56942257, - 346.13786088, - -7.93209392, - 1000.0, - 300.0, - 5.0, - -317.48515644, - -237.70246887, - 238.69661676, - 0.0, - 0.0, - 0.0, - 0.5, - 0.0, - 1001.0, - 3.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 6.0, - 7.77508859, - 260.16762947, - -171.02427873, - -20.46326319, - 179.43194042, - 485.07810635, - 1000.0, - 400.0, - 1.0, - 7.77508859, - 260.16762947, - -171.02427873, - 0.0, - 0.0, - 0.0, - 0.5, - 0.0, - ], - }, - ], + "lookAtPosition": { + "x": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[0], + "y": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[1], + "z": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[2], }, - "plotData": { - "version": CURRENT_VERSION.PLOT_DATA, - "data": ["plot data goes here"], + "upVector": { + "x": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[0], + "y": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[1], + "z": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[2], }, + "fovDegrees": DEFAULT_CAMERA_SETTINGS.FOV_DEGREES, }, ), - # 2 sphere group agents with 3 spheres each for 3 frames ( - sphere_group_agents(), + sphere_group_data["trajectoryInfo"]["cameraDefault"], { - "trajectoryInfo": { - "version": CURRENT_VERSION.TRAJECTORY_INFO, - "timeUnits": { - "magnitude": 1.0, - "name": "s", - }, - "timeStepSize": 0.5, - "totalSteps": 3, - "spatialUnits": { - "magnitude": 1.0, - "name": "m", - }, - "size": {"x": 100.0, "y": 100.0, "z": 100.0}, - "cameraDefault": { - "position": { - "x": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[2], - }, - "lookAtPosition": { - "x": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[0], - "y": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[1], - "z": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[2], - }, - "upVector": { - "x": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[0], - "y": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[1], - "z": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[2], - }, - "fovDegrees": DEFAULT_CAMERA_SETTINGS.FOV_DEGREES, - }, - "typeMapping": { - "0": { - "name": "A", - "geometry": { - "displayType": "SPHERE_GROUP", - }, - }, - "1": { - "name": "B", - "geometry": { - "displayType": "SPHERE_GROUP", - }, - }, - }, + "position": { + "x": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[0], + "y": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[1], + "z": DEFAULT_CAMERA_SETTINGS.CAMERA_POSITION[2], }, - "spatialData": { - "version": CURRENT_VERSION.SPATIAL_DATA, - "msgType": 1, - "bundleStart": 0, - "bundleSize": 3, - "bundleData": [ - { - "frameNumber": 0, - "time": 0.0, - "data": [ - 1000.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 12.0, - 10.0, - 12.0, - 0.0, - 2.0, - 12.0, - 9.0, - 0.0, - 1.0, - 8.0, - 9.0, - 0.0, - 1.0, - 1000.0, - 1.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 12.0, - 0.0, - 10.0, - 12.0, - 1.0, - 0.0, - 12.0, - 9.0, - 2.0, - 0.0, - 8.0, - 9.0, - 2.0, - ], - }, - { - "frameNumber": 1, - "time": 0.5, - "data": [ - 1000.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 12.0, - 11.0, - 13.0, - 1.0, - 2.0, - 13.0, - 10.0, - 1.0, - 1.0, - 9.0, - 10.0, - 1.0, - 1.0, - 1000.0, - 1.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 12.0, - 1.0, - 10.0, - 12.0, - 1.0, - 1.0, - 12.0, - 9.0, - 2.0, - 1.0, - 8.0, - 9.0, - 2.0, - ], - }, - { - "frameNumber": 2, - "time": 1.0, - "data": [ - 1000.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 12.0, - 11.0, - 13.0, - 1.0, - 2.0, - 13.0, - 10.0, - 1.0, - 1.0, - 9.0, - 10.0, - 1.0, - 1.0, - 1000.0, - 1.0, - 1.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 0.0, - 1.0, - 12.0, - 1.0, - 10.0, - 12.0, - 1.0, - 1.0, - 12.0, - 9.0, - 2.0, - 1.0, - 8.0, - 9.0, - 2.0, - ], - }, - ], + "lookAtPosition": { + "x": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[0], + "y": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[1], + "z": DEFAULT_CAMERA_SETTINGS.LOOK_AT_POSITION[2], }, - "plotData": { - "version": CURRENT_VERSION.PLOT_DATA, - "data": ["plot data goes here"], + "upVector": { + "x": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[0], + "y": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[1], + "z": DEFAULT_CAMERA_SETTINGS.UP_VECTOR[2], }, + "fovDegrees": DEFAULT_CAMERA_SETTINGS.FOV_DEGREES, + }, + ), + ], +) +def test_camera_defaults(camera, expected_camera): + assert camera == expected_camera + + +# test type mapping +@pytest.mark.parametrize( + "typeMapping, expected_typeMapping", + [ + ( + default_agents_data["trajectoryInfo"]["typeMapping"], + minimal_custom_type_mappings(), + ), + ( + mixed_agents_data["trajectoryInfo"]["typeMapping"], + mixed_agents_type_mapping(), + ), + ( + fiber_agents_data["trajectoryInfo"]["typeMapping"], + fiber_agents_type_mapping(), + ), + ( + sphere_group_data["trajectoryInfo"]["typeMapping"], + { + "0": { + "name": "A", + "geometry": { + "displayType": "SPHERE_GROUP", + }, + }, + "1": { + "name": "B", + "geometry": { + "displayType": "SPHERE_GROUP", + }, + }, + }, + ), + ], +) +def test_type_mapping(typeMapping, expected_typeMapping): + assert typeMapping == expected_typeMapping + + +# test model info +@pytest.mark.parametrize( + "modelInfo, expected_modelInfo", + [ + ( + default_agents_data["trajectoryInfo"].get("modelInfo", {}), + {}, + ), + ( + mixed_agents_data["trajectoryInfo"]["modelInfo"], + { + "title": "Some agent-based model", + "version": "8.1", + "authors": "A Modeler", + "description": ( + "An agent-based model started with " "low agent concentrations" + ), + "doi": "10.7554/eLife.49840", + "inputDataUrl": "https://allencell.org", + }, + ), + ( + fiber_agents_data["trajectoryInfo"]["modelInfo"], + { + "title": "Some fibers", + "authors": "A Modeler", + }, + ), + ( + sphere_group_data["trajectoryInfo"].get("modelInfo", {}), + {}, + ), + ], +) +def test_model_info(modelInfo, expected_modelInfo): + assert modelInfo == expected_modelInfo + + +# test spatial data +@pytest.mark.parametrize( + "spatial_version, expected_version", + [ + (default_agents_data["spatialData"]["version"], CURRENT_VERSION.SPATIAL_DATA), + (mixed_agents_data["spatialData"]["version"], CURRENT_VERSION.SPATIAL_DATA), + (fiber_agents_data["spatialData"]["version"], CURRENT_VERSION.SPATIAL_DATA), + (sphere_group_data["spatialData"]["version"], CURRENT_VERSION.SPATIAL_DATA), + ], +) +def test_versions_spatial_data(spatial_version, expected_version): + assert spatial_version == expected_version + + +# Each test trajectory has 3 frames +@pytest.mark.parametrize( + "bundleSize, expected_bundleSize", + [ + (default_agents_data["spatialData"]["bundleSize"], 3), + (mixed_agents_data["spatialData"]["bundleSize"], 3), + (fiber_agents_data["spatialData"]["bundleSize"], 3), + (sphere_group_data["spatialData"]["bundleSize"], 3), + ], +) +def test_bundle_size(bundleSize, expected_bundleSize): + assert bundleSize == expected_bundleSize + + +# Each test trajectory starts at 0 +@pytest.mark.parametrize( + "bundleStart, expected_bundleStart", + [ + (default_agents_data["spatialData"]["bundleStart"], 0), + (mixed_agents_data["spatialData"]["bundleStart"], 0), + (fiber_agents_data["spatialData"]["bundleStart"], 0), + (sphere_group_data["spatialData"]["bundleStart"], 0), + ], +) +def test_bundle_start(bundleStart, expected_bundleStart): + assert bundleStart == expected_bundleStart + + +# Each test trajectory has msg type 1 +@pytest.mark.parametrize( + "msgType, expected_msgType", + [ + (default_agents_data["spatialData"]["msgType"], 1), + (mixed_agents_data["spatialData"]["msgType"], 1), + (fiber_agents_data["spatialData"]["msgType"], 1), + (sphere_group_data["spatialData"]["msgType"], 1), + ], +) +def test_msg_type(msgType, expected_msgType): + assert msgType == expected_msgType + + +@pytest.mark.parametrize( + "data, expected_data", + [ + ( + default_agents_data["spatialData"]["bundleData"][0], + { + "frameNumber": 0, + "time": 0.0, + "data": [ + VIZ_TYPE.DEFAULT, # agent 1 + 0.0, + 0.0, + 4.89610492, + -29.81564851, + 40.77254057, + 0.0, + 0.0, + 0.0, + 8.38656327, + 0.0, + VIZ_TYPE.DEFAULT, # agent 2 + 1.0, + 1.0, + 43.43048197, + 48.00424379, + -36.02881338, + 0.0, + 0.0, + 0.0, + 6.18568039, + 0.0, + VIZ_TYPE.DEFAULT, # agent 3 + 2.0, + 0.0, + 29.84924588, + -38.02769707, + 2.46644825, + 0.0, + 0.0, + 0.0, + 6.61459206, + 0.0, + ], + }, + ), + ( + default_agents_data["spatialData"]["bundleData"][1], + { + "frameNumber": 1, + "time": 0.5, + "data": [ + VIZ_TYPE.DEFAULT, + 0.0, + 1.0, + -43.37181102, + -13.41127423, + -17.31316927, + 0.0, + 0.0, + 0.0, + 5.26366739, + 0.0, + VIZ_TYPE.DEFAULT, + 1.0, + 2.0, + 9.62132397, + 13.4774314, + -20.30846039, + 0.0, + 0.0, + 0.0, + 6.69209780, + 0.0, + VIZ_TYPE.DEFAULT, + 2.0, + 3.0, + 41.41039848, + -45.85543786, + 49.06208485, + 0.0, + 0.0, + 0.0, + 9.88033853, + 0.0, + ], + }, + ), + ( + default_agents_data["spatialData"]["bundleData"][2], + { + "frameNumber": 2, + "time": 1.0, + "data": [ + VIZ_TYPE.DEFAULT, + 0.0, + 4.0, + -24.91450698, + -44.79360525, + 13.32273796, + 0.0, + 0.0, + 0.0, + 8.91022619, + 0.0, + VIZ_TYPE.DEFAULT, + 1.0, + 5.0, + 4.10861266, + 43.86451151, + 21.93697483, + 0.0, + 0.0, + 0.0, + 9.01379396, + 0.0, + VIZ_TYPE.DEFAULT, + 2.0, + 6.0, + -7.16740679, + -13.06491594, + 44.97026158, + 0.0, + 0.0, + 0.0, + 8.39880154, + 0.0, + ], + }, + ), + ], +) +def test_bundle_data_default_agents(data, expected_data): + assert data == expected_data + + +@pytest.mark.parametrize( + "data, expected_data", + [ + ( + mixed_agents_data["spatialData"]["bundleData"][0], + { + "frameNumber": 0, + "time": 0.0, + "data": [ + VIZ_TYPE.DEFAULT, + 0.0, + 0.0, + 4.89610492, + -29.81564851, + 40.77254057, + 0.0, + 0.0, + 0.0, + 8.38656327, + 0.0, + VIZ_TYPE.FIBER, + 1.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 9.0, + -243.14059805, + 207.75566987, + -95.33921063, + -20.54663446, + 475.97201603, + 14.43506311, + -76.45581828, + -97.31170699, + -144.30184731, + VIZ_TYPE.FIBER, + 2.0, + 2.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 12.0, + 108.28447939, + 175.55049775, + -274.34792273, + 13.44237701, + 258.21483663, + -65.05452787, + 224.55922362, + -455.56482869, + -351.23389958, + -286.95502659, + 330.12683064, + 183.79420473, + VIZ_TYPE.DEFAULT, + 3.0, + 3.0, + 43.43048197, + 48.00424379, + -36.02881338, + 0.0, + 0.0, + 0.0, + 6.18568039, + 0.0, + VIZ_TYPE.FIBER, + 4.0, + 4.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 6.0, + 49.76236816, + -353.11708296, + 226.84570983, + -234.5462914, + 105.46507228, + 17.16552317, + ], + }, + ), + ( + mixed_agents_data["spatialData"]["bundleData"][1], + { + "frameNumber": 1, + "time": 1.0, + "data": [ + VIZ_TYPE.FIBER, + 0.0, + 5.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 9.0, + -442.27202981, + 202.83568625, + -262.13407113, + -372.23130078, + 217.21997368, + 404.88561338, + 171.37918011, + 205.80515525, + -65.95336727, + VIZ_TYPE.DEFAULT, + 1.0, + 6.0, + -43.37181102, + -13.41127423, + -17.31316927, + 0.0, + 0.0, + 0.0, + 6.69209780, + 0.0, + VIZ_TYPE.FIBER, + 2.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 9.0, + 245.9111405, + 372.15936027, + -261.94702214, + 3.50037066, + 441.92904046, + 321.75701298, + 146.23928574, + -315.3241668, + 82.00405173, + VIZ_TYPE.FIBER, + 3.0, + 7.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 6.0, + 104.82606074, + -413.76671598, + 366.66127719, + 136.7228888, + -210.69313998, + -465.59967482, + VIZ_TYPE.DEFAULT, + 4.0, + 6.0, + 9.62132397, + 13.4774314, + -20.30846039, + 0.0, + 0.0, + 0.0, + 9.88033853, + 0.0, + ], + }, + ), + ( + mixed_agents_data["spatialData"]["bundleData"][2], + { + "frameNumber": 2, + "time": 2.0, + "data": [ + VIZ_TYPE.DEFAULT, + 0.0, + 8.0, + -24.91450698, + -44.79360525, + 13.32273796, + 0.0, + 0.0, + 0.0, + 8.91022619, + 0.0, + VIZ_TYPE.DEFAULT, + 1.0, + 9.0, + 4.10861266, + 43.86451151, + 21.93697483, + 0.0, + 0.0, + 0.0, + 9.01379396, + 0.0, + VIZ_TYPE.FIBER, + 2.0, + 10.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 9.0, + -148.70447678, + 225.27562348, + -273.51318785, + -5.32043612, + -55.97783429, + 413.32948686, + 165.64239994, + 322.63703294, + -2.2348818, + VIZ_TYPE.FIBER, + 3.0, + 10.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 6.0, + -317.48515644, + -237.70246887, + 238.69661676, + 94.56942257, + 346.13786088, + -7.93209392, + VIZ_TYPE.FIBER, + 4.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 6.0, + 7.77508859, + 260.16762947, + -171.02427873, + -20.46326319, + 179.43194042, + 485.07810635, + ], + }, + ), + ], +) +def test_bundle_data_mixed_agents(data, expected_data): + assert data == expected_data + + +@pytest.mark.parametrize( + "data, expected_data", + [ + ( + fiber_agents_data["spatialData"]["bundleData"][0], + { + "frameNumber": 0, + "time": 0.0, + "data": [ + VIZ_TYPE.FIBER, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 9.0, + -243.14059805, + 207.75566987, + -95.33921063, + -20.54663446, + 475.97201603, + 14.43506311, + -76.45581828, + -97.31170699, + -144.30184731, + VIZ_TYPE.DEFAULT, + 200.0, + 0.0, + -243.14059805, + 207.75566987, + -95.33921063, + 0.0, + 0.0, + 0.0, + 0.5, + 0.0, + VIZ_TYPE.DEFAULT, + 202.0, + 0.0, + -76.45581828, + -97.31170699, + -144.30184731, + 0.0, + 0.0, + 0.0, + 0.5, + 0.0, + VIZ_TYPE.FIBER, + 2.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 12.0, + 108.28447939, + 175.55049775, + -274.34792273, + 13.44237701, + 258.21483663, + -65.05452787, + 224.55922362, + -455.56482869, + -351.23389958, + -286.95502659, + 330.12683064, + 183.79420473, + VIZ_TYPE.DEFAULT, + 300.0, + 1.0, + 108.28447939, + 175.55049775, + -274.34792273, + 0.0, + 0.0, + 0.0, + 0.5, + 0.0, + VIZ_TYPE.DEFAULT, + 302.0, + 1.0, + 224.55922362, + -455.56482869, + -351.23389958, + 0.0, + 0.0, + 0.0, + 0.5, + 0.0, + VIZ_TYPE.FIBER, + 3.0, + 2.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 6.0, + 49.76236816, + -353.11708296, + 226.84570983, + -234.5462914, + 105.46507228, + 17.16552317, + VIZ_TYPE.DEFAULT, + 400.0, + 2.0, + 49.76236816, + -353.11708296, + 226.84570983, + 0.0, + 0.0, + 0.0, + 0.5, + 0.0, + ], }, ), - # Agent IDs are larger than a 32 bit int can represent + ( + fiber_agents_data["spatialData"]["bundleData"][1], + { + "frameNumber": 1, + "time": 1.00001, + "data": [ + VIZ_TYPE.FIBER, + 1.0, + 3.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 9.0, + -442.27202981, + 202.83568625, + -262.13407113, + -372.23130078, + 217.21997368, + 404.88561338, + 171.37918011, + 205.80515525, + -65.95336727, + VIZ_TYPE.DEFAULT, + 200.0, + 3.0, + -442.27202981, + 202.83568625, + -262.13407113, + 0.0, + 0.0, + 0.0, + 0.5, + 0.0, + VIZ_TYPE.DEFAULT, + 202.0, + 3.0, + 171.37918011, + 205.80515525, + -65.95336727, + 0.0, + 0.0, + 0.0, + 0.5, + 0.0, + VIZ_TYPE.FIBER, + 2.0, + 4.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 9.0, + 245.9111405, + 372.15936027, + -261.94702214, + 3.50037066, + 441.92904046, + 321.75701298, + 146.23928574, + -315.3241668, + 82.00405173, + 1000.0, + 300.0, + 4.0, + 245.9111405, + 372.15936027, + -261.94702214, + 0.0, + 0.0, + 0.0, + 0.5, + 0.0, + VIZ_TYPE.DEFAULT, + 302.0, + 4.0, + 146.23928574, + -315.3241668, + 82.00405173, + 0.0, + 0.0, + 0.0, + 0.5, + 0.0, + VIZ_TYPE.FIBER, + 3.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 6.0, + 104.82606074, + -413.76671598, + 366.66127719, + 136.7228888, + -210.69313998, + -465.59967482, + VIZ_TYPE.DEFAULT, + 400.0, + 1.0, + 104.82606074, + -413.76671598, + 366.66127719, + 0.0, + 0.0, + 0.0, + 0.5, + 0.0, + ], + }, + ), + ( + fiber_agents_data["spatialData"]["bundleData"][2], + { + "frameNumber": 2, + "time": 2.00001, + "data": [ + VIZ_TYPE.FIBER, + 1.0, + 5.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 9.0, + -148.70447678, + 225.27562348, + -273.51318785, + -5.32043612, + -55.97783429, + 413.32948686, + 165.64239994, + 322.63703294, + -2.2348818, + VIZ_TYPE.DEFAULT, + 200.0, + 5.0, + -148.70447678, + 225.27562348, + -273.51318785, + 0.0, + 0.0, + 0.0, + 0.5, + 0.0, + VIZ_TYPE.DEFAULT, + 202.0, + 5.0, + 165.64239994, + 322.63703294, + -2.2348818, + 0.0, + 0.0, + 0.0, + 0.5, + 0.0, + VIZ_TYPE.FIBER, + 2.0, + 5.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 6.0, + -317.48515644, + -237.70246887, + 238.69661676, + 94.56942257, + 346.13786088, + -7.93209392, + VIZ_TYPE.DEFAULT, + 300.0, + 5.0, + -317.48515644, + -237.70246887, + 238.69661676, + 0.0, + 0.0, + 0.0, + 0.5, + 0.0, + VIZ_TYPE.FIBER, + 3.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 6.0, + 7.77508859, + 260.16762947, + -171.02427873, + -20.46326319, + 179.43194042, + 485.07810635, + VIZ_TYPE.DEFAULT, + 400.0, + 1.0, + 7.77508859, + 260.16762947, + -171.02427873, + 0.0, + 0.0, + 0.0, + 0.5, + 0.0, + ], + }, + ), + ], +) +def test_bundle_data_fiber_agents(data, expected_data): + assert data == expected_data + + +@pytest.mark.parametrize( + "data, expected_data", + [ + ( + sphere_group_data["spatialData"]["bundleData"][0], + { + "frameNumber": 0, + "time": 0.0, + "data": [ + 1000.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 12.0, + 10.0, + 12.0, + 0.0, + 2.0, + 12.0, + 9.0, + 0.0, + 1.0, + 8.0, + 9.0, + 0.0, + 1.0, + 1000.0, + 1.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 12.0, + 0.0, + 10.0, + 12.0, + 1.0, + 0.0, + 12.0, + 9.0, + 2.0, + 0.0, + 8.0, + 9.0, + 2.0, + ], + }, + ), + ( + sphere_group_data["spatialData"]["bundleData"][1], + { + "frameNumber": 1, + "time": 0.5, + "data": [ + 1000.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 12.0, + 11.0, + 13.0, + 1.0, + 2.0, + 13.0, + 10.0, + 1.0, + 1.0, + 9.0, + 10.0, + 1.0, + 1.0, + 1000.0, + 1.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 12.0, + 1.0, + 10.0, + 12.0, + 1.0, + 1.0, + 12.0, + 9.0, + 2.0, + 1.0, + 8.0, + 9.0, + 2.0, + ], + }, + ), + ( + sphere_group_data["spatialData"]["bundleData"][2], + { + "frameNumber": 2, + "time": 1.0, + "data": [ + 1000.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 12.0, + 11.0, + 13.0, + 1.0, + 2.0, + 13.0, + 10.0, + 1.0, + 1.0, + 9.0, + 10.0, + 1.0, + 1.0, + 1000.0, + 1.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0, + 12.0, + 1.0, + 10.0, + 12.0, + 1.0, + 1.0, + 12.0, + 9.0, + 2.0, + 1.0, + 8.0, + 9.0, + 2.0, + ], + }, + ), + ] +) +def test_bundle_data_sphere_group(data, expected_data): + assert data == expected_data + + +# test plot data +@pytest.mark.parametrize( + "plot_version, expected_version", + [ + (default_agents_data["plotData"]["version"], CURRENT_VERSION.PLOT_DATA), + (mixed_agents_data["plotData"]["version"], CURRENT_VERSION.PLOT_DATA), + (fiber_agents_data["plotData"]["version"], CURRENT_VERSION.PLOT_DATA), + (sphere_group_data["plotData"]["version"], CURRENT_VERSION.PLOT_DATA), + ], +) +def test_versions_plot_data(plot_version, expected_version): + assert plot_version == expected_version + + +@pytest.mark.parametrize( + "plot_data, expected_plot_data", + [ + (default_agents_data["plotData"]["data"], []), + (mixed_agents_data["plotData"]["data"], ["plot data goes here"]), + (fiber_agents_data["plotData"]["data"], ["plot data goes here"]), + (sphere_group_data["plotData"]["data"], ["plot data goes here"]), + ], +) +def test_plot_data(plot_data, expected_plot_data): + assert plot_data == expected_plot_data + + +def test_unique_ids_per_frame(): + assert JsonWriter._check_agent_ids_are_unique_per_frame(default_agents_data) + assert JsonWriter._check_agent_ids_are_unique_per_frame(mixed_agents_data) + assert JsonWriter._check_agent_ids_are_unique_per_frame(fiber_agents_data) + assert JsonWriter._check_agent_ids_are_unique_per_frame(sphere_group_data) + + +# Test invalid agent IDs errors +@pytest.mark.parametrize( + "trajectory, expected_data", + [ pytest.param( mixed_agents_invalid_agent_id(), {}, @@ -1231,9 +1393,8 @@ def mixed_agents_invalid_agent_id(): ), ], ) -def test_trajectory_reader(trajectory, expected_data): +def test_invalid_agent_id(trajectory, expected_data): converter = TrajectoryConverter(trajectory) buffer_data = JsonWriter.format_trajectory_data(converter._data) JsonWriter._validate_ids(converter._data) assert expected_data == buffer_data - assert JsonWriter._check_agent_ids_are_unique_per_frame(buffer_data) diff --git a/simulariumio/tests/data/cytosim/3_fibers_3_frames/test.txt b/simulariumio/tests/data/cytosim/3_fibers_3_frames/test.txt new file mode 100644 index 00000000..eae4d6e3 --- /dev/null +++ b/simulariumio/tests/data/cytosim/3_fibers_3_frames/test.txt @@ -0,0 +1,38 @@ +% frame 0 +% time 0.1 +% start 0.1 +% id pos_x pos_y pos_z +% fiber f0:1:228 + + 1 -0.00370929 0.110164 -0.400052 + 1 -0.00970537 0.110184 -0.391947 + 1 -0.0157378 0.110304 -0.38387 +% fiber f0:2:212 + + 2 0.03944 -0.0604351 -0.344994 + 2 0.0378824 -0.05056 -0.347361 + 2 0.0363195 -0.0406802 -0.349704 + 2 0.0347773 -0.030804 -0.352077 + 2 0.033265 -0.0209349 -0.354497 + 2 0.0318441 -0.0110556 -0.356932 +% end + +% frame 1 +% time 0.2 +% start 0.2 +% id pos_x pos_y pos_z +% fiber f0:1:228 + + 1 -0.00569782 0.129971 -0.393008 + 1 -0.0152907 0.127437 -0.394796 + 1 -0.0248686 0.124766 -0.396463 +% fiber f0:2:212 + + 2 0.0190975 -0.0446282 -0.345032 + 2 0.0287449 -0.0412174 -0.345948 + 2 0.0384093 -0.0378622 -0.346891 + 2 0.0480874 -0.0345692 -0.347909 + 2 0.0577825 -0.0313358 -0.348956 + 2 0.0674886 -0.0281453 -0.350033 +% end + diff --git a/simulariumio/tests/data/medyan/test.traj b/simulariumio/tests/data/medyan/test.traj new file mode 100644 index 00000000..b969554b --- /dev/null +++ b/simulariumio/tests/data/medyan/test.traj @@ -0,0 +1,18 @@ +0 0 2 0 0 0 0 +FILAMENT 0 0 2 0 0 +454.3434234 363.439226 265.4405349 519.7377041 351.5737487 180.312405 +FILAMENT 1 0 2 0 0 +547.5943503 280.3075619 307.4127023 535.194707 173.0325428 308.9355694 + +1 1.000038293 2 2 1 0 0 +FILAMENT 0 0 6 1 3 +443.3162276 369.8644852 293.1521372 458.4600122 366.5425284 274.4414626 525.5102849 351.3129172 191.1648549 595.4174881 336.6403217 110.1741389 672.5234407 322.3132598 35.94250437 678.3129825 321.2378855 30.3779709 +FILAMENT 1 0 5 1 2 +549.7619454 310.7627687 302.0296124 547.773019 286.5808386 303.3456815 537.9496947 179.2424416 309.5407552 518.8214547 73.12680239 314.8723733 509.9893907 28.15495189 317.0372613 +LINKER 0 0 +216.8006048 854.8097767 302.9108981 191.2656514 867.5975965 281.4725825 +LINKER 7 1 +657.3317212 421.4935263 212.7250047 662.1669685 436.2944039 182.6128889 +MOTOR 57 1 1 +541.3878582 216.8108805 307.3724794 584.5992533 412.7637236 381.2579975 + diff --git a/simulariumio/tests/data/smoldyn/example_data.txt b/simulariumio/tests/data/smoldyn/example_data.txt new file mode 100644 index 00000000..046caddd --- /dev/null +++ b/simulariumio/tests/data/smoldyn/example_data.txt @@ -0,0 +1,4 @@ +0 0 +S(solution) -0.8748 -0.451012 500 +E(front) 0.844989 -0.534784 600 +ES(front) 0.666775 0.745259 606 diff --git a/simulariumio/tests/data/springsalad/test.txt b/simulariumio/tests/data/springsalad/test.txt new file mode 100644 index 00000000..a8886a91 --- /dev/null +++ b/simulariumio/tests/data/springsalad/test.txt @@ -0,0 +1,22 @@ +TotalTime 0.1 +dtimage 0.1 +xsize 50.0 +ysize 50.0 +z_outside 10.0 +z_inside 40.0 + +SCENE +SceneNumber 0 CurrentTime 0.0 +ID 100000000 2.0 GREEN -23.515194 41.677663 -2.872943 +ID 100010000 2.0 GREEN -11.726563 37.363461 -4.718130 +ID 100200001 2.0 RED -3.749313 6.674895 -5.000000 +ID 100200000 2.0 GRAY -3.749313 6.674895 0.000000 +Link 100200000 : 100200001 + +SCENE +SceneNumber 1 CurrentTime 0.10000000998802996 +ID 100200001 2.0 RED 38.385085 -25.307899 -5.000000 +ID 100200000 2.0 GRAY 37.610036 -24.899603 0.000000 +ID 100210001 2.0 RED 9.422604 11.849763 -5.000000 +Link 100200000 : 100200001 +