pub struct LinearBuilder { /* private fields */ }Expand description
Builder for linear polymer architectures.
Supports homopolymers, random/alternating/block copolymers — all derived from a single BigSMILES string.
Implementations§
Source§impl LinearBuilder
impl LinearBuilder
Sourcepub fn new(bigsmiles: BigSmiles, strategy: BuildStrategy) -> Self
pub fn new(bigsmiles: BigSmiles, strategy: BuildStrategy) -> Self
Creates a new builder from a parsed BigSMILES and a build strategy.
Sourcepub fn homopolymer(&self) -> Result<PolymerChain, PolySimError>
pub fn homopolymer(&self) -> Result<PolymerChain, PolySimError>
Generates a linear homopolymer (single repeat unit, repeated n times).
§Errors
PolySimError::NoStochasticObjectif the BigSMILES contains no stochastic object ({...}).PolySimError::RepeatUnitCountif the stochastic object contains ≠ 1 repeat unit.PolySimError::BuildStrategyif the strategy yields n = 0.
§Example
use polysim_core::{parse, builder::{linear::LinearBuilder, BuildStrategy}};
let bs = parse("{[]CC(C)[]}").unwrap(); // polypropylene
let chain = LinearBuilder::new(bs, BuildStrategy::ByRepeatCount(3))
.homopolymer()
.unwrap();
assert_eq!(chain.smiles, "CC(C)CC(C)CC(C)");
assert_eq!(chain.repeat_count, 3);Sourcepub fn random_copolymer(
&self,
fractions: &[f64],
) -> Result<PolymerChain, PolySimError>
pub fn random_copolymer( &self, fractions: &[f64], ) -> Result<PolymerChain, PolySimError>
Generates a random (statistical) copolymer.
fractions — weight fraction of each repeat unit (must sum to 1.0).
The BigSMILES must contain exactly fractions.len() repeat units.
Uses an optional seed (set via Self::seed) for reproducibility.
Sourcepub fn alternating_copolymer(&self) -> Result<PolymerChain, PolySimError>
pub fn alternating_copolymer(&self) -> Result<PolymerChain, PolySimError>
Generates an alternating copolymer (–A–B–A–B– or –A–B–C–A–B–C–).
The BigSMILES must contain at least 2 repeat units.
Sourcepub fn block_copolymer(
&self,
block_lengths: &[usize],
) -> Result<PolymerChain, PolySimError>
pub fn block_copolymer( &self, block_lengths: &[usize], ) -> Result<PolymerChain, PolySimError>
Generates a block copolymer (–AAAA–BBBB–).
block_lengths — number of repeat units per block, in order.
The BigSMILES must contain exactly block_lengths.len() repeat units.
The BuildStrategy is ignored — block_lengths fully determines the chain.
Sourcepub fn gradient_copolymer(
&self,
profile: &GradientProfile,
) -> Result<PolymerChain, PolySimError>
pub fn gradient_copolymer( &self, profile: &GradientProfile, ) -> Result<PolymerChain, PolySimError>
Generates a gradient copolymer where the composition of monomer A varies
along the chain according to the given GradientProfile.
The BigSMILES must contain exactly 2 repeat units (A and B).
Sourcepub fn cyclic_homopolymer(&self) -> Result<PolymerChain, PolySimError>
pub fn cyclic_homopolymer(&self) -> Result<PolymerChain, PolySimError>
Generates a cyclic homopolymer (ring closure connecting first and last atom).
The BigSMILES must contain exactly 1 repeat unit.