Files
ReactionSystems/src/rsprocess/classical.rs

26 lines
945 B
Rust
Raw Normal View History

//! 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 00:10:23 +02:00
use super::structure::{RSset, RSreaction};
/// 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) {
Some(reaction.products())
2025-05-19 00:10:23 +02:00
} else {
None
2025-05-19 00:10:23 +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 {
reactions.iter().fold(RSset::new(), |acc, r| acc.union_option(compute_step(current_state, r)))
2025-05-19 00:10:23 +02:00
}