biocrnpyler.core.mechanism
Classes
|
Mechanism that generates no species or reactions. |
|
Base class for mechanisms that generate species and reactions. |
- class biocrnpyler.core.mechanism.EmptyMechanism(name, mechanism_type)[source]
Mechanism that generates no species or reactions.
A placeholder mechanism used when a mechanism type is required but no actual reactions should be generated. Commonly used in Expression Mixtures where translation is disabled, or to temporarily disable specific mechanisms without removing them from the code.
- Parameters:
- namestr
Name of the mechanism instance.
- mechanism_typestr
Type identifier for the mechanism (e.g., ‘translation’).
See also
MechanismBase class for all mechanisms.
Notes
Both
update_speciesandupdate_reactionsreturn empty lists, ensuring no CRN elements are generated when this mechanism is called.Examples
Use EmptyMechanism to disable translation in a mixture:
>>> rnap = bcp.Species('RNAP') >>> mixture = bcp.Mixture( ... mechanisms={ ... 'transcription': bcp.Transcription_MM(rnap), ... 'translation': bcp.EmptyMechanism( ... 'no_translation', 'translation') ... } ... )
Create a DNA assembly that transcribes but doesn’t translate:
>>> promoter = bcp.Promoter('pconst') >>> assembly = bcp.DNAassembly( ... name='tx_only', ... promoter=promoter, ... mechanisms={ ... 'translation': bcp.EmptyMechanism('empty', 'translation') ... } ... )
- update_reactions(component=None, part_id=None, **kwargs)[source]
Generate empty list of reactions.
- Parameters:
- componentComponent, optional
The component calling this mechanism (unused).
- part_idstr, optional
Part identifier (unused).
- **kwargs
Additional keyword arguments (unused).
- Returns:
- list
Empty list.
- update_species(component=None, part_id=None, **kwargs)[source]
Generate empty list of species.
- Parameters:
- componentComponent, optional
The component calling this mechanism (unused).
- part_idstr, optional
Part identifier (unused).
- **kwargs
Additional keyword arguments (unused).
- Returns:
- list
Empty list.
- class biocrnpyler.core.mechanism.Mechanism(name: str, mechanism_type='')[source]
Base class for mechanisms that generate species and reactions.
Mechanisms are reaction schemas that define how components interact and transform during CRN compilation. They represent molecular processes such as transcription, translation, binding, catalysis, and degradation. Each mechanism is called by components during compilation to generate the appropriate species and reactions.
- Parameters:
- namestr
Name of the mechanism instance for identification and debugging.
- mechanism_typestr, default=’’
Type identifier for the mechanism (e.g., ‘transcription’, ‘translation’, ‘binding’). Used for mechanism lookup in components and mixtures.
- Attributes:
- namestr
Name of the mechanism.
- mechanism_typestr
Type identifier for the mechanism.
See also
ComponentBase class that calls mechanisms during compilation.
MixtureContainer that provides default mechanisms to components.
Notes
Subclasses must override
update_speciesandupdate_reactionsto implement specific mechanism behavior. The base class implementations return empty lists and issue warnings.If
mechanism_typeis empty or None, a warning is issued as this may prevent proper mechanism inheritance and lookup.Examples
Create a custom mechanism by subclassing:
>>> class CustomTranscription(bcp.Mechanism): ... def __init__(self, name="custom_tx"): ... super().__init__(name=name, mechanism_type="transcription") ... ... def update_species(self, dna, transcript, **kwargs): ... # Generate RNA species ... return [transcript] ... ... def update_reactions(self, dna, transcript, **kwargs): ... # Generate transcription reaction ... return [Reaction([dna], [dna, transcript], k=0.01)]
Use a mechanism in a mixture:
>>> mixture = bcp.Mixture( ... mechanisms={'transcription': CustomTranscription()} ... )
- update_reactions(component=None, part_id=None) List[source]
Generate reactions for this mechanism.
- Parameters:
- componentComponent, optional
The component calling this mechanism. May be used to access component-specific parameters or attributes.
- part_idstr, optional
Part identifier for parameter lookup. Used to retrieve part-specific parameters from the parameter database.
- Returns:
- list of Reaction
List of reaction objects generated by this mechanism. This base implementation returns an empty list.
- Warns:
- UserWarning
Issues a warning when the base class method is called, indicating that subclasses should override this method.
Notes
Subclasses must override this method to implement mechanism-specific reaction generation logic.
- update_species(component=None, part_id=None) List[source]
Generate species for this mechanism.
- Parameters:
- componentComponent, optional
The component calling this mechanism. May be used to access component-specific parameters or attributes.
- part_idstr, optional
Part identifier for parameter lookup. Used to retrieve part-specific parameters from the parameter database.
- Returns:
- list of Species
List of species objects generated by this mechanism. This base implementation returns an empty list.
- Warns:
- UserWarning
Issues a warning when the base class method is called, indicating that subclasses should override this method.
Notes
Subclasses must override this method to implement mechanism-specific species generation logic.