Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions cellpack/autopack/Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,10 +755,7 @@ def add_ingredient_positions_to_plot(
)
# plot the sphere
if ingr.use_rbsphere:
(
ext_recipe,
pts,
) = ingr.getInterpolatedSphere(
(ext_recipe, pts,) = ingr.getInterpolatedSphere(
seed_ingredient_positions[-i - 1],
seed_ingredient_positions[-i],
)
Expand Down Expand Up @@ -860,9 +857,9 @@ def update_pairwise_distances(
ingr.name,
ingr2.name,
):
pairwise_distance_dict[seed_index][f"{ingr.name}_{ingr2.name}"] = (
self.env.calc_pairwise_distances(ingr.name, ingr2.name).tolist()
)
pairwise_distance_dict[seed_index][
f"{ingr.name}_{ingr2.name}"
] = self.env.calc_pairwise_distances(ingr.name, ingr2.name).tolist()

return pairwise_distance_dict

Expand Down
12 changes: 10 additions & 2 deletions cellpack/autopack/Compartment.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ def transformMesh(self, pos, rotation):

def buildSphere(self, mesh_store):
geom = None

if self.type == "multi_sphere":
_, r_max = self.representations.get_min_max_radius()
self.radius = r_max
geom = mesh_store.create_sphere(self.gname, 4, self.radius)
self.faces, self.vertices, self.vnormals = mesh_store.decompose_mesh(
geom, edit=False, copy=False, tri=True
Expand All @@ -243,13 +247,17 @@ def initialize_shape(self, mesh_store):
if self.is_sphere:
# one sphere, geom is a dictionary
self.buildSphere(mesh_store)
if self.vertices is None and self.type == "mesh":
if (
self.vertices is None
and self.type == "mesh"
and mesh_store.get_mesh(self.gname) is not None
):
self.faces, self.vertices, self.vnormals = self.getMesh(mesh_store)
self.ref_obj = self.name
if self.meshType == "raw":
# need to build the mesh from v,f,n
self.buildMesh(self.meshFile, mesh_store)
if self.type == "mb":
if self.type == "multi_sphere":
# one sphere, geom is a dictionary
self.buildSphere(mesh_store)
if self.vertices is not None and len(self.vertices):
Expand Down
12 changes: 6 additions & 6 deletions cellpack/autopack/DBRecipeHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ def replace_region_references(self, composition_data):
continue
for index, item in enumerate(composition_data["regions"][region_name]):
if isinstance(item, str):
composition_data["regions"][region_name][index] = (
self.comp_to_path_map.get(item)
)
composition_data["regions"][region_name][
index
] = self.comp_to_path_map.get(item)
elif isinstance(item, dict):
# process nested regions recursively
if "regions" in item and item["regions"]:
Expand Down Expand Up @@ -291,9 +291,9 @@ def convert_representation(doc, db):
and doc_value["packing"] is not None
):
position_value = doc_value["packing"]["positions"]
convert_doc["representations"]["packing"]["positions"] = (
ObjectDoc.convert_positions_in_representation(position_value)
)
convert_doc["representations"]["packing"][
"positions"
] = ObjectDoc.convert_positions_in_representation(position_value)
return convert_doc

@staticmethod
Expand Down
14 changes: 7 additions & 7 deletions cellpack/autopack/Environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,10 +628,10 @@ def resolve_gradient_data_objects(self, gradient_data):
"""
# 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"]
)
gradient_data["mode_settings"][
"object"
] = self.get_compartment_object_by_name(
gradient_data["mode_settings"]["object"]
)
return gradient_data

Expand Down Expand Up @@ -2567,9 +2567,9 @@ def store_asJson(self, resultfilename=None, indent=True):
if r:
self.result_json["exteriorRecipe"] = OrderedDict()
for ingr in r.ingredients:
self.result_json["exteriorRecipe"][ingr.composition_name] = (
self.dropOneIngrJson(ingr, self.result_json["exteriorRecipe"])
)
self.result_json["exteriorRecipe"][
ingr.composition_name
] = self.dropOneIngrJson(ingr, self.result_json["exteriorRecipe"])

# compartment ingr
for orga in self.compartments:
Expand Down
7 changes: 6 additions & 1 deletion cellpack/autopack/GeometryTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,12 @@ def region_2_integrand(self, theta, rho, d):

def region_2(self, rho, d):
# require scipy
i4 = d**3 / 6.0 * (rho**2 / d**2 - 1) * (pi / 4 - self.region_1_2_theta(rho, d))
i4 = (
d**3
/ 6.0
* (rho**2 / d**2 - 1)
* (pi / 4 - self.region_1_2_theta(rho, d))
)
i3 = (
d**2
* rho
Expand Down
6 changes: 3 additions & 3 deletions cellpack/autopack/Graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1523,9 +1523,9 @@ def displayCompartmentsIngredients(self):
elif self.vi.host == "dejavu":
self.orgaToMasterGeom[ingr] = ingr.mesh
elif self.vi.host == "softimage":
self.orgaToMasterGeom[ingr] = (
ingr.mesh
) # self.getMasterInstance(polygon)
self.orgaToMasterGeom[
ingr
] = ingr.mesh # self.getMasterInstance(polygon)
# polygon already an instance from a different object\

j += 1
Expand Down
19 changes: 6 additions & 13 deletions cellpack/autopack/MeshStore.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,24 +307,17 @@ def build_mesh(self, data, geomname):
vertices = numpy.array(data["verts"]).reshape((nv, 3))
faces = numpy.array(data["faces"]).reshape((nf, 3))
vnormals = numpy.array(data["normals"]).reshape((nv, 3))
geom = self.create_mesh(geomname, vertices, None, faces)[0]

autopack.helper.saveDejaVuMesh(
autopack.cache_geoms + os.sep + geomname, self.vertices, self.faces
)
autopack.helper.saveObjMesh(
autopack.cache_geoms + os.sep + geomname + ".obj",
self.vertices,
self.faces,
)
# self.saveObjMesh(autopack.cache_geoms + os.sep + geomname + ".obj")
geom = self.create_mesh(geomname, vertices, None, faces)
return geom, vertices, faces, vnormals

def get_mesh(self, mesh_name, file_path=None):
geometry = self.get_object(mesh_name)
if geometry is None and file_path is not None:
geometry = self.read_mesh_file(file_path)
self.add_mesh_to_scene(geometry, mesh_name)

if geometry is None:
if file_path is not None:
geometry = self.read_mesh_file(file_path)
self.add_mesh_to_scene(geometry, mesh_name)
return geometry

@staticmethod
Expand Down
23 changes: 11 additions & 12 deletions cellpack/autopack/ingredient/Ingredient.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,19 +488,16 @@ def initialize_mesh(self, mesh_store):
# get the collision mesh
mesh_path = self.representations.get_mesh_path()
meshName = self.representations.get_mesh_name()
meshType = "file"
meshFormat = self.representations.get_mesh_format()
self.mesh = None
if meshFormat == ".raw":
self.buildMesh(mesh_store)
if mesh_path is not None:
if meshType == "file":
self.mesh = self.getMesh(mesh_path, meshName, mesh_store)
self.log.info(f"OK got {self.mesh}")
if self.mesh is None:
# display a message ?
self.log.warning("no geometries for ingredient " + self.name)
# TODO: add back in raw option
elif meshType == "raw":
# need to build the mesh from v,f,n
self.buildMesh(mesh_store)
self.mesh = self.getMesh(mesh_path, meshName, mesh_store)
self.log.info(f"OK got {self.mesh}")
if self.mesh is None:
# display a message ?
self.log.warning("no geometries for ingredient " + self.name)

if self.mesh is not None:
self.getEncapsulatingRadius()
Expand Down Expand Up @@ -700,7 +697,8 @@ def buildMesh(self, mesh_store):
Create a polygon mesh object from a dictionary verts,faces,normals
"""
geom, vertices, faces, vnormals = mesh_store.build_mesh(
self.mesh_info["file"], self.mesh_info["name"]
self.representations.get_mesh_contents(),
self.representations.get_mesh_name(),
)
self.vertices = vertices
self.faces = faces
Expand Down Expand Up @@ -1664,6 +1662,7 @@ def get_rotation(self, pt_ind, env, compartment):
pt_ind, env.grid.masterGridPositions[pt_ind], env.mesh_store
)
try:

rot_mat = numpy.array(rotVectToVect(v1, v2), "f")
except Exception as e:
print(f"PROBLEM: {self.name}, {e}")
Expand Down
20 changes: 10 additions & 10 deletions cellpack/autopack/ingredient/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ def __init__(
self.partners = partners
self.packing_mode = packing_mode

assert self.packing_mode in [
"random",
"close",
"closePartner",
"randomPartner",
"gradient",
"hexatile",
"squaretile",
"triangletile",
]
# assert self.packing_mode in [
# "random",
# "close",
# "closePartner",
# "randomPartner",
# "gradient",
# "hexatile",
# "squaretile",
# "triangletile",
# ]
Comment on lines +28 to +37
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something weird is going on with packing_mode. I would love some help on this if possible. i added a migrate script to make sure it's defined, and still hit this error

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the packing and the result looked good! What error are you seeing, or is there a way I can reproduce it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you uncomment these lines

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example packing code ran for me after uncommenting these lines. Could you let me know the error message/repro steps?

self.place_method = place_method
self.mesh_3d = None
self.is_attractor = is_attractor
Expand Down
4 changes: 3 additions & 1 deletion cellpack/autopack/ingredient/single_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,9 @@ def cube_surface_distance(
current_distance = numpy.sqrt(dist_x**2 + dist_y**2)
else:
# vertex is the closest
current_distance = numpy.sqrt(dist_x**2 + dist_y**2 + dist_z**2)
current_distance = numpy.sqrt(
dist_x**2 + dist_y**2 + dist_z**2
)
return current_distance

def get_signed_distance(
Expand Down
5 changes: 1 addition & 4 deletions cellpack/autopack/ingredient/single_sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,7 @@ def collision_jitter(
distance_to_packing_location - radius_of_ing_being_packed
)

(
insidePoints,
newDistPoints,
) = self.get_new_distances_and_inside_points(
(insidePoints, newDistPoints,) = self.get_new_distances_and_inside_points(
env,
jtrans,
rotMat,
Expand Down
16 changes: 15 additions & 1 deletion cellpack/autopack/interface_objects/representations.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,15 @@ def _get_spheres(self):
# can be passed in directly, or they were just read from a file
positions = self.packing["positions"]
radii = self.packing["radii"]
if positions is None or positions[0] is None or positions[0][0] is None:
if (
positions is None
or (len(positions) == 1 and positions[0] is None)
or (
len(positions) == 1
and len(positions[0]) == 1
and positions[0][0] is None
)
):
positions = [[[0, 0, 0]]]
if radii is None:
radii = [[0]]
Expand All @@ -108,6 +116,12 @@ def get_mesh_name(self):
else:
return self.mesh["name"]

def get_mesh_contents(self):
if not self.has_mesh():
return None
else:
return self.mesh["file"]

def get_mesh_path(self):
if not self.has_mesh():
return None
Expand Down
Loading