Struct chemfiles::Atom[][src]

pub struct Atom { /* fields omitted */ }
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

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");

Get the atom mass, in atomic mass units.

Example

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

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);

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

Example

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

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);

Get the atom name.

Example

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

Get the atom type.

Example

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

Set the atom name to name.

Example

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

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

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");

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");

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);

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);

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);

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())));

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);

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.