pub struct Molecule { /* private fields */ }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).
For a non-panicking variant, use Self::atom_opt.
Sourcepub fn atom_opt(&self, idx: AtomIdx) -> Option<&Atom>
pub fn atom_opt(&self, idx: AtomIdx) -> Option<&Atom>
Borrow atom by index, returning None if out of range.
Sourcepub fn bond(&self, idx: BondIdx) -> &BondEntry
pub fn bond(&self, idx: BondIdx) -> &BondEntry
Borrow bond by index.
§Panics
Panics if idx is out of range (should not happen with indices from this molecule).
For a non-panicking variant, use Self::bond_opt.
Sourcepub fn bond_opt(&self, idx: BondIdx) -> Option<&BondEntry>
pub fn bond_opt(&self, idx: BondIdx) -> Option<&BondEntry>
Borrow bond by index, returning None if out of range.
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).
§Panics
Panics if idx is out of range (should not happen with indices from this molecule).
For a non-panicking variant, use Self::neighbors_opt.
Sourcepub fn neighbors_opt(&self, idx: AtomIdx) -> Option<Vec<(AtomIdx, BondIdx)>>
pub fn neighbors_opt(&self, idx: AtomIdx) -> Option<Vec<(AtomIdx, BondIdx)>>
Iterate over neighbors of idx as (neighbor_atom_idx, bond_idx), returning None if out of range.
Sourcepub fn degree(&self, idx: AtomIdx) -> usize
pub fn degree(&self, idx: AtomIdx) -> usize
Degree (number of connected bonds) of atom idx.
§Panics
Panics if idx is out of range (should not happen with indices from this molecule).
For a non-panicking variant, use Self::degree_opt.
Sourcepub fn degree_opt(&self, idx: AtomIdx) -> Option<usize>
pub fn degree_opt(&self, idx: AtomIdx) -> Option<usize>
Degree (number of connected bonds) of atom idx, returning None if out of range.
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 implicit_hydrogen_count(&self, idx: AtomIdx) -> u8
pub fn implicit_hydrogen_count(&self, idx: AtomIdx) -> u8
Implicit hydrogen count for atom idx based on valence rules.
Delegates to crate::valence::implicit_hcount.
Sourcepub fn total_formula(&self) -> String
pub fn total_formula(&self) -> String
Hill-order molecular formula including implicit hydrogens.
Unlike Self::formula (which counts only explicit heavy atoms),
this method adds the implicit H count for every atom so the result
reflects the true molecular composition (e.g. methane → “CH4”).
Sourcepub fn formula_with_isotopes(&self) -> String
pub fn formula_with_isotopes(&self) -> String
Hill-order molecular formula with isotope labels.
Like Self::formula but prefixes each element symbol with its
isotope number when atom.isotope is Some(n).
Example: a molecule with one ¹³C and one O → "¹³CO".
Sourcepub fn with_atom_aromatic(&self, idx: AtomIdx, aromatic: bool) -> Molecule
pub fn with_atom_aromatic(&self, idx: AtomIdx, aromatic: bool) -> Molecule
Return a new Molecule with atom idx’s aromatic flag changed.
Sourcepub fn with_bond_order(&self, idx: BondIdx, order: BondOrder) -> Molecule
pub fn with_bond_order(&self, idx: BondIdx, order: BondOrder) -> Molecule
Return a new Molecule with bond idx’s order changed.
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.
Source§impl Molecule
impl Molecule
Sourcepub fn remove_atom(&mut self, idx: AtomIdx) -> Vec<Option<AtomIdx>>
pub fn remove_atom(&mut self, idx: AtomIdx) -> Vec<Option<AtomIdx>>
Remove atom idx and all bonds involving it.
Returns a remapping table: remap[old_idx] gives the new AtomIdx
for surviving atoms, or None for the removed atom. Atom indices
of atoms after the removed slot shift down by 1.
Sourcepub fn add_bond(
&mut self,
a: AtomIdx,
b: AtomIdx,
order: BondOrder,
) -> Result<BondIdx, MolError>
pub fn add_bond( &mut self, a: AtomIdx, b: AtomIdx, order: BondOrder, ) -> Result<BondIdx, MolError>
Add a bond between a and b with the given order.
Returns Err if a == b or the bond already exists.
Sourcepub fn remove_bond(&mut self, idx: BondIdx)
pub fn remove_bond(&mut self, idx: BondIdx)
Remove bond idx. Atom indices are unchanged; bond indices of
surviving bonds shift down past the removed slot.
Sourcepub fn set_charge(&mut self, idx: AtomIdx, charge: i8)
pub fn set_charge(&mut self, idx: AtomIdx, charge: i8)
Set the formal charge of atom idx in-place.
Sourcepub fn set_element(&mut self, idx: AtomIdx, el: Element)
pub fn set_element(&mut self, idx: AtomIdx, el: Element)
Set the element of atom idx in-place.
Chirality and hydrogen count are reset (element-specific properties).
Sourcepub fn set_cip_code(&mut self, idx: AtomIdx, code: Option<CipCode>)
pub fn set_cip_code(&mut self, idx: AtomIdx, code: Option<CipCode>)
Set the CIP stereo code of atom idx in-place.
Sourcepub fn stereo_groups(&self) -> &[StereoGroup]
pub fn stereo_groups(&self) -> &[StereoGroup]
Return the enhanced stereo groups attached to this molecule.
Sourcepub fn set_stereo_groups(&mut self, groups: Vec<StereoGroup>)
pub fn set_stereo_groups(&mut self, groups: Vec<StereoGroup>)
Replace the stereo group list in-place.
Sourcepub fn add_stereo_group(&mut self, group: StereoGroup)
pub fn add_stereo_group(&mut self, group: StereoGroup)
Add a single stereo group in-place.
Sourcepub fn stereo_neighbor_order(&self, idx: AtomIdx) -> Option<&[u32]>
pub fn stereo_neighbor_order(&self, idx: AtomIdx) -> Option<&[u32]>
SMILES-text-order neighbor sequence for a chiral atom.
Returns None for atoms not parsed from SMILES or without stereo.
The slice contains neighbor atom indices in SMILES text order;
STEREO_H_SENTINEL (u32::MAX) marks the implicit bracket-H slot.
Sourcepub fn set_stereo_neighbor_order(&mut self, idx: AtomIdx, order: Vec<u32>)
pub fn set_stereo_neighbor_order(&mut self, idx: AtomIdx, order: Vec<u32>)
Set the SMILES stereo neighbor order for atom idx.