[][src]Struct chemfiles::Frame

pub struct Frame { /* fields omitted */ }

A Frame contains data from one simulation step: the current unit cell, the topology, the positions, and the velocities of the particles in the system. If some information is missing (topology or velocity or unit cell), the corresponding data is filled with a default value.

Methods

impl Frame
[src]

Create an empty frame. It will be resized by the library as needed.

Example

let frame = Frame::new().unwrap();

Get a copy of the atom at index index in this frame.

Example

let mut frame = Frame::new().unwrap();
frame.add_atom(&Atom::new("Zn").unwrap(), [0.0; 3], None).unwrap();

let atom = frame.atom(0).unwrap();
assert_eq!(atom.name(), Ok(String::from("Zn")));

Get the current number of atoms in this frame.

Example

let mut frame = Frame::new().unwrap();
assert_eq!(frame.size(), Ok(0));

frame.resize(67).unwrap();
assert_eq!(frame.size(), Ok(67));

Resize the positions and the velocities in this frame, to make space for natoms atoms. Previous data is conserved, as well as the presence of absence of velocities.

Example

let mut frame = Frame::new().unwrap();
frame.resize(67).unwrap();
assert_eq!(frame.size(), Ok(67));

Add an Atom and the corresponding position and optionally velocity data to this frame.

Example

let mut frame = Frame::new().unwrap();
frame.add_atom(&Atom::new("Zn").unwrap(), [1.0, 1.0, 2.0], None).unwrap();

frame.add_velocities().unwrap();
frame.add_atom(&Atom::new("Zn").unwrap(), [-1.0, 1.0, 2.0], [0.2, 0.1, 0.0]).unwrap();

Remove the atom at index i in this frame.

Example

let mut frame = Frame::new().unwrap();
frame.add_atom(&Atom::new("Zn").unwrap(), [0.0; 3], None).unwrap();
frame.add_atom(&Atom::new("Fe").unwrap(), [0.0; 3], None).unwrap();
frame.add_atom(&Atom::new("Sn").unwrap(), [0.0; 3], None).unwrap();
assert_eq!(frame.size(), Ok(3));

frame.remove(1).unwrap();
assert_eq!(frame.size(), Ok(2));
assert_eq!(frame.atom(1).unwrap().name().unwrap(), "Sn");

Add a bond between the atoms at indexes i and j in the frame.

Example

let mut frame = Frame::new().unwrap();
for i in 0..5 {
   frame.add_atom(&Atom::new("C").unwrap(), [0.0; 3], None).unwrap();
}

frame.add_bond(0, 1).unwrap();
frame.add_bond(3, 1).unwrap();
frame.add_bond(2, 4).unwrap();

let bonds = frame.topology().unwrap().bonds().unwrap();
assert_eq!(bonds, vec![[0, 1], [1, 3], [2, 4]]);

Remove any existing bond between the atoms at indexes i and j in the frame.

This function does nothing if there is no bond between i and j.

Example

let mut frame = Frame::new().unwrap();
for i in 0..5 {
   frame.add_atom(&Atom::new("C").unwrap(), [0.0; 3], None).unwrap();
}

frame.add_bond(0, 1).unwrap();
frame.add_bond(3, 1).unwrap();
frame.add_bond(2, 4).unwrap();

let bonds = frame.topology().unwrap().bonds().unwrap();
assert_eq!(bonds, vec![[0, 1], [1, 3], [2, 4]]);

frame.remove_bond(2, 4).unwrap();
let bonds = frame.topology().unwrap().bonds().unwrap();
assert_eq!(bonds, vec![[0, 1], [1, 3]]);

Remove any existing bond between the atoms at indexes i and j in the frame.

This function does nothing if there is no bond between i and j.

Example

let mut frame = Frame::new().unwrap();

let residue = Residue::new("foo").unwrap();
frame.add_residue(&residue).unwrap();

let topology = frame.topology().unwrap();
assert_eq!(topology.residues_count(), Ok(1));
assert_eq!(topology.residue(0).unwrap().name().unwrap(), "foo");

Get the distance between the atoms at indexes i and j in this frame, accounting for periodic boundary conditions. The result is expressed in Angstroms.

Example

let mut frame = Frame::new().unwrap();
frame.add_atom(&Atom::new("A").unwrap(), [0.0, 0.0, 0.0], None).unwrap();
frame.add_atom(&Atom::new("B").unwrap(), [1.0, 2.0, 3.0], None).unwrap();

assert_eq!(frame.distance(0, 1), Ok(f64::sqrt(14.0)));

Get the angle formed by the atoms at indexes i, j and k in this frame, accounting for periodic boundary conditions. The result is expressed in radians.

Example

let mut frame = Frame::new().unwrap();
frame.add_atom(&Atom::new("A").unwrap(), [1.0, 0.0, 0.0], None).unwrap();
frame.add_atom(&Atom::new("B").unwrap(), [0.0, 0.0, 0.0], None).unwrap();
frame.add_atom(&Atom::new("B").unwrap(), [0.0, 1.0, 0.0], None).unwrap();

assert_eq!(frame.angle(0, 1, 2), Ok(f64::consts::PI / 2.0));

Get the dihedral angle formed by the atoms at indexes i, j, k and m in this frame, accounting for periodic boundary conditions. The result is expressed in radians.

Example

let mut frame = Frame::new().unwrap();
frame.add_atom(&Atom::new("A").unwrap(), [1.0, 0.0, 0.0], None).unwrap();
frame.add_atom(&Atom::new("B").unwrap(), [0.0, 0.0, 0.0], None).unwrap();
frame.add_atom(&Atom::new("B").unwrap(), [0.0, 1.0, 0.0], None).unwrap();
frame.add_atom(&Atom::new("B").unwrap(), [0.0, 1.0, 1.0], None).unwrap();

assert_eq!(frame.dihedral(0, 1, 2, 3), Ok(f64::consts::PI / 2.0));

Get the out of plane distance formed by the atoms at indexes i, j, k and m in this frame, accounting for periodic boundary conditions. The result is expressed in angstroms.

This is the distance betweent the atom j and the ikm plane. The j atom is the center of the improper dihedral angle formed by i, j, k and m.

Example

let mut frame = Frame::new().unwrap();
frame.add_atom(&Atom::new("A").unwrap(), [0.0, 0.0, 0.0], None).unwrap();
frame.add_atom(&Atom::new("B").unwrap(), [0.0, 0.0, 2.0], None).unwrap();
frame.add_atom(&Atom::new("B").unwrap(), [1.0, 0.0, 0.0], None).unwrap();
frame.add_atom(&Atom::new("B").unwrap(), [0.0, 1.0, 0.0], None).unwrap();

assert_eq!(frame.out_of_plane(0, 1, 2, 3), Ok(2.0));

Get a view into the positions of this frame.

Example

let mut frame = Frame::new().unwrap();
frame.resize(67).unwrap();

let positions = frame.positions().unwrap();
assert_eq!(positions.len(), 67);
assert_eq!(positions[0], [0.0, 0.0, 0.0]);

Get a mutable view into the positions of this frame.

Example

let mut frame = Frame::new().unwrap();
frame.resize(67).unwrap();
{
    let positions = frame.positions_mut().unwrap();
    assert_eq!(positions[0], [0.0, 0.0, 0.0]);
    positions[0] = [1.0, 2.0, 3.0];
}

let positions = frame.positions().unwrap();
assert_eq!(positions[0], [1.0, 2.0, 3.0]);

Get a view into the velocities of this frame.

Example

let mut frame = Frame::new().unwrap();
frame.resize(67).unwrap();
frame.add_velocities().unwrap();

let velocities = frame.velocities().unwrap();
assert_eq!(velocities.len(), 67);
assert_eq!(velocities[0], [0.0, 0.0, 0.0]);

Get a mutable view into the velocities of this frame.

Example

let mut frame = Frame::new().unwrap();
frame.resize(67).unwrap();
frame.add_velocities().unwrap();
{
    let velocities = frame.velocities_mut().unwrap();
    assert_eq!(velocities[0], [0.0, 0.0, 0.0]);
    velocities[0] = [1.0, 2.0, 3.0];
}

let velocities = frame.velocities().unwrap();
assert_eq!(velocities[0], [1.0, 2.0, 3.0]);

Check if this frame contains velocity data.

Example

let mut frame = Frame::new().unwrap();
assert_eq!(frame.has_velocities(), Ok(false));

frame.add_velocities().unwrap();
assert_eq!(frame.has_velocities(), Ok(true));

Add velocity data to this frame. If the frame already have velocities, this does nothing.

Example

let mut frame = Frame::new().unwrap();
assert_eq!(frame.has_velocities(), Ok(false));

frame.add_velocities().unwrap();
assert_eq!(frame.has_velocities(), Ok(true));

Get a copy of the UnitCell from this frame.

Example

let frame = Frame::new().unwrap();

let cell = frame.cell().unwrap();
assert_eq!(cell.shape(), Ok(CellShape::Infinite));

Set the UnitCell of this frame to cell.

Example

let mut frame = Frame::new().unwrap();

frame.set_cell(&UnitCell::new([10.0, 10.0, 10.0]).unwrap()).unwrap();

let cell = frame.cell().unwrap();
assert_eq!(cell.shape(), Ok(CellShape::Orthorhombic));
assert_eq!(cell.lengths(), Ok([10.0, 10.0, 10.0]));

Get a copy of the Topology from this frame.

Example

let mut frame = Frame::new().unwrap();
frame.resize(42).unwrap();

let topology = frame.topology().unwrap();
assert_eq!(topology.size(), Ok(42));

Set the Topology of this frame to topology. The topology must contain the same number of atoms that this frame.

Example

let mut frame = Frame::new().unwrap();
frame.resize(2).unwrap();

let mut topology = Topology::new().unwrap();
topology.add_atom(&Atom::new("Cl").unwrap()).unwrap();
topology.add_atom(&Atom::new("Cl").unwrap()).unwrap();
topology.add_bond(0, 1);

frame.set_topology(&topology);
assert_eq!(frame.atom(0).unwrap().name(), Ok(String::from("Cl")));

Get this frame step, i.e. the frame number in the trajectory

Example

let frame = Frame::new().unwrap();
assert_eq!(frame.step(), Ok(0));

Set this frame step to step.

Example

let mut frame = Frame::new().unwrap();
assert_eq!(frame.step(), Ok(0));

frame.set_step(10).unwrap();
assert_eq!(frame.step(), Ok(10));

Guess the bonds, angles and dihedrals in this frame.

The bonds are guessed using a distance-based algorithm, and then angles and dihedrals are guessed from the bonds.

Example

let mut frame = Frame::new().unwrap();

frame.add_atom(&Atom::new("Cl").unwrap(), [0.0, 0.0, 0.0], None).unwrap();
frame.add_atom(&Atom::new("Cl").unwrap(), [1.5, 0.0, 0.0], None).unwrap();
assert_eq!(frame.topology().unwrap().bonds_count(), Ok(0));

frame.guess_topology().unwrap();
assert_eq!(frame.topology().unwrap().bonds_count(), Ok(1));

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

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

Examples

let mut frame = Frame::new().unwrap();
frame.set("a string", Property::String("hello".into()));

assert_eq!(frame.get("a string").unwrap(), Some(Property::String("hello".into())));

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

Examples

let mut frame = Frame::new().unwrap();
frame.set("foo", Property::Double(22.2));

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

Trait Implementations

impl Clone for Frame
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Drop for Frame
[src]

Executes the destructor for this type. Read more

Auto Trait Implementations

impl !Send for Frame

impl !Sync for Frame

Blanket Implementations

impl<T> From for T
[src]

Performs the conversion.

impl<T, U> Into for T where
    U: From<T>, 
[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

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

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T> Borrow for T where
    T: ?Sized
[src]

Immutably borrows from an owned value. Read more

impl<T> Any for T where
    T: 'static + ?Sized
[src]

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

this method will likely be replaced by an associated static

Gets the TypeId of self. Read more

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T> BorrowMut for T where
    T: ?Sized
[src]

Mutably borrows from an owned value. Read more