Skip to main content

molrs_compute/
lib.rs

1//! Analysis compute modules for molrs molecular simulation.
2//!
3//! Trajectory analysis (RDF, MSD, clustering, gyration/inertia, PCA,
4//! k-means) built around a single unified [`Compute`] trait.
5//! Every analysis is stateless — orchestrate from the caller.
6//!
7//! # Stateless `Compute` — orchestrate from the caller
8//!
9//! Each [`Compute`] impl is a pure function: `&self` is an immutable
10//! parameter bag. Two `compute` calls with identical `frames` + `args`
11//! always produce identical output. There is no hidden mutable state,
12//! no DAG, no store — just the trait and per-analysis modules.
13//!
14//! For DAG orchestration (topological order, diamond reuse, external
15//! input validation), use `molpy.compute.Workflow` on the Python side.
16//! It composes `Compute` nodes via Python's stdlib `graphlib` and
17//! calls each Rust kernel directly.
18//!
19//! # Unified trait
20//!
21//! Every analysis implements [`Compute`]. A single frame, a trajectory, and a
22//! whole dataset are the same kind of input — a slice `&[&F]` — and each
23//! impl decides how to interpret it:
24//!
25//! - **Whole-sequence accumulators** (RDF) iterate every frame.
26//! - **Time-series analyses** (MSD) use `frames[0]` as a reference.
27//! - **Per-frame analyses** (Cluster, COM) return one result per frame.
28//! - **Matrix consumers** (PCA, k-means) take upstream per-frame outputs as
29//!   rows (via [`DescriptorRow`]).
30//!
31//! # Results
32//!
33//! Every Compute output implements [`ComputeResult`]. Accumulating outputs
34//! (RDF) override [`finalize`](ComputeResult::finalize) to normalize; other
35//! outputs use the default no-op.
36//!
37//! # Available analyses
38//!
39//! | Module | Args | Output |
40//! |--------|------|--------|
41//! | [`rdf`] | `&Vec<NeighborList>` | [`RDFResult`] |
42//! | [`msd`] | `()` | [`MSDTimeSeries`] |
43//! | [`cluster`] | `&Vec<NeighborList>` | `Vec<`[`ClusterResult`]`>` |
44//! | [`cluster_centers`] | `&Vec<ClusterResult>` | `Vec<`[`ClusterCentersResult`]`>` |
45//! | [`center_of_mass`] | `&Vec<ClusterResult>` | `Vec<`[`COMResult`]`>` |
46//! | [`gyration_tensor`] | `(&Vec<ClusterResult>, &Vec<ClusterCentersResult>)` | `Vec<`[`GyrationTensorResult`]`>` |
47//! | [`inertia_tensor`] | `(&Vec<ClusterResult>, &Vec<COMResult>)` | `Vec<`[`InertiaTensorResult`]`>` |
48//! | [`radius_of_gyration`] | `(&Vec<ClusterResult>, &Vec<COMResult>)` | `Vec<`[`RgResult`]`>` |
49//! | [`pca`] | `&Vec<T: DescriptorRow>` | [`PcaResult`] |
50//! | [`kmeans`] | `&PcaResult` | [`KMeansResult`] |
51
52pub mod center_of_mass;
53pub mod cluster;
54pub mod cluster_centers;
55pub mod density;
56pub mod dielectric;
57pub mod diffraction;
58pub mod environment;
59pub mod error;
60pub mod gyration_tensor;
61pub mod inertia_tensor;
62pub mod jacf;
63pub mod kmeans;
64pub mod msd;
65pub mod onsager;
66pub mod order;
67pub mod pca;
68pub mod persist;
69pub mod pmft;
70pub mod radius_of_gyration;
71pub mod rdf;
72pub mod result;
73pub mod spectra;
74pub mod traits;
75pub mod util;
76pub mod validate;
77
78// Re-exports
79pub use center_of_mass::{COMResult, CenterOfMass};
80pub use cluster::{Cluster, ClusterProperties, ClusterPropertiesResult, ClusterResult};
81pub use cluster_centers::{ClusterCenters, ClusterCentersResult};
82pub use density::{
83    CorrelationFunction, CorrelationFunctionResult, GaussianDensity, GaussianDensityResult,
84    LocalDensity, LocalDensityResult, SphereVoxelization, SphereVoxelizationResult,
85};
86pub use dielectric::{
87    ConductivityResult, DielectricSpectrum, StaticDielectricResult, compute_current_density,
88    compute_dipole_moment, decompose_current, einstein_helfand_conductivity,
89    einstein_helfand_spectrum, green_kubo_spectrum, static_dielectric_constant,
90    static_dielectric_constant_components,
91};
92pub use diffraction::{
93    DiffractionPattern, DiffractionPatternResult, StaticStructureFactorDebye,
94    StaticStructureFactorDebyeResult, StaticStructureFactorDirect,
95    StaticStructureFactorDirectResult,
96};
97pub use environment::{
98    AngularSeparationGlobal, AngularSeparationGlobalResult, AngularSeparationNeighbor,
99    AngularSeparationNeighborResult, BondOrder, BondOrderResult, LocalBondProjection,
100    LocalBondProjectionResult, LocalDescriptors, LocalDescriptorsResult, MatchEnv, MatchEnvResult,
101};
102pub use error::ComputeError;
103pub use gyration_tensor::{GyrationTensor, GyrationTensorResult};
104pub use inertia_tensor::{InertiaTensor, InertiaTensorResult};
105pub use jacf::{JacfResult, green_kubo_conductivity};
106pub use kmeans::{KMeans, KMeansResult};
107pub use msd::{MSD, MSDResult, MSDTimeSeries, MsdMode};
108pub use onsager::{OnsagerResult, onsager_correlation};
109pub use order::{
110    ContinuousCoordination, ContinuousCoordinationResult, Cubatic, CubaticResult, Hexatic,
111    HexaticResult, Nematic, NematicResult, RotationalAutocorrelation,
112    RotationalAutocorrelationResult, SolidLiquid, SolidLiquidResult, Steinhardt, SteinhardtResult,
113};
114pub use pca::{Pca2, PcaResult};
115pub use persist::{PersistResult, SurvivalMethod, pair_survival_tcf};
116pub use pmft::{
117    PMFTR12, PMFTR12Args, PMFTR12Result, PMFTXY, PMFTXYArgs, PMFTXYResult, PMFTXYT, PMFTXYTArgs,
118    PMFTXYTResult, PMFTXYZ, PMFTXYZArgs, PMFTXYZResult,
119};
120pub use radius_of_gyration::{RadiusOfGyration, RgResult};
121pub use rdf::{RDF, RDFResult};
122pub use result::{ComputeResult, DescriptorRow};
123pub use spectra::{RamanSpectrum, Spectrum, ir_spectrum, power_spectrum, raman_spectrum};
124pub use traits::Compute;