CellDesigner layout
pd2af.building.celldesigner.layout
Build the AF layout, reusing the input map's glyphs where possible.
make_and_add_layout is the layout pass: it walks the model elements built
by :mod:pd2af.building.celldesigner.model and fills context.layout_elements
and context.layout_model_pairs, from which momapy.core.make_map computes
the layout-model mapping. The leaf primitives below -- synthetic nodes,
modulation arcs, mapping helpers, and background cloning for overlay -- do the
per-element construction.
:mod:pd2af.core invokes this pass through a
:class:pd2af.building.context.BuilderContext after
the model pass.
Functions:
| Name | Description |
|---|---|
add_dimmed_background |
Return |
add_mappings_for_layout_and_descendants |
Pair an input glyph and its descendants with their model elements. |
clone_layout_pruning_foreground |
Clone an input layout element as a builder, to serve as dimmed background. |
make_and_add_layout |
Fill |
make_decoration_stripped_layout |
Return a frozen copy of |
make_logic_arc |
Build a |
make_modulation_arc |
Build the arc layout for |
make_synthetic_gate_layout |
Build a placeholder gate node for |
make_synthetic_layout |
Build a placeholder Node for |
add_dimmed_background
add_dimmed_background(context: BuilderContext, new_map: Any) -> Any
Return new_map with the input layout's remaining glyphs added, dimmed.
The background is added after momapy.core.make_map, as drawing only:
make_map would put every unpaired arc touching a drawn glyph into the
key of that glyph. Being unmapped, the model-driven writer drops it, so
overlay round-trips identically to plain.
Any input subtree already drawn in new_map -- a top-level glyph reused
verbatim, or a promoted subunit lifted out of a dissolved complex -- is
pruned from the clones, so the background never duplicates a foreground
glyph.
momapy draws layout_elements in order (later elements paint on top), so
the background goes after the foreground compartments, which are the
leading elements, but before the rest of the foreground: compartments
render an opaque white interior that would hide the background if it sat
behind them, while the foreground species and influence arcs must stay on
top of the background.
Source code in src/pd2af/building/celldesigner/layout.py
add_mappings_for_layout_and_descendants
add_mappings_for_layout_and_descendants(context: BuilderContext, input_layout: Any, original_to_stripped: dict[int, Any] | None = None)
Pair an input glyph and its descendants with their model elements.
With original_to_stripped, the glyphs actually placed are the stripped
clones of :func:make_decoration_stripped_layout: a clone may be a fresh
dataclasses.replace copy that is not a key of the input layout-model
mapping (keyed by the input frozen objects), so we walk the input originals
and follow each to its stripped counterpart. Dropped decoration glyphs are
absent from that map, so they never get mapped -- and being absent from the
layout, never render.
Source code in src/pd2af/building/celldesigner/layout.py
clone_layout_pruning_foreground
clone_layout_pruning_foreground(input_layout_element: Any, foreground_ids: set[str], object_to_builder: dict) -> Any
Clone an input layout element as a builder, to serve as dimmed background.
Any descendant subtree whose id_ is in foreground_ids
(already drawn in the foreground) is omitted, and None is returned when
the element itself belongs to the foreground.
Clones share object_to_builder so structure shared across the input
layout stays shared once cloned, and they are builders -- not the input
frozen objects -- so dimming the background never mutates the input
map's layout.
Source code in src/pd2af/building/celldesigner/layout.py
make_and_add_layout
make_and_add_layout(context: BuilderContext)
Fill context.layout_elements and context.layout_model_pairs (pass 2).
The overlay foreground is the plain layout; its dimmed background is added
by :func:add_dimmed_background once the map is made.
Source code in src/pd2af/building/celldesigner/layout.py
make_decoration_stripped_layout
make_decoration_stripped_layout(input_layout: Any, original_to_stripped: dict[int, Any] | None) -> Any
Return a frozen copy of input_layout stripped of its decoration glyphs.
Every PTM-decoration and active-border sub-glyph is dropped, at any depth,
and id(original) -> stripped recorded for every kept element.
The merged reading (keep_species off) strips the model's species of their
decorations; this drops the matching layout glyphs
(ModificationLayout / StructuralStateLayout and the *ActiveLayout
active-border sibling -- see _STRIPPABLE_SPECIES_DECORATION_CLASSES) so a
stripped species renders plain. Subunit glyphs of kept complexes are
preserved (and recursively stripped), so the real glyph size and subunit
structure -- which the dot layout deliberately keeps -- survive.
Frozen objects throughout (via :func:dataclasses.replace), never builders,
so the result pickles and round-trips like the reused input glyphs of the
non-stripping path; a subtree that needs no change is returned unchanged
(shared with the input). original_to_stripped lets the caller map the
surviving glyphs back to their model elements
(:func:add_mappings_for_layout_and_descendants).
Source code in src/pd2af/building/celldesigner/layout.py
make_logic_arc
make_logic_arc(context: BuilderContext, gate_layout: Any, input_layout: Any) -> Any
Build a LogicArcLayout from a gate to one of its input species.
The CellDesigner writer locates a gate's inputs by scanning for logic arcs
whose source is the gate layout, so the arc runs gate -> input species
(the CellDesigner convention), not input -> gate.
Source code in src/pd2af/building/celldesigner/layout.py
make_modulation_arc
make_modulation_arc(context: BuilderContext, modulation: Any, source_layout: Any, target_layout: Any) -> Any
Build the arc layout for modulation between two node layouts.
In the dot mode the segments are placeholders that graphviz overwrites;
otherwise they are computed from the two layouts' real geometry.
Source code in src/pd2af/building/celldesigner/layout.py
make_synthetic_gate_layout
Build a placeholder gate node for gate.
Used by the dot mode when the input gate has no curated layout.
index seeds the position so two content-equal synthetic gates stay
content-distinct; make_auto_layout repositions every node before render.
Source code in src/pd2af/building/celldesigner/layout.py
make_synthetic_layout
Build a placeholder Node for species.
index seeds the position so two synthetic layouts for
content-equal species (same class, same name) are themselves
content-distinct. Layout dataclasses have compare=False on
id_, so identical content collapses to one mapping key — and
the layout-model mapping then drops every synthetic but the first.
The position itself is throwaway: make_auto_layout repositions
every node before render.