Skip to content

Commit

Permalink
resolve compartment object for surface gradient (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
mogres authored Apr 25, 2023
1 parent e47671d commit a97be56
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
20 changes: 15 additions & 5 deletions cellpack/autopack/Environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,17 +793,27 @@ def sortIngredient(self, reset=False):
if o.surfaceRecipe:
o.surfaceRecipe.sort()

def resolve_gradient_data_objects(self, gradient_data):
"""
Resolves gradient data objects for some modes
"""
# TODO: check if other modes need to be resolved
if gradient_data["mode"] == "surface":
gradient_data["mode_settings"][
"object"
] = self.get_compartment_object_by_name(
gradient_data["mode_settings"]["object"]
)
return gradient_data

def set_gradient(self, gradient_data):
"""
create a grdaient
assign weight to point
listorganelle influenced
listingredient influenced
"""
if "surface_name" in gradient_data:
gradient_data["object"] = self.get_compartment_object_by_name(
gradient_data["surface_name"]
)
gradient_data = self.resolve_gradient_data_objects(gradient_data)
gradient = Gradient(gradient_data)
# default gradient 1-linear Decoy X
self.gradients[gradient_data["name"]] = gradient
Expand Down Expand Up @@ -1369,7 +1379,7 @@ def buildGrid(self, rebuild=True):
for g in self.gradients:
gradient = self.gradients[g]
if gradient.mode == "surface":
gradient.object.get_surface_distances(
gradient.mode_settings["object"].get_surface_distances(
self, self.grid.masterGridPositions
)
self.gradients[g].build_weight_map(
Expand Down
13 changes: 9 additions & 4 deletions cellpack/autopack/Gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,17 @@ def build_surface_distance_weight_map(self):
build a map of weights based on the distance from a surface
assumes self.distances include surface distances
"""
if getattr(self.object, "surface_distances", None) is None:
if getattr(self.mode_settings["object"], "surface_distances", None) is None:
raise ValueError("Surface distances are not set")
elif self.scale_to_next_surface:
self.distances = self.object.scaled_distance_to_next_surface
elif self.mode_settings["scale_to_next_surface"]:
self.distances = self.mode_settings[
"object"
].scaled_distance_to_next_surface
else:
self.distances = self.object.surface_distances / self.object.max_distance
self.distances = (
self.mode_settings["object"].surface_distances
/ self.mode_settings["object"].max_distance
)
self.set_weights_by_mode()

def build_directional_weight_map(self, bb, master_grid_positions):
Expand Down

0 comments on commit a97be56

Please sign in to comment.