use molframe_core::structure::{
AtomRef, ChainRef, ModelRef, ResidueRef, Structure as CoreStructure,
};
use super::collections::{Atoms, Chains, Models, Residues};
use super::editor::StructureEditor;
#[cfg(feature = "query")]
use super::query::QueryStructure;
#[cfg(feature = "query")]
use super::selection::Selection;
#[cfg(feature = "query")]
use molframe_core::contract::AnalysisPolicy;
#[cfg(feature = "query")]
use molframe_core::diagnostic::Findings;
#[derive(Clone, Debug)]
pub struct Structure(CoreStructure);
impl Structure {
#[must_use]
pub fn metadata(&self) -> &molframe_core::structure::EntryMetadata {
&self.0.data().entry
}
#[must_use]
pub fn cell(&self) -> Option<molframe_core::structure::UnitCell> {
self.0.data().cell
}
#[must_use]
pub fn bonds(&self) -> &molframe_core::BondTable {
&self.0.data().bonds
}
#[must_use]
pub fn anisotropy(&self) -> &molframe_core::AnisotropyTable {
&self.0.data().anisotropy
}
#[must_use]
pub fn secondary_structure(&self) -> &[molframe_core::SecondaryStructure] {
self.0.secondary_structure()
}
#[must_use]
pub fn secondary_source(&self) -> &[molframe_core::SecondarySource] {
self.0.secondary_source()
}
#[must_use]
pub fn annotations(&self) -> &molframe_core::annotation::AtomAnnotations {
&self.0.data().annotations
}
#[must_use]
pub fn coordinates(&self) -> &[[f32; 3]] {
self.0.positions()
}
#[must_use]
pub fn model_coordinates(
&self,
model: molframe_core::index::ModelIndex,
) -> Option<&[[f32; 3]]> {
self.0.model_positions(model)
}
#[must_use]
pub fn chains(&self) -> Chains<'_> {
Chains::new(&self.0)
}
#[must_use]
pub fn residues(&self) -> Residues<'_> {
Residues::new(&self.0)
}
#[must_use]
pub fn atoms(&self) -> Atoms<'_> {
Atoms::new(&self.0)
}
#[must_use]
pub fn models(&self) -> Models<'_> {
Models::new(&self.0)
}
#[must_use]
pub fn chain_at(&self, position: usize) -> Option<ChainRef<'_>> {
self.chains().get(position)
}
#[must_use]
pub fn residue_at(&self, position: usize) -> Option<ResidueRef<'_>> {
self.residues().get(position)
}
#[must_use]
pub fn atom_at(&self, position: usize) -> Option<AtomRef<'_>> {
self.atoms().get(position)
}
#[must_use]
pub fn model_at(&self, position: usize) -> Option<ModelRef<'_>> {
self.models().get(position)
}
#[must_use]
pub fn chain(&self, label: &str) -> Option<ChainRef<'_>> {
self.0.data().chain_named(label)
}
#[must_use]
pub fn model_count(&self) -> usize {
self.0.model_count()
}
#[must_use]
pub fn chain_count(&self) -> usize {
self.0.chain_count()
}
#[must_use]
pub fn residue_count(&self) -> usize {
self.0.residue_count()
}
#[must_use]
pub fn atom_count(&self) -> u32 {
self.0.atom_count()
}
#[must_use]
pub fn edit(&self) -> StructureEditor {
StructureEditor::new(&self.0)
}
#[cfg(feature = "query")]
pub fn select(&self, source: &str, policy: &AnalysisPolicy) -> Result<Selection, Findings> {
let evaluation = QueryStructure::select_text(&self.0, source, policy)?;
Ok(Selection::from(self.0.view_of(evaluation.selection)))
}
#[must_use]
pub fn engine(&self) -> &CoreStructure {
&self.0
}
#[must_use]
pub fn into_engine(self) -> CoreStructure {
self.0
}
}
impl From<CoreStructure> for Structure {
fn from(inner: CoreStructure) -> Self {
Self(inner)
}
}
impl From<Structure> for CoreStructure {
fn from(structure: Structure) -> Self {
structure.0
}
}
impl std::fmt::Display for Structure {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.0, f)
}
}
#[cfg(feature = "query")]
impl molframe_query::StructureValues for Structure {
fn chain_labels(&self) -> Box<dyn Iterator<Item = &str> + '_> {
molframe_query::StructureValues::chain_labels(&self.0)
}
fn residue_names(&self) -> Box<dyn Iterator<Item = &str> + '_> {
molframe_query::StructureValues::residue_names(&self.0)
}
fn atom_names(&self) -> Box<dyn Iterator<Item = &str> + '_> {
molframe_query::StructureValues::atom_names(&self.0)
}
}