Struct Molecule
pub struct Molecule { /* private fields */ }Expand description
A named molecular entity with formula and optional structural primitives.
Implementations§
§impl Molecule
impl Molecule
pub fn new(
name: &str,
formula: ChemicalFormula,
) -> Result<Molecule, MoleculeValidationError>
pub fn new( name: &str, formula: ChemicalFormula, ) -> Result<Molecule, MoleculeValidationError>
Creates a molecule from a name and formula.
§Errors
Returns MoleculeValidationError::EmptyName when name is empty after trimming.
pub fn builder(name: &str) -> MoleculeBuilder
pub fn builder(name: &str) -> MoleculeBuilder
Starts a molecule builder.
pub const fn name(&self) -> &MoleculeName
pub const fn name(&self) -> &MoleculeName
Returns the molecule name.
pub fn formula(&self) -> &ChemicalFormula
pub fn formula(&self) -> &ChemicalFormula
Returns the molecule formula.
pub const fn molecular_formula(&self) -> &MolecularFormula
pub const fn molecular_formula(&self) -> &MolecularFormula
Returns the molecule formula wrapper.
pub fn atoms(&self) -> &[MolecularAtom]
pub fn atoms(&self) -> &[MolecularAtom]
Returns explicit atoms in insertion order.
pub fn atom_count(&self) -> usize
pub fn atom_count(&self) -> usize
Returns the number of explicit atoms.
pub fn atom_count_value(&self) -> AtomCount
pub fn atom_count_value(&self) -> AtomCount
Returns the explicit atom count wrapper.
pub fn connections(&self) -> &[AtomConnection]
pub fn connections(&self) -> &[AtomConnection]
Returns explicit atom connections in insertion order.
pub const fn charge(&self) -> MoleculeCharge
pub const fn charge(&self) -> MoleculeCharge
Returns the formal molecule charge.
pub fn kinds(&self) -> &[MoleculeKind]
pub fn kinds(&self) -> &[MoleculeKind]
Returns molecule kind labels in insertion order.
pub fn with_kind(self, kind: MoleculeKind) -> Molecule
pub fn with_kind(self, kind: MoleculeKind) -> Molecule
Adds a kind label if it is not already present.
pub const fn with_charge(self, charge: MoleculeCharge) -> Molecule
pub const fn with_charge(self, charge: MoleculeCharge) -> Molecule
Sets the formal molecule charge.
pub fn with_atom(self, atom: MolecularAtom) -> Molecule
pub fn with_atom(self, atom: MolecularAtom) -> Molecule
Adds an explicit atom.
pub fn try_with_connection(
self,
connection: AtomConnection,
) -> Result<Molecule, MoleculeValidationError>
pub fn try_with_connection( self, connection: AtomConnection, ) -> Result<Molecule, MoleculeValidationError>
Adds an atom connection after validating its indices against the explicit atom list.
§Errors
Returns MoleculeValidationError::InvalidConnectionIndex when the connection references an
atom index outside the explicit atom list.