Skip to main content

readcon_db/
select.rs

1use crate::keys::TrajId;
2
3/// Non-SQL selection builder (ASE.db-competitive campaign filters via secondary indexes).
4#[derive(Clone, Debug, Default)]
5pub struct Select {
6    pub traj_id: Option<TrajId>,
7    pub natoms_min: Option<u32>,
8    pub natoms_max: Option<u32>,
9    pub symbols_all: Vec<String>,
10    pub content_hash: Option<[u8; 16]>,
11    pub energy_min: Option<f64>,
12    pub energy_max: Option<f64>,
13    pub fmax_min: Option<f64>,
14    pub fmax_max: Option<f64>,
15    pub mass_min: Option<f64>,
16    pub mass_max: Option<f64>,
17    pub volume_min: Option<f64>,
18    pub volume_max: Option<f64>,
19    /// Exact PBC mask from metadata (`pbc`); frames without `pbc` key never match.
20    pub pbc_exact: Option<[bool; 3]>,
21    pub time_min: Option<f64>,
22    pub time_max: Option<f64>,
23    pub timestep_min: Option<f64>,
24    pub timestep_max: Option<f64>,
25    pub frame_index_min: Option<f64>,
26    pub frame_index_max: Option<f64>,
27    pub neb_bead_min: Option<f64>,
28    pub neb_bead_max: Option<f64>,
29    pub neb_band_min: Option<f64>,
30    pub neb_band_max: Option<f64>,
31    pub charge_min: Option<f64>,
32    pub charge_max: Option<f64>,
33    pub magmom_min: Option<f64>,
34    pub magmom_max: Option<f64>,
35    pub element_count_min: Vec<(String, u32)>,
36    pub element_count_exact: Vec<(String, u32)>,
37    pub exact_formula: Option<String>,
38    /// Bonded-topology HEX from `seams fingerprint` (`idx_topo` prefix).
39    pub topo_key: Option<String>,
40    pub require_forces: bool,
41    pub require_velocities: bool,
42    pub require_energy: bool,
43    pub limit: Option<usize>,
44}
45
46impl Select {
47    pub fn new() -> Self {
48        Self::default()
49    }
50    pub fn trajectory(mut self, id: TrajId) -> Self {
51        self.traj_id = Some(id);
52        self
53    }
54    pub fn natoms_range(mut self, min: u32, max: u32) -> Self {
55        self.natoms_min = Some(min);
56        self.natoms_max = Some(max);
57        self
58    }
59    pub fn require_symbol(mut self, s: impl Into<String>) -> Self {
60        self.symbols_all.push(s.into());
61        self
62    }
63    pub fn exact_hash(mut self, hash: [u8; 16]) -> Self {
64        self.content_hash = Some(hash);
65        self
66    }
67    pub fn energy_range(mut self, min: f64, max: f64) -> Self {
68        self.energy_min = Some(min);
69        self.energy_max = Some(max);
70        self
71    }
72    pub fn fmax_range(mut self, min: f64, max: f64) -> Self {
73        self.fmax_min = Some(min);
74        self.fmax_max = Some(max);
75        self
76    }
77    pub fn mass_range(mut self, min: f64, max: f64) -> Self {
78        self.mass_min = Some(min);
79        self.mass_max = Some(max);
80        self
81    }
82    pub fn volume_range(mut self, min: f64, max: f64) -> Self {
83        self.volume_min = Some(min);
84        self.volume_max = Some(max);
85        self
86    }
87    pub fn pbc(mut self, xyz: [bool; 3]) -> Self {
88        self.pbc_exact = Some(xyz);
89        self
90    }
91    pub fn time_range(mut self, min: f64, max: f64) -> Self {
92        self.time_min = Some(min);
93        self.time_max = Some(max);
94        self
95    }
96    pub fn timestep_range(mut self, min: f64, max: f64) -> Self {
97        self.timestep_min = Some(min);
98        self.timestep_max = Some(max);
99        self
100    }
101    pub fn frame_index_range(mut self, min: f64, max: f64) -> Self {
102        self.frame_index_min = Some(min);
103        self.frame_index_max = Some(max);
104        self
105    }
106    pub fn neb_bead_range(mut self, min: f64, max: f64) -> Self {
107        self.neb_bead_min = Some(min);
108        self.neb_bead_max = Some(max);
109        self
110    }
111    pub fn neb_band_range(mut self, min: f64, max: f64) -> Self {
112        self.neb_band_min = Some(min);
113        self.neb_band_max = Some(max);
114        self
115    }
116    pub fn charge_range(mut self, min: f64, max: f64) -> Self {
117        self.charge_min = Some(min);
118        self.charge_max = Some(max);
119        self
120    }
121    pub fn magmom_range(mut self, min: f64, max: f64) -> Self {
122        self.magmom_min = Some(min);
123        self.magmom_max = Some(max);
124        self
125    }
126    pub fn element_min(mut self, symbol: impl Into<String>, count: u32) -> Self {
127        self.element_count_min.push((symbol.into(), count));
128        self
129    }
130    pub fn element_exact(mut self, symbol: impl Into<String>, count: u32) -> Self {
131        self.element_count_exact.push((symbol.into(), count));
132        self
133    }
134    pub fn exact_composition(mut self, formula: impl Into<String>) -> Self {
135        self.exact_formula = Some(formula.into());
136        self
137    }
138    pub fn topo_key(mut self, hex: impl Into<String>) -> Self {
139        self.topo_key = Some(hex.into());
140        self
141    }
142    pub fn require_forces(mut self) -> Self {
143        self.require_forces = true;
144        self
145    }
146    pub fn require_velocities(mut self) -> Self {
147        self.require_velocities = true;
148        self
149    }
150    pub fn require_energy(mut self) -> Self {
151        self.require_energy = true;
152        self
153    }
154    pub fn limit(mut self, n: usize) -> Self {
155        self.limit = Some(n);
156        self
157    }
158}