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    pub require_forces: bool,
39    pub require_velocities: bool,
40    pub require_energy: bool,
41    pub limit: Option<usize>,
42}
43
44impl Select {
45    pub fn new() -> Self {
46        Self::default()
47    }
48    pub fn trajectory(mut self, id: TrajId) -> Self {
49        self.traj_id = Some(id);
50        self
51    }
52    pub fn natoms_range(mut self, min: u32, max: u32) -> Self {
53        self.natoms_min = Some(min);
54        self.natoms_max = Some(max);
55        self
56    }
57    pub fn require_symbol(mut self, s: impl Into<String>) -> Self {
58        self.symbols_all.push(s.into());
59        self
60    }
61    pub fn exact_hash(mut self, hash: [u8; 16]) -> Self {
62        self.content_hash = Some(hash);
63        self
64    }
65    pub fn energy_range(mut self, min: f64, max: f64) -> Self {
66        self.energy_min = Some(min);
67        self.energy_max = Some(max);
68        self
69    }
70    pub fn fmax_range(mut self, min: f64, max: f64) -> Self {
71        self.fmax_min = Some(min);
72        self.fmax_max = Some(max);
73        self
74    }
75    pub fn mass_range(mut self, min: f64, max: f64) -> Self {
76        self.mass_min = Some(min);
77        self.mass_max = Some(max);
78        self
79    }
80    pub fn volume_range(mut self, min: f64, max: f64) -> Self {
81        self.volume_min = Some(min);
82        self.volume_max = Some(max);
83        self
84    }
85    pub fn pbc(mut self, xyz: [bool; 3]) -> Self {
86        self.pbc_exact = Some(xyz);
87        self
88    }
89    pub fn time_range(mut self, min: f64, max: f64) -> Self {
90        self.time_min = Some(min);
91        self.time_max = Some(max);
92        self
93    }
94    pub fn timestep_range(mut self, min: f64, max: f64) -> Self {
95        self.timestep_min = Some(min);
96        self.timestep_max = Some(max);
97        self
98    }
99    pub fn frame_index_range(mut self, min: f64, max: f64) -> Self {
100        self.frame_index_min = Some(min);
101        self.frame_index_max = Some(max);
102        self
103    }
104    pub fn neb_bead_range(mut self, min: f64, max: f64) -> Self {
105        self.neb_bead_min = Some(min);
106        self.neb_bead_max = Some(max);
107        self
108    }
109    pub fn neb_band_range(mut self, min: f64, max: f64) -> Self {
110        self.neb_band_min = Some(min);
111        self.neb_band_max = Some(max);
112        self
113    }
114    pub fn charge_range(mut self, min: f64, max: f64) -> Self {
115        self.charge_min = Some(min);
116        self.charge_max = Some(max);
117        self
118    }
119    pub fn magmom_range(mut self, min: f64, max: f64) -> Self {
120        self.magmom_min = Some(min);
121        self.magmom_max = Some(max);
122        self
123    }
124    pub fn element_min(mut self, symbol: impl Into<String>, count: u32) -> Self {
125        self.element_count_min.push((symbol.into(), count));
126        self
127    }
128    pub fn element_exact(mut self, symbol: impl Into<String>, count: u32) -> Self {
129        self.element_count_exact.push((symbol.into(), count));
130        self
131    }
132    pub fn exact_composition(mut self, formula: impl Into<String>) -> Self {
133        self.exact_formula = Some(formula.into());
134        self
135    }
136    pub fn require_forces(mut self) -> Self {
137        self.require_forces = true;
138        self
139    }
140    pub fn require_velocities(mut self) -> Self {
141        self.require_velocities = true;
142        self
143    }
144    pub fn require_energy(mut self) -> Self {
145        self.require_energy = true;
146        self
147    }
148    pub fn limit(mut self, n: usize) -> Self {
149        self.limit = Some(n);
150        self
151    }
152}