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.
Sourcepub fn alternating_copolymer(&self) -> Result<PolymerChain, PolySimError>
pub fn alternating_copolymer(&self) -> Result<PolymerChain, PolySimError>
Generates an alternating copolymer (–A–B–A–B–).
The BigSMILES must contain exactly 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.
Auto Trait Implementations§
impl Freeze for LinearBuilder
impl RefUnwindSafe for LinearBuilder
impl Send for LinearBuilder
impl Sync for LinearBuilder
impl Unpin for LinearBuilder
impl UnsafeUnpin for LinearBuilder
impl UnwindSafe for LinearBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more