[−][src]Struct chemfiles::Selection
A Selection
allow to select atoms in a Frame
, from a selection
language. The selection language is built by combining basic operations.
Each basic operation follows the <selector>[(<variable>)] <operator> <value>
structure, where <operator>
is a comparison operator in
== != < <= > >=
.
Methods
impl Selection
[src]
pub fn new<'a, S: Into<&'a str>>(selection: S) -> Result<Selection, Error>
[src]
Create a new selection from the given selection string.
Example
let selection = Selection::new("pairs: name(#1) H and name(#2) O").unwrap();
pub fn size(&self) -> usize
[src]
Get the size of the selection, i.e. the number of atoms we are selecting together.
This value is 1 for the 'atom' context, 2 for the 'pair' and 'bond' context, 3 for the 'three' and 'angles' context and 4 for the 'four' and 'dihedral' context.
Example
let selection = Selection::new("pairs: name(#1) H and name(#2) O").unwrap(); assert_eq!(selection.size(), 2);
pub fn string(&self) -> String
[src]
Get the selection string used to create this selection.
Example
let selection = Selection::new("name H").unwrap(); assert_eq!(selection.string(), "name H");
pub fn evaluate(&mut self, frame: &Frame) -> Result<Vec<Match>, Error>
[src]
Evaluate a selection for a given frame, and return the corresponding matches.
Example
let mut frame = Frame::new(); frame.add_atom(&Atom::new("H"), [1.0, 0.0, 0.0], None); frame.add_atom(&Atom::new("O"), [0.0, 0.0, 0.0], None); frame.add_atom(&Atom::new("H"), [-1.0, 0.0, 0.0], None); let mut selection = Selection::new("pairs: name(#1) H and name(#2) O").unwrap(); let matches = selection.evaluate(&frame).unwrap(); assert_eq!(matches.len(), 2); assert_eq!(matches[0].len(), 2); assert_eq!(matches[0][0], 0); assert_eq!(matches[0][1], 1); assert_eq!(matches[1].len(), 2); assert_eq!(matches[1][0], 2); assert_eq!(matches[1][1], 1);
pub fn list(&mut self, frame: &Frame) -> Result<Vec<usize>, Error>
[src]
Evaluates a selection of size 1 on a given frame
. This function
returns the list of atomic indexes in the frame matching this selection.
Example
let mut frame = Frame::new(); frame.add_atom(&Atom::new("H"), [1.0, 0.0, 0.0], None); frame.add_atom(&Atom::new("O"), [0.0, 0.0, 0.0], None); frame.add_atom(&Atom::new("H"), [-1.0, 0.0, 0.0], None); let mut selection = Selection::new("name H").unwrap(); let matches = selection.list(&frame).unwrap(); assert_eq!(matches.len(), 2); assert_eq!(matches[0], 0); assert_eq!(matches[1], 2);
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Selection
impl !Send for Selection
impl !Sync for Selection
impl Unpin for Selection
impl UnwindSafe for Selection
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
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, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,