Loading...
Searching...
No Matches
data.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * InputData: parsed input configuration for a Q3 calculation.
5 *
6 * Holds all user-specified parameters read from input files, including
7 * theory selection, convergence settings, plane-wave cutoffs, k-point grid
8 * dimensions, crystal structure data, and output control options.
9 */
10
11#include <stdexcept>
12#include <string>
13#include <utility>
14#include <vector>
15
18
23
24namespace q3 {
25
26/// Parsed input data — holds raw values read from input files.
27struct InputData {
28 // Theory selection
29 std::string theory = "kohn_sham";
30
31 // SCF convergence
34
35 // Kohn-Sham
36 /**
37 * Empty when the input names no functional. parse_input() then fills in
38 * the one the pseudopotentials state, as pw.x does without input_dft; the
39 * former default, "PZ", ran PBE datasets as LDA without a word.
40 */
43 /**
44 * Initial magnetization per species, parallel to `species` (QE
45 * starting_magnetization(i) convention: values in [-1, 1], negative =
46 * opposite sublattice for AFM). May be shorter than `species`; missing
47 * entries mean 0. Empty = unset (spin-polarized runs then use a default).
48 */
49 std::vector<Real> starting_magnetization;
50 /**
51 * Initial magnetization per ATOM, parallel to `atoms` (same [-1, 1]
52 * convention). Empty = unset. When set it overrides
53 * `starting_magnetization` atom by atom, so atoms of one species can start
54 * with different moments (a same-species antiferromagnet); such atoms are
55 * also kept symmetry-inequivalent (see site_symmetry_classes_from_input).
56 */
58 std::string mixing_mode = "broyden";
61 /**
62 * Davidson working basis size as a multiple of the band count. Two arrays
63 * of this many vectors dominate the solver's memory, so this is the one
64 * deck key that trades restart frequency against footprint.
65 */
67 /**
68 * Whether the deck named method.scf.davidson.basis_expansion_factor itself.
69 * A non-self-consistent pass raises the default to its own floor, but keeps
70 * a factor the deck asked for.
71 */
73 std::string mixing_preconditioning = "default";
75 std::string smearing = "none";
77 int methfessel_paxton_order = 1; // Hermite order N of Methfessel-Paxton smearing
78 std::string dispersion_correction = "none"; // "none" or "d3bj"
79 /**
80 * Net cell charge in electrons removed (QE tot_charge convention):
81 * positive = cationic (electrons removed), negative = anionic (electrons added).
82 */
84 // DFT+U (Dudarev). Empty `hubbard` = no Hubbard correction.
85 std::vector<HubbardSpecification> hubbard;
86 /**
87 * Projector convention for the Hubbard manifold: "atomic" (raw pseudo-atomic UPF
88 * orbitals, QE's HUBBARD {atomic} card) or "ortho-atomic" (Lowdin-orthogonalized
89 * over the FULL system-wide atomic-orbital set, then the Hubbard manifold's columns
90 * selected out -- QE's HUBBARD {ortho-atomic} card). A single joint diagonalization
91 * over the whole system, so this is a per-run choice, not settable per manifold.
92 */
93 std::string hubbard_projector_type = "atomic";
94
95 /**
96 * First-iteration occupation-eigenvalue overrides (drop-in
97 * `starting_ns_eigenvalue`, YAML `hubbard_starting_eigenvalues`).
98 * Empty = no seeding. Indices are 0-based here; parsers convert.
99 */
100 std::vector<HubbardStartingEigenvalue> hubbard_starting_eigenvalues;
101
102 /**
103 * SCF iterations for which the seeded occupation matrix is held in place
104 * (drop-in `mixing_fixed_ns`). 0 = seed the first iteration and let
105 * self-consistency take over immediately.
106 */
108
109 // Planewave
113 std::string diagonalization_method = "davidson";
114
115 // Pseudopotential / calculation type
116 std::string calculation = "self_consistent_field";
117 std::vector<std::pair<std::string, Vector3D>> band_path;
119
120 /**
121 * Explicit k-point list for NSCF calculations (calculation == "non_self_consistent_field").
122 * Each entry is (crystal-coordinate k-vector, weight).
123 * Takes precedence over kpoint_grid when non-empty.
124 */
125 std::vector<std::pair<Vector3D, Real>> kpoints_list;
126
127 // System
129 Real cell_dimension_1 = 0.0; // lattice constant in bohr
130 /**
131 * The remaining cell dimensions, in the same convention as
132 * `get_lattice_vectors_from_bravais_index`: b/a, c/a, and three cosines
133 * whose meaning depends on the Bravais index. Zero for every lattice that
134 * does not need them (all cubic ones), which is why the default is 0 rather
135 * than 1.
136 */
142 /**
143 * Explicit lattice vectors (rows a1,a2,a3 in units of cell_dimension_1).
144 * Set for "free" lattices (bravais_lattice_index == 0): YAML general cells
145 * (hexagonal, slab, triclinic, explicit vectors) and QE CELL_PARAMETERS.
146 */
151
152 // Species
153 std::vector<AtomSpecies> species;
154
155 // Atoms (crystal coords)
156 std::vector<Atom> atoms;
157
158 // K-points
161
162 // Pseudopotential directory
163 std::string pseudopotential_directory = "./";
164
165 /**
166 * Canonical name of the registered input format this run was read from
167 * ("yaml", "qe", or a name a build-time add-on registers), recorded by
168 * parse_input(). Empty for an InputData assembled in code.
169 *
170 * The finished run is handed back to that format for the companion
171 * outputs its own conventions expect (io/output/companion_outputs.hpp),
172 * so those files are written only beside a run that was read from it.
173 */
174 std::string source_format;
175
176 // Output control
177 std::string output_directory = "./";
178 std::string prefix = "q3";
179 /**
180 * How much the run says about itself on stdout: "default" (the physics and
181 * the SCF trajectory) or "high" (that, plus the per-iteration and per-phase
182 * diagnostics -- Davidson micro-iterations, timing breakdowns, mixer
183 * internals -- which are logged at debug level). Quantum ESPRESSO's
184 * `verbosity` maps onto this; an explicit --log-level overrides it.
185 */
186 std::string verbosity = "default";
187 /**
188 * true = use no symmetry at all: the k-point mesh is not reduced, and the density,
189 * forces and stress are not symmetrized (Quantum ESPRESSO's nosym + noinv). A shifted
190 * mesh then gives the raw-mesh energy rather than the symmetrized-mesh one.
191 */
192 bool disable_symmetry = false;
193 std::string ibz_reduction_method = "internal"; // "internal" or "spglib"
194
195 /**
196 * Stress tensor options
197 * "analytical" (default) = differentiate Lagrange interpolation polynomial (matches QE)
198 * "numerical" = finite-difference derivatives of beta projectors and Ylm
199 */
200 std::string nonlocal_stress_derivative_method = "analytical";
201
202 /**
203 * Isolated (charged) system correction: "none" (default) or "makov-payne" (QE's
204 * assume_isolated='makov-payne' analog). Cubic lattices only (see
205 * MakovPayneCorrectionCalculator); opt-in since it's meaningless for genuinely
206 * periodic bulk systems and only appropriate for a net-charged cell modeling an
207 * isolated defect/molecule.
208 */
209 std::string isolated_system_correction = "none";
210
211 /**
212 * Mean-field export for an external many-body-perturbation-theory code:
213 * "none" (default) or "berkeleygw" (writes WFN/RHO/vxc.dat -- see
214 * create_mean_field_exporter()). BerkeleyGW normally consumes an NSCF run
215 * with many empty (conduction) bands rather than the SCF run itself, but
216 * the export is wired into both flavors unconditionally (Null object for
217 * "none"), writing into output_directory.
218 */
219 std::string mean_field_export = "none";
220
221 /**
222 * With mean_field_export "berkeleygw", also write the nonlocal
223 * pseudopotential at every k-point as BerkeleyGW's VKB file -- the
224 * projectors ParaBands needs, with VSC, to add bands to WFN. Off by
225 * default: VKB holds one plane-wave vector per projector channel per
226 * k-point, usually more than WFN's own bands. Norm-conserving runs only
227 * (see add_kleinman_bylander_projectors_to_mean_field_record()).
228 */
230
231 // DOS parameters (used when calculation == "density_of_states")
232 Real dos_broadening = 0.02; // Gaussian broadening in Ry
233 Real dos_energy_min = -100.0; // Energy range lower bound in Ry (auto-set if 0)
234 Real dos_energy_max = 100.0; // Energy range upper bound in Ry (auto-set if 0)
235 int dos_energy_steps = 2000; // Number of energy grid points
236
237 /**
238 * Atomic-orbital (ortho-atomic/Löwdin) projections, used when
239 * calculation == "non_self_consistent_field". Opt-in: adds a Löwdin
240 * orthogonalization + projection pass per k-point on top of plain NSCF.
241 */
243
244 /**
245 * `control.interpolation`: a build request on an NSCF run, an evaluation
246 * request on calculation == "interpolation" (see the struct's header).
247 */
249
250 /**
251 * Start the SCF from the charge density a previous run saved in
252 * output_directory/prefix.save (pw.x startingpot = 'file'), rather than
253 * from overlapping atoms. A relaxation driven step by step sets it, so
254 * each geometry starts from the last one's density. A density that does
255 * not fit this run's grid, or a missing one, falls back to the atoms.
256 * The saved bands are offered the same way, as the starting
257 * wavefunctions; a k-point whose file does not fit this basis starts from
258 * the atomic + random guess.
259 */
261
262 /**
263 * True when the input asked for a relaxation ('relax'/'vc-relax'), which
264 * runs here as one SCF at the input's geometry -- a step of the relaxation
265 * q3.workflows drives. The relaxation parameters below are then reported
266 * in the results' provenance, for that driver to read.
267 */
268 bool is_relaxation_step = false;
269
270 // Relaxation parameters (reported when is_relaxation_step)
272 Real relax_force_threshold = 1.0e-3; // Convergence threshold for max |force| in Ry/bohr
273 Real relax_energy_threshold = 1.0e-4; // Convergence threshold for energy change in Ry
274
275 /**
276 * Parallelization
277 * Number of k-point pool groups. Each pool handles a subset of k-points.
278 * 0 = choose automatically from the irreducible k-point count.
279 */
281
282 /**
283 * FFT planning determinism. false (default) = FFTW_MEASURE: each process
284 * times several transform algorithms at startup and keeps the fastest,
285 * which is the better-performing choice but makes runs whose SCF
286 * trajectory is sensitive to Allreduce/summation-order noise (e.g. a
287 * metallic system with a soft, nearly-degenerate magnetic moment under
288 * hot smearing) vary slightly from run to run. true = FFTW_ESTIMATE: a
289 * fixed heuristic plan with no runtime timing, giving bit-reproducible
290 * repeated runs at some performance cost. See TODOs.md §2.3.
291 */
293
294 /**
295 * Wavefunction FFT grid size. false (default) = the 2 x ecutwfc grid: faster,
296 * but approximate -- V(r)ψ(r) and |ψ(r)|² alias, which is harmless where the
297 * wavefunctions have little weight near the cutoff and up to mRy off pw.x on
298 * hard pseudopotentials at low cutoffs. true = the exact grid, sized for
299 * 4 x ecutwfc as pw.x sizes it, at 1.4x to 2.3x the solver time on the silicon
300 * and copper examples. YAML `control.use_exact_wavefunction_grid`; the
301 * QE-format reader always sets it, so a pw.x deck runs on pw.x's grid.
302 */
304
305 /**
306 * Store a "free" lattice (bravais_lattice_index 0) from explicit lattice
307 * vectors given in bohr. Single source for both input formats that build
308 * an explicit cell: the YAML general-lattice path and the QE
309 * CELL_PARAMETERS bohr/angstrom card.
310 *
311 * @param vectors_bohr Rows a1,a2,a3 in bohr.
312 * @param preset_lattice_parameter If > 0, used as alat directly (QE's
313 * celldm(1)-takes-precedence rule when CELL_PARAMETERS coexists
314 * with an explicit celldm). If <= 0 (the YAML case: there is no
315 * prior alat), alat is derived as |a1| instead.
316 */
317 void set_free_lattice_vectors(const Matrix3x3& vectors_bohr,
318 Real preset_lattice_parameter = 0.0) {
319 Real lattice_parameter =
320 (preset_lattice_parameter > 0.0) ? preset_lattice_parameter : vectors_bohr[0].norm();
321 if (lattice_parameter <= 0.0)
322 throw std::runtime_error("Lattice vector a1 must have nonzero length");
324 cell_dimension_1 = lattice_parameter;
325 for (int row = 0; row < 3; ++row) {
326 lattice_vectors[row] = vectors_bohr[row] * (1.0 / lattice_parameter);
327 }
329 }
330};
331
332} // namespace q3
double Real
Parsed input data — holds raw values read from input files.
Definition data.hpp:27
std::string dispersion_correction
Definition data.hpp:78
bool use_exact_wavefunction_grid
Definition data.hpp:303
int number_of_kpoint_pools
Definition data.hpp:280
std::vector< std::pair< std::string, Vector3D > > band_path
Definition data.hpp:117
std::string smearing
Definition data.hpp:75
std::string diagonalization_method
Definition data.hpp:113
Real cell_dimension_4
Definition data.hpp:139
int kpoint_grid_dimension_3
Definition data.hpp:159
Real mixing_beta
Definition data.hpp:59
Real charge_density_energy_cutoff
Definition data.hpp:111
int kpoint_grid_shift_1
Definition data.hpp:160
std::string mean_field_export
Definition data.hpp:219
Real relax_energy_threshold
Definition data.hpp:273
std::vector< AtomSpecies > species
Definition data.hpp:153
std::string prefix
Definition data.hpp:178
bool is_relaxation_step
Definition data.hpp:268
Real dos_energy_max
Definition data.hpp:234
int hubbard_fixed_occupation_iterations
Definition data.hpp:107
int maximum_iterations
Definition data.hpp:33
int kpoint_grid_dimension_1
Definition data.hpp:159
std::vector< Atom > atoms
Definition data.hpp:156
Real cell_dimension_6
Definition data.hpp:141
std::vector< HubbardStartingEigenvalue > hubbard_starting_eigenvalues
Definition data.hpp:100
bool has_explicit_lattice_vectors
Definition data.hpp:148
std::vector< std::pair< Vector3D, Real > > kpoints_list
Definition data.hpp:125
std::string verbosity
Definition data.hpp:186
bool disable_symmetry
Definition data.hpp:192
std::vector< HubbardSpecification > hubbard
Definition data.hpp:85
int kpoint_grid_dimension_2
Definition data.hpp:159
std::string calculation
Definition data.hpp:116
int band_path_points_per_segment
Definition data.hpp:118
int methfessel_paxton_order
Definition data.hpp:77
InterpolationSpecification interpolation
Definition data.hpp:248
std::string isolated_system_correction
Definition data.hpp:209
int mixing_history_size
Definition data.hpp:60
int dos_energy_steps
Definition data.hpp:235
Real mixing_q0
Definition data.hpp:74
std::string mixing_preconditioning
Definition data.hpp:73
std::string hubbard_projector_type
Definition data.hpp:93
std::string mixing_mode
Definition data.hpp:58
Real convergence_threshold
Definition data.hpp:32
std::vector< Real > atomic_starting_magnetization
Definition data.hpp:57
std::string pseudopotential_directory
Definition data.hpp:163
Real relax_force_threshold
Definition data.hpp:272
int kpoint_grid_shift_2
Definition data.hpp:160
std::string theory
Definition data.hpp:29
void set_free_lattice_vectors(const Matrix3x3 &vectors_bohr, Real preset_lattice_parameter=0.0)
Definition data.hpp:317
bool davidson_basis_expansion_factor_set_by_deck
Definition data.hpp:72
Real smearing_width
Definition data.hpp:76
bool use_deterministic_fft_planning
Definition data.hpp:292
Real cell_dimension_1
Definition data.hpp:129
std::string ibz_reduction_method
Definition data.hpp:193
int number_of_bands
Definition data.hpp:112
std::string source_format
Definition data.hpp:174
int number_of_atoms
Definition data.hpp:149
Real dos_energy_min
Definition data.hpp:233
int kpoint_grid_shift_3
Definition data.hpp:160
Real wavefunction_energy_cutoff
Definition data.hpp:110
std::string exchange_correlation_functional
Definition data.hpp:41
int bravais_lattice_index
Definition data.hpp:128
std::string nonlocal_stress_derivative_method
Definition data.hpp:200
int relax_maximum_steps
Definition data.hpp:271
bool start_from_saved_charge_density
Definition data.hpp:260
Real cell_dimension_2
Definition data.hpp:137
Real cell_dimension_5
Definition data.hpp:140
Real dos_broadening
Definition data.hpp:232
int davidson_basis_expansion_factor
Definition data.hpp:66
Real cell_dimension_3
Definition data.hpp:138
bool mean_field_export_kleinman_bylander_projectors
Definition data.hpp:229
int number_of_species
Definition data.hpp:150
std::vector< Real > starting_magnetization
Definition data.hpp:49
bool compute_projections
Definition data.hpp:242
std::string output_directory
Definition data.hpp:177
Real total_charge
Definition data.hpp:83
Matrix3x3 lattice_vectors
Definition data.hpp:147
int number_of_spin_components
Definition data.hpp:42
3×3 matrix stored row-major: row i = mat[i]