18#include "magic_enum/magic_enum.hpp"
24#include <nlohmann/json.hpp>
29using json = nlohmann::json;
33 return std::string(magic_enum::enum_name(val));
38 auto result = magic_enum::enum_cast<E>(j.get<std::string>(),
39 magic_enum::case_insensitive);
40 return result.value_or(fallback);
46#define JSON_OPT(j, key, target) \
47 if ((j).contains(key)) \
48 (target) = (j).at(key).get<decltype(target)>()
52#include "eon/generated/ParametersSSOTJson.inc"
103 j[
"Structure Comparison"] = {
104 {
"distance_difference",
111 {
"indistinguishable_atoms",
114 {
"energy_difference",
116 {
"remove_translation",
126 {
"convergence_metric",
137 j[
"Optimizer"][
"LBFGS"] = {
139 {
"inverse_curvature",
141 {
"max_inverse_curvature",
168 j[
"Optimizer"][
"Xtsci"] = {
188 {
"andersen_collision_period",
191 {
"langevin_friction",
196 {
"path_eco_omega_max",
208 j[
"Nudged Elastic Band"] = {
215 {
"solid_state_weight",
217 {
"solid_state_pressure",
223 {
"tunnel_wall_points",
226 j[
"Nudged Elastic Band"][
"spring"] = {
234 j[
"Nudged Elastic Band"][
"climbing_image"] = {
243 j[
"Nudged Elastic Band"][
"zoom"] = {
244 {
"enabled", zoom.enabled},
245 {
"alpha", zoom.alpha},
246 {
"offset", zoom.offset},
248 {
"activation_threshold", zoom.activation_threshold},
250 {
"stability_count", zoom.stability_count},
251 {
"max_iterations", zoom.max_iterations},
271 j[
"Saddle Search"] = {
278 {
"displace_magnitude",
284 {
"prfo_refine_force",
286 {
"prfo_refine_max_iterations",
292 {
"irc_converged_force",
320 {
"diagonal_preconditioner",
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},
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},
395 {
"write_movies_interval",
397 {
"write_deprecated_outs",
410 project_ssot_json_write(j, p);
415 for (
char &ch : value) {
416 ch =
static_cast<char>(std::tolower(
static_cast<unsigned char>(ch)));
422 if (value.is_array()) {
423 return value.get<std::vector<double>>();
425 if (!value.is_string()) {
426 throw std::invalid_argument(
427 "[Instanton] temperatures must be a list or a comma-separated "
430 std::vector<double> out;
431 std::stringstream ss(value.get<std::string>());
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) {
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 "
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 " +
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>();
472 throw std::invalid_argument(
"[Dynamics] path_seed must be non-negative");
474 th.path_seed =
static_cast<std::uint64_t
>(seed);
480 if (s.contains(
"thermostat")) {
481 th.kind =
lowerCopy(s.at(
"thermostat").get<std::string>());
483 if (s.contains(
"kind")) {
484 th.kind =
lowerCopy(s.at(
"kind").get<std::string>());
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);
495 if (j.contains(
"Main")) {
496 auto &m = j.at(
"Main");
497 if (m.contains(
"job"))
518 bool writeConForces =
520 JSON_OPT(m,
"write_con_forces", writeConForces);
524 auto inputFormat =
main.inputFormat;
525 auto cell =
main.cell;
527 auto vacuum =
main.defaultVacuum;
528 JSON_OPT(m,
"input_format", inputFormat);
531 JSON_OPT(m,
"default_vacuum", vacuum);
534 main.inputFormat = std::move(inputFormat);
535 main.cell = std::move(cell);
537 main.defaultVacuum = vacuum;
541 if (j.contains(
"Potential")) {
542 auto &s = j.at(
"Potential");
543 if (s.contains(
"potential"))
568 if (j.contains(
"Structure Comparison")) {
569 auto &s = j.at(
"Structure Comparison");
572 .distance_difference);
574 s,
"neighbor_cutoff",
579 JSON_OPT(s,
"indistinguishable_atoms",
581 .indistinguishable_atoms);
587 .remove_translation);
591 if (j.contains(
"Optimizer")) {
592 auto &s = j.at(
"Optimizer");
593 if (s.contains(
"opt_method"))
601 c =
static_cast<char>(std::tolower(
static_cast<unsigned char>(c)));
608 throw std::invalid_argument(std::format(
609 "unknown convergence_metric: {}",
615 c =
static_cast<char>(std::tolower(
static_cast<unsigned char>(c)));
619 throw std::invalid_argument(
620 std::format(
"unknown opt_backend: {} (eon, rgmin)",
633 if (s.contains(
"LBFGS")) {
634 auto &l = s.at(
"LBFGS");
638 l,
"inverse_curvature",
640 JSON_OPT(l,
"max_inverse_curvature",
642 .lbfgs.max_inverse_curvature);
675 if (s.contains(
"Xtsci")) {
676 auto &x = s.at(
"Xtsci");
686 if (j.contains(
"Dynamics")) {
687 auto &s = j.at(
"Dynamics");
695 if (j.contains(
"Thermostat")) {
700 if (j.contains(
"Nudged Elastic Band")) {
701 auto &s = j.at(
"Nudged Elastic Band");
705 if (s.contains(
"opt_method"))
726 if (s.contains(
"spring")) {
727 auto &sp = s.at(
"spring");
737 if (s.contains(
"climbing_image")) {
738 auto &ci = s.at(
"climbing_image");
742 ci,
"converged_only",
747 if (s.contains(
"zoom")) {
748 auto &z = s.at(
"zoom");
750 JSON_OPT(z,
"enabled", zoom.enabled);
753 if (z.contains(
"mode")) {
756 JSON_OPT(z,
"activation_threshold", zoom.activation_threshold);
757 if (z.contains(
"interpolation")) {
761 JSON_OPT(z,
"stability_count", zoom.stability_count);
762 JSON_OPT(z,
"max_iterations", zoom.max_iterations);
767 if (j.contains(
"Dimer")) {
768 auto &s = j.at(
"Dimer");
776 if (s.contains(
"opt_method"))
780 if (s.contains(
"rotation_backend"))
782 s.at(
"rotation_backend"),
789 if (j.contains(
"Saddle Search")) {
790 auto &s = j.at(
"Saddle Search");
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);
812 s,
"irc_converged_force",
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>();
835 if (j.contains(
"Debug")) {
836 auto &s = j.at(
"Debug");
839 JSON_OPT(s,
"write_movies_interval",
841 JSON_OPT(s,
"write_deprecated_outs",
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>());
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>());
859 JSON_OPT(s,
"checkpoint_path", h.checkpoint_path);
860 JSON_OPT(s,
"write_modes", h.write_modes);
864 if (j.contains(
"Instanton")) {
865 auto &s = j.at(
"Instanton");
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);
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")) {
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>();
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 " +
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");
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");
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");
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>());
921 if (s.contains(
"friction")) {
922 o.friction =
lowerCopy(s.at(
"friction").get<std::string>());
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 " +
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>());
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)");
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");
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>());
952 if (o.springs !=
"trotter" && o.springs !=
"eco") {
953 throw std::invalid_argument(
954 "[Instanton] springs must be trotter or eco, not " + o.springs);
956 if (o.mode !=
"splitting" && o.mode !=
"rate") {
957 throw std::invalid_argument(
"[Instanton] mode must be splitting or "
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>());
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);
973 if (s.contains(
"pi_direction")) {
974 o.pi_direction =
lowerCopy(s.at(
"pi_direction").get<std::string>());
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);
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;
993 project_ssot_json_read(j, p);
1001 auto j = json::parse(json_str);
1004 }
catch (
const json::exception &e) {
1006 }
catch (
const std::invalid_argument &) {
int main(int argc, char **argv)
#define JSON_OPT(j, key, target)
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 ¶ms)
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 ¶ms)
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.
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 indistinguishable_atoms
double distance_difference
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.
long write_movies_interval
bool write_deprecated_outs
DimerRotationBackend rotation_backend
std::string checkpoint_path
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,...
double max_inverse_curvature
double max_time_step_input
std::string backend
"eon" or "rgmin".
std::string convergence_metric
struct eonc::optimizer_options_t::xtsci_t xtsci
std::string convergence_metric_label
struct eonc::optimizer_options_t::lbfgs_t lbfgs
std::string potentialsPath
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.
double displace_magnitude
std::string minmode_method
struct eonc::saddle_search_options_t::prfo_refine_t prfo_refine
struct eonc::saddle_search_options_t::irc_t irc
double path_pile_tau_input
std::string path_gle_file
double langevin_friction_input
double andersen_tcol_input
double path_eco_omega_max