biocrnpyler.core.Mechanism
- class biocrnpyler.core.Mechanism(name: str, mechanism_type='')[source]
Bases:
objectBase 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:
name (
str) – Name of the mechanism instance for identification and debugging.mechanism_type (
str, default'') – Type identifier for the mechanism (e.g., ‘transcription’, ‘translation’, ‘binding’). Used for mechanism lookup in components and mixtures.
- Attributes:
name (
str) – Name of the mechanism.mechanism_type (
str) – Type identifier for the mechanism.
See also
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()} ... )
Methods
Generate reactions for this mechanism.
Generate species for this mechanism.
- update_reactions(component=None, part_id=None) List[source]
Generate reactions for this mechanism.
- Parameters:
component (
Component, optional) – The component calling this mechanism. May be used to access component-specific parameters or attributes.part_id (
str, optional) – Part identifier for parameter lookup. Used to retrieve part-specific parameters from the parameter database.
- Returns:
List of reaction objects generated by this mechanism. This base implementation returns an empty list.
- Return type:
listofReaction- 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:
component (
Component, optional) – The component calling this mechanism. May be used to access component-specific parameters or attributes.part_id (
str, optional) – Part identifier for parameter lookup. Used to retrieve part-specific parameters from the parameter database.
- Returns:
List of species objects generated by this mechanism. This base implementation returns an empty list.
- Return type:
listofSpecies- 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.