Skip to main content

MoleculeBuilder

Struct MoleculeBuilder 

Source
pub struct MoleculeBuilder { /* private fields */ }
Expand description

Builder for constructing a Molecule incrementally.

Usage: add atoms, add bonds, then call build().

Implementations§

Source§

impl MoleculeBuilder

Source

pub fn new() -> Self

Source

pub fn from_molecule(mol: &Molecule) -> Self

Create a builder pre-populated with all atoms and bonds from mol.

Use this to make incremental edits to an existing molecule instead of reconstructing it from scratch.

Source

pub fn set_stereo_neighbor_order(&mut self, idx: AtomIdx, order: Vec<u32>)

Set the SMILES stereo neighbor order for atom idx.

Source

pub fn clear_stereo_neighbor_order(&mut self, idx: AtomIdx)

Remove the stereo neighbor order entry for atom idx.

Source

pub fn add_stereo_group(&mut self, group: StereoGroup)

Append a stereo group to this builder.

Source

pub fn copy_stereo_from(&mut self, mol: &Molecule)

Copy all stereo neighbor order entries from mol into this builder.

Source

pub fn atom_at(&self, idx: AtomIdx) -> &Atom

Read-only reference to an atom already added to the builder.

Used by the SMILES parser to infer implicit bond types without consuming the builder (e.g. aromatic-aromatic → Aromatic bond).

§Panics

Panics if idx is out of range.

Source

pub fn atom_count(&self) -> usize

Number of atoms added so far.

Source

pub fn atom_neighbors( &self, idx: AtomIdx, ) -> impl Iterator<Item = (BondIdx, AtomIdx)> + '_

Iterate over already-added neighbors of idx as (bond_idx, neighbor_atom_idx). Used by kekulization tests to check whether a bond already exists in the builder.

Source

pub fn add_atom(&mut self, atom: Atom) -> AtomIdx

Add an atom and return its index.

Source

pub fn add_bond( &mut self, a: AtomIdx, b: AtomIdx, order: BondOrder, ) -> Result<BondIdx, MolError>

Add a bond between two existing atoms.

Returns an error if either atom index is invalid or if the bond already exists.

Source

pub fn build(self) -> Molecule

Consume the builder and return an immutable Molecule.

Trait Implementations§

Source§

impl Default for MoleculeBuilder

Source§

fn default() -> MoleculeBuilder

Returns the “default value” for a type. Read more

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.