From 21bbaa6638168fd036d01bc95be8e7c5f832b0d9 Mon Sep 17 00:00:00 2001 From: Saurabh Mogre Date: Wed, 30 Aug 2023 17:36:35 -0700 Subject: [PATCH 01/11] set surface distances in Gradient.py --- cellpack/autopack/Gradient.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/cellpack/autopack/Gradient.py b/cellpack/autopack/Gradient.py index 4ef47cb44..c397c809c 100644 --- a/cellpack/autopack/Gradient.py +++ b/cellpack/autopack/Gradient.py @@ -175,10 +175,7 @@ def build_surface_distance_weight_map(self): "object" ].scaled_distance_to_next_surface else: - self.distances = ( - self.mode_settings["object"].surface_distances - / self.mode_settings["object"].max_distance - ) + self.distances = self.mode_settings["object"].surface_distances self.set_weights_by_mode() def build_directional_weight_map(self, bb, master_grid_positions): From 4e6a840bd06ef608d6cb0cfe521faf455c95734f Mon Sep 17 00:00:00 2001 From: Saurabh Mogre Date: Fri, 8 Sep 2023 14:06:59 -0700 Subject: [PATCH 02/11] Change grid point size to be relative to the grid spacing --- cellpack/autopack/writers/__init__.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cellpack/autopack/writers/__init__.py b/cellpack/autopack/writers/__init__.py index 64736a0a9..69e610d44 100644 --- a/cellpack/autopack/writers/__init__.py +++ b/cellpack/autopack/writers/__init__.py @@ -167,10 +167,16 @@ def save_as_simularium(self, env, all_ingr_as_array, compartments): if grid_positions is not None and len(env.gradients): for _, gradient in env.gradients.items(): env.helper.add_grid_data_to_scene( - f"{gradient.name}-distances", grid_positions, gradient.distances + f"{gradient.name}-distances", + grid_positions, + gradient.distances, + env.grid.gridSpacing / 4, ) env.helper.add_grid_data_to_scene( - f"{gradient.name}-weights", grid_positions, gradient.weight + f"{gradient.name}-weights", + grid_positions, + gradient.weight, + env.grid.gridSpacing / 4, ) env.helper.writeToFile(env.result_file, env.boundingBox, env.name, env.version) From 9b5d909293694243123d869b01acaed3dd780442 Mon Sep 17 00:00:00 2001 From: Saurabh Mogre Date: Fri, 8 Sep 2023 14:07:18 -0700 Subject: [PATCH 03/11] sort grid points by stored values --- cellpack/autopack/upy/simularium/simularium_helper.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cellpack/autopack/upy/simularium/simularium_helper.py b/cellpack/autopack/upy/simularium/simularium_helper.py index ac0db6bc3..052fa57e8 100644 --- a/cellpack/autopack/upy/simularium/simularium_helper.py +++ b/cellpack/autopack/upy/simularium/simularium_helper.py @@ -333,10 +333,13 @@ def concatObjectMatrix(self): def GetAbsPosUntilRoot(self, obj): return [0, 0.0, 0.0] - def add_grid_data_to_scene(self, incoming_name, positions, values): + def add_grid_data_to_scene(self, incoming_name, positions, values, radius=0.5): colormap = matplotlib.cm.Reds(values) + inds = np.argsort(values) + values = values[inds] + positions = positions[inds] for index, value in enumerate(values): - name = f"{incoming_name}#{value}" + name = f"{incoming_name}#{value:.3f}" self.display_data[name] = DisplayData( name=name, display_type=DISPLAY_TYPE.SPHERE, @@ -348,7 +351,7 @@ def add_grid_data_to_scene(self, incoming_name, positions, values): name, None, f"{incoming_name}-{index}", - 0.5, + radius, point_pos, np.identity(4), None, From ed9a904e9d149c13ed3faf5f335be106e5326be5 Mon Sep 17 00:00:00 2001 From: Saurabh Mogre Date: Fri, 8 Sep 2023 14:07:41 -0700 Subject: [PATCH 04/11] ignore nan values while scaling distances --- cellpack/autopack/Gradient.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cellpack/autopack/Gradient.py b/cellpack/autopack/Gradient.py index c397c809c..be8dbf7b8 100644 --- a/cellpack/autopack/Gradient.py +++ b/cellpack/autopack/Gradient.py @@ -117,8 +117,8 @@ def get_normalized_values(self, values): """ Scale values between 0 and 1 """ - max_value = max(values) - min_value = min(values) + max_value = numpy.nanmax(values) + min_value = numpy.nanmin(values) return (values - min_value) / (max_value - min_value) def pickPoint(self, listPts): From d8063fee1d8d5aa789fcc001dc24036d1097d042 Mon Sep 17 00:00:00 2001 From: Saurabh Mogre Date: Fri, 8 Sep 2023 14:08:17 -0700 Subject: [PATCH 05/11] set `scale_to_next_surface` as an option --- cellpack/autopack/Environment.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cellpack/autopack/Environment.py b/cellpack/autopack/Environment.py index 9c90038fc..c26b0918c 100644 --- a/cellpack/autopack/Environment.py +++ b/cellpack/autopack/Environment.py @@ -1194,7 +1194,6 @@ def BuildCompartmentsGrids(self): ) # return inside and surface point aInteriorGrids.append(points_inside_compartments) aSurfaceGrids.append(points_on_compartment_surfaces) - self.grid.aInteriorGrids = aInteriorGrids self.grid.aSurfaceGrids = aSurfaceGrids self.log.info("I'm out of the loop and have build my grid with inside points") @@ -1310,7 +1309,9 @@ def buildGrid(self, rebuild=True): gradient.mode_settings["object"], "surface_distances" ): gradient.mode_settings["object"].set_surface_distances( - self, self.grid.masterGridPositions + self, + self.grid.masterGridPositions, + gradient.mode_settings.get("scale_to_next_surface", False), ) self.gradients[g].build_weight_map( boundingBox, self.grid.masterGridPositions From 06a798d645695f23010320b5e27c47243affd644 Mon Sep 17 00:00:00 2001 From: Saurabh Mogre Date: Fri, 8 Sep 2023 14:08:36 -0700 Subject: [PATCH 06/11] do not calculate scaled surface distances if not needed --- cellpack/autopack/Compartment.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/cellpack/autopack/Compartment.py b/cellpack/autopack/Compartment.py index 2364e95bd..0215c27b2 100644 --- a/cellpack/autopack/Compartment.py +++ b/cellpack/autopack/Compartment.py @@ -1077,7 +1077,9 @@ def prepare_buildgrid_box(self, env): len(env.grid.masterGridPositions), ) - def set_surface_distances(self, env, master_grid_positions): + def set_surface_distances( + self, env, master_grid_positions, calc_distance_between_surfaces=False + ): surface_mask = numpy.equal(self.number, env.grid.compartment_ids) surface_ids = numpy.nonzero(surface_mask) surface_positions = master_grid_positions[surface_ids] @@ -1094,7 +1096,11 @@ def set_surface_distances(self, env, master_grid_positions): all_surface_distances = numpy.full(master_grid_positions.shape[0], numpy.nan) all_surface_distances[grid_pt_indexes] = surface_distances - if self.parent is not None and parent_id != 0: + if ( + calc_distance_between_surfaces + and self.parent is not None + and parent_id != 0 + ): grid_pts_between_surfaces = numpy.equal( env.grid.compartment_ids, -parent_id ) @@ -1318,8 +1324,9 @@ def BuildGrid_trimesh( ) self.log.info(f"GOT POINTS IN SPHERE {len(points_in_encap_sphere)}") - point_compartment_ids = compartment_ids[points_in_encap_sphere] - point_ids_to_assign = points_in_encap_sphere[point_compartment_ids == 0] + # point_compartment_ids = compartment_ids[points_in_encap_sphere] + # point_ids_to_assign = points_in_encap_sphere[numpy.abs(point_compartment_ids) < number] + point_ids_to_assign = points_in_encap_sphere point_positions = numpy.float16(master_grid_positions[point_ids_to_assign]) # check surface points From c292f6f8c8e54b436fcd96eaabccff6e0edccecc Mon Sep 17 00:00:00 2001 From: Saurabh Mogre Date: Tue, 12 Sep 2023 15:37:17 -0700 Subject: [PATCH 07/11] only reassign select grid points --- cellpack/autopack/Compartment.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cellpack/autopack/Compartment.py b/cellpack/autopack/Compartment.py index 0215c27b2..e5a35b9d6 100644 --- a/cellpack/autopack/Compartment.py +++ b/cellpack/autopack/Compartment.py @@ -1324,9 +1324,9 @@ def BuildGrid_trimesh( ) self.log.info(f"GOT POINTS IN SPHERE {len(points_in_encap_sphere)}") - # point_compartment_ids = compartment_ids[points_in_encap_sphere] - # point_ids_to_assign = points_in_encap_sphere[numpy.abs(point_compartment_ids) < number] - point_ids_to_assign = points_in_encap_sphere + point_compartment_ids = compartment_ids[points_in_encap_sphere] + # largest compartments need to be created first for this to work + point_ids_to_assign = points_in_encap_sphere[numpy.abs(point_compartment_ids) < number] point_positions = numpy.float16(master_grid_positions[point_ids_to_assign]) # check surface points From 91f4f176b687b22b1836d17c8f46b7db624b8121 Mon Sep 17 00:00:00 2001 From: Saurabh Mogre Date: Tue, 12 Sep 2023 16:12:44 -0700 Subject: [PATCH 08/11] * remove nans and sort grid values * user relative size for grid points in simularium --- .../upy/simularium/simularium_helper.py | 27 ++++++++++++++++--- cellpack/autopack/writers/__init__.py | 6 ++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/cellpack/autopack/upy/simularium/simularium_helper.py b/cellpack/autopack/upy/simularium/simularium_helper.py index 052fa57e8..4e46416ae 100644 --- a/cellpack/autopack/upy/simularium/simularium_helper.py +++ b/cellpack/autopack/upy/simularium/simularium_helper.py @@ -332,12 +332,32 @@ def concatObjectMatrix(self): def GetAbsPosUntilRoot(self, obj): return [0, 0.0, 0.0] + + @staticmethod + def remove_nans(positions, values): + naninds = np.isnan(values) + values = values[~naninds] + positions = positions[~naninds] + return positions, values - def add_grid_data_to_scene(self, incoming_name, positions, values, radius=0.5): - colormap = matplotlib.cm.Reds(values) + @staticmethod + def sort_values(positions, values): inds = np.argsort(values) values = values[inds] positions = positions[inds] + return positions, values + + def add_grid_data_to_scene(self, incoming_name, positions, values, radius=0.5): + + positions, values = self.remove_nans(positions, values) + if len(values) == 0: + print("no values to display") + return + + positions, values = self.sort_values(positions, values) + + colormap = matplotlib.cm.Reds(values) + for index, value in enumerate(values): name = f"{incoming_name}#{value:.3f}" self.display_data[name] = DisplayData( @@ -455,6 +475,7 @@ def init_scene_with_objects( grid_point_positions=None, grid_point_compartment_ids=None, show_sphere_trees=False, + grid_pt_radius=0.5, ): self.time = 0 instance_number = 0 @@ -531,7 +552,7 @@ def init_scene_with_objects( name, None, f"{name}-{index}", - 0.5, + grid_pt_radius, point_pos, np.identity(4), None, diff --git a/cellpack/autopack/writers/__init__.py b/cellpack/autopack/writers/__init__.py index 69e610d44..68494e9c7 100644 --- a/cellpack/autopack/writers/__init__.py +++ b/cellpack/autopack/writers/__init__.py @@ -155,7 +155,11 @@ def save_as_simularium(self, env, all_ingr_as_array, compartments): grid_positions = env.grid.masterGridPositions if env.show_grid_spheres else None compartment_ids = env.grid.compartment_ids if env.show_grid_spheres else None env.helper.init_scene_with_objects( - all_ingr_as_array, grid_positions, compartment_ids, env.show_sphere_trees + objects=all_ingr_as_array, + grid_point_positions=grid_positions, + grid_point_compartment_ids=compartment_ids, + show_sphere_trees=env.show_sphere_trees, + grid_pt_radius=env.grid.gridSpacing / 4, ) if compartments is not None: From 4d6787a75c38b4f3e54b189c8243fd969278b895 Mon Sep 17 00:00:00 2001 From: Saurabh Mogre Date: Thu, 14 Sep 2023 16:08:32 -0700 Subject: [PATCH 09/11] reduce chunk size for mesh point calculations --- cellpack/autopack/MeshStore.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cellpack/autopack/MeshStore.py b/cellpack/autopack/MeshStore.py index 94ecd2173..31a57381b 100644 --- a/cellpack/autopack/MeshStore.py +++ b/cellpack/autopack/MeshStore.py @@ -4,7 +4,7 @@ import trimesh from cellpack import autopack -CHUNK_SIZE = 100000 +CHUNK_SIZE = 50000 class MeshStore: @@ -261,6 +261,7 @@ def contains_point(self, geomname, point): def contains_points_mesh(self, geomname, points): mesh = self.get_object(geomname) + inside = numpy.full(len(points), False) if mesh is not None: if len(points) <= CHUNK_SIZE: return mesh.contains(points) # TODO: check for memory leak @@ -273,7 +274,7 @@ def contains_points_mesh(self, geomname, points): else: inside = numpy.append(inside, mesh.contains(chunk)) return inside - return numpy.full(len(points), False) + return inside def get_smallest_radius(self, geomname, center): mesh = self.get_object(geomname) From b84336d257970fe8c81c7ceb562c933f188f5e8c Mon Sep 17 00:00:00 2001 From: Saurabh Mogre Date: Tue, 19 Sep 2023 11:50:28 -0700 Subject: [PATCH 10/11] update peroxisome packing config --- examples/packing-configs/peroxisome_packing_config.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/packing-configs/peroxisome_packing_config.json b/examples/packing-configs/peroxisome_packing_config.json index ceed2efd1..a7ff885a4 100644 --- a/examples/packing-configs/peroxisome_packing_config.json +++ b/examples/packing-configs/peroxisome_packing_config.json @@ -4,15 +4,15 @@ "inner_grid_method": "trimesh", "live_packing": false, "ordered_packing": false, - "number_of_packings": 10, + "number_of_packings": 1, "out": "out/analyze", "overwrite_place_method": true, "place_method": "spheresSST", "save_analyze_result": true, "show_grid_plot": false, - "save_plot_figures": false, + "save_plot_figures": true, "spacing": 2.5, "use_periodicity": false, "show_sphere_trees": false, - "load_from_grid_file": true + "load_from_grid_file": false } \ No newline at end of file From 8d761762b4e6f2bba57330f9224a226ea951050b Mon Sep 17 00:00:00 2001 From: Saurabh Mogre Date: Tue, 19 Sep 2023 11:50:59 -0700 Subject: [PATCH 11/11] formatting --- cellpack/autopack/Compartment.py | 4 +++- cellpack/autopack/upy/simularium/simularium_helper.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cellpack/autopack/Compartment.py b/cellpack/autopack/Compartment.py index e5a35b9d6..693172ad6 100644 --- a/cellpack/autopack/Compartment.py +++ b/cellpack/autopack/Compartment.py @@ -1326,7 +1326,9 @@ def BuildGrid_trimesh( point_compartment_ids = compartment_ids[points_in_encap_sphere] # largest compartments need to be created first for this to work - point_ids_to_assign = points_in_encap_sphere[numpy.abs(point_compartment_ids) < number] + point_ids_to_assign = points_in_encap_sphere[ + numpy.abs(point_compartment_ids) < number + ] point_positions = numpy.float16(master_grid_positions[point_ids_to_assign]) # check surface points diff --git a/cellpack/autopack/upy/simularium/simularium_helper.py b/cellpack/autopack/upy/simularium/simularium_helper.py index 4e46416ae..349fc37d0 100644 --- a/cellpack/autopack/upy/simularium/simularium_helper.py +++ b/cellpack/autopack/upy/simularium/simularium_helper.py @@ -332,7 +332,7 @@ def concatObjectMatrix(self): def GetAbsPosUntilRoot(self, obj): return [0, 0.0, 0.0] - + @staticmethod def remove_nans(positions, values): naninds = np.isnan(values)