MADNESS 0.10.1
response_parameters.h
Go to the documentation of this file.
1// Copyright 2021 Adrian Hurtado
2
3/// \file ResponseParameters
4/// \brief Input parameters for a response calculation.
5
6#ifndef SRC_APPS_MOLRESPONSE_RESPONSE_PARAMETERS_H_
7#define SRC_APPS_MOLRESPONSE_RESPONSE_PARAMETERS_H_
8
12#include <madness/mra/mra.h>
15
16#include <functional>
17#include <numeric>
18#include <string>
19#include <vector>
20
21#include "madness/tensor/tensor_json.hpp"
22namespace madness {
23
25 ResponseParameters(const ResponseParameters &other) = default;
26
28 initialize<std::string>("archive", "../moldft.restartdata", "file to read ground parameters from");
29 initialize<bool>("nwchem", false, "Using nwchem files for intelligent starting guess");
30 initialize<std::string>("nwchem_dir", "none", "Root name of nwchem files for intelligent starting guess");
31 initialize<size_t>("states", 1, "Number of excited states requested");
32 initialize<int>("print_level", 3, "0: no output; 1: final energy; 2: iterations; 3: timings; 10: debug");
33 initialize<bool>("tda", false, "turn on Tam-Danchof approximation (excitations energy");
34 initialize<bool>("first_run", true, "Are we on the default guess");
35 initialize<bool>("plot", false, "turn on plotting of final orbitals. Output format is .vts");
36 initialize<bool>("plot_range", false, "controls which orbitals will be plotted");
37 initialize<std::vector<int>>("plot_data", std::vector<int>{0}, "Orbitals to plot");
38 initialize<std::vector<double>>("plot_cell", std::vector<double>(),
39 "lo-hi plot cell (default is all space)");
40 initialize<double>("plot_l", -1.0, "Controls the plotting box size");
41 initialize<size_t>("plot_pts", 51, "Controls number of points in plots");
42 initialize<bool>("plot_all_orbitals", false, "Turn on 2D plotting of response orbitals ");
43 initialize<size_t>("maxiter", 25, "maximum number of iterations");
44 initialize<double>("dconv", 1.e-4, "recommended values: 1.e-4 < dconv < 1.e-8");
45 initialize<bool>("conv_only_dens", false,
46 "if true remove bsh_residual from convergence criteria (deprecated)");
47 initialize<bool>("dconv_set", false, "Convergence flage for the orbtial density");
48 initialize<bool>("guess_xyz", true, "ExcitedState intial guess functions ground MO * <x,y,z>");
49 initialize<double>("lo", 1.e-10, "smallest length scale we need to resolve");
50 initialize<std::vector<double>>("protocol", {1.e-4, 1.e-6}, "Defines convergence and truncation protocol");
51 initialize<size_t>("larger_subspace", 0,
52 "Number of iterations to diagonalize in a subspace "
53 "consisting of old and new vectors");
54 initialize<int>("k", -1, "polynomial order");
55 initialize<bool>("random", true, "Use random guess for initial response functions");
56 initialize<bool>("store_potential", true, "Store the potential instead of computing each iteration");
57 initialize<bool>("e_range", false, "Use an energy range to excite from");
58 initialize<double>("e_range_lo", 0, "Energy range (lower end) for orbitals to excite from");
59 initialize<double>("e_range_hi", 1, "Energy range (upper end) for orbitals to excite from");
60 initialize<bool>("plot_initial", false, "Flag to plot the ground state orbitals read in from archivie");
61 initialize<bool>("restart", false, "Flag to restart scf loop from file");
62 initialize<std::string>("restart_file", "none", "file to read ground parameters from");
63 initialize<bool>("kain", false, "Turn on Krylov Accelarated Inexact Newton Solver");
64 initialize<double>("maxrotn", 100, "Max orbital rotation per iteration");
65 initialize<double>("maxbsh", 10, "Max bsh residual");
66 initialize<size_t>("maxsub", 10, "size of iterative subspace ... set to 0 or 1 to disable");
67 initialize<std::string>("xc", "hf", "XC input line");
68 initialize<bool>("save", false, "if true save orbitals to disk");
69 initialize<std::string>("save_file", "none", "File name to save orbitals for restart");
70 initialize<bool>("save_density", false, "Flag to save density at each iteration");
71 initialize<int>("vnucextra", 2, "load balance parameter for nuclear pot");
72 initialize<int>("loadbalparts", 2, "??");
73 initialize<std::string>("save_density_file", "none", "File name to save density for restart");
74 initialize<bool>("load_density", false, "Flag to load density for restart");
75 initialize<std::string>("load_density_file", "none", "File name to load density for restart");
76 initialize<size_t>("guess_max_iter", 5, "maximum number of guess iterations");
77 initialize<std::string>("calc_type", "full", "full,static,tda");
78 initialize<bool>("excited_state", false, "Flag to turn on excited state calc");
79 initialize<bool>("first_order", false, "Flag to turn on first order response calc");
80 initialize<bool>("dipole", false, "Sets RHS to dipole operator 3 x num_orbitals");
81 initialize<bool>("nuclear", false, "Sets RHS to nuclear derivative 3 x num_atoms x num_orbitals");
82 initialize<double>("omega", 0.0, "Incident energy for dynamic response");
83 initialize<double>("l", 20, "user coordinates box size");
84 initialize<size_t>("num_orbitals", 0, "number of ground state orbtials");
85 initialize<bool>("spinrestricted", true, "is spinrestricted calculation");
86 initialize<std::string>("localize", "canon", "localization method", {"pm", "boys", "new", "canon"});
87 }
88
89 public:
91
92 std::string localize() const { return get<std::string>("localize"); }
93 std::string archive() const { return get<std::string>("archive"); }
94 std::string calc_type() const { return get<std::string>("calc_type"); }
95 std::string nwchem_dir() const { return get<std::string>("nwchem_dir"); }
96 bool nwchem() const { return get<bool>("nwchem"); }
97 size_t num_states() const { return get<size_t>("states"); }
98 size_t num_orbitals() const { return get<size_t>("num_orbitals"); }
99 int print_level() const { return get<int>("print_level"); }
100 bool tda() const { return get<bool>("tda"); }
101 bool plot() const { return get<bool>("plot"); }
102
103 double plot_l() const { return get<double>("plot_l"); }
104 size_t plot_pts() const { return get<size_t>("plot_pts"); }
105 bool plot_all_orbitals() const { return get<bool>("plot_all_orbitals"); }
106 size_t maxiter() const { return get<size_t>("maxiter"); }
107 double dconv() const { return get<double>("dconv"); }
108 bool guess_xyz() const { return get<bool>("guess_xyz"); }
109 double lo() const { return get<double>("lo"); }
110 std::vector<double> protocol() const { return get<std::vector<double>>("protocol"); }
111 size_t larger_subspace() const { return get<size_t>("larger_subspace"); }
112 int k() const { return get<int>("k"); }
113 bool random() const { return get<bool>("random"); }
114 bool store_potential() const { return get<bool>("store_potential"); }
115
116
117 bool plot_initial() const { return get<bool>("plot_initial"); }
118 bool restart() const { return get<bool>("restart"); }
119 std::string restart_file() const { return get<std::string>("restart_file"); }
120 bool kain() const { return get<bool>("kain"); }
121 size_t maxsub() const { return get<size_t>("maxsub"); }
122 std::string xc() const { return get<std::string>("xc"); }
123 bool save() const { return get<bool>("save"); }
124 std::string save_file() const { return get<std::string>("save_file"); }
125 size_t guess_max_iter() const { return get<size_t>("guess_max_iter"); }
126 bool property() const { return get<bool>("property"); }
127 int loadbalparts() const { return get<int>("loadbalparts"); }
128 bool excited_state() const { return get<bool>("excited_state"); }
129 bool first_order() const { return get<bool>("first_order"); }
130 bool second_order() const { return get<bool>("second_order"); }
131 bool third_order() const { return get<bool>("third_order"); }
132 bool dipole() const { return get<bool>("dipole"); }
133 bool nuclear() const { return get<bool>("nuclear"); }
134 std::string d2_types() const { return get<std::string>("d2_types"); }
135 double omega() const { return get<double>("omega"); }
136 double L() const { return get<double>("l"); }
137
138 bool spinrestricted() const { return get<bool>("spinrestricted"); }
140 set_derived_value<size_t>("num_orbitals", g_params.n_orbitals());
141 set_derived_value<bool>("spinrestricted", g_params.is_spinrestricted());
142 set_derived_value<double>("l", g_params.get_L());
143 set_derived_value<double>("lo", g_params.molecule().smallest_length_scale());
144 set_derived_value<std::string>("xc", g_params.get_xc());
145 set_derived_value<std::string>("localize", g_params.get_localize_method());
146 }
148 // read the parameters from file and brodcast
149 // tag
150 vector<std::string> calculation_type;
151 vector<bool> calc_flags;
152 if (first_order()) {
153 if (omega() == 0) {
154 set_derived_value<std::string>("calc_type", "static");
155 } else {
156 set_derived_value<std::string>("calc_type", "full");
157 }
158
159 if (dipole()) {
160 set_derived_value<size_t>("states", 3);
161 } else if (nuclear()) {
162 set_derived_value<size_t>("states", 3 * molecule.natom());
163 }
164 } else if (excited_state()) {
165 if (tda()) {
166 set_derived_value<std::string>("calc_type", "tda");
167 } else {
168 set_derived_value<std::string>("calc_type", "full");
169 }
170 } else if (second_order()) {
171 if (omega() == 0) {
172 set_derived_value<std::string>("calc_type", "static");
173 } else {
174 set_derived_value<std::string>("calc_type", "full");
175 }
176 vector<int> nstates;// states 1
177 for (size_t i = 0; i < 2; i++) {
178 if (d2_types().at(i) == 'd') {
179 nstates.push_back(3);
180 } else if (d2_types().at(i) == 'n') {
181 nstates.push_back(3 * molecule.natom());
182 } else {
183 MADNESS_EXCEPTION("not a valid response state ", 0);
184 }
185 }
186 size_t states;
187 states = std::accumulate(nstates.begin(), nstates.end(), 1, std::multiplies<>());
188 set_derived_value<size_t>("states", states);
189 }
190 }
191
192 // convenience getters
193 double econv() const { return get<double>("econv"); }
194 bool first_run() const { return get<bool>("first_run"); }
195 std::string local() const { return get<std::string>("local"); }
196 };
197 void from_json(const nlohmann::json &, ResponseParameters &p);
198 bool operator==(const ResponseParameters &p1, const ResponseParameters &p2);
199 bool operator!=(const ResponseParameters &p1, const ResponseParameters &p2);
200 // convenience getters
201 void to_json(nlohmann::json &j);
202};// namespace madness
203
204// namespace madness
205
206#endif// SRC_APPS_MOLRESPONSE_RESPONSE_PARAMETERS_H_
Definition ground_parameters.h:25
std::string get_localize_method() const
Definition ground_parameters.h:69
double get_L() const
Definition ground_parameters.h:62
std::string get_xc() const
Definition ground_parameters.h:68
unsigned int n_orbitals() const
Definition ground_parameters.h:54
bool is_spinrestricted() const
Definition ground_parameters.h:52
Molecule molecule() const
Definition ground_parameters.h:60
Definition molecule.h:124
double smallest_length_scale() const
Definition molecule.cc:641
size_t natom() const
Definition molecule.h:387
class for holding the parameters for calculation
Definition QCCalculationParametersBase.h:290
virtual void read_input_and_commandline_options(World &world, const commandlineparser &parser, const std::string tag)
Definition QCCalculationParametersBase.h:325
A parallel world class.
Definition world.h:132
char * p(char *buf, const char *name, int k, int initial_level, double thresh, int order)
Definition derivatives.cc:72
#define MADNESS_EXCEPTION(msg, value)
Macro for throwing a MADNESS exception.
Definition madness_exception.h:119
Main include file for MADNESS and defines Function interface.
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
bool operator!=(const ResponseParameters &p1, const ResponseParameters &p2)
Definition response_parameters.cpp:17
bool operator==(const ResponseParameters &p1, const ResponseParameters &p2)
Definition response_parameters.cpp:12
void to_json(nlohmann::json &j)
void from_json(const nlohmann::json &, ResponseParameters &p)
Definition response_parameters.cpp:8
Implements ParallelInputArchive and ParallelOutputArchive for parallel serialization of data.
Definition response_parameters.h:24
bool first_order() const
Definition response_parameters.h:129
size_t num_orbitals() const
Definition response_parameters.h:98
std::string save_file() const
Definition response_parameters.h:124
bool dipole() const
Definition response_parameters.h:132
std::string calc_type() const
Definition response_parameters.h:94
bool guess_xyz() const
Definition response_parameters.h:108
bool first_run() const
Definition response_parameters.h:194
ResponseParameters(const ResponseParameters &other)=default
bool store_potential() const
Definition response_parameters.h:114
double lo() const
Definition response_parameters.h:109
bool tda() const
Definition response_parameters.h:100
std::string d2_types() const
Definition response_parameters.h:134
bool second_order() const
Definition response_parameters.h:130
bool spinrestricted() const
Definition response_parameters.h:138
double L() const
Definition response_parameters.h:136
std::string local() const
Definition response_parameters.h:195
double econv() const
Definition response_parameters.h:193
bool plot_initial() const
Definition response_parameters.h:117
bool kain() const
Definition response_parameters.h:120
bool plot() const
Definition response_parameters.h:101
int k() const
Definition response_parameters.h:112
size_t maxsub() const
Definition response_parameters.h:121
bool third_order() const
Definition response_parameters.h:131
double dconv() const
Definition response_parameters.h:107
void set_derived_values(World &world, Molecule molecule)
Definition response_parameters.h:147
std::string xc() const
Definition response_parameters.h:122
bool random() const
Definition response_parameters.h:113
size_t maxiter() const
Definition response_parameters.h:106
bool nwchem() const
Definition response_parameters.h:96
size_t guess_max_iter() const
Definition response_parameters.h:125
bool restart() const
Definition response_parameters.h:118
bool excited_state() const
Definition response_parameters.h:128
int print_level() const
Definition response_parameters.h:99
std::string nwchem_dir() const
Definition response_parameters.h:95
std::string localize() const
Definition response_parameters.h:92
std::vector< double > protocol() const
Definition response_parameters.h:110
size_t plot_pts() const
Definition response_parameters.h:104
size_t num_states() const
Definition response_parameters.h:97
double plot_l() const
Definition response_parameters.h:103
double omega() const
Definition response_parameters.h:135
bool plot_all_orbitals() const
Definition response_parameters.h:105
bool nuclear() const
Definition response_parameters.h:133
bool property() const
Definition response_parameters.h:126
ResponseParameters()
Definition response_parameters.h:27
size_t larger_subspace() const
Definition response_parameters.h:111
int loadbalparts() const
Definition response_parameters.h:127
std::string archive() const
Definition response_parameters.h:93
bool save() const
Definition response_parameters.h:123
std::string restart_file() const
Definition response_parameters.h:119
void set_ground_state_calculation_data(GroundStateCalculation g_params)
Definition response_parameters.h:139
static Molecule molecule
Definition testperiodicdft.cc:38