[−][src]Struct chemfiles::Trajectory
The Trajectory
type is the main entry point when using chemfiles. A
Trajectory
behave a bit like a file, allowing to read and/or write
Frame
.
Methods
impl Trajectory
[src]
pub fn open<P>(path: P, mode: char) -> Result<Trajectory, Error> where
P: AsRef<Path>,
[src]
P: AsRef<Path>,
Open the file at the given path
in the given mode
.
Valid modes are 'r'
for read, 'w'
for write and 'a'
for append.
Example
let trajectory = Trajectory::open("water.xyz", 'r').unwrap();
pub fn open_with_format<'a, P, S>(
filename: P,
mode: char,
format: S
) -> Result<Trajectory, Error> where
P: AsRef<Path>,
S: Into<&'a str>,
[src]
filename: P,
mode: char,
format: S
) -> Result<Trajectory, Error> where
P: AsRef<Path>,
S: Into<&'a str>,
Open the file at the given path
using a specific file format
and
the given mode
.
Valid modes are 'r'
for read, 'w'
for write and 'a'
for append.
Specifying a format is needed when the file format does not match the
extension, or when there is not standard extension for this format. If
format
is an empty string, the format will be guessed from the
extension.
Example
let trajectory = Trajectory::open_with_format("water.zeo", 'r', "XYZ").unwrap();
pub fn read(&mut self, frame: &mut Frame) -> Result<(), Error>
[src]
Read the next step of this trajectory into a frame
.
If the number of atoms in frame does not correspond to the number of atom in the next step, the frame is resized.
Example
let mut trajectory = Trajectory::open("water.xyz", 'r').unwrap(); let mut frame = Frame::new(); trajectory.read(&mut frame).unwrap();
pub fn read_step(&mut self, step: u64, frame: &mut Frame) -> Result<(), Error>
[src]
Read a specific step
of this trajectory into a frame
.
If the number of atoms in frame does not correspond to the number of atom at this step, the frame is resized.
Example
let mut trajectory = Trajectory::open("water.xyz", 'r').unwrap(); let mut frame = Frame::new(); trajectory.read_step(10, &mut frame).unwrap();
pub fn write(&mut self, frame: &Frame) -> Result<(), Error>
[src]
Write a frame
to this trajectory.
Example
let mut trajectory = Trajectory::open("water.pdb", 'w').unwrap(); let mut frame = Frame::new(); trajectory.write(&mut frame).unwrap();
pub fn set_topology(&mut self, topology: &Topology)
[src]
Set the topology
associated with this trajectory. This topology will
be used when reading and writing the files, replacing any topology in
the frames or files.
Example
let mut topology = Topology::new(); topology.add_atom(&Atom::new("H")); topology.add_atom(&Atom::new("O")); topology.add_atom(&Atom::new("H")); topology.add_bond(0, 1); topology.add_bond(1, 2); let mut trajectory = Trajectory::open("water.xyz", 'r').unwrap(); trajectory.set_topology(&topology);
pub fn set_topology_file<P>(&mut self, path: P) -> Result<(), Error> where
P: AsRef<Path>,
[src]
P: AsRef<Path>,
Set the topology associated with this trajectory by reading the first
frame of the file at the given path
using the file format in
format
; and extracting the topology of this frame.
Example
let mut trajectory = Trajectory::open("water.nc", 'r').unwrap(); trajectory.set_topology_file("topology.pdb").unwrap();
pub fn set_topology_with_format<'a, P, S>(
&mut self,
path: P,
format: S
) -> Result<(), Error> where
P: AsRef<Path>,
S: Into<&'a str>,
[src]
&mut self,
path: P,
format: S
) -> Result<(), Error> where
P: AsRef<Path>,
S: Into<&'a str>,
Set the topology associated with this trajectory by reading the first
frame of the file at the given path
using the file format in
format
; and extracting the topology of this frame.
If format
is an empty string, the format will be guessed from the
path
extension.
Example
let mut trajectory = Trajectory::open("water.nc", 'r').unwrap(); trajectory.set_topology_with_format("topology.mol", "PDB").unwrap();
pub fn set_cell(&mut self, cell: &UnitCell)
[src]
Set the unit cell
associated with a trajectory. This cell will be
used when reading and writing the files, replacing any unit cell in the
frames or files.
Example
let mut trajectory = Trajectory::open("water.xyz", 'r').unwrap(); trajectory.set_cell(&UnitCell::new([10.0, 11.0, 12.5]));
pub fn nsteps(&mut self) -> Result<u64, Error>
[src]
Get the number of steps (the number of frames) in a trajectory.
Example
let mut trajectory = Trajectory::open("water.xyz", 'r').unwrap(); let steps = trajectory.nsteps().unwrap(); println!("This trajectory contains {} steps", steps);
pub fn path(&self) -> String
[src]
Get file path for this trajectory.
Example
let trajectory = Trajectory::open("water.xyz", 'r').unwrap(); assert_eq!(trajectory.path(), "water.xyz");
Trait Implementations
impl Drop for Trajectory
[src]
Auto Trait Implementations
impl !Send for Trajectory
impl !Sync for Trajectory
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,