Psi4
hamiltonian.h
Go to the documentation of this file.
1 /*
2  * @BEGIN LICENSE
3  *
4  * Psi4: an open-source quantum chemistry software package
5  *
6  * Copyright (c) 2007-2017 The Psi4 Developers.
7  *
8  * The copyrights for code used from other parties are included in
9  * the corresponding files.
10  *
11  * This file is part of Psi4.
12  *
13  * Psi4 is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU Lesser General Public License as published by
15  * the Free Software Foundation, version 3.
16  *
17  * Psi4 is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License along
23  * with Psi4; if not, write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  *
26  * @END LICENSE
27  */
28 
29 #ifndef HAMILTONIAN_H
30 #define HAMILTONIAN_H
31 
32 #include <vector>
33 
34 namespace psi {
35 
36 class Matrix;
37 class Vector;
38 class JK;
39 class VBase;
40 
41 // => BASE CLASSES <= //
42 
43 class Hamiltonian {
44 
45 protected:
46 
48  int print_;
50  int debug_;
52  int bench_;
56  std::shared_ptr<JK> jk_;
58  std::shared_ptr<VBase> v_;
59 
60  void common_init();
61 
62 public:
63  // => Constructors < = //
64 
65  Hamiltonian(std::shared_ptr<JK> jk);
66  Hamiltonian(std::shared_ptr<JK> jk, std::shared_ptr<VBase> v);
68  virtual ~Hamiltonian();
69 
70  // => Accessors <= //
71 
76  std::shared_ptr<JK> jk() const { return jk_; }
81  std::shared_ptr<VBase> v() const { return v_; }
82 
87  virtual void print_header() const = 0;
88 
89  // => Knobs <= //
90 
95  void set_JK(std::shared_ptr<JK> jk) { jk_ = jk; }
100  void set_V(std::shared_ptr<VBase> v) { v_ = v; }
102  void set_print(int print) { print_ = print; }
104  void set_debug(int debug) { debug_ = debug; }
106  void set_bench(int bench) { bench_ = bench; }
109 };
110 
111 class RHamiltonian : public Hamiltonian {
112 
113 public:
114  // => Constructors < = //
115 
116  RHamiltonian(std::shared_ptr<JK> jk);
117  RHamiltonian(std::shared_ptr<JK> jk, std::shared_ptr<VBase> v);
119  virtual ~RHamiltonian();
120 
121  // => Required Methods <= //
122 
129  virtual std::shared_ptr<Vector> diagonal() = 0;
135  virtual void product(const std::vector<std::shared_ptr<Vector> >& x,
136  std::vector<std::shared_ptr<Vector> >& b) = 0;
137 
142 
143 };
144 
145 class UHamiltonian : public Hamiltonian {
146 
147 public:
148  // => Constructors < = //
149 
150  UHamiltonian(std::shared_ptr<JK> jk);
151  UHamiltonian(std::shared_ptr<JK> jk, std::shared_ptr<VBase> v);
153  virtual ~UHamiltonian();
154 
155  // => Required Methods <= //
156 
164  virtual std::pair<std::shared_ptr<Vector>,
165  std::shared_ptr<Vector> > diagonal() = 0;
171  virtual void product(const std::vector<std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> > >& x,
172  std::vector<std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> > >& b) = 0;
176  std::pair<SharedMatrix, SharedMatrix > explicit_hamiltonian();
177 };
178 
179 // => APPLIED CLASSES <= //
180 
182 
183 protected:
184 
186 
187 public:
188 
190  virtual ~MatrixRHamiltonian();
191 
192  virtual void print_header() const;
193  virtual std::shared_ptr<Vector> diagonal();
194  virtual void product(const std::vector<std::shared_ptr<Vector> >& x,
195  std::vector<std::shared_ptr<Vector> >& b);
196 
197 };
198 
200 
201 protected:
202 
203  std::pair<SharedMatrix, SharedMatrix > M_;
204 
205 public:
206 
207  MatrixUHamiltonian(std::pair<SharedMatrix, SharedMatrix > M);
208  virtual ~MatrixUHamiltonian();
209 
210  virtual void print_header() const;
211  virtual std::pair<std::shared_ptr<Vector>,
212  std::shared_ptr<Vector> > diagonal();
213  virtual void product(const std::vector<std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> > >& x,
214  std::vector<std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> > >& b);
215 
216 };
217 
219 
220 protected:
221 
222  bool singlet_;
225  std::shared_ptr<Vector> eps_aocc_;
226  std::shared_ptr<Vector> eps_avir_;
227 
228 public:
229  CISRHamiltonian(std::shared_ptr<JK> jk,
230  SharedMatrix Caocc,
231  SharedMatrix Cavir,
232  std::shared_ptr<Vector> eps_aocc,
233  std::shared_ptr<Vector> eps_avir,
234  std::shared_ptr<VBase> v = std::shared_ptr<VBase>());
235  virtual ~CISRHamiltonian();
236 
237  virtual void print_header() const;
238  virtual std::shared_ptr<Vector> diagonal();
239  virtual void product(const std::vector<std::shared_ptr<Vector> >& x,
240  std::vector<std::shared_ptr<Vector> >& b);
241 
242  virtual std::vector<SharedMatrix > unpack(const std::shared_ptr<Vector>& x);
243 
244  void set_singlet(bool singlet) { singlet_ = singlet; }
245 
246 };
247 
249 
250 protected:
251 
252  bool singlet_;
255  std::shared_ptr<Vector> eps_aocc_;
256  std::shared_ptr<Vector> eps_avir_;
257 
258 public:
259  TDHFRHamiltonian(std::shared_ptr<JK> jk,
260  SharedMatrix Caocc,
261  SharedMatrix Cavir,
262  std::shared_ptr<Vector> eps_aocc,
263  std::shared_ptr<Vector> eps_avir,
264  std::shared_ptr<VBase> v = std::shared_ptr<VBase>());
265  virtual ~TDHFRHamiltonian();
266 
267  virtual void print_header() const;
268  virtual std::shared_ptr<Vector> diagonal();
269  virtual void product(const std::vector<std::shared_ptr<Vector> >& x,
270  std::vector<std::shared_ptr<Vector> >& b);
271 
272  void set_singlet(bool singlet) { singlet_ = singlet; }
273 };
274 
276 
277 protected:
278 
281  std::shared_ptr<Vector> eps_aocc_;
282  std::shared_ptr<Vector> eps_avir_;
283 
284 public:
285  CPHFRHamiltonian(std::shared_ptr<JK> jk,
286  SharedMatrix Caocc,
287  SharedMatrix Cavir,
288  std::shared_ptr<Vector> eps_aocc,
289  std::shared_ptr<Vector> eps_avir,
290  std::shared_ptr<VBase> v = std::shared_ptr<VBase>());
291  virtual ~CPHFRHamiltonian();
292 
293  virtual void print_header() const;
294  virtual std::shared_ptr<Vector> diagonal();
295  virtual void product(const std::vector<std::shared_ptr<Vector> >& x,
296  std::vector<std::shared_ptr<Vector> >& b);
297 
298  virtual std::map<std::string, SharedVector> pack(const std::map<std::string, std::shared_ptr<Matrix> >& b);
299  virtual std::vector<SharedMatrix > unpack(const std::vector<SharedVector >& x);
300 };
301 
303 
304 protected:
305 
307 
308 public:
309  TDARHamiltonian(std::shared_ptr<JK> jk,
310  std::shared_ptr<VBase> v,
311  SharedMatrix Cocc,
312  SharedMatrix Caocc,
313  SharedMatrix Cavir,
314  std::shared_ptr<Vector> eps_aocc,
315  std::shared_ptr<Vector> eps_avir);
316  virtual ~TDARHamiltonian();
317 
318  virtual void print_header() const;
319  virtual void product(const std::vector<std::shared_ptr<Vector> >& x,
320  std::vector<std::shared_ptr<Vector> >& b);
321 };
322 
324 
325 protected:
326 
328 
329 public:
330  TDDFTRHamiltonian(std::shared_ptr<JK> jk,
331  std::shared_ptr<VBase> v,
332  SharedMatrix Cocc,
333  SharedMatrix Caocc,
334  SharedMatrix Cavir,
335  std::shared_ptr<Vector> eps_aocc,
336  std::shared_ptr<Vector> eps_avir);
337  virtual ~TDDFTRHamiltonian();
338 
339  virtual void print_header() const;
340  virtual void product(const std::vector<std::shared_ptr<Vector> >& x,
341  std::vector<std::shared_ptr<Vector> >& b);
342 };
343 
345 
346 protected:
347 
349 
350 public:
351  CPKSRHamiltonian(std::shared_ptr<JK> jk,
352  std::shared_ptr<VBase> v,
353  SharedMatrix Cocc,
354  SharedMatrix Caocc,
355  SharedMatrix Cavir,
356  std::shared_ptr<Vector> eps_aocc,
357  std::shared_ptr<Vector> eps_avir);
358  virtual ~CPKSRHamiltonian();
359 
360  virtual void print_header() const;
361  virtual void product(const std::vector<std::shared_ptr<Vector> >& x,
362  std::vector<std::shared_ptr<Vector> >& b);
363 };
364 
365 // "Hamiltonian" for UHF stability analysis.
367 
368 protected:
369 
374  std::shared_ptr<Vector> eps_occa_;
375  std::shared_ptr<Vector> eps_vira_;
376  std::shared_ptr<Vector> eps_occb_;
377  std::shared_ptr<Vector> eps_virb_;
378 
379 public:
380 
381 // Should really use a map of matrices here. But meh.
382  USTABHamiltonian(std::shared_ptr<JK> jk,
383  SharedMatrix Cocca,
384  SharedMatrix Cvira,
385  SharedMatrix Coccb,
386  SharedMatrix Cvirb,
387  std::shared_ptr<Vector> eps_occa,
388  std::shared_ptr<Vector> eps_vira,
389  std::shared_ptr<Vector> eps_occb,
390  std::shared_ptr<Vector> eps_virb,
391  std::shared_ptr<VBase> v = std::shared_ptr<VBase>());
392  virtual ~USTABHamiltonian();
393 
394  virtual void print_header() const;
395  virtual std::pair<std::shared_ptr<Vector>,
396  std::shared_ptr<Vector> > diagonal();
397  virtual void product(const std::vector<std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> > >& x,
398  std::vector<std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> > >& b);
399 
400 // Working with a pair is annoying, so we define a new function below
401  virtual std::vector<std::pair<SharedMatrix,SharedMatrix > > unpack(
402  const std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> >& x){} ;
403  virtual std::vector<std::pair<SharedMatrix,SharedMatrix > > unpack_paired(
404  const std::shared_ptr<Vector>& x);
405 
406 };
407 
408 }
409 #endif
void set_singlet(bool singlet)
Definition: hamiltonian.h:272
virtual void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b)
Definition: hamiltonian.cc:516
virtual std::shared_ptr< Vector > diagonal()=0
std::shared_ptr< VBase > v_
v object
Definition: hamiltonian.h:58
int print_
Print flag, defaults to 1.
Definition: hamiltonian.h:48
Definition: hamiltonian.h:218
std::shared_ptr< Vector > eps_avir_
Definition: hamiltonian.h:256
virtual void print_header() const
Definition: hamiltonian.cc:1286
void set_print(int print)
Print flag (defaults to 1)
Definition: hamiltonian.h:102
virtual ~TDHFRHamiltonian()
Definition: hamiltonian.cc:470
Definition: hamiltonian.h:275
virtual ~USTABHamiltonian()
Definition: hamiltonian.cc:1414
virtual ~MatrixRHamiltonian()
Definition: hamiltonian.cc:121
Definition: hamiltonian.h:302
MatrixRHamiltonian(SharedMatrix M)
Definition: hamiltonian.cc:117
std::shared_ptr< JK > jk_
jk object
Definition: hamiltonian.h:56
Definition: hamiltonian.h:248
void diag(void)
Definition: diag.cc:137
int debug_
Debug flag, defaults to 0.
Definition: hamiltonian.h:50
std::shared_ptr< Vector > eps_virb_
Definition: hamiltonian.h:377
std::shared_ptr< Vector > eps_aocc_
Definition: hamiltonian.h:225
void set_singlet(bool singlet)
Definition: hamiltonian.h:244
SharedMatrix explicit_hamiltonian()
Definition: hamiltonian.cc:80
virtual void print_header() const =0
virtual std::shared_ptr< Vector > diagonal()
Definition: hamiltonian.cc:479
virtual void product(const std::vector< std::pair< std::shared_ptr< Vector >, std::shared_ptr< Vector > > > &x, std::vector< std::pair< std::shared_ptr< Vector >, std::shared_ptr< Vector > > > &b)
Definition: hamiltonian.cc:1494
std::shared_ptr< VBase > v() const
Definition: hamiltonian.h:81
virtual ~CPHFRHamiltonian()
Definition: hamiltonian.cc:694
virtual void print_header() const
Definition: hamiltonian.cc:1417
void common_init()
Definition: hamiltonian.cc:61
CISRHamiltonian(std::shared_ptr< JK > jk, SharedMatrix Caocc, SharedMatrix Cavir, std::shared_ptr< Vector > eps_aocc, std::shared_ptr< Vector > eps_avir, std::shared_ptr< VBase > v=std::shared_ptr< VBase >())
Definition: hamiltonian.cc:209
virtual void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b)=0
virtual void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b)
Definition: hamiltonian.cc:278
virtual ~Hamiltonian()
Destructor.
Definition: hamiltonian.cc:58
Definition: hamiltonian.h:323
void set_V(std::shared_ptr< VBase > v)
Definition: hamiltonian.h:100
void set_exact_diagonal(bool diag)
User the exact diagonal, if available? (defaults to false)
Definition: hamiltonian.h:108
virtual std::pair< std::shared_ptr< Vector >, std::shared_ptr< Vector > > diagonal()
Definition: hamiltonian.cc:172
SharedMatrix Coccb_
Definition: hamiltonian.h:372
virtual ~TDARHamiltonian()
Definition: hamiltonian.cc:921
virtual ~TDDFTRHamiltonian()
Definition: hamiltonian.cc:1081
virtual std::vector< SharedMatrix > unpack(const std::vector< SharedVector > &x)
Definition: hamiltonian.cc:874
virtual std::vector< std::pair< SharedMatrix, SharedMatrix > > unpack(const std::pair< std::shared_ptr< Vector >, std::shared_ptr< Vector > > &x)
Definition: hamiltonian.h:401
virtual ~CPKSRHamiltonian()
Definition: hamiltonian.cc:1283
virtual void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b)
Definition: hamiltonian.cc:1090
TDHFRHamiltonian(std::shared_ptr< JK > jk, SharedMatrix Caocc, SharedMatrix Cavir, std::shared_ptr< Vector > eps_aocc, std::shared_ptr< Vector > eps_avir, std::shared_ptr< VBase > v=std::shared_ptr< VBase >())
Definition: hamiltonian.cc:461
SharedMatrix Caocc_
Definition: hamiltonian.h:279
virtual void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b)
Definition: hamiltonian.cc:144
virtual ~UHamiltonian()
Destructor.
Definition: hamiltonian.cc:113
Definition: hamiltonian.h:366
virtual ~RHamiltonian()
Destructor.
Definition: hamiltonian.cc:77
virtual void print_header() const
Definition: hamiltonian.cc:124
CPHFRHamiltonian(std::shared_ptr< JK > jk, SharedMatrix Caocc, SharedMatrix Cavir, std::shared_ptr< Vector > eps_aocc, std::shared_ptr< Vector > eps_avir, std::shared_ptr< VBase > v=std::shared_ptr< VBase >())
Definition: hamiltonian.cc:685
SharedMatrix Cocc_
Definition: hamiltonian.h:348
SharedMatrix Cavir_
Definition: hamiltonian.h:254
std::shared_ptr< Vector > eps_occb_
Definition: hamiltonian.h:376
SharedMatrix Caocc_
Definition: hamiltonian.h:223
virtual void print_header() const
Definition: hamiltonian.cc:473
UHamiltonian(std::shared_ptr< JK > jk)
Definition: hamiltonian.cc:105
SharedMatrix Cvira_
Definition: hamiltonian.h:371
SharedMatrix Cavir_
Definition: hamiltonian.h:224
std::pair< SharedMatrix, SharedMatrix > explicit_hamiltonian()
SharedMatrix Caocc_
Definition: hamiltonian.h:253
std::shared_ptr< Vector > eps_avir_
Definition: hamiltonian.h:226
MatrixUHamiltonian(std::pair< SharedMatrix, SharedMatrix > M)
Definition: hamiltonian.cc:159
Definition: hamiltonian.h:111
int bench_
Bench flag, defaults to 0.
Definition: hamiltonian.h:52
virtual std::pair< std::shared_ptr< Vector >, std::shared_ptr< Vector > > diagonal()=0
bool singlet_
Definition: hamiltonian.h:252
void set_bench(int bench)
Bench flag (defaults to 0)
Definition: hamiltonian.h:106
TDDFTRHamiltonian(std::shared_ptr< JK > jk, std::shared_ptr< VBase > v, SharedMatrix Cocc, SharedMatrix Caocc, SharedMatrix Cavir, std::shared_ptr< Vector > eps_aocc, std::shared_ptr< Vector > eps_avir)
Definition: hamiltonian.cc:1060
virtual ~MatrixUHamiltonian()
Definition: hamiltonian.cc:163
virtual void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b)
Definition: hamiltonian.cc:1292
SharedMatrix Cvirb_
Definition: hamiltonian.h:373
std::shared_ptr< Vector > eps_aocc_
Definition: hamiltonian.h:255
virtual std::pair< std::shared_ptr< Vector >, std::shared_ptr< Vector > > diagonal()
Definition: hamiltonian.cc:1424
void set_JK(std::shared_ptr< JK > jk)
Definition: hamiltonian.h:95
std::pair< SharedMatrix, SharedMatrix > M_
Definition: hamiltonian.h:203
virtual void print_header() const
Definition: hamiltonian.cc:697
CPKSRHamiltonian(std::shared_ptr< JK > jk, std::shared_ptr< VBase > v, SharedMatrix Cocc, SharedMatrix Caocc, SharedMatrix Cavir, std::shared_ptr< Vector > eps_aocc, std::shared_ptr< Vector > eps_avir)
Definition: hamiltonian.cc:1262
virtual std::shared_ptr< Vector > diagonal()
Definition: hamiltonian.cc:227
Definition: hamiltonian.h:344
std::shared_ptr< Matrix > SharedMatrix
Definition: adc.h:49
Definition: hamiltonian.h:181
std::shared_ptr< Vector > eps_vira_
Definition: hamiltonian.h:375
std::shared_ptr< Vector > eps_avir_
Definition: hamiltonian.h:282
virtual void print_header() const
Definition: hamiltonian.cc:1084
USTABHamiltonian(std::shared_ptr< JK > jk, SharedMatrix Cocca, SharedMatrix Cvira, SharedMatrix Coccb, SharedMatrix Cvirb, std::shared_ptr< Vector > eps_occa, std::shared_ptr< Vector > eps_vira, std::shared_ptr< Vector > eps_occb, std::shared_ptr< Vector > eps_virb, std::shared_ptr< VBase > v=std::shared_ptr< VBase >())
Definition: hamiltonian.cc:1400
virtual void print_header() const
Definition: hamiltonian.cc:166
virtual std::vector< std::pair< SharedMatrix, SharedMatrix > > unpack_paired(const std::shared_ptr< Vector > &x)
Definition: hamiltonian.cc:1830
virtual void print_header() const
Definition: hamiltonian.cc:924
virtual std::shared_ptr< Vector > diagonal()
Definition: hamiltonian.cc:703
Definition: hamiltonian.h:145
std::shared_ptr< Vector > eps_occa_
Definition: hamiltonian.h:374
bool singlet_
Definition: hamiltonian.h:222
RHamiltonian(std::shared_ptr< JK > jk)
Definition: hamiltonian.cc:69
virtual ~CISRHamiltonian()
Definition: hamiltonian.cc:218
std::shared_ptr< JK > jk() const
Definition: hamiltonian.h:76
virtual void print_header() const
Definition: hamiltonian.cc:221
SharedMatrix Cocca_
Definition: hamiltonian.h:370
virtual std::map< std::string, SharedVector > pack(const std::map< std::string, std::shared_ptr< Matrix > > &b)
Definition: hamiltonian.cc:738
std::shared_ptr< Vector > eps_aocc_
Definition: hamiltonian.h:281
virtual void product(const std::vector< std::pair< std::shared_ptr< Vector >, std::shared_ptr< Vector > > > &x, std::vector< std::pair< std::shared_ptr< Vector >, std::shared_ptr< Vector > > > &b)
Definition: hamiltonian.cc:190
virtual void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b)
Definition: hamiltonian.cc:930
virtual void product(const std::vector< std::pair< std::shared_ptr< Vector >, std::shared_ptr< Vector > > > &x, std::vector< std::pair< std::shared_ptr< Vector >, std::shared_ptr< Vector > > > &b)=0
Hamiltonian(std::shared_ptr< JK > jk)
Definition: hamiltonian.cc:48
Definition: hamiltonian.h:199
SharedMatrix Cocc_
Definition: hamiltonian.h:306
virtual void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b)
Definition: hamiltonian.cc:770
Definition: hamiltonian.h:43
TDARHamiltonian(std::shared_ptr< JK > jk, std::shared_ptr< VBase > v, SharedMatrix Cocc, SharedMatrix Caocc, SharedMatrix Cavir, std::shared_ptr< Vector > eps_aocc, std::shared_ptr< Vector > eps_avir)
Definition: hamiltonian.cc:900
SharedMatrix M_
Definition: hamiltonian.h:185
SharedMatrix Cocc_
Definition: hamiltonian.h:327
void set_debug(int debug)
Debug flag (defaults to 0)
Definition: hamiltonian.h:104
SharedMatrix Cavir_
Definition: hamiltonian.h:280
bool exact_diagonal_
Use exact diagonal, if available?
Definition: hamiltonian.h:54
virtual std::shared_ptr< Vector > diagonal()
Definition: hamiltonian.cc:130
virtual std::vector< SharedMatrix > unpack(const std::shared_ptr< Vector > &x)
Definition: hamiltonian.cc:438