Skip to content

Commit

Permalink
Feature: migrate v1 partner recipes (#207)
Browse files Browse the repository at this point in the history
* [wip] debugging

* fix v1 to v2 partners

* delete the partners key if there is none

* delete partners if there is none

* correct tests

* simplify

* set binding_probability in v2 to v2.1

* migrate color to v2 recipes

* fix test
  • Loading branch information
rugeli authored Nov 6, 2023
1 parent c176ac8 commit 2c5e04b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions cellpack/autopack/loaders/migrate_v1_to_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def migrate_ingredient(old_ingredient):
new_ingredient["representations"] = get_representations(old_ingredient)
if new_ingredient["type"] == INGREDIENT_TYPE.SINGLE_SPHERE:
new_ingredient["radius"] = old_ingredient["radii"][0][0]
if "partners" in new_ingredient and not new_ingredient["partners"].get("names"):
del new_ingredient["partners"]
return new_ingredient


Expand Down
7 changes: 5 additions & 2 deletions cellpack/autopack/loaders/migrate_v2_to_v2_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

def convert_partners(object_data):
partners_list = []
if "names" not in "partners":
if "names" not in object_data["partners"]:
return partners_list
for index, name in enumerate(object_data["partners"]["names"]):
positions = object_data["partners"]["positions"]
Expand All @@ -16,7 +16,10 @@ def convert_partners(object_data):
binding_probability = 1.0
if "probability_binding" in object_data["partners"]:
binding_probability = object_data["partners"]["probability_binding"]
if "probability_repelled" in object_data["partners"]:
if (
"probability_repelled" in object_data["partners"]
and object_data["partners"]["probability_repelled"] < 0
):
binding_probability = -object_data["partners"]["probability_repelled"]

partner = {
Expand Down
1 change: 1 addition & 0 deletions cellpack/autopack/loaders/v1_v2_attribute_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

v1_to_v2_name_map = {
"Type": "type",
"color": "color",
"distExpression": "distance_expression",
"distFunction": "distance_function",
"isAttractor": "is_attractor",
Expand Down
11 changes: 8 additions & 3 deletions cellpack/tests/test_recipe_version_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ def test_create_packing_atomic_representation(
"encapsulatingRadius": 100,
"nbMol": 15,
"orientBiasRotRangeMax": 12,
"partners_name": [],
"proba_binding": 0.5,
"Type": "MultiSphere",
},
{
"count": 15,
"orient_bias_range": [-pi, 12],
"partners": {"probability_binding": 0.5},
"representations": RecipeLoader.default_values["representations"],
"type": INGREDIENT_TYPE.MULTI_SPHERE,
},
Expand Down Expand Up @@ -179,7 +179,6 @@ def test_create_packing_atomic_representation(
{
"count": 15,
"orient_bias_range": [6, 12],
"partners": {"probability_binding": 0.5},
"radius": 100,
"representations": RecipeLoader.default_values["representations"],
"type": INGREDIENT_TYPE.SINGLE_SPHERE,
Expand Down Expand Up @@ -275,7 +274,6 @@ def test_get_v1_ingredient():
"orient_bias_range": [6, pi],
},
"C": {
"partners": {"probability_binding": 0.5},
"orient_bias_range": [-pi, 12],
"radius": 10,
"representations": {
Expand Down Expand Up @@ -400,6 +398,11 @@ def test_migrate_version_error():
"rotation_range": 6.2831,
"max_jitter": [1, 1, 0],
"perturb_axis_amplitude": 0.1,
"color": [
0.498,
0.498,
0.498,
],
"is_attractor": False,
"principal_vector": [1, 0, 0],
"packing_mode": "random",
Expand Down Expand Up @@ -430,6 +433,7 @@ def test_migrate_version_error():
"rotation_range": 6.2831,
"max_jitter": [1, 1, 0],
"perturb_axis_amplitude": 0.1,
"color": [0.306, 0.45100001, 0.81599998],
"is_attractor": False,
"principal_vector": [1, 0, 0],
"packing_mode": "random",
Expand All @@ -449,6 +453,7 @@ def test_migrate_version_error():
"rotation_range": 6.2831,
"max_jitter": [1, 1, 0],
"perturb_axis_amplitude": 0.1,
"color": [0.306, 0.45100001, 0.81599998],
"is_attractor": False,
"principal_vector": [1, 0, 0],
"packing_mode": "random",
Expand Down

0 comments on commit 2c5e04b

Please sign in to comment.