Skip to main content

polysim_core/
error.rs

1use thiserror::Error;
2
3/// All errors that can be produced by polysim operations.
4#[derive(Debug, Error)]
5pub enum PolySimError {
6    /// A BigSMILES string could not be parsed.
7    #[error("BigSMILES parse error: {0}")]
8    Parse(#[from] bigsmiles::ParseError),
9
10    /// The [`BuildStrategy`](crate::BuildStrategy) is invalid or not yet supported.
11    #[error("Invalid build strategy: {0}")]
12    BuildStrategy(String),
13
14    /// The BigSMILES contains no stochastic object (`{...}`), so no repeat units
15    /// are available for chain generation.
16    #[error("No stochastic object (repeat units) found in BigSMILES")]
17    NoStochasticObject,
18
19    /// The stochastic object contains the wrong number of repeat units for the
20    /// requested architecture.
21    #[error(
22        "Incompatible repeat unit count for {architecture}: got {got}, need at least {need_min}"
23    )]
24    RepeatUnitCount {
25        architecture: &'static str,
26        got: usize,
27        need_min: usize,
28    },
29
30    /// The block ratios supplied to a block copolymer ensemble do not sum to 1.0.
31    #[error("Block ratios must sum to 1.0 (got {sum:.4})")]
32    InvalidBlockRatios { sum: f64 },
33
34    /// The weight fractions supplied to a copolymer builder do not sum to 1.0.
35    #[error("Weight fractions must sum to 1.0 (got {sum:.4})")]
36    InvalidFractions { sum: f64 },
37
38    /// An ensemble was created with zero chains.
39    #[error("Cannot create an ensemble with zero chains")]
40    EmptyEnsemble,
41
42    /// A single repeat unit already uses more than 99 distinct ring-closure numbers,
43    /// which exceeds the SMILES specification.
44    #[error(
45        "Ring number overflow: the repeat unit uses {max_ring} ring closure(s), \
46         SMILES maximum is {max_supported}"
47    )]
48    RingNumberOverflow { max_ring: u32, max_supported: u32 },
49}