Skip to main content

LinearBuilder

Struct LinearBuilder 

Source
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

Source

pub fn new(bigsmiles: BigSmiles, strategy: BuildStrategy) -> Self

Creates a new builder from a parsed BigSMILES and a build strategy.

Source

pub fn seed(self, seed: u64) -> Self

Set a random seed for reproducible copolymer generation.

Source

pub fn homopolymer(&self) -> Result<PolymerChain, PolySimError>

Generates a linear homopolymer (single repeat unit, repeated n times).

§Errors
§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);
Source

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.

Source

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.

Source

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.

Source

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).

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V