[][src]Struct chemfiles::Selection

pub struct Selection { /* fields omitted */ }

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]

Create a new selection from the given selection string.

Example

let selection = Selection::new("pairs: name(#1) H and name(#2) O").unwrap();

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' contextes and 4 for the 'four' and 'dihedral' contextes.

Example

let selection = Selection::new("pairs: name(#1) H and name(#2) O").unwrap();
assert_eq!(selection.size(), Ok(2));

Get the selection string used to create this selection.

Example

let selection = Selection::new("name H").unwrap();
assert_eq!(selection.string(), Ok(String::from("name H")));

Evaluate a selection for a given frame, and return the corresponding matches.

Example

let mut frame = Frame::new().unwrap();
frame.add_atom(&Atom::new("H").unwrap(), [1.0, 0.0, 0.0], None).unwrap();
frame.add_atom(&Atom::new("O").unwrap(), [0.0, 0.0, 0.0], None).unwrap();
frame.add_atom(&Atom::new("H").unwrap(), [-1.0, 0.0, 0.0], None).unwrap();

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);

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().unwrap();
frame.add_atom(&Atom::new("H").unwrap(), [1.0, 0.0, 0.0], None).unwrap();
frame.add_atom(&Atom::new("O").unwrap(), [0.0, 0.0, 0.0], None).unwrap();
frame.add_atom(&Atom::new("H").unwrap(), [-1.0, 0.0, 0.0], None).unwrap();

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

impl Drop for Selection
[src]

Executes the destructor for this type. Read more

impl Clone for Selection
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl !Send for Selection

impl !Sync for Selection

Blanket Implementations

impl<T> From for T
[src]

Performs the conversion.

impl<T, U> Into for T where
    U: From<T>, 
[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<T> Borrow for T where
    T: ?Sized
[src]

Immutably borrows from an owned value. Read more

impl<T> Any for T where
    T: 'static + ?Sized
[src]

🔬 This is a nightly-only experimental API. (get_type_id)

this method will likely be replaced by an associated static

Gets the TypeId of self. Read more

impl<T> BorrowMut for T where
    T: ?Sized
[src]

Mutably borrows from an owned value. Read more

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.