11#include <nlohmann/json.hpp>
12#include <madness/tensor/tensor_json.hpp>
15#include <unordered_map>
28 virtual void from_json(
const nlohmann::json &j) = 0;
33template <
class T,
class F>
39template <
class T,
class F>
40inline void get_if_exists(
const nlohmann::json &j,
const std::string &key,
72 [[
nodiscard]] std::string
key()
const override {
return "metadata"; }
99 auto print_time = std::chrono::system_clock::now();
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"; }
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"; }
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"])
320 if (j.contains(
"raman_spectra")) {
322 for (
const auto &item : j[
"raman_spectra"].items()) {
323 double freq = std::stod(item.key());
325 for (
const auto &
mode_json : item.value()) {
339 j[
"polarizability_derivatives"] = nlohmann::json::array();
342 j[
"polarizability_derivatives_normal_modes"] = nlohmann::json::array();
344 j[
"polarizability_derivatives_normal_modes"].push_back(
346 j[
"raman_spectra"] = nlohmann::json::object();
349 for (
const auto &
mode_data : item.second) {
354 j[
"raman_spectra"][std::to_string(item.first)] =
spectrum_json;
376 energy = j.value(
"energy", 0.0);
377 if (j.count(
"dipole") == 1)
379 if (j.count(
"gradient") == 1)
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;
467 if (j.contains(
"scf_eigenvalues_a"))
472 if (j.contains(
"scf_fock_a"))
482 if (j.contains(
"model"))
483 model = j.value(
"model", std::string(
"scf"));
484 if (j.contains(
"scf_total_energy"))
488 if (j.contains(
"properties")) {
496 if (j.contains(
"molecule"))
500 is_opt = j.value(
"is_opt",
false);
528 if (j.count(
"excitations") > 0) {
529 for (
const auto &
ex : j[
"excitations"]) {
532 ei.omega =
ex.value(
"omega", 0.0);
533 ei.current_error =
ex.value(
"current_error", 0.0);
534 ei.oscillator_strength_length =
535 ex.value(
"oscillator_strength_length", 0.0);
536 ei.oscillator_strength_velocity =
537 ex.value(
"oscillator_strength_velocity", 0.0);
541 nfreeze = j.value(
"nfreeze", -1);
542 model = j.value(
"model",
"unknown");
551 if (j.count(
"excitations") > 0) {
552 for (
const auto &
ex : j[
"excitations"]) {
555 ei.omega =
ex.value(
"omega", 0.0);
556 ei.current_error =
ex.value(
"current_error", 0.0);
557 ei.oscillator_strength_length =
558 ex.value(
"oscillator_strength_length", 0.0);
559 ei.oscillator_strength_velocity =
560 ex.value(
"oscillator_strength_velocity", 0.0);
564 nfreeze = j.value(
"nfreeze", -1);
565 model = j.value(
"model",
"unknown");
574 ex_json[
"current_error"] =
ex.current_error;
575 ex_json[
"oscillator_strength_length"] =
ex.oscillator_strength_length;
576 ex_json[
"oscillator_strength_velocity"] =
ex.oscillator_strength_velocity;
577 j[
"excitations"].push_back(
ex_json);
596 model = j.value(
"model",
"mp2");
608 model = j.value(
"model",
"mp2");
656 B = j.value(
"B", 0.0);
661 B = j.value(
"B", 0.0);
688 model = j.value(
"model",
"oaep");
689 drho = j.value(
"drho", 0.0);
690 devir14 = j.value(
"devir14", 0.0);
691 devir17 = j.value(
"devir17", 0.0);
692 Ex_vir = j.value(
"Ex_vir", 0.0);
693 Ex_conv = j.value(
"Ex_conv", 0.0);
694 Ex_HF = j.value(
"Ex_HF", 0.0);
695 E_kin_HF = j.value(
"E_kin_HF", 0.0);
696 E_kin_KS = j.value(
"E_kin_KS", 0.0);
697 Econv = j.value(
"Econv", 0.0);
702 model = j.value(
"model",
"oaep");
703 drho = j.value(
"drho", 0.0);
704 devir14 = j.value(
"dvir14", 0.0);
705 devir17 = j.value(
"dvir17", 0.0);
706 Ex_vir = j.value(
"Ex_vir", 0.0);
707 Ex_conv = j.value(
"Ex_conv", 0.0);
708 Ex_HF = j.value(
"Ex_HF", 0.0);
709 E_kin_HF = j.value(
"E_kin_HF", 0.0);
710 E_kin_KS = j.value(
"E_kin_KS", 0.0);
711 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:605
CC2Results & set_energies(const double scf_energy, const double corr_energy)
Definition Results.h:624
CC2Results & set_properties(const PropertyResults &props)
Definition Results.h:639
CC2Results(const nlohmann::json &j)
construct from JSON
Definition Results.h:594
CC2Results & set_total_energy(const double total_energy)
Definition Results.h:635
CC2Results(long nfreeze, const std::string &model)
constructor with nfreeze and model
Definition Results.h:602
CC2Results & set_model(const std::string &model)
Definition Results.h:643
double correlation_energy
Definition Results.h:590
CC2Results & set_correlation_energy(const double corr_energy)
setters with chaining
Definition Results.h:631
CC2Results()
Definition Results.h:587
nlohmann::json to_json() const override
serialize the results to a JSON object
Definition Results.h:613
PropertyResults properties
Definition Results.h:589
double total_energy
Definition Results.h:592
std::vector< excitation_info > excitations
Definition Results.h:518
nlohmann::json to_json() const override
serialize the results to a JSON object
Definition Results.h:568
CISResults(const nlohmann::json &j)
construct from JSON
Definition Results.h:527
std::string model
Definition Results.h:520
std::string key() const override
Definition Results.h:522
void from_json(const nlohmann::json &j) override
Definition Results.h:549
long nfreeze
Definition Results.h:519
CISResults(long nfreeze, const std::string &model)
constructor with nfreeze and model
Definition Results.h:546
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:714
double Ex_vir
Definition Results.h:677
double devir14
Definition Results.h:675
double Econv
Definition Results.h:682
double Ex_HF
Definition Results.h:679
void from_json(const nlohmann::json &j) override
Definition Results.h:686
double drho
Definition Results.h:674
OEPResults(const nlohmann::json &j)
construct from JSON
Definition Results.h:701
double E_kin_KS
Definition Results.h:681
double Ex_conv
Definition Results.h:678
double E_kin_HF
Definition Results.h:680
double devir17
Definition Results.h:676
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
nlohmann::json to_json() const override
serialize the results to a JSON object
Definition Results.h:440
std::string model
Definition Results.h:429
Tensor< double > aeps
Definition Results.h:421
void from_json(const nlohmann::json &j) override
Definition Results.h:465
double scf_total_energy
Definition Results.h:430
SCFResults(const nlohmann::json &j)
construct from JSON
Definition Results.h:436
PropertyResults properties
Definition Results.h:432
Tensor< double > afock
Definition Results.h:422
bool is_opt
Definition Results.h:427
std::string key() const override
Definition Results.h:438
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:1419
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:659
nlohmann::json to_json() const override
serialize the results to a JSON object
Definition Results.h:664
double B
Definition Results.h:651
ZnemoResults(const nlohmann::json &j)
construct from JSON
Definition Results.h:655
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 DFParameters.h:10
nlohmann::json tensor_out(const Tensor< T > &t)
Definition Results.h:46
std::tuple< SCFResults, PropertyResults, ConvergenceResults, OptimizationResults > SCFResultsTuple
Definition Results.h:732
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
static XNonlinearSolver< std::vector< Function< T, NDIM > >, T, vector_function_allocator< T, NDIM > > nonlinear_vector_solver(World &world, const long nvec)
Definition nonlinsol.h:371
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 thresh
Definition rk.cc:45
double oscillator_strength_length
Definition Results.h:515
double omega
Definition Results.h:513
double oscillator_strength_velocity
Definition Results.h:516
std::string irrep
Definition Results.h:512
double current_error
Definition Results.h:514
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