#[cfg(not(feature = "chemfiles"))]
use crate::chemfiles_import::ChemfilesImportError;
#[cfg(not(feature = "chemfiles"))]
use crate::types::ConFrame;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SelectionMatch {
pub size: usize,
pub atoms: [usize; 4],
}
impl SelectionMatch {
pub fn indices(&self) -> &[usize] {
&self.atoms[..self.size.min(4)]
}
}
#[derive(Debug, Clone)]
pub struct SelectionResult {
pub selection: String,
pub context_size: usize,
pub matches: Vec<SelectionMatch>,
}
impl SelectionResult {
pub fn primary_indices(&self) -> Vec<usize> {
self.matches
.iter()
.filter_map(|m| m.indices().first().copied())
.collect()
}
}
#[cfg(feature = "chemfiles")]
#[path = "chemfiles_selection_imp.rs"]
mod imp;
#[cfg(feature = "chemfiles")]
pub use imp::{
apply_con_bonds_to_chemfiles_frame, chemfiles_frame_from_con_frame,
evaluate_selection_on_chemfiles_frame, evaluate_selection_on_con_frame, parse_selection_string,
select_atom_indices,
};
#[cfg(not(feature = "chemfiles"))]
pub fn evaluate_selection_on_con_frame(
_selection: &str,
_frame: &ConFrame,
) -> Result<SelectionResult, ChemfilesImportError> {
Err(ChemfilesImportError::FeatureDisabled)
}
#[cfg(not(feature = "chemfiles"))]
pub fn select_atom_indices(
_selection: &str,
_frame: &ConFrame,
) -> Result<Vec<usize>, ChemfilesImportError> {
Err(ChemfilesImportError::FeatureDisabled)
}
#[cfg(not(feature = "chemfiles"))]
pub fn parse_selection_string(_selection: &str) -> Result<usize, ChemfilesImportError> {
Err(ChemfilesImportError::FeatureDisabled)
}
#[cfg(all(test, not(feature = "chemfiles")))]
mod stub_tests {
use super::*;
use crate::chemfiles_import::ChemfilesImportError;
use crate::types::ConFrameBuilder;
#[test]
fn selection_stub_is_feature_disabled() {
let frame = ConFrameBuilder::new([10.0; 3], [90.0; 3]).build();
let err = evaluate_selection_on_con_frame("name O", &frame).unwrap_err();
assert!(matches!(err, ChemfilesImportError::FeatureDisabled));
}
}