caroli_cli/input.rs
1//! The input file: TOML tables read with serde. Unknown keys are errors, so that a misspelt
2//! option does not pass unnoticed.
3
4use serde::Deserialize;
5use std::collections::BTreeMap;
6
7/// A number, or an expression of the parameters (`"J/2"`, `"2*pi/3"`; see
8/// [`caroli::model::continuum`] for the syntax).
9#[derive(Clone, Debug, Deserialize, PartialEq)]
10#[serde(untagged)]
11pub enum Num {
12 /// A plain number.
13 Value(f64),
14 /// An expression of the parameters, evaluated by [`Params::num`](crate::build::Params::num).
15 Expr(String),
16}
17
18/// Values of a scanned quantity: one number, a list, or a range.
19#[derive(Clone, Debug, Deserialize, PartialEq)]
20#[serde(untagged)]
21pub enum Values {
22 /// A single value.
23 One(Num),
24 /// Values in this order.
25 List(Vec<Num>),
26 /// Evenly spaced values.
27 Range(Range),
28}
29
30/// `{ from, to, count }` (both ends included) or `{ from, to, step }`.
31#[derive(Clone, Debug, Deserialize, PartialEq)]
32#[serde(deny_unknown_fields)]
33pub struct Range {
34 /// First value.
35 pub from: Num,
36 /// Last value; with `step`, the values stop at it (included when it falls on the grid).
37 pub to: Num,
38 /// Number of values from `from` to `to` (only `from` for 1); exactly one of `count` and `step`.
39 pub count: Option<usize>,
40 /// Spacing of the values `from + k·step` (positive).
41 pub step: Option<Num>,
42}
43
44/// The input file: parameters, clean model, disorder, sample and calculations.
45#[derive(Clone, Debug, Deserialize)]
46#[serde(deny_unknown_fields)]
47pub struct Input {
48 /// Title, printed first by `caroli check`.
49 pub title: Option<String>,
50 /// Named numbers (or expressions of the others) used by every expression of the file.
51 #[serde(default)]
52 pub parameters: BTreeMap<String, Num>,
53 /// The clean model, `[model]`.
54 pub model: ModelInput,
55 /// Disorder terms, `[[disorder]]` (none by default).
56 #[serde(default)]
57 pub disorder: Vec<DisorderInput>,
58 /// The sample, `[system]`.
59 #[serde(default)]
60 pub system: SystemInput,
61 /// The calculations, `[[run]]` (at least one), numbered from 0 in the order of the file.
62 #[serde(default, rename = "run")]
63 pub runs: Vec<RunInput>,
64}
65
66/// The clean model, `[model]`: exactly one of `preset`, `continuum` and `lattice`, and the terms
67/// added to it.
68#[derive(Clone, Debug, Default, Deserialize)]
69#[serde(deny_unknown_fields)]
70pub struct ModelInput {
71 /// `bhz`, `bhz-up`, `bhz-down`, `graphene`, `chain`, `square`, `cubic`, `qwz`.
72 pub preset: Option<String>,
73 /// A k·p Hamiltonian discretised on a chain, square or cubic lattice of constant `spacing`.
74 pub continuum: Option<String>,
75 /// A lattice of one's own, with `onsite` and `hopping` entries.
76 pub lattice: Option<LatticeInput>,
77 /// Lattice constant (continuum, chain, square, cubic) or nearest-neighbour distance
78 /// (graphene). Default 1.
79 pub spacing: Option<Num>,
80 /// BHZ parameters (defaults: the HgTe values of the thesis).
81 pub a: Option<Num>,
82 /// BHZ `B`, of the mass `M − B k²` (default −0.376406).
83 pub b: Option<Num>,
84 /// BHZ `C`, a uniform energy shift (default 0).
85 pub c: Option<Num>,
86 /// BHZ `D`, of the term `C − D k²` common to both orbitals (default −0.280933).
87 pub d: Option<Num>,
88 /// BHZ mass `M` (default −0.137, the inverted regime `M/B > 0`).
89 pub mass: Option<Num>,
90 /// BHZ `λ`, a spin-orbit coupling between the spin blocks (default 0).
91 pub lambda: Option<Num>,
92 /// Hopping energy of the graphene, chain, square and cubic presets (`−t` between neighbours,
93 /// default 1).
94 pub t: Option<Num>,
95 /// Mass of the `qwz` preset (default 1; a Chern insulator for `0 < |m| < 2`).
96 pub m: Option<Num>,
97 /// Spin degeneracy for the graphene, chain, square and cubic presets (two orbitals per site,
98 /// spin fastest).
99 #[serde(default)]
100 pub spin: bool,
101 /// On-site matrices: set for a lattice of one's own, added to a preset.
102 #[serde(default)]
103 pub onsite: Vec<OnsiteInput>,
104 /// Hoppings added to the model.
105 #[serde(default, rename = "hopping")]
106 pub hoppings: Vec<HoppingInput>,
107 /// Uniform magnetic field: phase per unit area (the flux quantum is 2π).
108 pub field: Option<Num>,
109}
110
111/// A lattice of one's own, `[model.lattice]`: its primitive vectors and sublattices.
112#[derive(Clone, Debug, Deserialize)]
113#[serde(deny_unknown_fields)]
114pub struct LatticeInput {
115 /// Primitive vectors (1 to 3, each with 1 to 3 components).
116 pub vectors: Vec<Vec<f64>>,
117 /// Sublattices, numbered from 0 in this order (the indices of the `onsite` and `hopping` terms).
118 pub sublattices: Vec<SublatticeInput>,
119}
120
121/// A sublattice of a [`LatticeInput`]: `{ name, position, orbitals }`.
122#[derive(Clone, Debug, Deserialize)]
123#[serde(deny_unknown_fields)]
124pub struct SublatticeInput {
125 /// Name (default `s0`, `s1`, ... after its index).
126 pub name: Option<String>,
127 /// Position in the unit cell (cartesian, missing components 0; default the origin).
128 #[serde(default)]
129 pub position: Vec<f64>,
130 /// Orbitals on each site (default 1).
131 #[serde(default = "one")]
132 pub orbitals: usize,
133}
134
135fn one() -> usize {
136 1
137}
138
139/// An on-site term, `[[model.onsite]]`.
140#[derive(Clone, Debug, Deserialize)]
141#[serde(deny_unknown_fields)]
142pub struct OnsiteInput {
143 /// Index of the sublattice (default 0).
144 #[serde(default)]
145 pub sublattice: usize,
146 /// Matrix expression, square of the sublattice's number of orbitals.
147 pub matrix: String,
148}
149
150/// A hopping, `[[model.hopping]]`: `⟨(R, from)| H |(R + offset, to)⟩`, the reverse hop added.
151#[derive(Clone, Debug, Deserialize)]
152#[serde(deny_unknown_fields)]
153pub struct HoppingInput {
154 /// Sublattice of the site in cell `R` (default 0).
155 #[serde(default)]
156 pub from: usize,
157 /// Sublattice of the site in cell `R + offset` (default 0).
158 #[serde(default)]
159 pub to: usize,
160 /// Cell offset of the `to` site (one integer per lattice direction).
161 pub offset: Vec<i64>,
162 /// Matrix expression: rows the orbitals of `from`, columns those of `to`.
163 pub matrix: String,
164}
165
166/// A disorder term, `[[disorder]]`, drawn anew for each configuration on its cells and
167/// sublattices.
168#[derive(Clone, Debug, Deserialize)]
169#[serde(deny_unknown_fields)]
170pub struct DisorderInput {
171 /// `anderson` or `magnetic`.
172 #[serde(rename = "type")]
173 pub kind: String,
174 /// Anderson: on-site energies uniform in [−W/2, W/2].
175 pub strength: Option<Num>,
176 /// Magnetic: fraction of the sites carrying a moment, exchange `J` (`J n·S`).
177 pub concentration: Option<Num>,
178 /// Magnetic: exchange energy `J` of the coupling `J n·S` of a moment `n` (required).
179 pub exchange: Option<Num>,
180 /// `isotropic`, `polarized` (mean `mz` along z) or `cone` (half-angle `theta0`, degrees).
181 pub moments: Option<String>,
182 /// Polarized moments: mean `n_z` in [0, 1], `n_z` uniform in `[2 mz − 1, 1]` (default 1).
183 pub mz: Option<Num>,
184 /// Cone moments: half-angle around z (degrees; required).
185 pub theta0: Option<Num>,
186 /// Spin matrices `S`: `same-g` or `opposite-g` (BHZ), `pauli` (two orbitals), or three
187 /// matrix expressions.
188 pub spin: Option<SpinInput>,
189 /// Cells where the disorder lies: `[first, end)` per lattice direction (`x`, `y`, `z`).
190 pub cells: Option<CellsInput>,
191 /// Sublattices that carry it (all by default).
192 pub sublattices: Option<Vec<usize>>,
193 /// Seed of the first configuration; configuration `c` uses `seed + c`.
194 pub seed: Option<u64>,
195}
196
197/// The spin matrices `S` of a magnetic disorder: a name, or three matrix expressions.
198#[derive(Clone, Debug, Deserialize)]
199#[serde(untagged)]
200pub enum SpinInput {
201 /// `pauli` (the Pauli matrices, two orbitals), `same-g` or `opposite-g` (BHZ, `g_E = ±g_H`).
202 Name(String),
203 /// `[S_x, S_y, S_z]`, square of the number of orbitals of a site.
204 Matrices(Vec<String>),
205}
206
207/// Cells of a disorder term: `[first, end)` along each lattice direction, numbered from 0 (all the
208/// cells of a direction without a range).
209#[derive(Clone, Debug, Default, Deserialize)]
210#[serde(deny_unknown_fields)]
211pub struct CellsInput {
212 /// Cells `[first, end)` along the first lattice direction (all by default).
213 pub x: Option<[i64; 2]>,
214 /// Cells `[first, end)` along the second lattice direction (all by default).
215 pub y: Option<[i64; 2]>,
216 /// Cells `[first, end)` along the third lattice direction (all by default).
217 pub z: Option<[i64; 2]>,
218}
219
220/// The sample, `[system]`: its size, its boundaries and its leads.
221#[derive(Clone, Debug, Default, Deserialize)]
222#[serde(deny_unknown_fields)]
223pub struct SystemInput {
224 /// Cells along each lattice direction.
225 pub size: Option<Vec<usize>>,
226 /// Periodic boundaries in every direction (a torus): spectra, densities of states,
227 /// conductivities, time evolution.
228 #[serde(default)]
229 pub periodic: bool,
230 /// Leads on the faces of the sample, `-x`, `+x`, `-y`, `+y`, `-z`, `+z` (default `-x`, `+x`).
231 pub leads: Option<Vec<String>>,
232}
233
234/// One calculation.
235#[derive(Clone, Debug, Deserialize)]
236#[serde(tag = "type", rename_all = "kebab-case")]
237pub enum RunInput {
238 /// `type = "transmission"`: transmissions between the leads.
239 Transmission(TransmissionRun),
240 /// `type = "local"`: scattering states on every site.
241 Local(LocalRun),
242 /// `type = "bands"`: bands of the ribbon or of the bulk.
243 Bands(BandsRun),
244 /// `type = "spectrum"`: eigenvalues of the sample.
245 Spectrum(SpectrumRun),
246 /// `type = "dos"`: densities of states by the kernel polynomial method.
247 Dos(DosRun),
248 /// `type = "conductivity"`: Kubo–Bastin conductivities of a periodic sample.
249 Conductivity(ConductivityRun),
250 /// `type = "scba"`: the self-consistent Born approximation of the disorder.
251 Scba(ScbaRun),
252 /// `type = "evolution"`: time evolution on a torus under a uniform force.
253 Evolution(EvolutionRun),
254}
255
256/// Transmissions between the leads, averaged over nothing: one row per configuration.
257#[derive(Clone, Debug, Deserialize)]
258#[serde(deny_unknown_fields)]
259pub struct TransmissionRun {
260 /// File name of the table (default `NN-transmission.csv`, `NN` the index of the run).
261 pub output: Option<String>,
262 /// Energies of the transmissions (the `energy` column).
263 pub energies: Values,
264 /// Scanned parameters (name → values, each declared in `[parameters]`): every combination.
265 #[serde(default)]
266 pub scan: BTreeMap<String, Values>,
267 /// Number of disorder configurations, the `config` column (default 1).
268 pub configurations: Option<usize>,
269 /// Labels of the orbitals of a lead site (spin sectors: `[0, 0, 1, 1]` for BHZ): the
270 /// transmissions between sectors.
271 pub sectors: Option<Vec<usize>>,
272}
273
274/// Scattering states: bond currents, densities and local densities of states on every site.
275#[derive(Clone, Debug, Deserialize)]
276#[serde(deny_unknown_fields)]
277pub struct LocalRun {
278 /// File name of the table (default `NN-local.csv`, `NN` the index of the run).
279 pub output: Option<String>,
280 /// Energies of the window (the quantities are averaged over them).
281 pub energies: Values,
282 /// Scanned parameters (name → values, each declared in `[parameters]`): every combination.
283 #[serde(default)]
284 pub scan: BTreeMap<String, Values>,
285 /// Number of disorder configurations, the `config` column (default 1).
286 pub configurations: Option<usize>,
287 /// Occupation of each lead (default: the first lead injects, the others are empty).
288 pub occupations: Option<Vec<f64>>,
289 /// On-site operators (name → matrix expression): their densities and currents.
290 #[serde(default)]
291 pub operators: BTreeMap<String, String>,
292}
293
294/// Bands of the ribbon (the sample's cross-section repeated along the first lead axis), or of
295/// the bulk along a path.
296#[derive(Clone, Debug, Deserialize)]
297#[serde(deny_unknown_fields)]
298pub struct BandsRun {
299 /// File name of the table (default `NN-bands.csv`, `NN` the index of the run).
300 pub output: Option<String>,
301 /// Scanned parameters (name → values, each declared in `[parameters]`): every combination.
302 #[serde(default)]
303 pub scan: BTreeMap<String, Values>,
304 /// Bloch phases `k·a` of the ribbon (default 201 values in [−π, π]).
305 pub k: Option<Values>,
306 /// Bulk bands: corners of a path in Bloch phases (one per lattice direction).
307 pub path: Option<Vec<Vec<Num>>>,
308 /// Points per segment of the path.
309 pub points: Option<usize>,
310}
311
312/// Eigenvalues of the finite (or periodic) sample.
313#[derive(Clone, Debug, Deserialize)]
314#[serde(deny_unknown_fields)]
315pub struct SpectrumRun {
316 /// File name of the table (default `NN-spectrum.csv`, `NN` the index of the run).
317 pub output: Option<String>,
318 /// Scanned parameters (name → values, each declared in `[parameters]`): every combination.
319 #[serde(default)]
320 pub scan: BTreeMap<String, Values>,
321 /// Number of disorder configurations, the `config` column (default 1).
322 pub configurations: Option<usize>,
323}
324
325/// Densities of states by the kernel polynomial method.
326#[derive(Clone, Debug, Deserialize)]
327#[serde(deny_unknown_fields)]
328pub struct DosRun {
329 /// File name of the table (default `NN-dos.csv`, `NN` the index of the run).
330 pub output: Option<String>,
331 /// Energies of the densities of states (the `energy` column).
332 pub energies: Values,
333 /// Scanned parameters (name → values, each declared in `[parameters]`): every combination.
334 #[serde(default)]
335 pub scan: BTreeMap<String, Values>,
336 /// Number of disorder configurations, the `config` column (default 1).
337 pub configurations: Option<usize>,
338 /// Chebyshev moments, which set the energy resolution (default 512).
339 pub moments: Option<usize>,
340 /// Random vectors of the stochastic trace (default 10).
341 pub vectors: Option<usize>,
342 /// Seed of the random vectors, `seed + c` for configuration `c` (default: seed 1 for all).
343 pub seed: Option<u64>,
344 /// Bounds `[lower, upper]` of the spectrum, tighter than Gershgorin's for a finer resolution:
345 /// they must hold every eigenvalue.
346 pub bounds: Option<[f64; 2]>,
347 /// On-site operators (name → matrix expression): projected densities of states.
348 #[serde(default)]
349 pub projections: BTreeMap<String, String>,
350}
351
352/// Kubo–Bastin conductivities of a periodic sample.
353#[derive(Clone, Debug, Deserialize)]
354#[serde(deny_unknown_fields)]
355pub struct ConductivityRun {
356 /// File name of the table (default `NN-conductivity.csv`, `NN` the index of the run).
357 pub output: Option<String>,
358 /// Chemical potentials.
359 pub energies: Values,
360 /// Scanned parameters (name → values, each declared in `[parameters]`): every combination.
361 #[serde(default)]
362 pub scan: BTreeMap<String, Values>,
363 /// Number of disorder configurations, the `config` column (default 1).
364 pub configurations: Option<usize>,
365 /// Components, `xx`, `xy`, ... (default `xx`, `xy`).
366 pub components: Option<Vec<String>>,
367 /// Temperature `k_B T` of the Fermi function (energy units; default 0, a step).
368 pub temperature: Option<Num>,
369 /// Chebyshev moments (default 256; the cost grows as their square).
370 pub moments: Option<usize>,
371 /// Random vectors of the stochastic trace (default 10).
372 pub vectors: Option<usize>,
373 /// Seed of the random vectors, `seed + c` for configuration `c` (default: seed 1 for all).
374 pub seed: Option<u64>,
375 /// Bounds `[lower, upper]` of the spectrum, tighter than Gershgorin's for a finer resolution:
376 /// they must hold every eigenvalue.
377 pub bounds: Option<[f64; 2]>,
378}
379
380/// The self-consistent Born approximation of the model with its disorder.
381#[derive(Clone, Debug, Deserialize)]
382#[serde(deny_unknown_fields)]
383pub struct ScbaRun {
384 /// File name of the table (default `NN-scba.csv`, `NN` the index of the run).
385 pub output: Option<String>,
386 /// Energies, solved in this order, each from the previous solution.
387 pub energies: Values,
388 /// Scanned parameters (name → values, each declared in `[parameters]`): every combination.
389 #[serde(default)]
390 pub scan: BTreeMap<String, Values>,
391 /// k points per lattice direction (default 64).
392 pub k_grid: Option<Vec<usize>>,
393 /// Imaginary part of the energy (default 1e-3).
394 pub eta: Option<Num>,
395}
396
397/// Time evolution on a torus under a uniform force.
398#[derive(Clone, Debug, Deserialize)]
399#[serde(deny_unknown_fields)]
400pub struct EvolutionRun {
401 /// File name of the table (default `NN-evolution.csv`, `NN` the index of the run).
402 pub output: Option<String>,
403 /// Scanned parameters (name → values, each declared in `[parameters]`): every combination.
404 #[serde(default)]
405 pub scan: BTreeMap<String, Values>,
406 /// Number of disorder configurations, the `config` column (default 1).
407 pub configurations: Option<usize>,
408 /// Force on the electrons (an electric field, the charge absorbed): `k → k + F t`.
409 pub force: Option<Vec<Num>>,
410 /// Time step (in units of `ħ` over the energy unit).
411 pub dt: Num,
412 /// Number of time steps.
413 pub steps: usize,
414 /// Observables every `every` steps (default 1).
415 pub every: Option<usize>,
416 /// Fermi energy of the excited-carrier count (default 0).
417 pub fermi: Option<Num>,
418 /// The initial state (`fermi-sea`, `band` or `localized`).
419 pub initial: InitialInput,
420}
421
422/// The initial state of an [`EvolutionRun`], tagged by its `type`.
423#[derive(Clone, Debug, Deserialize)]
424#[serde(tag = "type", rename_all = "kebab-case")]
425pub enum InitialInput {
426 /// The Fermi sea below `fermi`, as random-phase superpositions of the occupied states: the
427 /// clean bands, or with disorder the ground state of the disordered Hamiltonian (a Chebyshev
428 /// projection with `moments` terms, default 1024).
429 FermiSea {
430 /// Fermi energy (default 0).
431 fermi: Option<Num>,
432 /// Random-phase vectors of the stochastic trace (default 1).
433 vectors: Option<usize>,
434 /// Seed of the random phases, `seed + c` for configuration `c` (default 1).
435 seed: Option<u64>,
436 /// Chebyshev moments of the projection, with disorder only (default 1024).
437 moments: Option<usize>,
438 },
439 /// The clean bands below `fermi` (only those on `orbitals` of the cell if given, e.g. one
440 /// spin), as random-phase superpositions, also with disorder (which sets them in motion); the
441 /// excited carriers are counted in the same bands.
442 Band {
443 /// Fermi energy (default 0).
444 fermi: Option<Num>,
445 /// Random-phase vectors of the stochastic trace (default 1).
446 vectors: Option<usize>,
447 /// Seed of the random phases, `seed + c` for configuration `c` (default 1).
448 seed: Option<u64>,
449 /// Orbitals of the unit cell whose bands are filled (default all): whole groups that the
450 /// hoppings couple, e.g. `[0, 2]` for one spin of spinful graphene.
451 orbitals: Option<Vec<usize>>,
452 },
453 /// One orbital of one cell, projected on the band states in `window` if given.
454 Localized {
455 /// Cell `[x, y]` of the orbital, inside the `n × n` torus.
456 cell: Vec<usize>,
457 /// Orbital of the unit cell, every sublattice counted (default 0).
458 orbital: Option<usize>,
459 /// Energy window `[lo, hi]` of the clean band states it is projected on (default: none).
460 window: Option<[f64; 2]>,
461 },
462}