Struct chemfiles::Atom

source ·
pub struct Atom { /* private fields */ }
Expand description

An Atom is a particle in the current Frame. It stores the following atomic properties:

  • atom name;
  • atom type;
  • atom mass;
  • atom charge.

The atom name is usually an unique identifier (H1, C_a) while the atom type will be shared between all particles of the same type: H, Ow, CH3.

Implementations§

source§

impl Atom

source

pub fn new<'a>(name: impl Into<&'a str>) -> Atom

Create an atom with the given name, and set the atom type to name.

Example
let atom = Atom::new("He");
assert_eq!(atom.name(), "He");
source

pub fn mass(&self) -> f64

Get the atom mass, in atomic mass units.

Example
let atom = Atom::new("He");
assert_eq!(atom.mass(), 4.002602);
source

pub fn set_mass(&mut self, mass: f64)

Set the atom mass to mass, in atomic mass units.

Example
let mut atom = Atom::new("He");

atom.set_mass(34.9);
assert_eq!(atom.mass(), 34.9);
source

pub fn charge(&self) -> f64

Get the atom charge, in number of the electron charge e.

Example
let atom = Atom::new("He");
assert_eq!(atom.charge(), 0.0);
source

pub fn set_charge(&mut self, charge: f64)

Set the atom charge to charge, in number of the electron charge e.

Example
let mut atom = Atom::new("He");

atom.set_charge(-2.0);
assert_eq!(atom.charge(), -2.0);
source

pub fn name(&self) -> String

Get the atom name.

Example
let atom = Atom::new("He");
assert_eq!(atom.name(), "He");
source

pub fn atomic_type(&self) -> String

Get the atom type.

Example
let atom = Atom::new("He");
assert_eq!(atom.atomic_type(), "He");
source

pub fn set_name<'a>(&mut self, name: impl Into<&'a str>)

Set the atom name to name.

Example
let mut atom = Atom::new("He");

atom.set_name("Zn3");
assert_eq!(atom.name(), "Zn3");
source

pub fn set_atomic_type<'a>(&mut self, atomic_type: impl Into<&'a str>)

Set the atom type to atomic_type.

Example
let mut atom = Atom::new("He");

atom.set_atomic_type("F");
assert_eq!(atom.atomic_type(), "F");
source

pub fn full_name(&self) -> String

Try to get the full name of the atom from the atomic type. For example, the full name of “He” is “Helium”, and so on. If the name can not be found, this function returns the empty string.

Example
let atom = Atom::new("Zn");
assert_eq!(atom.full_name(), "Zinc");
source

pub fn vdw_radius(&self) -> f64

Try to get the Van der Waals radius of the atom from the atomic type. If the radius can not be found, returns 0.

Example
assert_eq!(Atom::new("He").vdw_radius(), 1.4);
assert_eq!(Atom::new("Xxx").vdw_radius(), 0.0);
source

pub fn covalent_radius(&self) -> f64

Try to get the covalent radius of the atom from the atomic type. If the radius can not be found, returns 0.

Example
assert_eq!(Atom::new("He").covalent_radius(), 0.32);
assert_eq!(Atom::new("Xxx").covalent_radius(), 0.0);
source

pub fn atomic_number(&self) -> u64

Try to get the atomic number of the atom from the atomic type. If the number can not be found, returns 0.

Example
assert_eq!(Atom::new("He").atomic_number(), 2);
assert_eq!(Atom::new("Xxx").atomic_number(), 0);
source

pub fn set(&mut self, name: &str, property: impl Into<Property>)

Add a new property with the given name to this atom.

If a property with the same name already exists, this function override the existing property with the new one.

Examples
let mut atom = Atom::new("He");
atom.set("a bool", true);
atom.set("a string", "test");

assert_eq!(atom.get("a bool"), Some(Property::Bool(true)));
assert_eq!(atom.get("a string"), Some(Property::String("test".into())));
source

pub fn get(&self, name: &str) -> Option<Property>

Get a property with the given name in this atom, if it exist.

Examples
let mut atom = Atom::new("He");
atom.set("foo", Property::Double(22.2));

assert_eq!(atom.get("foo"), Some(Property::Double(22.2)));
assert_eq!(atom.get("Bar"), None);
source

pub fn properties(&self) -> PropertiesIter<'_>

Get an iterator over all (name, property) pairs for this atom

Examples
let mut atom = Atom::new("He");
atom.set("foo", Property::Double(22.2));
atom.set("bar", Property::Bool(false));

for (name, property) in atom.properties() {
    if name == "foo" {
        assert_eq!(property, Property::Double(22.2));
    } else if name == "bar" {
        assert_eq!(property, Property::Bool(false));
    }
}

Trait Implementations§

source§

impl Clone for Atom

source§

fn clone(&self) -> Atom

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 Atom

source§

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

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

impl Drop for Atom

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Atom

§

impl !Send for Atom

§

impl !Sync for Atom

§

impl Unpin for Atom

§

impl UnwindSafe for Atom

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> 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> 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.