Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement an implied default compartment when compartment definitions are omitted #27

Closed
wants to merge 2 commits into from
Closed
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
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,30 @@ at 50 nm.

</details>

<details>
<summary>Implied default compartment.</summary>

If you omit the `"compartments"` field from the `"space"` section, and don't
set the `"compartments"` field in any of the segments in the `"segments"`
section, a single default compartment is implied.
This compartment is set up like this.

```json
{
"id": "main",
"shape": "cuboid"
}
```

Each segment, when the compartment is implied, is assigned to that `"main"`
compartment.

Note that when the `"compartments"` field on any segment is not set, its
compartment id will be set to `"main"`, even when a compartment is defined in
the `"space"` section.

</details>

#### Output

In **output**, we set a **title** and **dir**ectory to write the placement list
Expand Down
17 changes: 15 additions & 2 deletions src/bentopy/pack/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from .segment import Segment
from .space import Space

DEFAULT_COMPARTMENT_ID = "main"


class Configuration:
def __init__(
Expand All @@ -16,20 +18,31 @@ def __init__(
):
config = json.loads(json_src)
space = config["space"]
compartments = space.get("compartments")
self.space = Space(
space["size"],
space["resolution"],
space["compartments"],
compartments or [{"id": DEFAULT_COMPARTMENT_ID, "shape": "cuboid"}],
space.get("constraint"),
)
segments = config["segments"]
# Verify that if `output.compartments` is unset, the `compartments`
# field is unset for every segment, as well.
if compartments is None:
assert all(s.get("compartments") is None for s in segments), """
If no `compartments` are defined in the `space` section,
compartment selections in segment definitions are not allowed.
When no compartments are defined in the `space` section, a single
default compartment is implied. To set each segment's compartment
to the implied default compartment, remove the `compartments`
field from all segment definitions."""
self.segments = [
Segment(
s["name"],
s["number"],
s["path"],
self.space.resolution,
s["compartments"],
s.get("compartments") or [DEFAULT_COMPARTMENT_ID],
s.get("rotation_axes"),
s.get("center"),
)
Expand Down