Model
pd2af.building.model
The parts of the model pass that are the same for either language.
:mod:pd2af.building.celldesigner.model and :mod:pd2af.building.sbgn.model
build their own compartments, species and influences, but read the clingo atoms,
resolve an influence source and walk the input subunit trees the same way. The logical-operator pass is
shared too: the CellDesigner builder makes BooleanLogicGate objects and the
SBGN-AF builder LogicalOperator objects, and otherwise the two do the
same thing -- read the operator atoms, resolve each operator's inputs through
key_to_activity, and add to the model those operators that actually source
an influence. Each builder passes in the classes it wants and the model
collection to add to.
Functions:
| Name | Description |
|---|---|
add_model_element_if_new |
Append |
build_subunit_to_top_level |
Map |
collect_atoms |
Sort the |
make_and_add_operators |
Build every authored logical operator, adding the used ones to the model. |
register_or_reuse |
Intern |
resolve_influence_source |
Resolve an influence |
add_model_element_if_new
Append model_element to collection unless it was already appended.
Identities already added are tracked in seen_identities.
model_element is assumed to already be the canonical instance (e.g. the
result of :func:register_or_reuse); this only guards against adding the
same identity twice. Returns True if it was added this call, False
if it was a duplicate.
Source code in src/pd2af/building/model.py
build_subunit_to_top_level
Map id(subunit) -> the top-level element it belongs to.
Every subunit of top_level_elements is covered, at any depth.
A subunit is a structural component, never an independent activity, so both
builders attribute it to its outermost element: the CellDesigner builder
takes the top-level species' compartment, the SBGN-AF builder the top-level
entity pool's.
Source code in src/pd2af/building/model.py
collect_atoms
collect_atoms(context: BuilderContext, clingo_model: Any) -> None
Sort the new(...) atoms into the context scratch lists by payload type.
Activities, influences, logical operators and operator inputs each get their own list.
Source code in src/pd2af/building/model.py
make_and_add_operators
make_and_add_operators(context: BuilderContext, operator_type_to_class: dict[str, type], operator_input_class: type, model_operators: Any) -> None
Build every authored logical operator, adding the used ones to the model.
An operator reaches model_operators when it sources an influence or is
reachable from such an operator through input edges (SBGN-PD nesting: the
inner operators of an influence-sourcing AND are part of the output). It is
added only when it has at least one resolved input: an operator whose
inputs all failed to resolve (every referred element carries no activity
key, e.g. every input suppressed) is dropped entirely -- it emits neither a
node nor a sourced influence, and its consumer keeps only its remaining
resolved inputs. An operator with some resolved inputs keeps exactly those
inputs; the unresolved ones are skipped.
Every surviving operator is built into context.key_to_operator, so the
influence pass can resolve an operator source. The added operators are
appended to context.operator_emissions in dependency order, inner
operators first, so the layout pass finds each input's glyph already
registered. The CellDesigner writer emits a gate only through its
modulation, so dropping unused gates keeps the output round-trip-safe.
Source code in src/pd2af/building/model.py
register_or_reuse
Intern element by content in cache.
First-registered wins: if a content-equal element is already cached, return
it; otherwise record element as the canonical instance and return it.
Source code in src/pd2af/building/model.py
resolve_influence_source
resolve_influence_source(context: BuilderContext, source_key: Any) -> Any
Resolve an influence source key to its model element.
A logical operator resolves through key_to_operator, any activity key
through key_to_activity. None when the gate or the activity was not
built, so the caller skips the edge.