2025-05-19 13:10:05 +02:00
|
|
|
//! Definitions for the 'classical' mechanism for computation.
|
|
|
|
|
//!
|
|
|
|
|
//! This initial part allows to define the 'classical' mechanism to compute in a
|
|
|
|
|
//! Reaction System (RS) Framework.
|
|
|
|
|
//! The data is held in RSset or RSreaction, in the latter the reagents,
|
|
|
|
|
//! inhibitors and products are held.
|
2025-05-21 00:03:36 +02:00
|
|
|
#![allow(dead_code)]
|
2025-05-19 13:10:05 +02:00
|
|
|
|
2025-05-19 00:10:23 +02:00
|
|
|
use super::structure::{RSset, RSreaction};
|
|
|
|
|
|
2025-05-19 13:10:05 +02:00
|
|
|
/// Computes the result of a single reaction (if enabled returns the products)
|
|
|
|
|
/// otherwise returns None.
|
2025-06-16 14:46:04 +02:00
|
|
|
pub fn compute_step<'a>(current_state: &'a RSset, reaction: &'a RSreaction) -> Option<&'a RSset> {
|
2025-05-19 00:10:23 +02:00
|
|
|
if reaction.enabled(current_state) {
|
2025-05-19 13:10:05 +02:00
|
|
|
Some(reaction.products())
|
2025-05-19 00:10:23 +02:00
|
|
|
} else {
|
2025-05-19 13:10:05 +02:00
|
|
|
None
|
2025-05-19 00:10:23 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-19 13:10:05 +02:00
|
|
|
/// Computes the result of a series of reactions. Returns the union of all
|
|
|
|
|
/// products.
|
2025-06-16 14:46:04 +02:00
|
|
|
pub fn compute_all<'a>(current_state: &'a RSset, reactions: Vec<&'a RSreaction>) -> RSset {
|
2025-05-19 13:10:05 +02:00
|
|
|
reactions.iter().fold(RSset::new(), |acc, r| acc.union_option(compute_step(current_state, r)))
|
2025-05-19 00:10:23 +02:00
|
|
|
}
|