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

  1. http://goldbook.iupac.org/M03986.html
  2. 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

source

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

Chemical formula

source

pub fn formula(&self) -> String

Return the molecule formula represented in string according to the Hill system order. Return empty string if molecule containing no atom.

source

pub fn reduced_symbols(&self) -> HashMap<String, usize>

Return a hashmap for counting atom symbols.

source§

impl Molecule

Lattice related methods

source

pub fn set_lattice(&mut self, lat: Lattice)

Set periodic lattice as lat.

source

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.

source

pub fn is_periodic(&self) -> bool

Return true if Molecule is a periodic structure.

source

pub fn unbuild_crystal(&mut self) -> Option<Lattice>

Unbuild current crystal structure leaving a nonperiodic structure. Return Lattice object if periodic, otherwise return None.

source

pub fn scaled_positions(&self) -> Option<impl Iterator<Item = [f64; 3]> + '_>

👎Deprecated: use get_scaled_positions instead

Return fractional coordinates relative to unit cell. Return None if not a periodic structure

source

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

source

pub fn set_scaled_positions<T, P>(&mut self, scaled: T)
where T: IntoIterator<Item = P>, P: Into<Vector3f>,

Set fractional coordinates of atoms in sequence order.

Panics if Molecule is aperiodic.

source

pub fn set_scaled_positions_from<T, P>(&mut self, scaled: T)
where T: IntoIterator<Item = (usize, P)>, P: Into<Vector3f>,

Set fractional coordinates of atoms specified in serial numbers.

Panics if Molecule is aperiodic.

source§

impl Molecule

source

pub fn bounding_box(&self, padding: f64) -> [f64; 3]

Return minimal bounding box in x, y, z directions

source§

impl Molecule

Molecule constructors

source

pub fn new(name: &str) -> Self

Create a new empty molecule with specific name

source

pub fn from_atoms<T>(atoms: T) -> Self
where T: IntoIterator, T::Item: Into<Atom>,

Build a molecule from iterator of atoms associated with serial numbers from 1.

source

pub fn from_graph(graph: NxGraph<Atom, Bond>) -> Self

Build Molecule from raw graph struct.

source

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

Core methods

source

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.

source

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.

source

pub fn natoms(&self) -> usize

Return the number of atoms in the molecule.

source

pub fn nbonds(&self) -> usize

Return the number of bonds in the molecule.

source

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

source

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

source

pub fn clear(&mut self)

Remove all atoms and bonds. To remove bonds only, see unbound method.

source

pub fn atoms(&self) -> impl Iterator<Item = (usize, &Atom)>

Iterate over atoms ordered by serial numbers.

source

pub fn bonds(&self) -> impl Iterator<Item = (usize, usize, &Bond)>

Iterate over bonds in arbitrary order.

source

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

source

pub fn numbers(&self) -> impl Iterator<Item = usize> + '_

A shorter alias to serial_numbers method.

source

pub fn symbols(&self) -> impl Iterator<Item = &str>

Iterate over atom symbols ordered by serial numbers.

source

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.

source

pub fn atomic_numbers(&self) -> impl Iterator<Item = usize> + '_

Iterate over atomic numbers.

source

pub fn positions(&self) -> impl Iterator<Item = Point3> + '_

Iterate over atom positions ordered by serial numbers.

source

pub fn title(&self) -> String

A short description of the molecule.

NOTE: for long title, only the first line will be return for safely storing in various chemical file formats such as xyz.

source§

impl Molecule

Edit Molecule

source

pub fn get_atom(&self, sn: usize) -> Option<&Atom>

Read access to atom by atom serial number.

source

pub fn get_atom_unchecked(&self, sn: usize) -> &Atom

Read access to atom by atom serial number. Panic if no this atom.

source

pub fn has_atom(&self, sn: usize) -> bool

Returns true if the molecule contains atom with the given sn

source

pub fn get_atom_mut(&mut self, sn: usize) -> Option<&mut Atom>

Mutable access to atom by atom serial number.

source

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.

source

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.

source

pub fn has_bond(&self, sn1: usize, sn2: usize) -> bool

Returns true if the molcule contains bond between atom sn1 and sn2

source

pub fn get_bond_mut(&mut self, sn1: usize, sn2: usize) -> Option<&mut Bond>

Mutable access to bond by a pair of atoms.

source

pub fn set_position<P: Into<Vector3f>>(&mut self, sn: usize, position: P)

Set atom position.

Panic if atom sn does not exist.

source

pub fn set_symbol<S: Into<AtomKind>>(&mut self, sn: usize, sym: S)

Set atom symbol.

Panic if atom sn does not exist.

source

pub fn add_atoms_from<T, P>(&mut self, atoms: T)
where T: IntoIterator<Item = (usize, P)>, P: Into<Atom>,

Add a list of atoms into molecule.

source

pub fn set_title<S: AsRef<str>>(&mut self, title: S)

Set molecular title.

source

pub fn add_bonds_from<T>(&mut self, bonds: T)
where T: IntoIterator<Item = (usize, usize, Bond)>,

Add a list of bonds into molecule.

source

pub fn set_positions<T, P>(&mut self, positions: T)
where T: IntoIterator<Item = P>, P: Into<Vector3f>,

Set positions of atoms in sequential order.

source

pub fn update_positions<T, P>(&mut self, positions: T)
where T: IntoIterator<Item = P>, P: Into<Vector3f>,

Update positions of atoms in sequential order, with freezing coordinates ignored.

source

pub fn set_positions_from<T, P>(&mut self, selected_positions: T)
where T: IntoIterator<Item = (usize, P)>, P: Into<Vector3f>,

Set positions of specified atoms

source

pub fn set_symbols<T, S>(&mut self, symbols: T)
where T: IntoIterator<Item = S>, S: Into<AtomKind>,

Set element symbols

source

pub fn remove_atoms_from(&mut self)

Remove atoms from .. (unimplemented)

source

pub fn remove_bonds_from(&mut self)

Remove bonds from .. (unimplemented)

Trait Implementations§

source§

impl Clone for Molecule

source§

fn clone(&self) -> Molecule

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Molecule

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Molecule

source§

fn default() -> Molecule

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Molecule

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Serialize for Molecule

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> Configure for T

source§

fn print_toml(&self)

👎Deprecated: plan to be removed
Print current configuration in toml format.
source§

fn from_json(s: &str) -> Result<Self, Error>

Deserialize an instance of type T from a string of JSON text.
source§

fn from_toml(s: &str) -> Result<Self, Error>

Deserialize an instance of type T from a string of TOML text.
source§

fn to_json(&self) -> Result<String, Error>

Serialize it to a JSON string.
source§

fn to_toml(&self) -> Result<String, Error>

Serialize self to a TOML string.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,