Struct chemfiles::Frame [] [src]

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]

[src]

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

Example

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

[src]

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, 0.0, 0.0), None).unwrap();

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

[src]

Get the current number of atoms in this frame.

Example

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

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

[src]

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.natoms(), Ok(67));

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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.natoms(), Ok(42));

[src]

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

[src]

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

Example

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

[src]

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

[src]

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

Trait Implementations

impl Clone for Frame
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Drop for Frame
[src]

[src]

Executes the destructor for this type. Read more