molframe_query/execution/spatial.rs
1//! Boundary between query planning and spatial execution.
2
3use molframe_core::diagnostic::Diagnostic;
4use molframe_core::selection::AtomSelection;
5
6/// A fully planned geometric predicate.
7#[derive(Clone, Copy, Debug)]
8#[non_exhaustive]
9pub enum GeometricRequest<'a> {
10 /// Radius search around target atoms.
11 Within {
12 /// Atoms eligible for the result.
13 universe: &'a AtomSelection,
14 /// Centres of the radius search.
15 target: &'a AtomSelection,
16 /// Radius in ångström.
17 radius: f32,
18 /// Whether target atoms remain in the result.
19 include_target: bool,
20 },
21 /// Atoms further than a radius from every target.
22 Beyond {
23 /// Atoms eligible for the result.
24 universe: &'a AtomSelection,
25 /// Centres excluded around.
26 target: &'a AtomSelection,
27 /// Exclusion radius in ångström.
28 radius: f32,
29 },
30 /// Sphere around the target centre of geometry.
31 SphereZone {
32 /// Atoms eligible for the result.
33 universe: &'a AtomSelection,
34 /// Atoms defining the centre.
35 target: &'a AtomSelection,
36 /// Sphere radius in ångström.
37 radius: f32,
38 },
39 /// Spherical shell around the target centre of geometry.
40 SphereLayer {
41 /// Atoms eligible for the result.
42 universe: &'a AtomSelection,
43 /// Atoms defining the centre.
44 target: &'a AtomSelection,
45 /// Inclusive inner radius.
46 inner: f32,
47 /// Inclusive outer radius.
48 outer: f32,
49 },
50 /// Union of shells around each target atom.
51 IsoLayer {
52 /// Atoms eligible for the result.
53 universe: &'a AtomSelection,
54 /// Shell centres.
55 target: &'a AtomSelection,
56 /// Inclusive inner radius.
57 inner: f32,
58 /// Inclusive outer radius.
59 outer: f32,
60 },
61 /// Cylinder around the target centre and global z axis.
62 CylinderZone {
63 /// Atoms eligible for the result.
64 universe: &'a AtomSelection,
65 /// Atoms defining the centre.
66 target: &'a AtomSelection,
67 /// Radial cutoff.
68 radius: f32,
69 /// Maximum signed z displacement.
70 z_max: f32,
71 /// Minimum signed z displacement.
72 z_min: f32,
73 },
74 /// Cylindrical shell around the target centre and global z axis.
75 CylinderLayer {
76 /// Atoms eligible for the result.
77 universe: &'a AtomSelection,
78 /// Atoms defining the centre.
79 target: &'a AtomSelection,
80 /// Inclusive inner radial cutoff.
81 inner: f32,
82 /// Inclusive outer radial cutoff.
83 outer: f32,
84 /// Maximum signed z displacement.
85 z_max: f32,
86 /// Minimum signed z displacement.
87 z_min: f32,
88 },
89 /// Sphere around an absolute Cartesian point.
90 Point {
91 /// Atoms eligible for the result.
92 universe: &'a AtomSelection,
93 /// Cartesian centre in ångström.
94 point: [f32; 3],
95 /// Sphere radius in ångström.
96 radius: f32,
97 },
98}
99
100/// Executes geometric plan nodes without making the query crate depend on a
101/// particular spatial index implementation.
102pub trait SpatialResolver {
103 /// Evaluates one planned predicate.
104 ///
105 /// # Errors
106 ///
107 /// Returns a diagnostic when periodicity, coordinates or parameters make
108 /// the operation undefined.
109 fn resolve(&self, request: GeometricRequest<'_>) -> Result<AtomSelection, Diagnostic>;
110}