SIRIUS 7.5.0
Electronic structure library and applications
simulation_parameters.hpp
Go to the documentation of this file.
1// Copyright (c) 2013-2021 Anton Kozhevnikov, Thomas Schulthess
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without modification, are permitted provided that
5// the following conditions are met:
6//
7// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
8// following disclaimer.
9// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
10// and the following disclaimer in the documentation and/or other materials provided with the distribution.
11//
12// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
13// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
14// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
15// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
16// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
17// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
18// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19
20/** \file simulation_parameters.hpp
21 *
22 * \brief Contains definition and implementation of sirius::Simulation_parameters class.
23 */
24
25#ifndef __SIMULATION_PARAMETERS_HPP__
26#define __SIMULATION_PARAMETERS_HPP__
27
28#include "core/typedefs.hpp"
29#include "core/sf/specfunc.hpp"
30#include "core/cmd_args.hpp"
31#include "core/json.hpp"
32#include "SDDK/memory.hpp"
33#include "dft/smearing.hpp"
34#include "context/config.hpp"
35
36namespace sirius {
37
38/// Get all possible options for initializing sirius. It is a json dictionary.
39nlohmann::json const& get_options_dictionary();
40
41nlohmann::json const& get_section_options(std::string const& section__);
42
43class Config : public config_t
44{
45 public:
46 Config();
47 void import(nlohmann::json const& in__);
48 void lock()
49 {
50 dict_["locked"] = true;
51 }
52 void unlock()
53 {
54 dict_.erase("locked");
55 }
56};
57
58/// Set of basic parameters of a simulation.
59/** This class provides shortcuts to the mostly used input parameters, for example `verbosity`. */
61{
62 private:
63 /// All user-provided paramters are stored here.
65
66 public:
67 Config& cfg()
68 {
69 return cfg_;
70 }
71
72 Config const& cfg() const
73 {
74 return cfg_;
75 }
76
77 protected:
78 /// Type of the processing unit.
79 sddk::device_t processing_unit_{sddk::device_t::CPU};
80
81 /// Type of relativity for valence states.
82 relativity_t valence_relativity_{relativity_t::zora};
83
84 /// Type of relativity for core states.
85 relativity_t core_relativity_{relativity_t::dirac};
86
87 /// Type of electronic structure method.
89
90 /// Type of occupation numbers smearing.
91 smearing::smearing_t smearing_{smearing::smearing_t::gaussian};
92
93 /* copy constructor is forbidden */
95
96 public:
98 {
99 }
100
101 /// Import parameters from a file or a serialized json string.
102 void import(std::string const& str__);
103
104 /// Import parameters from a json dictionary.
105 void import(nlohmann::json const& dict__);
106
107 /// Import from command line arguments.
108 void import(cmd_args const& args__);
109
110 void lmax_apw(int lmax_apw__)
111 {
112 cfg().parameters().lmax_apw(lmax_apw__);
113 }
114
115 void lmax_rho(int lmax_rho__)
116 {
117 cfg().parameters().lmax_rho(lmax_rho__);
118 }
119
120 void lmax_pot(int lmax_pot__)
121 {
122 cfg().parameters().lmax_pot(lmax_pot__);
123 }
124
125 void set_num_mag_dims(int num_mag_dims__)
126 {
127 RTE_ASSERT(num_mag_dims__ == 0 || num_mag_dims__ == 1 || num_mag_dims__ == 3);
128
129 cfg().parameters().num_mag_dims(num_mag_dims__);
130 }
131
132 void set_hubbard_correction(bool hubbard_correction__)
133 {
134 cfg().parameters().hubbard_correction(hubbard_correction__);
135 cfg().hubbard().simplified(false);
136 }
137
138 /// Set flag for Gamma-point calculation.
139 bool gamma_point(bool gamma_point__)
140 {
141 cfg().parameters().gamma_point(gamma_point__);
142 return gamma_point__;
143 }
144
145 /// Set dimensions of MPI grid for band diagonalization problem.
146 std::vector<int> mpi_grid_dims(std::vector<int> mpi_grid_dims__)
147 {
148 cfg().control().mpi_grid_dims(mpi_grid_dims__);
149 return mpi_grid_dims__;
150 }
151
152 void add_xc_functional(std::string name__)
153 {
154 auto xcfunc = cfg().parameters().xc_functionals();
155 xcfunc.push_back(name__);
156 cfg().parameters().xc_functionals(xcfunc);
157 }
158
159 void electronic_structure_method(std::string name__);
160
161 auto electronic_structure_method() const
162 {
164 }
165
166 /// Set core relativity for the LAPW method.
167 void core_relativity(std::string name__);
168
169 /// Set valence relativity for the LAPW method.
170 void valence_relativity(std::string name__);
171
172 void processing_unit(std::string name__);
173
174 void smearing(std::string name__);
175
176 auto smearing() const
177 {
178 return smearing_;
179 }
180
181 void molecule(bool molecule__)
182 {
183 cfg().parameters().molecule(molecule__);
184 }
185
186 auto verbosity() const
187 {
188 return cfg().control().verbosity();
189 }
190
191 /// Set verbosity level.
192 int verbosity(int level__)
193 {
194 cfg().control().verbosity(level__);
195 return level__;
196 }
197
198 inline int lmax_rho() const
199 {
200 return cfg().parameters().lmax_rho();
201 }
202
203 inline int lmmax_rho() const
204 {
205 return sf::lmmax(lmax_rho());
206 }
207
208 inline int lmax_pot() const
209 {
210 return cfg().parameters().lmax_pot();
211 }
212
213 inline int lmmax_pot() const
214 {
215 return sf::lmmax(this->lmax_pot());
216 }
217
218 inline double aw_cutoff() const
219 {
220 return cfg().parameters().aw_cutoff();
221 }
222
223 inline double aw_cutoff(double aw_cutoff__)
224 {
225 cfg().parameters().aw_cutoff(aw_cutoff__);
226 return aw_cutoff__;
227 }
228
229 /// Plane-wave cutoff for G-vectors (in 1/[a.u.]).
230 inline double pw_cutoff() const
231 {
232 return cfg().parameters().pw_cutoff();
233 }
234
235 /// Set plane-wave cutoff.
236 inline double pw_cutoff(double pw_cutoff__)
237 {
238 cfg().parameters().pw_cutoff(pw_cutoff__);
239 return pw_cutoff__;
240 }
241
242 /// Cutoff for G+k vectors (in 1/[a.u.]).
243 inline double gk_cutoff() const
244 {
245 return cfg().parameters().gk_cutoff();
246 }
247
248 /// Set the cutoff for G+k vectors.
249 inline double gk_cutoff(double gk_cutoff__)
250 {
251 cfg().parameters().gk_cutoff(gk_cutoff__);
252 return gk_cutoff__;
253 }
254
255 /// Number of dimensions in the magnetization vector.
256 inline int num_mag_dims() const
257 {
258 auto nmd = cfg().parameters().num_mag_dims();
259 RTE_ASSERT(nmd == 0 || nmd == 1 || nmd == 3);
260 return nmd;
261 }
262
263 /// Number of spin components.
264 /** This parameter can take only two values: 1 -- non-magnetic calcaulation and wave-functions,
265 * 2 -- spin-polarized calculation and wave-functions. */
266 inline int num_spins() const
267 {
268 return (num_mag_dims() == 0) ? 1 : 2;
269 }
270
271 /// Number of components in the complex density matrix.
272 /** In case of non-collinear magnetism only one out of two non-diagonal components is stored. */
273 inline int num_mag_comp() const // TODO: rename; current name does not reflect the meaning
274 {
275 return (num_mag_dims() == 3) ? 3 : num_spins(); // std::max(mag_dims, spins)
276 }
277
278 /// Number of non-zero spinor components.
279 /** In non magnetic case this is equal to 1, in collinear magnetic case it is also equal to 1 (pure spinors),
280 * in non-collinear case the number of components is 2 (general spinor case). */
281 inline int num_spinor_comp() const
282 {
283 if (num_mag_dims() != 3) {
284 return 1;
285 } else {
286 return 2;
287 }
288 }
289
290 /// Number of spinor wave-functions labeled by a sinlge band index.
291 /** In magnetic collinear case the wave-functions have two spin components, but they describe different
292 * states (pure spin-up, pure spin-dn), thus the number of spinors packed in a single band index is 2.
293 * In non-collinear case we have full two-component spinors for each band index. */
294 inline int num_spinors() const
295 {
296 if (num_mag_dims() == 1) {
297 return 2;
298 } else {
299 return 1;
300 }
301 }
302
303 /// Set the number of first-variational states.
304 inline int num_fv_states(int num_fv_states__)
305 {
306 cfg().parameters().num_fv_states(num_fv_states__);
307 return num_fv_states__;
308 }
309
310 /// Number of first-variational states.
311 inline int num_fv_states() const
312 {
313 return cfg().parameters().num_fv_states();
314 }
315
316 /// Set the number of bands.
317 inline int num_bands(int num_bands__)
318 {
319 cfg().parameters().num_bands(num_bands__);
320 return num_bands__;
321 }
322
323 /// Total number of bands.
324 int num_bands() const
325 {
326 if (this->num_fv_states() != -1) {
327 return this->num_fv_states() * this->num_spinor_comp();
328 } else {
329 return cfg().parameters().num_bands();
330 }
331 }
332
333 /// Maximum band occupancy.
334 inline int max_occupancy() const
335 {
336 return (this->num_mag_dims() == 0) ? 2 : 1;
337 }
338
339 /// Minimum occupancy to consider band to be occupied.
340 inline double min_occupancy() const
341 {
342 return cfg_.settings().min_occupancy();
343 }
344
345 /// Set minimum occupancy.
346 inline double min_occupancy(double val__)
347 {
348 cfg().settings().min_occupancy(val__);
349 return cfg().settings().min_occupancy();
350 }
351
352 bool so_correction() const
353 {
354 return cfg().parameters().so_correction();
355 }
356
357 bool so_correction(bool so_correction__)
358 {
359 cfg().parameters().so_correction(so_correction__);
360 return so_correction__;
361 }
362
363 bool hubbard_correction() const
364 {
365 return cfg().parameters().hubbard_correction();
366 }
367
368 bool gamma_point() const
369 {
370 return cfg().parameters().gamma_point();
371 }
372
373 sddk::device_t processing_unit() const
374 {
375 return processing_unit_;
376 }
377
378 double smearing_width() const
379 {
380 return cfg().parameters().smearing_width();
381 }
382
383 double smearing_width(double smearing_width__)
384 {
385 cfg().parameters().smearing_width(smearing_width__);
386 return smearing_width__;
387 }
388
389 void set_auto_rmt(int auto_rmt__)
390 {
391 cfg().parameters().auto_rmt(auto_rmt__);
392 }
393
394 int auto_rmt() const
395 {
396 return cfg().parameters().auto_rmt();
397 }
398
399 bool need_sv() const
400 {
401 return (num_spins() == 2 || hubbard_correction() || so_correction());
402 }
403
404 std::vector<int> mpi_grid_dims() const
405 {
406 return cfg().control().mpi_grid_dims();
407 }
408
409 int cyclic_block_size() const
410 {
411 return cfg().control().cyclic_block_size();
412 }
413
414 bool full_potential() const
415 {
417 }
418
419 std::vector<std::string> xc_functionals() const
420 {
421 return cfg().parameters().xc_functionals();
422 }
423
424 /// Get the name of the standard eigen-value solver to use.
425 std::string std_evp_solver_name() const
426 {
427 return cfg().control().std_evp_solver_name();
428 }
429
430 /// Set the name of the standard eigen-value solver to use.
431 std::string std_evp_solver_name(std::string name__)
432 {
433 cfg().control().std_evp_solver_name(name__);
434 return name__;
435 }
436
437 /// Get the name of the generalized eigen-value solver to use.
438 std::string gen_evp_solver_name() const
439 {
440 return cfg().control().gen_evp_solver_name();
441 }
442
443 /// Set the name of the generalized eigen-value solver to use.
444 std::string gen_evp_solver_name(std::string name__)
445 {
446 cfg().control().gen_evp_solver_name(name__);
447 return name__;
448 }
449
450 relativity_t valence_relativity() const
451 {
452 return valence_relativity_;
453 }
454
455 relativity_t core_relativity() const
456 {
457 return core_relativity_;
458 }
459
460 double rmt_max() const
461 {
462 return cfg().control().rmt_max();
463 }
464
465 double spglib_tolerance() const
466 {
467 return cfg().control().spglib_tolerance();
468 }
469
470 bool molecule() const
471 {
472 return cfg().parameters().molecule();
473 }
474
475 /// Get a use_symmetry flag.
476 /** If crystal symmetry is used, density and potential are symmetrized. */
477 bool use_symmetry() const
478 {
479 return cfg().parameters().use_symmetry();
480 }
481
482 /// Set a use_symmetry flag.
483 bool use_symmetry(bool use_symmetry__)
484 {
485 cfg().parameters().use_symmetry(use_symmetry__);
486 return use_symmetry__;
487 }
488
489 std::string iterative_solver_type(std::string type__)
490 {
491 cfg().iterative_solver().type(type__);
492 return type__;
493 }
494
495 /// Set the tolerance for empty states.
496 double empty_states_tolerance(double tolerance__)
497 {
498 cfg().iterative_solver().empty_states_tolerance(tolerance__);
499 return tolerance__;
500 }
501
502 /// Set the variable which controls the type of sperical coverage.
503 inline int sht_coverage(int sht_coverage__)
504 {
505 cfg_.settings().sht_coverage(sht_coverage__);
506 return cfg_.settings().sht_coverage();
507 }
508
509};
510
511}; // namespace sirius
512
513#endif
Set of basic parameters of a simulation.
int verbosity(int level__)
Set verbosity level.
sddk::device_t processing_unit_
Type of the processing unit.
std::vector< int > mpi_grid_dims(std::vector< int > mpi_grid_dims__)
Set dimensions of MPI grid for band diagonalization problem.
std::string gen_evp_solver_name(std::string name__)
Set the name of the generalized eigen-value solver to use.
double pw_cutoff(double pw_cutoff__)
Set plane-wave cutoff.
int num_spins() const
Number of spin components.
smearing::smearing_t smearing_
Type of occupation numbers smearing.
bool gamma_point(bool gamma_point__)
Set flag for Gamma-point calculation.
int num_fv_states(int num_fv_states__)
Set the number of first-variational states.
bool use_symmetry(bool use_symmetry__)
Set a use_symmetry flag.
int num_spinors() const
Number of spinor wave-functions labeled by a sinlge band index.
int num_mag_comp() const
Number of components in the complex density matrix.
int max_occupancy() const
Maximum band occupancy.
int sht_coverage(int sht_coverage__)
Set the variable which controls the type of sperical coverage.
relativity_t valence_relativity_
Type of relativity for valence states.
void core_relativity(std::string name__)
Set core relativity for the LAPW method.
int num_bands() const
Total number of bands.
int num_bands(int num_bands__)
Set the number of bands.
int num_spinor_comp() const
Number of non-zero spinor components.
int num_mag_dims() const
Number of dimensions in the magnetization vector.
std::string std_evp_solver_name(std::string name__)
Set the name of the standard eigen-value solver to use.
double pw_cutoff() const
Plane-wave cutoff for G-vectors (in 1/[a.u.]).
Config cfg_
All user-provided paramters are stored here.
void valence_relativity(std::string name__)
Set valence relativity for the LAPW method.
bool use_symmetry() const
Get a use_symmetry flag.
double gk_cutoff() const
Cutoff for G+k vectors (in 1/[a.u.]).
relativity_t core_relativity_
Type of relativity for core states.
double min_occupancy() const
Minimum occupancy to consider band to be occupied.
int num_fv_states() const
Number of first-variational states.
double empty_states_tolerance(double tolerance__)
Set the tolerance for empty states.
std::string gen_evp_solver_name() const
Get the name of the generalized eigen-value solver to use.
electronic_structure_method_t electronic_structure_method_
Type of electronic structure method.
double gk_cutoff(double gk_cutoff__)
Set the cutoff for G+k vectors.
double min_occupancy(double val__)
Set minimum occupancy.
std::string std_evp_solver_name() const
Get the name of the standard eigen-value solver to use.
Contains definition and implementation of cmd_args class.
Interface to nlohmann::json library and helper functions.
Memory management functions and classes.
device_t
Type of the main processing unit.
Definition: memory.hpp:120
int lmmax(int lmax)
Maximum number of combinations for a given .
Definition: specfunc.hpp:44
Namespace of the SIRIUS library.
Definition: sirius.f90:5
relativity_t
Type of relativity treatment in the case of LAPW.
Definition: typedefs.hpp:95
electronic_structure_method_t
Type of electronic structure methods.
Definition: typedefs.hpp:76
@ full_potential_lapwlo
Full potential linearized augmented plane waves with local orbitals.
nlohmann::json const & get_section_options(std::string const &section__)
Get all possible options of a given input section. It is a json dictionary.
nlohmann::json const & get_options_dictionary()
Get all possible options for initializing sirius. It is a json dictionary.
Smearing functions used in finding the band occupancies.
Special functions.
Contains typedefs, enums and simple descriptors.