Loading...
Searching...
No Matches
ParametersJSON.cpp
Go to the documentation of this file.
1/*
2** This file is part of eOn.
3**
4** SPDX-License-Identifier: BSD-3-Clause
5**
6** Copyright (c) 2010--present, eOn Development Team
7** All rights reserved.
8**
9** Repo:
10** https://github.com/TheochemUI/eOn
11*/
12#include "eon/ParametersJSON.h"
13#include "eon/ChemfilesIO.h"
14#include "eon/HelperFunctions.h"
15#include "eon/PIQTST.h"
16#include "eon/Parameters.h"
17#include "eon/ParametersINI.h"
18#include "magic_enum/magic_enum.hpp"
19
20#include <cctype>
21#include <cmath>
22#include <cstdint>
23#include <format>
24#include <nlohmann/json.hpp>
25#include <sstream>
26#include <stdexcept>
27#include <vector>
28
29using json = nlohmann::json;
30
31// Helper: enum <-> string via magic_enum
32template <typename E> static json enum_to_json(E val) {
33 return std::string(magic_enum::enum_name(val));
34}
35
36template <typename E> static E enum_from_json(const json &j, E fallback) {
37 if (j.is_string()) {
38 auto result = magic_enum::enum_cast<E>(j.get<std::string>(),
39 magic_enum::case_insensitive);
40 return result.value_or(fallback);
41 }
42 return fallback;
43}
44
45// Macro for optional JSON field extraction with default
46#define JSON_OPT(j, key, target) \
47 if ((j).contains(key)) \
48 (target) = (j).at(key).get<decltype(target)>()
49
50namespace eonc::config {
51
52#include "eon/generated/ParametersSSOTJson.inc"
53
55 json j;
56
57 // [Main]
58 j["Main"] = {
67 {"finite_difference",
70 {"remove_net_force",
72 {"write_con_forces",
78 };
79
80 // [Potential]
81 j["Potential"] = {
82 {"potential",
84 {"mpi_poll_period",
86 {"lammps_logging",
88 {"lammps_threads",
90 {"emt_rasmussen",
92 {"log_potential",
95 {"potentials_path",
97 {"pair_switch_width",
100 };
101
102 // [Structure Comparison]
103 j["Structure Comparison"] = {
104 {"distance_difference",
107 {"neighbor_cutoff",
109 {"check_rotation",
111 {"indistinguishable_atoms",
114 {"energy_difference",
116 {"remove_translation",
119 };
120
121 // [Optimizer]
122 j["Optimizer"] = {
123 {"opt_method",
126 {"convergence_metric",
128 {"max_iterations",
131 {"converged_force",
134 {"max_time_step",
136 };
137 j["Optimizer"]["LBFGS"] = {
139 {"inverse_curvature",
141 {"max_inverse_curvature",
143 {"auto_scale",
145 {"angle_reset",
147 {"distance_reset",
150 {"project_rigid",
157 {"extra_updates",
159 {"cautious_eps",
161 {"cautious_alpha",
165 {"precon_rcut",
167 };
168 j["Optimizer"]["Xtsci"] = {
175 };
176
177 // [Dynamics]
178 j["Dynamics"] = {
181 };
182
183 // [Thermostat]
184 j["Thermostat"] = {
186 {"andersen_alpha",
188 {"andersen_collision_period",
191 {"langevin_friction",
194 {"path_springs",
196 {"path_eco_omega_max",
198 {"path_gle_file",
200 {"path_pile_tau",
202 {"path_pile_scale",
205 };
206
207 // [Nudged Elastic Band]
208 j["Nudged Elastic Band"] = {
211 {"opt_method",
215 {"solid_state_weight",
217 {"solid_state_pressure",
220 {"band_precon_mu", ParametersLoadAccess::neb_options(p).band.precon_mu},
223 {"tunnel_wall_points",
225 };
226 j["Nudged Elastic Band"]["spring"] = {
228 {"elastic_band",
230 {"doubly_nudged",
233 };
234 j["Nudged Elastic Band"]["climbing_image"] = {
236 {"converged_only",
238 {"band_slack",
240 };
241 {
242 const auto &zoom = ParametersLoadAccess::neb_options(p).zoom;
243 j["Nudged Elastic Band"]["zoom"] = {
244 {"enabled", zoom.enabled},
245 {"alpha", zoom.alpha},
246 {"offset", zoom.offset},
247 {"mode", enum_to_json(zoom.mode)},
248 {"activation_threshold", zoom.activation_threshold},
249 {"interpolation", enum_to_json(zoom.interpolation)},
250 {"stability_count", zoom.stability_count},
251 {"max_iterations", zoom.max_iterations},
252 };
253 }
254
255 // [Dimer]
256 j["Dimer"] = {
259 {"converged_angle",
262 {"opt_method",
264 {"rotation_backend",
266 {"lor_residual_tol",
268 };
269
270 // [Saddle Search]
271 j["Saddle Search"] = {
273 {"min_mode_method",
276 {"max_iterations",
278 {"displace_magnitude",
280 {"displace_radius",
282 {"prfo_refine",
284 {"prfo_refine_force",
286 {"prfo_refine_max_iterations",
290 {"irc_step_size",
292 {"irc_converged_force",
294 {"irc_max_steps",
296 };
297
298 // [Prefactor]
299 j["Prefactor"] = {
300 {"default_value",
304 };
305
306 // [Lanczos]
307 j["Lanczos"] = {
309 {"max_iterations",
313 };
314
315 // [Davidson]
316 j["Davidson"] = {
318 {"max_iterations",
320 {"diagonal_preconditioner",
323 };
324
325 // [Hessian]
326 j["Hessian"] = {
328 {"zero_freq_value",
332 {"checkpoint_path",
335 };
336
337 // [Instanton]
338 {
340 j["Instanton"] = {
341 {"mode", o.mode},
342 {"reactant_filename", o.reactant_filename},
343 {"product_filename", o.product_filename},
344 {"initial_path", o.initial_path},
345 {"initial_ring", o.initial_ring},
346 {"physical_bath_filename", o.physical_bath_filename},
347 {"beads", o.beads},
348 {"beta_hbar_omega", o.beta_hbar_omega},
349 {"max_iterations", o.max_iterations},
350 {"force_tolerance", o.force_tolerance},
351 {"hessian_stride", o.hessian_stride},
352 {"saddle_filename", o.saddle_filename},
353 {"temperature", o.temperature},
354 {"temperatures", o.temperatures},
355 {"half_ring", o.half_ring},
356 {"symmetrize", o.symmetrize},
357 {"initial_hessians", o.initial_hessians},
358 {"newton_limit", o.newton_limit},
359 {"lanczos_step", o.lanczos_step},
360 {"reactant_hessian_filename", o.reactant_hessian_filename},
361 {"saddle_hessian_filename", o.saddle_hessian_filename},
362 {"physical_hessian_step", o.physical_hessian_step},
363 {"energy_shift", o.energy_shift},
364 {"discretization", o.discretization},
365 {"friction", o.friction},
366 {"friction_eta", o.friction_eta},
367 {"friction_eta_beads", o.friction_eta_beads},
368 {"collapse_fraction", o.collapse_fraction},
369 {"rotation_zero_fraction", o.rotation_zero_fraction},
370 {"bead_ladder", o.bead_ladder},
371 {"hessian_final", o.hessian_final},
372 {"springs", o.springs},
373 {"pi_planes", o.pi_planes},
374 {"pi_beads", o.pi_beads},
375 {"pi_equilibration_steps", o.pi_equilibration_steps},
376 {"pi_sampling_steps", o.pi_sampling_steps},
377 {"pi_time_step", o.pi_time_step},
378 {"pi_thermostat", o.pi_thermostat},
379 {"pi_gle_file", o.pi_gle_file},
380 {"pi_pile_tau", o.pi_pile_tau},
381 {"pi_pile_scale", o.pi_pile_scale},
382 {"pi_seed", o.pi_seed},
383 {"pi_direction", o.pi_direction},
384 {"pi_reactant_extent", o.pi_reactant_extent},
385 {"pi_recrossing_parents", o.pi_recrossing_parents},
386 {"pi_recrossing_children", o.pi_recrossing_children},
387 {"pi_recrossing_time", o.pi_recrossing_time},
388 {"pi_recrossing_spacing", o.pi_recrossing_spacing},
389 };
390 }
391
392 // [Debug]
393 j["Debug"] = {
395 {"write_movies_interval",
397 {"write_deprecated_outs",
399 };
400
401 // [Serve]
402 j["Serve"] = {
408 };
409
410 project_ssot_json_write(j, p);
411 return j;
412}
413
414static std::string lowerCopy(std::string value) {
415 for (char &ch : value) {
416 ch = static_cast<char>(std::tolower(static_cast<unsigned char>(ch)));
417 }
418 return value;
419}
420
421static std::vector<double> temperaturesFromJson(const json &value) {
422 if (value.is_array()) {
423 return value.get<std::vector<double>>();
424 }
425 if (!value.is_string()) {
426 throw std::invalid_argument(
427 "[Instanton] temperatures must be a list or a comma-separated "
428 "string");
429 }
430 std::vector<double> out;
431 std::stringstream ss(value.get<std::string>());
432 std::string token;
433 while (std::getline(ss, token, ',')) {
434 const size_t start = token.find_first_not_of(" \t");
435 const size_t end = token.find_last_not_of(" \t");
436 if (start == std::string::npos) {
437 continue;
438 }
439 try {
440 out.push_back(std::stod(token.substr(start, end - start + 1)));
441 } catch (const std::exception &) {
442 throw std::invalid_argument(
443 "[Instanton] temperatures must be comma-separated kelvin "
444 "values, not " +
445 token);
446 }
447 }
448 return out;
449}
450
451// Path-integral keys live on [Dynamics] in an ini file and under Thermostat
452// in the JSON writer. Either object may carry them. The damping time is
453// stored in femtoseconds; from_json converts it once every object is read.
454static void readPathIntegralKeys(const json &s, Parameters &p) {
456 JSON_OPT(s, "path_beads", th.path_beads);
457 if (s.contains("path_springs")) {
458 th.path_springs = lowerCopy(s.at("path_springs").get<std::string>());
459 if (th.path_springs != "trotter" && th.path_springs != "eco") {
460 throw std::invalid_argument(
461 "[Dynamics] path_springs must be trotter or eco, not " +
462 th.path_springs);
463 }
464 }
465 JSON_OPT(s, "path_eco_omega_max", th.path_eco_omega_max);
466 JSON_OPT(s, "path_gle_file", th.path_gle_file);
467 JSON_OPT(s, "path_pile_tau", th.path_pile_tau_input);
468 JSON_OPT(s, "path_pile_scale", th.path_pile_scale);
469 if (s.contains("path_seed")) {
470 const long seed = s.at("path_seed").get<long>();
471 if (seed < 0) {
472 throw std::invalid_argument("[Dynamics] path_seed must be non-negative");
473 }
474 th.path_seed = static_cast<std::uint64_t>(seed);
475 }
476}
477
478static void readBathKeys(const json &s, Parameters &p) {
480 if (s.contains("thermostat")) {
481 th.kind = lowerCopy(s.at("thermostat").get<std::string>());
482 }
483 if (s.contains("kind")) {
484 th.kind = lowerCopy(s.at("kind").get<std::string>());
485 }
486 JSON_OPT(s, "andersen_alpha", th.andersen_alpha);
487 JSON_OPT(s, "andersen_collision_period", th.andersen_tcol_input);
488 JSON_OPT(s, "nose_mass", th.nose_mass);
489 JSON_OPT(s, "langevin_friction", th.langevin_friction_input);
491}
492
493void from_json(const json &j, Parameters &p) {
494 // [Main]
495 if (j.contains("Main")) {
496 auto &m = j.at("Main");
497 if (m.contains("job"))
499 m.at("job"), ParametersLoadAccess::main_options(p).job);
500 JSON_OPT(m, "random_seed",
502 JSON_OPT(m, "temperature",
504 JSON_OPT(m, "quiet", ParametersLoadAccess::main_options(p).quiet);
505 JSON_OPT(m, "write_log", ParametersLoadAccess::main_options(p).writeLog);
506 JSON_OPT(m, "checkpoint", ParametersLoadAccess::main_options(p).checkpoint);
507 JSON_OPT(m, "ini_filename",
509 JSON_OPT(m, "con_filename",
511 JSON_OPT(m, "finite_difference",
512 ParametersLoadAccess::main_options(p).finiteDifference);
513 JSON_OPT(m, "max_force_calls",
514 ParametersLoadAccess::main_options(p).maxForceCalls);
515 JSON_OPT(m, "remove_net_force",
516 ParametersLoadAccess::main_options(p).removeNetForce);
517 {
518 bool writeConForces =
520 JSON_OPT(m, "write_con_forces", writeConForces);
522 }
524 auto inputFormat = main.inputFormat;
525 auto cell = main.cell;
526 auto pbc = main.pbc;
527 auto vacuum = main.defaultVacuum;
528 JSON_OPT(m, "input_format", inputFormat);
529 JSON_OPT(m, "cell", cell);
530 JSON_OPT(m, "pbc", pbc);
531 JSON_OPT(m, "default_vacuum", vacuum);
532 // Readers consult the process copies, not this object.
533 eonc::io::publish_structure_input(inputFormat, cell, pbc, vacuum);
534 main.inputFormat = std::move(inputFormat);
535 main.cell = std::move(cell);
536 main.pbc = pbc;
537 main.defaultVacuum = vacuum;
538 }
539
540 // [Potential]
541 if (j.contains("Potential")) {
542 auto &s = j.at("Potential");
543 if (s.contains("potential"))
545 enum_from_json(s.at("potential"),
547 JSON_OPT(s, "mpi_poll_period",
549 JSON_OPT(s, "lammps_logging",
551 JSON_OPT(s, "lammps_threads",
553 JSON_OPT(s, "emt_rasmussen",
555 JSON_OPT(s, "log_potential",
557 JSON_OPT(s, "ext_pot_path",
559 JSON_OPT(s, "potentials_path",
561 JSON_OPT(s, "pair_switch_width",
562 ParametersLoadAccess::potential_options(p).pairSwitchWidth);
563 JSON_OPT(s, "pair_cutoff",
565 }
566
567 // [Structure Comparison]
568 if (j.contains("Structure Comparison")) {
569 auto &s = j.at("Structure Comparison");
570 JSON_OPT(s, "distance_difference",
572 .distance_difference);
573 JSON_OPT(
574 s, "neighbor_cutoff",
576 JSON_OPT(
577 s, "check_rotation",
579 JSON_OPT(s, "indistinguishable_atoms",
581 .indistinguishable_atoms);
582 JSON_OPT(s, "energy_difference",
584 .energy_difference);
585 JSON_OPT(s, "remove_translation",
587 .remove_translation);
588 }
589
590 // [Optimizer]
591 if (j.contains("Optimizer")) {
592 auto &s = j.at("Optimizer");
593 if (s.contains("opt_method"))
595 enum_from_json(s.at("opt_method"),
597 JSON_OPT(s, "convergence_metric",
598 ParametersLoadAccess::optimizer_options(p).convergence_metric);
599 for (char &c :
600 ParametersLoadAccess::optimizer_options(p).convergence_metric) {
601 c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
602 }
604 ParametersLoadAccess::optimizer_options(p).convergence_metric)) {
606 std::string(*label);
607 } else {
608 throw std::invalid_argument(std::format(
609 "unknown convergence_metric: {}",
610 ParametersLoadAccess::optimizer_options(p).convergence_metric));
611 }
612 JSON_OPT(s, "opt_backend",
614 for (char &c : ParametersLoadAccess::optimizer_options(p).backend) {
615 c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
616 }
617 if (ParametersLoadAccess::optimizer_options(p).backend != "eon" &&
618 ParametersLoadAccess::optimizer_options(p).backend != "rgmin") {
619 throw std::invalid_argument(
620 std::format("unknown opt_backend: {} (eon, rgmin)",
622 }
623 JSON_OPT(s, "max_iterations",
625 JSON_OPT(s, "max_move",
627 JSON_OPT(s, "converged_force",
628 ParametersLoadAccess::optimizer_options(p).converged_force);
629 JSON_OPT(s, "time_step",
630 ParametersLoadAccess::optimizer_options(p).time_step_input);
631 JSON_OPT(s, "max_time_step",
632 ParametersLoadAccess::optimizer_options(p).max_time_step_input);
633 if (s.contains("LBFGS")) {
634 auto &l = s.at("LBFGS");
635 JSON_OPT(l, "memory",
637 JSON_OPT(
638 l, "inverse_curvature",
639 ParametersLoadAccess::optimizer_options(p).lbfgs.inverse_curvature);
640 JSON_OPT(l, "max_inverse_curvature",
642 .lbfgs.max_inverse_curvature);
643 JSON_OPT(l, "auto_scale",
644 ParametersLoadAccess::optimizer_options(p).lbfgs.auto_scale);
645 JSON_OPT(l, "angle_reset",
646 ParametersLoadAccess::optimizer_options(p).lbfgs.angle_reset);
647 JSON_OPT(l, "distance_reset",
648 ParametersLoadAccess::optimizer_options(p).lbfgs.distance_reset);
649 JSON_OPT(l, "curvature",
650 ParametersLoadAccess::optimizer_options(p).lbfgs.curvature);
651 JSON_OPT(l, "project_rigid",
652 ParametersLoadAccess::optimizer_options(p).lbfgs.project_rigid);
653 JSON_OPT(l, "secant",
655 JSON_OPT(l, "precon",
657 JSON_OPT(l, "step",
660 JSON_OPT(l, "accept",
662 JSON_OPT(l, "extra_updates",
663 ParametersLoadAccess::optimizer_options(p).lbfgs.extra_updates);
664 JSON_OPT(l, "cautious_eps",
665 ParametersLoadAccess::optimizer_options(p).lbfgs.cautious_eps);
666 JSON_OPT(l, "cautious_alpha",
667 ParametersLoadAccess::optimizer_options(p).lbfgs.cautious_alpha);
668 JSON_OPT(l, "precon_A",
670 JSON_OPT(l, "precon_mu",
671 ParametersLoadAccess::optimizer_options(p).lbfgs.precon_mu);
672 JSON_OPT(l, "precon_rcut",
673 ParametersLoadAccess::optimizer_options(p).lbfgs.precon_rcut);
674 }
675 if (s.contains("Xtsci")) {
676 auto &x = s.at("Xtsci");
677 JSON_OPT(x, "method",
679 }
680 JSON_OPT(s, "xtsci_method",
682 }
683
684 // [Dynamics] Thermostat names on this object match the ini file.
685 // A later Thermostat object overrides the same keys.
686 if (j.contains("Dynamics")) {
687 auto &s = j.at("Dynamics");
688 JSON_OPT(s, "time_step",
689 ParametersLoadAccess::dynamics_options(p).time_step_input);
690 JSON_OPT(s, "time", ParametersLoadAccess::dynamics_options(p).time_input);
691 readBathKeys(s, p);
692 }
693
694 // [Thermostat]
695 if (j.contains("Thermostat")) {
696 readBathKeys(j.at("Thermostat"), p);
697 }
698
699 // [Nudged Elastic Band]
700 if (j.contains("Nudged Elastic Band")) {
701 auto &s = j.at("Nudged Elastic Band");
702 JSON_OPT(s, "images", ParametersLoadAccess::neb_options(p).image_count);
703 JSON_OPT(s, "max_iterations",
704 ParametersLoadAccess::neb_options(p).max_iterations);
705 if (s.contains("opt_method"))
707 s.at("opt_method"), ParametersLoadAccess::neb_options(p).opt_method);
708 JSON_OPT(s, "converged_force",
709 ParametersLoadAccess::neb_options(p).force_tolerance);
710 JSON_OPT(s, "solid_state",
711 ParametersLoadAccess::neb_options(p).solid_state.enabled);
712 JSON_OPT(s, "solid_state_weight",
713 ParametersLoadAccess::neb_options(p).solid_state.weight);
714 JSON_OPT(s, "solid_state_pressure",
715 ParametersLoadAccess::neb_options(p).solid_state.pressure);
716 JSON_OPT(s, "band_precon",
717 ParametersLoadAccess::neb_options(p).band.precon);
718 JSON_OPT(s, "band_precon_mu",
719 ParametersLoadAccess::neb_options(p).band.precon_mu);
720 JSON_OPT(s, "band_stepper",
721 ParametersLoadAccess::neb_options(p).band.stepper);
722 JSON_OPT(s, "temperature",
723 ParametersLoadAccess::neb_options(p).quantum_temperature);
724 JSON_OPT(s, "tunnel_wall_points",
725 ParametersLoadAccess::neb_options(p).tunnel_wall_points);
726 if (s.contains("spring")) {
727 auto &sp = s.at("spring");
728 JSON_OPT(sp, "constant",
729 ParametersLoadAccess::neb_options(p).spring.constant);
730 JSON_OPT(sp, "elastic_band",
731 ParametersLoadAccess::neb_options(p).spring.use_elastic_band);
732 JSON_OPT(sp, "doubly_nudged",
733 ParametersLoadAccess::neb_options(p).spring.doubly_nudged);
734 JSON_OPT(sp, "geometric",
735 ParametersLoadAccess::neb_options(p).spring.geometric);
736 }
737 if (s.contains("climbing_image")) {
738 auto &ci = s.at("climbing_image");
739 JSON_OPT(ci, "enabled",
740 ParametersLoadAccess::neb_options(p).climbing_image.enabled);
741 JSON_OPT(
742 ci, "converged_only",
743 ParametersLoadAccess::neb_options(p).climbing_image.converged_only);
744 JSON_OPT(ci, "band_slack",
745 ParametersLoadAccess::neb_options(p).climbing_image.band_slack);
746 }
747 if (s.contains("zoom")) {
748 auto &z = s.at("zoom");
750 JSON_OPT(z, "enabled", zoom.enabled);
751 JSON_OPT(z, "alpha", zoom.alpha);
752 JSON_OPT(z, "offset", zoom.offset);
753 if (z.contains("mode")) {
754 zoom.mode = enum_from_json(z.at("mode"), zoom.mode);
755 }
756 JSON_OPT(z, "activation_threshold", zoom.activation_threshold);
757 if (z.contains("interpolation")) {
758 zoom.interpolation =
759 enum_from_json(z.at("interpolation"), zoom.interpolation);
760 }
761 JSON_OPT(z, "stability_count", zoom.stability_count);
762 JSON_OPT(z, "max_iterations", zoom.max_iterations);
763 }
764 }
765
766 // [Dimer]
767 if (j.contains("Dimer")) {
768 auto &s = j.at("Dimer");
769 JSON_OPT(s, "rotation_angle",
770 ParametersLoadAccess::dimer_options(p).rotation_angle);
771 JSON_OPT(s, "improved", ParametersLoadAccess::dimer_options(p).improved);
772 JSON_OPT(s, "converged_angle",
773 ParametersLoadAccess::dimer_options(p).converged_angle);
774 JSON_OPT(s, "max_iterations",
775 ParametersLoadAccess::dimer_options(p).max_iterations);
776 if (s.contains("opt_method"))
778 enum_from_json(s.at("opt_method"),
780 if (s.contains("rotation_backend"))
782 s.at("rotation_backend"),
783 ParametersLoadAccess::dimer_options(p).rotation_backend);
784 JSON_OPT(s, "lor_residual_tol",
785 ParametersLoadAccess::dimer_options(p).lor_residual_tol);
786 }
787
788 // [Saddle Search]
789 if (j.contains("Saddle Search")) {
790 auto &s = j.at("Saddle Search");
791 JSON_OPT(s, "method",
793 JSON_OPT(s, "min_mode_method",
795 JSON_OPT(s, "max_energy",
797 JSON_OPT(s, "max_iterations",
799 JSON_OPT(s, "displace_magnitude",
800 ParametersLoadAccess::saddle_search_options(p).displace_magnitude);
801 JSON_OPT(s, "displace_radius",
804 JSON_OPT(s, "prfo_refine", prfo.enabled);
805 JSON_OPT(s, "prfo_refine_force", prfo.force);
806 JSON_OPT(s, "prfo_refine_max_iterations", prfo.max_iterations);
807 JSON_OPT(s, "irc_after",
809 JSON_OPT(s, "irc_step_size",
811 JSON_OPT(
812 s, "irc_converged_force",
813 ParametersLoadAccess::saddle_search_options(p).irc.converged_force);
814 JSON_OPT(s, "irc_max_steps",
816 }
817
818 // [Serve]
819 if (j.contains("Serve")) {
820 auto &s = j.at("Serve");
822 if (s.contains("port"))
824 s.at("port").get<uint16_t>();
825 if (s.contains("replicas"))
827 s.at("replicas").get<size_t>();
828 if (s.contains("gateway_port"))
830 s.at("gateway_port").get<uint16_t>();
831 JSON_OPT(s, "endpoints", ParametersLoadAccess::serve_options(p).endpoints);
832 }
833
834 // [Debug]
835 if (j.contains("Debug")) {
836 auto &s = j.at("Debug");
837 JSON_OPT(s, "write_movies",
839 JSON_OPT(s, "write_movies_interval",
840 ParametersLoadAccess::debug_options(p).write_movies_interval);
841 JSON_OPT(s, "write_deprecated_outs",
842 ParametersLoadAccess::debug_options(p).write_deprecated_outs);
843 }
844
845 // [Hessian] phva_atoms wins over the legacy atom_list, as in the ini.
846 if (j.contains("Hessian")) {
847 auto &s = j.at("Hessian");
849 if (s.contains("phva_atoms")) {
850 h.phva_atoms = lowerCopy(s.at("phva_atoms").get<std::string>());
851 } else if (s.contains("atom_list")) {
852 h.phva_atoms = lowerCopy(s.at("atom_list").get<std::string>());
853 }
854 JSON_OPT(s, "zero_freq_value", h.zero_freq_value);
855 if (s.contains("fd_scheme")) {
856 h.fd_scheme = lowerCopy(s.at("fd_scheme").get<std::string>());
857 }
858 JSON_OPT(s, "resume", h.resume);
859 JSON_OPT(s, "checkpoint_path", h.checkpoint_path);
860 JSON_OPT(s, "write_modes", h.write_modes);
861 }
862
863 // [Instanton]
864 if (j.contains("Instanton")) {
865 auto &s = j.at("Instanton");
867 JSON_OPT(s, "mode", o.mode);
868 JSON_OPT(s, "reactant_filename", o.reactant_filename);
869 JSON_OPT(s, "product_filename", o.product_filename);
870 JSON_OPT(s, "initial_path", o.initial_path);
871 JSON_OPT(s, "initial_ring", o.initial_ring);
872 JSON_OPT(s, "physical_bath_filename", o.physical_bath_filename);
873 JSON_OPT(s, "beads", o.beads);
874 JSON_OPT(s, "beta_hbar_omega", o.beta_hbar_omega);
875 JSON_OPT(s, "max_iterations", o.max_iterations);
876 JSON_OPT(s, "force_tolerance", o.force_tolerance);
877 JSON_OPT(s, "hessian_stride", o.hessian_stride);
878 JSON_OPT(s, "saddle_filename", o.saddle_filename);
879 JSON_OPT(s, "temperature", o.temperature);
880 if (s.contains("temperatures")) {
881 o.temperatures = temperaturesFromJson(s.at("temperatures"));
882 }
883 JSON_OPT(s, "half_ring", o.half_ring);
884 JSON_OPT(s, "symmetrize", o.symmetrize);
885 if (s.contains("initial_hessians")) {
886 o.initial_hessians = s.at("initial_hessians").get<std::string>();
887 }
888 if (o.initial_hessians != "saddle" &&
889 o.initial_hessians != "finite_difference") {
890 throw std::invalid_argument(
891 "[Instanton] initial_hessians must be saddle or "
892 "finite_difference, not " +
893 o.initial_hessians);
894 }
895 JSON_OPT(s, "newton_limit", o.newton_limit);
896 if (o.newton_limit < 0) {
897 throw std::invalid_argument(
898 "[Instanton] newton_limit must be nonnegative");
899 }
900 JSON_OPT(s, "reactant_hessian_filename", o.reactant_hessian_filename);
901 JSON_OPT(s, "saddle_hessian_filename", o.saddle_hessian_filename);
902 JSON_OPT(s, "lanczos_step", o.lanczos_step);
903 if (!(o.lanczos_step > 0.0) || !std::isfinite(o.lanczos_step)) {
904 throw std::invalid_argument("[Instanton] lanczos_step must be finite and "
905 "positive in sqrt(amu) Angstrom");
906 }
907 JSON_OPT(s, "physical_hessian_step", o.physical_hessian_step);
908 if (!(o.physical_hessian_step > 0.0) ||
909 !std::isfinite(o.physical_hessian_step)) {
910 throw std::invalid_argument(
911 "[Instanton] physical_hessian_step must be finite and positive "
912 "in sqrt(amu) Angstrom");
913 }
914 JSON_OPT(s, "energy_shift", o.energy_shift);
915 if (s.contains("discretization")) {
916 o.discretization.clear();
917 for (const auto &item : s.at("discretization")) {
918 o.discretization.push_back(item.get<double>());
919 }
920 }
921 if (s.contains("friction")) {
922 o.friction = lowerCopy(s.at("friction").get<std::string>());
923 }
924 if (o.friction != "none" && o.friction != "implicit" &&
925 o.friction != "explicit") {
926 throw std::invalid_argument(
927 "[Instanton] friction must be none, implicit or explicit, not " +
928 o.friction);
929 }
930 JSON_OPT(s, "friction_eta", o.friction_eta);
931 if (s.contains("friction_eta_beads")) {
932 o.friction_eta_beads.clear();
933 for (const auto &item : s.at("friction_eta_beads")) {
934 o.friction_eta_beads.push_back(item.get<double>());
935 }
936 }
937 JSON_OPT(s, "collapse_fraction", o.collapse_fraction);
938 if (!(o.collapse_fraction >= 0.0 && o.collapse_fraction < 1.0)) {
939 throw std::invalid_argument(
940 "[Instanton] collapse_fraction must be in [0, 1)");
941 }
942 JSON_OPT(s, "rotation_zero_fraction", o.rotation_zero_fraction);
943 if (!(o.rotation_zero_fraction > 0.0)) {
944 throw std::invalid_argument(
945 "[Instanton] rotation_zero_fraction must be positive");
946 }
947 JSON_OPT(s, "bead_ladder", o.bead_ladder);
948 JSON_OPT(s, "hessian_final", o.hessian_final);
949 if (s.contains("springs")) {
950 o.springs = lowerCopy(s.at("springs").get<std::string>());
951 }
952 if (o.springs != "trotter" && o.springs != "eco") {
953 throw std::invalid_argument(
954 "[Instanton] springs must be trotter or eco, not " + o.springs);
955 }
956 if (o.mode != "splitting" && o.mode != "rate") {
957 throw std::invalid_argument("[Instanton] mode must be splitting or "
958 "rate, not " +
959 o.mode);
960 }
961 JSON_OPT(s, "pi_planes", o.pi_planes);
962 JSON_OPT(s, "pi_beads", o.pi_beads);
963 JSON_OPT(s, "pi_equilibration_steps", o.pi_equilibration_steps);
964 JSON_OPT(s, "pi_sampling_steps", o.pi_sampling_steps);
965 JSON_OPT(s, "pi_time_step", o.pi_time_step);
966 if (s.contains("pi_thermostat")) {
967 o.pi_thermostat = lowerCopy(s.at("pi_thermostat").get<std::string>());
968 }
969 JSON_OPT(s, "pi_gle_file", o.pi_gle_file);
970 JSON_OPT(s, "pi_pile_tau", o.pi_pile_tau);
971 JSON_OPT(s, "pi_pile_scale", o.pi_pile_scale);
972 JSON_OPT(s, "pi_seed", o.pi_seed);
973 if (s.contains("pi_direction")) {
974 o.pi_direction = lowerCopy(s.at("pi_direction").get<std::string>());
975 }
976 JSON_OPT(s, "pi_reactant_extent", o.pi_reactant_extent);
977 JSON_OPT(s, "pi_recrossing_parents", o.pi_recrossing_parents);
978 JSON_OPT(s, "pi_recrossing_children", o.pi_recrossing_children);
979 JSON_OPT(s, "pi_recrossing_time", o.pi_recrossing_time);
980 JSON_OPT(s, "pi_recrossing_spacing", o.pi_recrossing_spacing);
982 }
983
984 // The ini loader derives these from the femtosecond inputs whether or
985 // not the keys are present; validate_and_link does not.
986 {
988 const double timeUnit = ParametersLoadAccess::constants(p).timeUnit;
989 th.andersen_tcol = timeUnit > 0.0 ? th.andersen_tcol_input / timeUnit : 0.0;
990 th.path_pile_tau = timeUnit > 0.0 ? th.path_pile_tau_input / timeUnit : 0.0;
991 }
992
993 project_ssot_json_read(j, p);
994
995 // Resolve computed fields
997}
998
999int load_json(std::string_view json_str, Parameters &params) {
1000 try {
1001 auto j = json::parse(json_str);
1002 from_json(j, params);
1003 return 0;
1004 } catch (const json::exception &e) {
1005 return 1;
1006 } catch (const std::invalid_argument &) {
1007 return 1;
1008 }
1009}
1010
1011} // namespace eonc::config
int main(int argc, char **argv)
#define JSON_OPT(j, key, target)
nlohmann::json json
static E enum_from_json(const json &j, E fallback)
static json enum_to_json(E val)
void from_json(const json &j, Parameters &p)
Deserialize JSON into Parameters, then resolve computed fields.
static std::string lowerCopy(std::string value)
static void readPathIntegralKeys(const json &s, Parameters &p)
int load_json(std::string_view json_str, Parameters &params)
Load Parameters from a JSON string. Returns 0 on success.
static void readBathKeys(const json &s, Parameters &p)
json to_json(const Parameters &p)
Serialize all Parameters to JSON.
void validate_and_link(Parameters &params)
Resolve cross-group defaults and time unit conversions.
static std::vector< double > temperaturesFromJson(const json &value)
std::optional< std::string_view > convergenceMetricLabel(std::string_view metric)
Display label for a force-convergence metric, or nullopt when the name is none of the four the optimi...
void publish_structure_input(std::string format, const std::string &cell, bool pbc, double vacuum)
Publish [Main] input_format, cell, pbc, and default_vacuum to the process-wide readers.
void validateOptions(const instanton_options_t &o)
Throws std::invalid_argument on an inconsistent [Instanton] pi_* key.
Definition PIQTSTJob.cpp:31
static lanczos_options_t & lanczos_options(Parameters &p)
static thermostat_options_t & thermostat_options(Parameters &p)
static dimer_options_t & dimer_options(Parameters &p)
static constants_t & constants(Parameters &p)
static debug_options_t & debug_options(Parameters &p)
static hessian_options_t & hessian_options(Parameters &p)
static instanton_options_t & instanton_options(Parameters &p)
static saddle_search_options_t & saddle_search_options(Parameters &p)
static dynamics_options_t & dynamics_options(Parameters &p)
static structure_comparison_options_t & structure_comparison_options(Parameters &p)
static main_options_t & main_options(Parameters &p)
static prefactor_options_t & prefactor_options(Parameters &p)
static neb_options_t & neb_options(Parameters &p)
static optimizer_options_t & optimizer_options(Parameters &p)
static serve_options_t & serve_options(Parameters &p)
static davidson_options_t & davidson_options(Parameters &p)
static potential_options_t & potential_options(Parameters &p)
bool diagonal_preconditioner
Heuristic | (H v)_i / v_i | preconditioner (not true diag(H); off by default).
std::string phva_atoms
PHVA mobile/active set for the Ritz space; "All" = all free atoms.
DimerRotationBackend rotation_backend
double defaultVacuum
Vacuum (Angstrom) on every side of the box built when neither the file nor cell supplies one.
bool pbc
Periodicity of that fallback cell.
std::string inputFormat
Chemfiles format substituted for a .con request.
shared_flag writeConForces
Opt-in "Forces of Component" sections in written .con frames (enables force+energy co-load on restart...
std::string cell
Fallback cell when a foreign file carries none: "a b c" or nine row-major lattice numbers.
double band_slack
When converged_only is on, the rest of the band may still be this many times the force tolerance.
double pressure
Hydrostatic pressure in eV/Angstrom^3.
bool geometric
Parallel force k (d_next^2 - d_prev^2).
struct eonc::neb_options_t::climbing_image_options_t climbing_image
struct eonc::neb_options_t::zoom_options_t zoom
struct eonc::neb_options_t::band_options_t band
struct eonc::neb_options_t::spring_options_t spring
struct eonc::neb_options_t::solid_state_options_t solid_state
double quantum_temperature
Temperature in kelvin for the harmonic quantum free-energy profile.
long tunnel_wall_points
Force calls past each end minimum of the converged band, along its end segment continued outward,...
std::string backend
"eon" or "rgmin".
struct eonc::optimizer_options_t::xtsci_t xtsci
struct eonc::optimizer_options_t::lbfgs_t lbfgs
double pairSwitchWidth
Width (Angstrom) of the C^2 quintic switch that takes the lj, ljcluster and morse_pt pair terms to ze...
double pairCutoff
Cutoff (Angstrom) of the lj, ljcluster and morse_pt pair terms.
struct eonc::saddle_search_options_t::prfo_refine_t prfo_refine
struct eonc::saddle_search_options_t::irc_t irc