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]
fn new() -> Result<Frame>
Create an empty frame. It will be resized by the library as needed.
Example
let frame = Frame::new().unwrap();
fn atom(&self, index: u64) -> Result<Atom>
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")));
fn natoms(&self) -> Result<u64>
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));
fn resize(&mut self, natoms: u64) -> Result<()>
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));
fn add_atom<V>(
&mut self,
atom: &Atom,
position: (f64, f64, f64),
velocity: V
) -> Result<()> where
V: Into<Option<(f64, f64, f64)>>,
&mut self,
atom: &Atom,
position: (f64, f64, f64),
velocity: V
) -> Result<()> where
V: Into<Option<(f64, f64, f64)>>,
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();
fn positions(&self) -> Result<&[[f64; 3]]>
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]);
fn positions_mut(&mut self) -> Result<&mut [[f64; 3]]>
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]);
fn velocities(&self) -> Result<&[[f64; 3]]>
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]);
fn velocities_mut(&mut self) -> Result<&mut [[f64; 3]]>
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]);
fn has_velocities(&self) -> Result<bool>
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));
fn add_velocities(&mut self) -> Result<()>
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));
fn cell(&self) -> Result<UnitCell>
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));
fn set_cell(&mut self, cell: &UnitCell) -> Result<()>
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)));
fn topology(&self) -> Result<Topology>
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));
fn set_topology(&mut self, topology: &Topology) -> Result<()>
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")));
fn step(&self) -> Result<u64>
Get this frame step, i.e. the frame number in the trajectory
Example
let frame = Frame::new().unwrap(); assert_eq!(frame.step(), Ok(0));
fn set_step(&mut self, step: u64) -> Result<()>
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));
fn guess_topology(&mut self) -> Result<()>
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]
fn clone(&self) -> Frame
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more