pub struct Selection { /* private fields */ }
Expand description
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
== != < <= > >=
.
Implementations§
source§impl Selection
impl Selection
sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
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);
sourcepub fn string(&self) -> String
pub fn string(&self) -> String
Get the selection string used to create this selection.
Example
let selection = Selection::new("name H").unwrap();
assert_eq!(selection.string(), "name H");
sourcepub fn evaluate(&mut self, frame: &Frame) -> Vec<Match>
pub fn evaluate(&mut self, frame: &Frame) -> Vec<Match>
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);
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);
sourcepub fn list(&mut self, frame: &Frame) -> Vec<usize>
pub fn list(&mut self, frame: &Frame) -> Vec<usize>
Evaluates a selection of size 1 on a given frame
. This function
returns the list of atomic indexes in the frame matching this selection.
Panics
If the selection size is not 1
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);
assert_eq!(matches.len(), 2);
assert_eq!(matches[0], 0);
assert_eq!(matches[1], 2);