Skip to main content

Molecule

Struct Molecule 

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

An immutable molecular graph built via MoleculeBuilder.

Representation: atom list + bond list + per-atom adjacency list. No external graph library is used; all graph traversal is domain-aware.

Implementations§

Source§

impl Molecule

Source

pub fn atom_count(&self) -> usize

Number of heavy atoms (does not count implicit H).

Source

pub fn bond_count(&self) -> usize

Number of bonds (edges).

Source

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

Borrow atom by index.

§Panics

Panics if idx is out of range (should not happen with indices from this molecule).

Source

pub fn bond(&self, idx: BondIdx) -> &BondEntry

Borrow bond by index.

Source

pub fn atoms(&self) -> impl Iterator<Item = (AtomIdx, &Atom)>

Iterate over all atoms as (AtomIdx, &Atom).

Source

pub fn bonds(&self) -> impl Iterator<Item = (BondIdx, &BondEntry)>

Iterate over all bonds as (BondIdx, &BondEntry).

Source

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

Iterate over neighbors of idx as (neighbor_atom_idx, bond_idx).

Source

pub fn degree(&self, idx: AtomIdx) -> usize

Degree (number of connected bonds) of atom idx.

Source

pub fn bond_between( &self, a: AtomIdx, b: AtomIdx, ) -> Option<(BondIdx, &BondEntry)>

Return the bond between a and b, or None if not connected.

Source

pub fn formula(&self) -> String

Molecular formula as a Hill-order string (C first, H second, then alphabetical).

Source§

impl Molecule

Source

pub fn with_atom_added(&self, atom: Atom) -> (Molecule, AtomIdx)

Return a new Molecule with one extra atom appended, along with the index that the new atom will have in the returned molecule.

Source

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

Return a new Molecule with one extra bond added, along with the index of the newly added bond in the returned molecule.

Returns Err if a == b or the bond already exists (same semantics as MoleculeBuilder::add_bond).

Source

pub fn with_atom_charge(&self, idx: AtomIdx, charge: i8) -> Molecule

Return a new Molecule with the formal charge of atom idx changed.

Source

pub fn with_atom_element(&self, idx: AtomIdx, el: Element) -> Molecule

Return a new Molecule with the element of atom idx changed.

Chirality and hydrogen count are reset to None when the element changes, since those properties are element-specific.

Source

pub fn with_atom_removed( &self, idx: AtomIdx, ) -> (Molecule, Vec<Option<AtomIdx>>)

Return a new Molecule with atom idx and all bonds involving it removed. Atom indices of survivors shift down past the removed slot.

The returned tuple also includes a mapping from old AtomIdx to new AtomIdx (indices that fall below idx are unchanged; indices above idx decrease by 1).

Source

pub fn with_bond_removed(&self, idx: BondIdx) -> Molecule

Return a new Molecule with bond idx removed.

Atom indices are unchanged. Bond indices of survivors shift down.

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.