11#include <nlohmann/json.hpp>
12#include <madness/tensor/tensor_json.hpp>
15#include <unordered_map>
27 [[nodiscard]]
virtual nlohmann::json
to_json()
const = 0;
28 virtual void from_json(
const nlohmann::json &j) = 0;
29 [[nodiscard]]
virtual std::string
key()
const = 0;
33template <
class T,
class F>
35 const std::optional<T> &
opt,
F &&to_json_fn) {
37 j[key] = to_json_fn(*
opt);
39template <
class T,
class F>
40inline void get_if_exists(
const nlohmann::json &j,
const std::string &key,
41 std::optional<T> &
opt,
F &&from_json_fn) {
43 opt = from_json_fn(j[key]);
47 return tensor_to_json(t);
50 return tensor_from_json<T>(j);
72 [[nodiscard]] std::string
key()
const override {
return "metadata"; }
79 [[nodiscard]] nlohmann::json
to_json()
const override {
90 j[
"host"] = std::string(HOST_SYSTEM);
99 auto print_time = std::chrono::system_clock::now();
100 auto in_time_t = std::chrono::system_clock::to_time_t(print_time);
101 std::stringstream ss;
102 ss << std::put_time(std::localtime(&in_time_t),
"%Y-%m-%d %X");
127 [[nodiscard]] std::string
key()
const override {
return "convergence"; }
139 [[nodiscard]] nlohmann::json
to_json()
const override {
165 nsteps = j.value(
"nsteps", 0);
168 max_step = j.value(
"max_step", 0.0);
169 if (j.contains(
"final_geometry"))
173 std::string
key()
const override {
return "optimization"; }
175 [[nodiscard]] nlohmann::json
to_json()
const override {
187 nsteps = j.value(
"nsteps", 0);
190 max_step = j.value(
"max_step", 0.0);
191 if (j.contains(
"final_geometry"))
199 std::optional<Tensor<double>>
216 [[nodiscard]] std::string
key()
const override {
return "vibrations"; }
249 std::string
key()
const override {
return "raman"; }
267 std::optional<double>
272 j[
"mode"] = row.
mode;
275 j[
"beta2"] = row.
beta2;
284 row.
mode = j.at(
"mode").get<
int>();
285 row.
freq_cm1 = j.at(
"freq_cm1").get<
double>();
286 row.
alpha2 = j.at(
"alpha2").get<
double>();
287 row.
beta2 = j.at(
"beta2").get<
double>();
288 if (j.contains(
"pol_int"))
289 row.
pol_int = j.at(
"pol_int").get<
double>();
290 if (j.contains(
"depol_int"))
291 row.
depol_int = j.at(
"depol_int").get<
double>();
292 if (j.contains(
"dep_ratio"))
293 row.
dep_ratio = j.at(
"dep_ratio").get<
double>();
303 if (j.contains(
"polarization_frequencies"))
305 j.at(
"polarization_frequencies").get<std::vector<double>>();
306 if (j.contains(
"vibrational_frequencies"))
308 j.at(
"vibrational_frequencies").get<std::vector<double>>();
309 if (j.contains(
"polarizability_derivatives")) {
311 for (
const auto &pd : j[
"polarizability_derivatives"])
314 if (j.contains(
"polarizability_derivatives_normal_modes")) {
316 for (
const auto &pd : j[
"polarizability_derivatives_normal_modes"])
318 tensor_in<double>(pd));
320 if (j.contains(
"raman_spectra")) {
322 for (
const auto &item : j[
"raman_spectra"].items()) {
323 double freq = std::stod(item.key());
324 std::vector<RamanModeRow> spectrum;
325 for (
const auto &mode_json : item.value()) {
328 spectrum.push_back(row);
339 j[
"polarizability_derivatives"] = nlohmann::json::array();
341 j[
"polarizability_derivatives"].push_back(tensor_out<double>(pd));
342 j[
"polarizability_derivatives_normal_modes"] = nlohmann::json::array();
344 j[
"polarizability_derivatives_normal_modes"].push_back(
345 tensor_out<double>(pd));
346 j[
"raman_spectra"] = nlohmann::json::object();
348 nlohmann::json spectrum_json = nlohmann::json::array();
349 for (
const auto &mode_data : item.second) {
350 nlohmann::json mode_json;
352 spectrum_json.push_back(mode_json);
354 j[
"raman_spectra"][std::to_string(item.first)] = spectrum_json;
376 energy = j.value(
"energy", 0.0);
377 if (j.count(
"dipole") == 1)
378 dipole = tensor_from_json<double>(j[
"dipole"]);
379 if (j.count(
"gradient") == 1)
380 gradient = tensor_from_json<double>(j[
"gradient"]);
383 std::string
key()
const override {
return "properties"; }
397 if (j.contains(
"energy"))
398 energy = j.value(
"energy", 0.0);
403 if (j.contains(
"vibrations")) {
414 return p.energy != 0.0 ||
p.dipole ||
p.gradient ||
415 (
p.vibrations &&
p.vibrations->has_data());
425 std::optional<Tensor<double>>
beps;
426 std::optional<Tensor<double>>
bfock;
450 j[
"scf_eigenvalues_a"] = tensor_out<double>(
aeps);
451 j[
"scf_fock_a"] = tensor_out<double>(
afock);
477 if (j.contains(
"scf_eigenvalues_a"))
478 aeps = tensor_in<double>(j.at(
"scf_eigenvalues_a"));
482 if (j.contains(
"scf_fock_a"))
483 afock = tensor_in<double>(j.at(
"scf_fock_a"));
492 if (j.contains(
"model"))
493 model = j.value(
"model", std::string(
"scf"));
494 if (j.contains(
"scf_total_energy"))
497 j.value(
"scf_dispersion_correction_energy", 0.0);
498 if (j.contains(
"citations") && j[
"citations"].is_object()) {
499 const auto &
c = j[
"citations"];
506 if (j.contains(
"properties")) {
514 if (j.contains(
"molecule"))
518 is_opt = j.value(
"is_opt",
false);
546 if (j.count(
"excitations") > 0) {
547 for (
const auto &ex : j[
"excitations"]) {
549 ei.
irrep = ex.value(
"irrep",
"");
550 ei.
omega = ex.value(
"omega", 0.0);
553 ex.value(
"oscillator_strength_length", 0.0);
555 ex.value(
"oscillator_strength_velocity", 0.0);
559 nfreeze = j.value(
"nfreeze", -1);
560 model = j.value(
"model",
"unknown");
569 if (j.count(
"excitations") > 0) {
570 for (
const auto &ex : j[
"excitations"]) {
572 ei.
irrep = ex.value(
"irrep",
"");
573 ei.
omega = ex.value(
"omega", 0.0);
576 ex.value(
"oscillator_strength_length", 0.0);
578 ex.value(
"oscillator_strength_velocity", 0.0);
582 nfreeze = j.value(
"nfreeze", -1);
583 model = j.value(
"model",
"unknown");
589 nlohmann::json ex_json;
590 ex_json[
"irrep"] = ex.irrep;
591 ex_json[
"omega"] = ex.omega;
592 ex_json[
"current_error"] = ex.current_error;
593 ex_json[
"oscillator_strength_length"] = ex.oscillator_strength_length;
594 ex_json[
"oscillator_strength_velocity"] = ex.oscillator_strength_velocity;
595 j[
"excitations"].push_back(ex_json);
614 model = j.value(
"model",
"mp2");
626 model = j.value(
"model",
"mp2");
643 this->correlation_energy = corr_energy;
644 this->total_energy = scf_energy + corr_energy;
674 B = j.value(
"B", 0.0);
679 B = j.value(
"B", 0.0);
706 model = j.value(
"model",
"oaep");
707 drho = j.value(
"drho", 0.0);
708 devir14 = j.value(
"devir14", 0.0);
709 devir17 = j.value(
"devir17", 0.0);
710 Ex_vir = j.value(
"Ex_vir", 0.0);
711 Ex_conv = j.value(
"Ex_conv", 0.0);
712 Ex_HF = j.value(
"Ex_HF", 0.0);
713 E_kin_HF = j.value(
"E_kin_HF", 0.0);
714 E_kin_KS = j.value(
"E_kin_KS", 0.0);
715 Econv = j.value(
"Econv", 0.0);
720 model = j.value(
"model",
"oaep");
721 drho = j.value(
"drho", 0.0);
722 devir14 = j.value(
"dvir14", 0.0);
723 devir17 = j.value(
"dvir17", 0.0);
724 Ex_vir = j.value(
"Ex_vir", 0.0);
725 Ex_conv = j.value(
"Ex_conv", 0.0);
726 Ex_HF = j.value(
"Ex_HF", 0.0);
727 E_kin_HF = j.value(
"E_kin_HF", 0.0);
728 E_kin_KS = j.value(
"E_kin_KS", 0.0);
729 Econv = j.value(
"Econv", 0.0);
Definition test_ar.cc:141
simple class for testing the solver
Definition derivatives.cc:60
void from_json(const nlohmann::json &j) override
Definition Results.h:623
CC2Results & set_energies(const double scf_energy, const double corr_energy)
Definition Results.h:642
CC2Results & set_properties(const PropertyResults &props)
Definition Results.h:657
CC2Results(const nlohmann::json &j)
construct from JSON
Definition Results.h:612
CC2Results & set_total_energy(const double total_energy)
Definition Results.h:653
CC2Results(long nfreeze, const std::string &model)
constructor with nfreeze and model
Definition Results.h:620
CC2Results & set_model(const std::string &model)
Definition Results.h:661
double correlation_energy
Definition Results.h:608
CC2Results & set_correlation_energy(const double corr_energy)
setters with chaining
Definition Results.h:649
CC2Results()
Definition Results.h:605
nlohmann::json to_json() const override
serialize the results to a JSON object
Definition Results.h:631
PropertyResults properties
Definition Results.h:607
double total_energy
Definition Results.h:610
std::vector< excitation_info > excitations
Definition Results.h:536
nlohmann::json to_json() const override
serialize the results to a JSON object
Definition Results.h:586
CISResults(const nlohmann::json &j)
construct from JSON
Definition Results.h:545
std::string model
Definition Results.h:538
std::string key() const override
Definition Results.h:540
void from_json(const nlohmann::json &j) override
Definition Results.h:567
long nfreeze
Definition Results.h:537
CISResults(long nfreeze, const std::string &model)
constructor with nfreeze and model
Definition Results.h:564
holds convergence results of the calculation
Definition Results.h:108
double converged_for_thresh
Definition Results.h:110
void from_json(const nlohmann::json &j) override
Definition Results.h:145
ConvergenceResults & set_converged_dconv(double dconv)
Definition Results.h:134
std::string key() const override
Definition Results.h:127
nlohmann::json to_json() const override
serialize the results to a JSON object
Definition Results.h:139
ConvergenceResults & set_converged_thresh(double thresh)
Definition Results.h:129
ConvergenceResults(const nlohmann::json &j)
construct from JSON
Definition Results.h:115
double converged_for_dconv
Definition Results.h:111
ConvergenceResults & operator=(const nlohmann::json &j)
assignment operator from JSON
Definition Results.h:121
ConvergenceResults()=default
Definition molecule.h:129
json to_json() const
Definition molecule.cc:512
void from_json(const json &mol_json)
Definition molecule.cc:537
nlohmann::json to_json() const override
serialize the results to a JSON object
Definition Results.h:732
double Ex_vir
Definition Results.h:695
double devir14
Definition Results.h:693
double Econv
Definition Results.h:700
double Ex_HF
Definition Results.h:697
void from_json(const nlohmann::json &j) override
Definition Results.h:704
double drho
Definition Results.h:692
OEPResults(const nlohmann::json &j)
construct from JSON
Definition Results.h:719
double E_kin_KS
Definition Results.h:699
double Ex_conv
Definition Results.h:696
double E_kin_HF
Definition Results.h:698
double devir17
Definition Results.h:694
OptimizationResults()=default
int nsteps
Definition Results.h:153
OptimizationResults(const nlohmann::json &j)
construct from JSON
Definition Results.h:164
std::string key() const override
Definition Results.h:173
double max_step
Definition Results.h:157
double max_gradient
Definition Results.h:155
madness::Molecule final_geometry
Definition Results.h:159
void from_json(const nlohmann::json &j) override
Definition Results.h:185
double rms_gradient
Definition Results.h:156
double final_energy
Definition Results.h:154
nlohmann::json to_json() const override
serialize the results to a JSON object
Definition Results.h:175
double rms_step
Definition Results.h:158
std::optional< Tensor< double > > dipole
Definition Results.h:367
std::string key() const override
Definition Results.h:383
PropertyResults()=default
PropertyResults(const nlohmann::json &j)
construct from JSON
Definition Results.h:375
std::optional< VibrationalResults > vibrations
Definition Results.h:369
void from_json(const nlohmann::json &j) override
Definition Results.h:395
std::optional< Tensor< double > > gradient
Definition Results.h:368
double energy
Definition Results.h:365
std::optional< RamanResults > raman
Definition Results.h:370
nlohmann::json to_json() const override
serialize the results to a JSON object
Definition Results.h:385
void from_json(const nlohmann::json &j, RamanModeRow &row) const
Definition Results.h:283
void to_json(const RamanModeRow &row, nlohmann::json &j) const
Definition Results.h:271
std::map< double, std::vector< RamanModeRow > > raman_spectra
Definition Results.h:297
nlohmann::json to_json() const override
serialize the results to a JSON object
Definition Results.h:335
std::vector< double > polarization_frequencies
Definition Results.h:252
Tensor< double > normal_modes
Definition Results.h:254
std::vector< Tensor< double > > polarizability_derivatives
Definition Results.h:255
std::vector< Tensor< double > > polarizability_derivatives_normal_modes
Definition Results.h:256
std::vector< double > vibrational_frequencies
Definition Results.h:253
void from_json(const nlohmann::json &j) override
Definition Results.h:302
std::string key() const override
Definition Results.h:249
virtual std::string key() const =0
virtual ~ResultsBase()=default
virtual nlohmann::json to_json() const =0
serialize the results to a JSON object
virtual void from_json(const nlohmann::json &j)=0
std::optional< Tensor< double > > bfock
Definition Results.h:426
Molecule scf_molecule
Definition Results.h:423
double scf_dispersion_correction_energy
Definition Results.h:433
nlohmann::json to_json() const override
serialize the results to a JSON object
Definition Results.h:446
std::string model
Definition Results.h:429
Tensor< double > aeps
Definition Results.h:421
bool uses_dftd3
Definition Results.h:434
void from_json(const nlohmann::json &j) override
Definition Results.h:475
double scf_total_energy
Definition Results.h:430
SCFResults(const nlohmann::json &j)
construct from JSON
Definition Results.h:442
PropertyResults properties
Definition Results.h:438
bool uses_pcm
Definition Results.h:435
Tensor< double > afock
Definition Results.h:422
bool is_opt
Definition Results.h:427
std::string key() const override
Definition Results.h:444
bool uses_libxc
Definition Results.h:436
std::optional< Tensor< double > > beps
Definition Results.h:425
A tensor is a multidimensional array.
Definition tensor.h:318
static std::size_t size()
Returns the number of threads in the pool.
Definition thread.h:1460
std::optional< Tensor< double > > intensities
Definition Results.h:201
std::string key() const override
Definition Results.h:216
VibrationalResults()=default
std::optional< Tensor< double > > frequencies
Definition Results.h:200
void from_json(const nlohmann::json &j) override
Definition Results.h:234
bool has_data() const
Definition Results.h:212
std::optional< Tensor< double > > reducedmass
Definition Results.h:202
std::optional< Tensor< double > > normalmodes_atomic
Definition Results.h:204
std::optional< Tensor< double > > normalmodes
Definition Results.h:203
nlohmann::json to_json() const override
serialize the results to a JSON object
Definition Results.h:218
std::optional< Tensor< double > > hessian
Definition Results.h:198
VibrationalResults(const nlohmann::json &)
Definition Results.h:210
static constexpr double au2invm
Definition Results.h:207
A parallel world class.
Definition world.h:134
ProcessID size() const
Returns the number of processes in this World (same as MPI_Comm_size()).
Definition world.h:354
void from_json(const nlohmann::json &j) override
Definition Results.h:677
nlohmann::json to_json() const override
serialize the results to a JSON object
Definition Results.h:682
double B
Definition Results.h:669
ZnemoResults(const nlohmann::json &j)
construct from JSON
Definition Results.h:673
Defines common mathematical and physical constants.
char * p(char *buf, const char *name, int k, int initial_level, double thresh, int order)
Definition derivatives.cc:72
Defines madness::MadnessException for exception handling.
#define MADNESS_EXCEPTION(msg, value)
Macro for throwing a MADNESS exception.
Definition madness_exception.h:119
constexpr double au2invcm
conversion from atomic units in reciprocal centimeter
Definition constants.h:272
Namespace for all elements and tools of MADNESS.
Definition DFConvergence.h:9
nlohmann::json tensor_out(const Tensor< T > &t)
Definition Results.h:46
std::tuple< SCFResults, PropertyResults, ConvergenceResults, OptimizationResults > SCFResultsTuple
Definition Results.h:750
bool has_data(const PropertyResults &p)
Definition Results.h:413
double wall_time()
Returns the wall time in seconds relative to an arbitrary origin.
Definition timers.cc:48
Tensor< T > tensor_in(const nlohmann::json &j)
Definition Results.h:49
void get_if_exists(const nlohmann::json &j, const std::string &key, std::optional< T > &opt, F &&from_json_fn)
Definition Results.h:40
void set_if_exists(nlohmann::json &j, const std::string &key, const std::optional< T > &opt, F &&to_json_fn)
Definition Results.h:34
static const double c
Definition relops.cc:10
static const double thresh
Definition rk.cc:45
double oscillator_strength_length
Definition Results.h:533
double omega
Definition Results.h:531
double oscillator_strength_velocity
Definition Results.h:534
std::string irrep
Definition Results.h:530
double current_error
Definition Results.h:532
std::optional< double > depol_int
Definition Results.h:266
std::optional< double > pol_int
Definition Results.h:265
double alpha2
Definition Results.h:263
int mode
Definition Results.h:259
std::optional< double > dep_ratio
Definition Results.h:268
double beta2
Definition Results.h:264
double freq_cm1
Definition Results.h:260
vector< FLOAT > opt(const vector< FLOAT > &x, const vector< FLOAT > &f, const vector< FLOAT > &w, const vector< FLOAT > &guess, int maxiter)
Definition y.cc:486