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; 3], 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.size(), Ok(0));

frame.resize(67).unwrap();
assert_eq!(frame.size(), 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.size(), 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]

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

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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

[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.size(), 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));

[src]

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

[src]

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]

[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