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]
pub fn new() -> Result<Frame>
[src]
Create an empty frame. It will be resized by the library as needed.
Example
let frame = Frame::new().unwrap();
pub fn atom(&self, index: u64) -> Result<Atom>
[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")));
pub fn size(&self) -> Result<u64>
[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));
pub fn resize(&mut self, natoms: u64) -> Result<()>
[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));
pub fn add_atom<V>(
&mut self,
atom: &Atom,
position: [f64; 3],
velocity: V
) -> Result<()> where
V: Into<Option<[f64; 3]>>,
[src]
&mut self,
atom: &Atom,
position: [f64; 3],
velocity: V
) -> Result<()> where
V: Into<Option<[f64; 3]>>,
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();
pub fn remove(&mut self, i: usize) -> Result<()>
[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");
pub fn add_bond(&mut self, i: usize, j: usize) -> Result<()>
[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]]);
pub fn remove_bond(&mut self, i: usize, j: usize) -> Result<()>
[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]]);
pub fn add_residue(&mut self, residue: &Residue) -> Result<()>
[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");
pub fn distance(&self, i: usize, j: usize) -> Result<f64>
[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)));
pub fn angle(&self, i: usize, j: usize, k: usize) -> Result<f64>
[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));
pub fn dihedral(&self, i: usize, j: usize, k: usize, m: usize) -> Result<f64>
[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));
pub fn out_of_plane(
&self,
i: usize,
j: usize,
k: usize,
m: usize
) -> Result<f64>
[src]
&self,
i: usize,
j: usize,
k: usize,
m: usize
) -> Result<f64>
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));
pub fn positions(&self) -> Result<&[[f64; 3]]>
[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]);
pub fn positions_mut(&mut self) -> Result<&mut [[f64; 3]]>
[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]);
pub fn velocities(&self) -> Result<&[[f64; 3]]>
[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]);
pub fn velocities_mut(&mut self) -> Result<&mut [[f64; 3]]>
[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]);
pub fn has_velocities(&self) -> Result<bool>
[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));
pub fn add_velocities(&mut self) -> Result<()>
[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));
pub fn cell(&self) -> Result<UnitCell>
[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));
pub fn set_cell(&mut self, cell: &UnitCell) -> Result<()>
[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]));
pub fn topology(&self) -> Result<Topology>
[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));
pub fn set_topology(&mut self, topology: &Topology) -> Result<()>
[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")));
pub fn step(&self) -> Result<u64>
[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));
pub fn set_step(&mut self, step: u64) -> Result<()>
[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));
pub fn guess_topology(&mut self) -> Result<()>
[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));
pub fn set(&mut self, name: &str, property: Property) -> Result<()>
[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())));
pub fn get(&mut self, name: &str) -> Result<Option<Property>>
[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]
fn clone(&self) -> Frame
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more