Struct gchemol_core::Molecule
source · pub struct Molecule {
pub properties: PropertyStore,
pub lattice: Option<Lattice>,
/* private fields */
}
Expand description
Molecule is the most important data structure in gchemol, which repsents “any singular entity, irrespective of its nature, used to concisely express any type of chemical particle that can exemplify some process: for example, atoms, molecules, ions, etc. can all undergo a chemical reaction”. Molecule may have chemical bonds between atoms.
§Reference
- http://goldbook.iupac.org/M03986.html
- https://en.wikipedia.org/wiki/Molecular_entity
Fields§
§properties: PropertyStore
Arbitrary property stored in key-value pair. Key is a string type, but it is the responsibility of the user to correctly interpret the value.
lattice: Option<Lattice>
Crystalline lattice for structure using periodic boundary conditions
Implementations§
source§impl Molecule
impl Molecule
sourcepub fn from_database(name: &str) -> Self
pub fn from_database(name: &str) -> Self
Returns Molecule
created from the internal database (mainly for tests).
Available names: CH4
, H2O
, HCN
source§impl Molecule
impl Molecule
Lattice related methods
sourcepub fn set_lattice(&mut self, lat: Lattice)
pub fn set_lattice(&mut self, lat: Lattice)
Set periodic lattice as lat
.
sourcepub fn set_lattice_scaled(&mut self, lat: Lattice)
pub fn set_lattice_scaled(&mut self, lat: Lattice)
Set periodic Lattice as lat
, and scaled atom positions to fit new
lattice. Will panic if not a periodic structure.
sourcepub fn is_periodic(&self) -> bool
pub fn is_periodic(&self) -> bool
Return true if Molecule
is a periodic structure.
sourcepub fn unbuild_crystal(&mut self) -> Option<Lattice>
pub fn unbuild_crystal(&mut self) -> Option<Lattice>
Unbuild current crystal structure leaving a nonperiodic
structure. Return Lattice
object if periodic, otherwise return None.
sourcepub fn scaled_positions(&self) -> Option<impl Iterator<Item = [f64; 3]> + '_>
👎Deprecated: use get_scaled_positions instead
pub fn scaled_positions(&self) -> Option<impl Iterator<Item = [f64; 3]> + '_>
Return fractional coordinates relative to unit cell. Return None if not a periodic structure
sourcepub fn get_scaled_positions(
&self
) -> Option<impl Iterator<Item = [f64; 3]> + '_>
pub fn get_scaled_positions( &self ) -> Option<impl Iterator<Item = [f64; 3]> + '_>
Return fractional coordinates relative to unit cell. Return None if not a periodic structure
sourcepub fn set_scaled_positions<T, P>(&mut self, scaled: T)
pub fn set_scaled_positions<T, P>(&mut self, scaled: T)
Set fractional coordinates of atoms in sequence order.
Panics if Molecule is aperiodic.
sourcepub fn set_scaled_positions_from<T, P>(&mut self, scaled: T)
pub fn set_scaled_positions_from<T, P>(&mut self, scaled: T)
Set fractional coordinates of atoms specified in serial numbers.
Panics if Molecule is aperiodic.
source§impl Molecule
impl Molecule
sourcepub fn bounding_box(&self, padding: f64) -> [f64; 3]
pub fn bounding_box(&self, padding: f64) -> [f64; 3]
Return minimal bounding box in x, y, z directions
source§impl Molecule
impl Molecule
Molecule
constructors
sourcepub fn from_atoms<T>(atoms: T) -> Self
pub fn from_atoms<T>(atoms: T) -> Self
Build a molecule from iterator of atoms associated with serial numbers from 1.
sourcepub fn from_graph(graph: NxGraph<Atom, Bond>) -> Self
pub fn from_graph(graph: NxGraph<Atom, Bond>) -> Self
Build Molecule
from raw graph struct.
sourcepub fn from_graph_raw(
graph: NxGraph<Atom, Bond>,
atoms: impl IntoIterator<Item = usize>
) -> Self
pub fn from_graph_raw( graph: NxGraph<Atom, Bond>, atoms: impl IntoIterator<Item = usize> ) -> Self
Build Molecule
from raw graph struct, with atom serial numbers.
source§impl Molecule
impl Molecule
Core methods
sourcepub fn add_atom(&mut self, a: usize, atom: Atom)
pub fn add_atom(&mut self, a: usize, atom: Atom)
Add atom a
into molecule. If Atom numbered as a
already exists in
molecule, then the associated Atom will be updated with atom
.
sourcepub fn remove_atom(&mut self, a: usize) -> Option<Atom>
pub fn remove_atom(&mut self, a: usize) -> Option<Atom>
Remove Atom a
from Molecule
.
Return the removed Atom on success, and return None if Atom a
does not
exist.
sourcepub fn add_bond(&mut self, a: usize, b: usize, bond: Bond)
pub fn add_bond(&mut self, a: usize, b: usize, bond: Bond)
Add bond
between Atom a
and Atom b
into molecule. The existing
Bond will be replaced if Atom a
already bonded with Atom b
.
Panic if the specified atom a
or b
does not exist
sourcepub fn remove_bond(&mut self, a: usize, b: usize) -> Option<Bond>
pub fn remove_bond(&mut self, a: usize, b: usize) -> Option<Bond>
Remove the bond between atom a
and atom b
.
Returns the removed Bond
on success
Panic if the specified atom a
or b
does not exist
sourcepub fn atoms(&self) -> impl Iterator<Item = (usize, &Atom)>
pub fn atoms(&self) -> impl Iterator<Item = (usize, &Atom)>
Iterate over atoms ordered by serial numbers.
sourcepub fn bonds(&self) -> impl Iterator<Item = (usize, usize, &Bond)>
pub fn bonds(&self) -> impl Iterator<Item = (usize, usize, &Bond)>
Iterate over bonds in arbitrary order.
sourcepub fn serial_numbers(&self) -> impl Iterator<Item = usize>
pub fn serial_numbers(&self) -> impl Iterator<Item = usize>
Iterate over atom serial numbers in ascending order. Serial number is an
unsigned integer (1-based, traditionally) for accessing Atom
in
Molecule
sourcepub fn numbers(&self) -> impl Iterator<Item = usize> + '_
pub fn numbers(&self) -> impl Iterator<Item = usize> + '_
A shorter alias to serial_numbers method.
sourcepub fn symbols(&self) -> impl Iterator<Item = &str>
pub fn symbols(&self) -> impl Iterator<Item = &str>
Iterate over atom symbols ordered by serial numbers.
sourcepub fn masses(&self) -> impl Iterator<Item = f64> + '_
pub fn masses(&self) -> impl Iterator<Item = f64> + '_
Iterate over atom’s mass ordered by atom’s serial numbers. Dummy atom has mass of zero.
sourcepub fn atomic_numbers(&self) -> impl Iterator<Item = usize> + '_
pub fn atomic_numbers(&self) -> impl Iterator<Item = usize> + '_
Iterate over atomic numbers.
source§impl Molecule
impl Molecule
Edit Molecule
sourcepub fn get_atom_unchecked(&self, sn: usize) -> &Atom
pub fn get_atom_unchecked(&self, sn: usize) -> &Atom
Read access to atom by atom serial number. Panic if no this atom.
sourcepub fn has_atom(&self, sn: usize) -> bool
pub fn has_atom(&self, sn: usize) -> bool
Returns true if the molecule contains atom with the given sn
sourcepub fn get_atom_mut(&mut self, sn: usize) -> Option<&mut Atom>
pub fn get_atom_mut(&mut self, sn: usize) -> Option<&mut Atom>
Mutable access to atom by atom serial number.
sourcepub fn get_atom_unchecked_mut(&mut self, sn: usize) -> &mut Atom
pub fn get_atom_unchecked_mut(&mut self, sn: usize) -> &mut Atom
Mutable access to atom by atom serial number. Panic if no this atom.
sourcepub fn get_bond(&self, sn1: usize, sn2: usize) -> Option<&Bond>
pub fn get_bond(&self, sn1: usize, sn2: usize) -> Option<&Bond>
Read access to bond by a pair of atoms. Return None if there is no bond
between Atom sn1
and Atom sn2
.
sourcepub fn has_bond(&self, sn1: usize, sn2: usize) -> bool
pub fn has_bond(&self, sn1: usize, sn2: usize) -> bool
Returns true if the molcule contains bond between atom sn1
and sn2
sourcepub fn get_bond_mut(&mut self, sn1: usize, sn2: usize) -> Option<&mut Bond>
pub fn get_bond_mut(&mut self, sn1: usize, sn2: usize) -> Option<&mut Bond>
Mutable access to bond by a pair of atoms.
sourcepub fn set_position<P: Into<Vector3f>>(&mut self, sn: usize, position: P)
pub fn set_position<P: Into<Vector3f>>(&mut self, sn: usize, position: P)
Set atom position.
Panic if atom sn
does not exist.
sourcepub fn set_symbol<S: Into<AtomKind>>(&mut self, sn: usize, sym: S)
pub fn set_symbol<S: Into<AtomKind>>(&mut self, sn: usize, sym: S)
Set atom symbol.
Panic if atom sn
does not exist.
sourcepub fn add_atoms_from<T, P>(&mut self, atoms: T)
pub fn add_atoms_from<T, P>(&mut self, atoms: T)
Add a list of atoms into molecule.
sourcepub fn add_bonds_from<T>(&mut self, bonds: T)
pub fn add_bonds_from<T>(&mut self, bonds: T)
Add a list of bonds into molecule.
sourcepub fn set_positions<T, P>(&mut self, positions: T)
pub fn set_positions<T, P>(&mut self, positions: T)
Set positions of atoms in sequential order.
sourcepub fn update_positions<T, P>(&mut self, positions: T)
pub fn update_positions<T, P>(&mut self, positions: T)
Update positions of atoms in sequential order, with freezing coordinates ignored.
sourcepub fn set_positions_from<T, P>(&mut self, selected_positions: T)
pub fn set_positions_from<T, P>(&mut self, selected_positions: T)
Set positions of specified atoms
sourcepub fn set_symbols<T, S>(&mut self, symbols: T)
pub fn set_symbols<T, S>(&mut self, symbols: T)
Set element symbols
sourcepub fn remove_atoms_from(&mut self)
pub fn remove_atoms_from(&mut self)
Remove atoms from .. (unimplemented)
sourcepub fn remove_bonds_from(&mut self)
pub fn remove_bonds_from(&mut self)
Remove bonds from .. (unimplemented)
Trait Implementations§
source§impl<'de> Deserialize<'de> for Molecule
impl<'de> Deserialize<'de> for Molecule
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Molecule
impl RefUnwindSafe for Molecule
impl Send for Molecule
impl Sync for Molecule
impl Unpin for Molecule
impl UnwindSafe for Molecule
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Configure for T
impl<T> Configure for T
source§fn print_toml(&self)
fn print_toml(&self)
source§fn from_json(s: &str) -> Result<Self, Error>
fn from_json(s: &str) -> Result<Self, Error>
source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moresource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.