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
impl Molecule
Sourcepub fn atom_count(&self) -> usize
pub fn atom_count(&self) -> usize
Number of heavy atoms (does not count implicit H).
Sourcepub fn bond_count(&self) -> usize
pub fn bond_count(&self) -> usize
Number of bonds (edges).
Sourcepub fn atom(&self, idx: AtomIdx) -> &Atom
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).
Sourcepub fn atoms(&self) -> impl Iterator<Item = (AtomIdx, &Atom)>
pub fn atoms(&self) -> impl Iterator<Item = (AtomIdx, &Atom)>
Iterate over all atoms as (AtomIdx, &Atom).
Sourcepub fn bonds(&self) -> impl Iterator<Item = (BondIdx, &BondEntry)>
pub fn bonds(&self) -> impl Iterator<Item = (BondIdx, &BondEntry)>
Iterate over all bonds as (BondIdx, &BondEntry).
Sourcepub fn neighbors(
&self,
idx: AtomIdx,
) -> impl Iterator<Item = (AtomIdx, BondIdx)> + '_
pub fn neighbors( &self, idx: AtomIdx, ) -> impl Iterator<Item = (AtomIdx, BondIdx)> + '_
Iterate over neighbors of idx as (neighbor_atom_idx, bond_idx).
Source§impl Molecule
impl Molecule
Sourcepub fn with_atom_added(&self, atom: Atom) -> (Molecule, AtomIdx)
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.
Sourcepub fn with_bond_added(
&self,
a: AtomIdx,
b: AtomIdx,
order: BondOrder,
) -> Result<(Molecule, BondIdx), MolError>
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).
Sourcepub fn with_atom_charge(&self, idx: AtomIdx, charge: i8) -> Molecule
pub fn with_atom_charge(&self, idx: AtomIdx, charge: i8) -> Molecule
Return a new Molecule with the formal charge of atom idx changed.
Sourcepub fn with_atom_element(&self, idx: AtomIdx, el: Element) -> Molecule
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.
Sourcepub fn with_atom_removed(
&self,
idx: AtomIdx,
) -> (Molecule, Vec<Option<AtomIdx>>)
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).
Sourcepub fn with_bond_removed(&self, idx: BondIdx) -> Molecule
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.