MADNESS 0.10.1
zcis.h
Go to the documentation of this file.
1/*
2 * Complexcis.h
3 *
4 * Created on: 21 Nov 2018
5 * Author: fbischoff
6 */
7
8#ifndef SRC_APPS_CHEM_ZCIS_H_
9#define SRC_APPS_CHEM_ZCIS_H_
10
12#include<madness/mra/mra.h>
13#include<tuple>
15
16
17namespace madness {
18
19
20
22public:
23
24 /// ctor reading out the input file
26 read_input_and_commandline_options(world,parser,"response");
27 }
28
30
31 /// the parameters with the enum key, the constructor taking the input file key and a default value
32 initialize<std::string>("guess_excitation_operators","dipole+");
33 initialize<std::vector<std::string> >("exops",{"x 1.0","y 1.0","z 1.0","x 2.0 , y 2.0 , z 2.0"});
34 initialize<int>("freeze",0);
35 initialize<int>("guess_excitations",4);
36 initialize<int>("guess_maxiter",4);
37 initialize<double>("thresh",FunctionDefaults<3>::get_thresh());
38 initialize<double>("omega",0.0);
39 initialize<int>("maxiter",10);
40 initialize<bool>("swap_ab",false);
41 initialize<double>("dconv",1.e-3);
42 initialize<int>("printlevel",1);
43
44 }
45
46 std::string guess_excitation_operators() const {return get<std::string>("guess_excitation_operators");};
47 std::vector<std::string> exops() const {return get<std::vector<std::string> >("exops");};
48 int freeze() const {return get<int>("freeze");};
49 int guess_excitations() const {return get<int>("guess_excitations");};
50 double thresh() const {return get<double>("thresh");};
51 double omega() const {return get<double>("omega");};
52 int maxiter() const {return get<int>("maxiter");};
53 int guess_maxiter() const {return get<int>("guess_maxiter");};
54 bool swap_ab() const {return get<bool>("swap_ab");};
55 double dconv() const {return get<double>("dconv");};
56 int printlevel() const {return get<int>("printlevel");};
57
58
59};
60
61
62class Zcis : public QCPropertyInterface {
63public:
64
65 struct root {
66 std::vector<complex_function_3d> afunction;
67 std::vector<complex_function_3d> bfunction;
68 std::vector<complex_function_3d> apot;
69 std::vector<complex_function_3d> bpot;
70 double omega=0.0;
71 double delta=1.e3; // last wave function error
72 double energy_change=1.e3; // last energy_change
73
74 /// inner product for the KAIN solver
75 friend
76 double_complex inner(const root& f, const root& g){
77 MADNESS_ASSERT(f.afunction.size()==g.afunction.size());
78 MADNESS_ASSERT(f.bfunction.size()==g.bfunction.size());
79 double_complex result=inner(f.afunction,g.afunction) + inner(f.bfunction,g.bfunction);
80 return result;
81 }
82
83
84 };
85
86 static std::vector<root> transform(World& world,
87 const std::vector<root>& v,
89 bool fence=true) {
90
91 int n = v.size(); // n is the old dimension
92 int m = c.dim(1); // m is the new dimension
93
94 int nocca=v.front().afunction.size();
95 int noccb=v.front().bfunction.size();
96
97 std::vector<root> result(m);
98
99 for (auto&& r : result) {
100 r.afunction= zero_functions_compressed<double_complex,3>(world, nocca, false);
101 r.bfunction= zero_functions_compressed<double_complex,3>(world, noccb, false);
102 r.apot= zero_functions_compressed<double_complex,3>(world, nocca, false);
103 r.bpot= zero_functions_compressed<double_complex,3>(world, noccb, false);
104 }
105 for (auto&& vv : v) {
106 compress(world, vv.afunction,false);
107 compress(world, vv.bfunction,false);
108 compress(world, vv.apot,false);
109 compress(world, vv.bpot,false);
110 }
111 world.gop.fence();
112
113 for (int i=0; i<m; ++i) {
114 for (int j=0; j<n; ++j) {
115 gaxpy(world,double_complex(1.0),result[i].afunction,c(j,i),v[j].afunction,false);
116 gaxpy(world,double_complex(1.0),result[i].bfunction,c(j,i),v[j].bfunction,false);
117 if (v[j].apot.size()>0) gaxpy(world,double_complex(1.0),result[i].apot,c(j,i),v[j].apot,false);
118 if (v[j].bpot.size()>0) gaxpy(world,double_complex(1.0),result[i].bpot,c(j,i),v[j].bpot,false);
119 }
120 }
121
122 if (fence) world.gop.fence();
123 return result;
124 }
125
126
127
128 Zcis(World& w, const commandlineparser& parser, std::shared_ptr<Znemo> n) : world(w), cis_param(world, parser), nemo(n),
129 Qa(nemo->amo,nemo->amo), Qb(nemo->bmo,nemo->bmo) {
130 cis_param.print("response","end");
131 print("Qa projector",Qa.get_ket_vector().size());
132 print("Qb projector",Qb.get_ket_vector().size());
133
134 }
135
136 virtual ~Zcis() {};
137
138 double value();
139
140 static void help() {
141 print_header2("help page for ZCIS");
142 print("The zcis code computes excited states for a znemo calculation in the CIS approximation");
143 print("\nYou can print all available calculation parameters by running\n");
144 print("zcis --print_parameters\n");
145 print("You can perform a simple calculation by running\n");
146 print("zcis --geometry=h2o.xyz\n");
147 print("provided you have an xyz file in your directory.");
148
149 }
150
151 static void print_parameters() {
153 print("The zcis program requires converged znemo orbitals");
154 print("\ndefault parameters for the response part of the zcis program are");
155 param.print("response","end");
156 print("\n\nthe molecular geometry must be specified in a separate block:");
158 }
159
160
161 std::string name() const {return "zcis";};
162
163 virtual bool selftest() {
164 return true;
165 };
166 void iterate(std::vector<root>& roots) const;
167
168 void compute_potentials(std::vector<root>& roots, const real_function_3d& totdens) const;
169
170 std::vector<complex_function_3d> compute_residuals(root& root) const;
171
172 std::vector<root> read_guess() const;
173
174 void save_guess(const std::vector<root>& roots) const;
175
176 std::vector<root> make_guess() const;
177
178 void canonicalize(const std::vector<complex_function_3d>& mo, const real_function_3d& density,
179 std::vector<complex_function_3d>& virtuals, Tensor<double>& veps) const;
180
182
183 Tensor<double_complex> compute_fock_pt(const std::vector<root>& roots) const;
184
185
186 /// return the active orbitals only
188 if (eps.size()<=cis_param.freeze()) return Tensor<double>();
189 return eps(Slice(cis_param.freeze(),-1,1));
190 }
191
192 /// return the active orbitals only
193 std::vector<complex_function_3d> active_mo(const std::vector<complex_function_3d>& mo) const {
194 if (mo.size()<=size_t(cis_param.freeze())) return std::vector<complex_function_3d> ();
195 std::vector<complex_function_3d> result;
196 result.insert(result.end(),mo.begin()+cis_param.freeze(),mo.end());
197 return result;
198 }
199
200 /// little helper function
201 template<typename T>
202 static Tensor<T> concatenate(const Tensor<T>& t1, const Tensor<T>& t2) {
203 MADNESS_ASSERT(t1.ndim()==1 or t1.size()==0);
204 MADNESS_ASSERT(t2.ndim()==1 or t2.size()==0);
205 Tensor<T> result(t1.size()+t2.size());
206 if (t1.size()>0) result(Slice(0,t1.size()-1,1))=t1; // slices count inclusive
207 if (t2.size()>0) result(Slice(t1.size(),-1,1))=t2;
208 return result;
209 }
210
211 template<typename T>
212 static std::tuple<Tensor<T>, Tensor<T> > split(const Tensor<T>& rhs, int dim1) {
213
214 MADNESS_ASSERT(dim1>=0 and dim1<=rhs.size());
215 if (dim1==0) return std::make_tuple(Tensor<T>(),rhs);
216 if (dim1==rhs.size()) return std::make_tuple(rhs,Tensor<T>());
217
218 Tensor<T> t1=rhs(Slice(0,dim1-1,1));
219 Tensor<T> t2=rhs(Slice(dim1,-1,1));
220 return std::make_tuple(t1,t2);
221 }
222
223 void orthonormalize(std::vector<root>& roots, const Tensor<double_complex>& fock_pt_a) const;
224
225 void orthonormalize(std::vector<root>& roots) const;
226
227 void normalize(std::vector<root>& roots) const;
228
229 void compare_to_file(const std::vector<complex_function_3d>& rhs, const std::string name) const {
230 if (nemo->cparam.spin_restricted()) {
231 save_function(rhs,name);
232
233 } else {
234 std::vector<complex_function_3d> rhs_file=zero_functions_compressed<double_complex,3>(world,rhs.size());
235 std::vector<complex_function_3d> rhs_file1;
236 load_function(world,rhs_file1,name);
237 for (size_t i=0; i<rhs_file1.size(); ++i) rhs_file[i]=rhs_file1[i];
238 std::vector<double> dnorm=norm2s(world,rhs-rhs_file);
239 print(name,"diffnorm",dnorm);
240 }
241 }
242
243
244 static std::tuple<std::vector<complex_function_3d>, std::vector<complex_function_3d> >
245 split(const std::vector<complex_function_3d>& rhs, int dim1) {
246
247 MADNESS_ASSERT(dim1>=0 and size_t(dim1)<=rhs.size());
248 if (dim1==0) return std::make_tuple(std::vector<complex_function_3d>(),rhs);
249 if (size_t(dim1)==rhs.size()) return std::make_tuple(rhs,std::vector<complex_function_3d>());
250
251 std::vector<complex_function_3d> t1,t2;
252 copy(rhs.begin(),rhs.begin()+dim1,back_inserter(t1));
253 copy(rhs.begin()+dim1,rhs.end(),back_inserter(t2));
254
255 return std::make_tuple(t1,t2);
256 }
257
258 /// the world
260
261 /// the parameters
263
264 /// the reference
265 std::shared_ptr<Znemo> nemo;
266
267 /// orthogonality projector
269
270 /// the x vectors
271 std::vector<root> roots;
272
273};
274
275} /* namespace madness */
276
277#endif /* SRC_APPS_CHEM_ZCIS_H_ */
double w(double t, double eps)
Definition DKops.h:22
std::complex< double > double_complex
Definition cfft.h:14
long ndim() const
Returns the number of dimensions in the tensor.
Definition basetensor.h:144
long size() const
Returns the number of elements in the tensor.
Definition basetensor.h:138
int guess_maxiter() const
Definition zcis.h:53
int guess_excitations() const
Definition zcis.h:49
std::vector< std::string > exops() const
Definition zcis.h:47
std::string guess_excitation_operators() const
Definition zcis.h:46
double dconv() const
Definition zcis.h:55
bool swap_ab() const
Definition zcis.h:54
Complex_CIS_Parameters(World &world, const commandlineparser &parser)
ctor reading out the input file
Definition zcis.h:25
double omega() const
Definition zcis.h:51
int freeze() const
Definition zcis.h:48
int maxiter() const
Definition zcis.h:52
Complex_CIS_Parameters()
Definition zcis.h:29
double thresh() const
Definition zcis.h:50
int printlevel() const
Definition zcis.h:56
FunctionDefaults holds default paramaters as static class members.
Definition funcdefaults.h:204
static void print_parameters()
Definition molecule.cc:110
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
void print(const std::string header="", const std::string footer="") const
print all parameters
Definition QCCalculationParametersBase.cc:22
class implementing properties of QC models
Definition QCPropertyInterface.h:11
virtual real_function_3d density() const
Definition QCPropertyInterface.h:25
orthogonality projector
Definition projector.h:186
vecfuncT get_ket_vector() const
Definition projector.h:243
A slice defines a sub-range or patch of a dimension.
Definition slice.h:103
A tensor is a multidimension array.
Definition tensor.h:317
void fence(bool debug=false)
Synchronizes all processes in communicator AND globally ensures no pending AM or tasks.
Definition worldgop.cc:161
A parallel world class.
Definition world.h:132
ProcessID size() const
Returns the number of processes in this World (same as MPI_Comm_size()).
Definition world.h:328
WorldGopInterface & gop
Global operations.
Definition world.h:205
Definition zcis.h:62
std::vector< root > make_guess() const
Definition madness/chem/zcis.cc:345
void compute_potentials(std::vector< root > &roots, const real_function_3d &totdens) const
Definition madness/chem/zcis.cc:152
virtual ~Zcis()
Definition zcis.h:136
virtual bool selftest()
Definition zcis.h:163
Tensor< double_complex > make_CIS_matrix(const Tensor< double > &veps, const Tensor< double > &oeps) const
Definition madness/chem/zcis.cc:511
static void print_parameters()
Definition zcis.h:151
QProjector< double_complex, 3 > Qa
orthogonality projector
Definition zcis.h:268
Tensor< double > noct(const Tensor< double > &eps) const
return the active orbitals only
Definition zcis.h:187
void canonicalize(const std::vector< complex_function_3d > &mo, const real_function_3d &density, std::vector< complex_function_3d > &virtuals, Tensor< double > &veps) const
Definition madness/chem/zcis.cc:491
static Tensor< T > concatenate(const Tensor< T > &t1, const Tensor< T > &t2)
little helper function
Definition zcis.h:202
std::vector< complex_function_3d > active_mo(const std::vector< complex_function_3d > &mo) const
return the active orbitals only
Definition zcis.h:193
double value()
Definition madness/chem/zcis.cc:14
static std::tuple< std::vector< complex_function_3d >, std::vector< complex_function_3d > > split(const std::vector< complex_function_3d > &rhs, int dim1)
Definition zcis.h:245
static std::tuple< Tensor< T >, Tensor< T > > split(const Tensor< T > &rhs, int dim1)
Definition zcis.h:212
Complex_CIS_Parameters cis_param
the parameters
Definition zcis.h:262
static void help()
Definition zcis.h:140
void normalize(std::vector< root > &roots) const
Definition madness/chem/zcis.cc:599
std::string name() const
Definition zcis.h:161
Tensor< double_complex > compute_fock_pt(const std::vector< root > &roots) const
Definition madness/chem/zcis.cc:219
void iterate(std::vector< root > &roots) const
iterate the roots
Definition madness/chem/zcis.cc:32
void orthonormalize(std::vector< root > &roots, const Tensor< double_complex > &fock_pt_a) const
Definition madness/chem/zcis.cc:541
std::vector< root > roots
the x vectors
Definition zcis.h:271
World & world
the world
Definition zcis.h:259
Zcis(World &w, const commandlineparser &parser, std::shared_ptr< Znemo > n)
Definition zcis.h:128
std::vector< complex_function_3d > compute_residuals(root &root) const
Definition madness/chem/zcis.cc:244
static std::vector< root > transform(World &world, const std::vector< root > &v, const Tensor< double_complex > &c, bool fence=true)
Definition zcis.h:86
std::vector< root > read_guess() const
Definition madness/chem/zcis.cc:303
void compare_to_file(const std::vector< complex_function_3d > &rhs, const std::string name) const
Definition zcis.h:229
QProjector< double_complex, 3 > Qb
Definition zcis.h:268
std::shared_ptr< Znemo > nemo
the reference
Definition zcis.h:265
void save_guess(const std::vector< root > &roots) const
Definition madness/chem/zcis.cc:326
static const double v
Definition hatom_sf_dirac.cc:20
#define MADNESS_ASSERT(condition)
Assert a condition that should be free of side-effects since in release builds this might be a no-op.
Definition madness_exception.h:134
Main include file for MADNESS and defines Function interface.
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
void save_function(const std::vector< Function< T, NDIM > > &f, const std::string name)
save a vector of functions
Definition vmra.h:2117
void print_header2(const std::string &s)
medium section heading
Definition print.cc:54
std::vector< double > norm2s(World &world, const std::vector< Function< T, NDIM > > &v)
Computes the 2-norms of a vector of functions.
Definition vmra.h:827
void compress(World &world, const std::vector< Function< T, NDIM > > &v, bool fence=true)
Compress a vector of functions.
Definition vmra.h:133
void print(const T &t, const Ts &... ts)
Print items to std::cout (items separated by spaces) and terminate with a new line.
Definition print.h:225
NDIM & f
Definition mra.h:2416
NDIM const Function< R, NDIM > & g
Definition mra.h:2416
void load_function(World &world, std::vector< Function< T, NDIM > > &f, const std::string name)
load a vector of functions
Definition vmra.h:2105
Function< T, NDIM > copy(const Function< T, NDIM > &f, const std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > &pmap, bool fence=true)
Create a new copy of the function with different distribution and optional fence.
Definition mra.h:2002
void gaxpy(const double a, ScalarResult< T > &left, const double b, const T &right, const bool fence=true)
the result type of a macrotask must implement gaxpy
Definition macrotaskq.h:140
static const double c
Definition relops.cc:10
static const double m
Definition relops.cc:9
Definition zcis.h:65
std::vector< complex_function_3d > afunction
Definition zcis.h:66
double omega
Definition zcis.h:70
friend double_complex inner(const root &f, const root &g)
inner product for the KAIN solver
Definition zcis.h:76
double delta
Definition zcis.h:71
std::vector< complex_function_3d > bpot
Definition zcis.h:69
std::vector< complex_function_3d > apot
Definition zcis.h:68
std::vector< complex_function_3d > bfunction
Definition zcis.h:67
double energy_change
Definition zcis.h:72
very simple command line parser
Definition commandlineparser.h:15
InputParameters param
Definition tdse.cc:203