Skip to main content

SelfAvoidingWalk

Struct SelfAvoidingWalk 

Source
pub struct SelfAvoidingWalk<S: GrowthStrategy> {
    pub n_chains: usize,
    pub chain_length: usize,
    pub bond_length: F,
    pub target_density: F,
    pub pbc: Pbc3,
    pub seed: u64,
    pub strategy: S,
}
Expand description

Configuration for a periodic/reflective, fixed-bond-length self-avoiding random walk that grows n_chains independent chains of chain_length monomers each.

Construct it as a struct literal and inject a GrowthStrategy via the strategy field, then call generate:

use molrs::builder::{OffLattice, SelfAvoidingWalk};

let walk = SelfAvoidingWalk {
    n_chains: 2,
    chain_length: 20,
    bond_length: 1.53,
    target_density: 0.05,
    pbc: [true, true, true],
    seed: 9062,
    strategy: OffLattice { excluded_radius: 1.0 },
};
let out = walk.generate().unwrap();
assert_eq!(out.paths.len(), 2);

target_density is in monomers per unit volume — mass is out of scope, so the cubic box edge is a = (n_chains * chain_length / target_density).cbrt() (a lattice strategy may round it up to stay commensurate).

Fields§

§n_chains: usize

Number of independent chains to grow.

§chain_length: usize

Number of monomers per chain.

§bond_length: F

Fixed distance between consecutive monomers.

§target_density: F

Target number density (monomers per unit volume) used to size the box.

§pbc: Pbc3

Per-axis boundary flags: true = periodic (wrap), false = reflective.

§seed: u64

Seed for the deterministic RNG; equal seeds give identical paths.

§strategy: S

The monomer-placement policy (a struct implementing GrowthStrategy).

Implementations§

Source§

impl<S: GrowthStrategy> SelfAvoidingWalk<S>

Source

pub fn generate(&self) -> Result<WalkOutput, WalkError>

Grow all chains and return their paths plus the box used.

Deterministic in seed. Returns WalkError::InvalidConfig for out-of-range parameters, WalkError::BoxError if the box cannot be built, and WalkError::DeadEnd if a chain cannot be completed within the retry/backtrack/restart budget.

Auto Trait Implementations§

§

impl<S> Freeze for SelfAvoidingWalk<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for SelfAvoidingWalk<S>
where S: RefUnwindSafe,

§

impl<S> Send for SelfAvoidingWalk<S>
where S: Send,

§

impl<S> Sync for SelfAvoidingWalk<S>
where S: Sync,

§

impl<S> Unpin for SelfAvoidingWalk<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for SelfAvoidingWalk<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for SelfAvoidingWalk<S>
where S: UnwindSafe,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.