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