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-07-01 19:22:50 +02:00
|
|
|
use super::structure::{RSreaction, RSset};
|
2025-05-19 00:10:23 +02:00
|
|
|
|
2025-05-19 13:10:05 +02:00
|
|
|
/// Computes the result of a single reaction (if enabled returns the products)
|
|
|
|
|
/// otherwise returns None.
|
2025-07-09 19:34:15 +02:00
|
|
|
/// see result
|
2025-06-19 23:48:16 +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-07-09 16:12:22 +02:00
|
|
|
Some(&reaction.products)
|
2025-05-19 00:10:23 +02:00
|
|
|
} else {
|
2025-07-01 19:22:50 +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-07-09 19:34:15 +02:00
|
|
|
/// see result
|
2025-06-19 23:48:16 +02:00
|
|
|
pub fn compute_all<'a>(
|
|
|
|
|
current_state: &'a RSset,
|
|
|
|
|
reactions: &'a [RSreaction]
|
|
|
|
|
) -> RSset {
|
2025-07-09 19:34:15 +02:00
|
|
|
reactions.iter().fold(RSset::new(), |mut acc, r| {
|
|
|
|
|
acc.union_option(compute_step(current_state, r));
|
|
|
|
|
acc
|
2025-07-01 19:22:50 +02:00
|
|
|
})
|
2025-05-19 00:10:23 +02:00
|
|
|
}
|