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 program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  *
25  * @END LICENSE
26  */
27 
28 #ifndef HAMILTONIAN_H
29 #define HAMILTONIAN_H
30 
31 namespace psi {
32 
33 class Matrix;
34 class Vector;
35 class JK;
36 class VBase;
37 
38 // => BASE CLASSES <= //
39 
40 class Hamiltonian {
41 
42 protected:
43 
45  int print_;
47  int debug_;
49  int bench_;
53  std::shared_ptr<JK> jk_;
55  std::shared_ptr<VBase> v_;
56 
57  void common_init();
58 
59 public:
60  // => Constructors < = //
61 
62  Hamiltonian(std::shared_ptr<JK> jk);
63  Hamiltonian(std::shared_ptr<JK> jk, std::shared_ptr<VBase> v);
65  virtual ~Hamiltonian();
66 
67  // => Accessors <= //
68 
73  std::shared_ptr<JK> jk() const { return jk_; }
78  std::shared_ptr<VBase> v() const { return v_; }
79 
84  virtual void print_header() const = 0;
85 
86  // => Knobs <= //
87 
92  void set_JK(std::shared_ptr<JK> jk) { jk_ = jk; }
97  void set_V(std::shared_ptr<VBase> v) { v_ = v; }
99  void set_print(int print) { print_ = print; }
101  void set_debug(int debug) { debug_ = debug; }
103  void set_bench(int bench) { bench_ = bench; }
106 };
107 
108 class RHamiltonian : public Hamiltonian {
109 
110 public:
111  // => Constructors < = //
112 
113  RHamiltonian(std::shared_ptr<JK> jk);
114  RHamiltonian(std::shared_ptr<JK> jk, std::shared_ptr<VBase> v);
116  virtual ~RHamiltonian();
117 
118  // => Required Methods <= //
119 
126  virtual std::shared_ptr<Vector> diagonal() = 0;
132  virtual void product(const std::vector<std::shared_ptr<Vector> >& x,
133  std::vector<std::shared_ptr<Vector> >& b) = 0;
134 
139 
140 };
141 
142 class UHamiltonian : public Hamiltonian {
143 
144 public:
145  // => Constructors < = //
146 
147  UHamiltonian(std::shared_ptr<JK> jk);
148  UHamiltonian(std::shared_ptr<JK> jk, std::shared_ptr<VBase> v);
150  virtual ~UHamiltonian();
151 
152  // => Required Methods <= //
153 
161  virtual std::pair<std::shared_ptr<Vector>,
162  std::shared_ptr<Vector> > diagonal() = 0;
168  virtual void product(const std::vector<std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> > >& x,
169  std::vector<std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> > >& b) = 0;
173  std::pair<SharedMatrix, SharedMatrix > explicit_hamiltonian();
174 };
175 
176 // => APPLIED CLASSES <= //
177 
179 
180 protected:
181 
183 
184 public:
185 
187  virtual ~MatrixRHamiltonian();
188 
189  virtual void print_header() const;
190  virtual std::shared_ptr<Vector> diagonal();
191  virtual void product(const std::vector<std::shared_ptr<Vector> >& x,
192  std::vector<std::shared_ptr<Vector> >& b);
193 
194 };
195 
197 
198 protected:
199 
200  std::pair<SharedMatrix, SharedMatrix > M_;
201 
202 public:
203 
204  MatrixUHamiltonian(std::pair<SharedMatrix, SharedMatrix > M);
205  virtual ~MatrixUHamiltonian();
206 
207  virtual void print_header() const;
208  virtual std::pair<std::shared_ptr<Vector>,
209  std::shared_ptr<Vector> > diagonal();
210  virtual void product(const std::vector<std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> > >& x,
211  std::vector<std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> > >& b);
212 
213 };
214 
216 
217 protected:
218 
219  bool singlet_;
222  std::shared_ptr<Vector> eps_aocc_;
223  std::shared_ptr<Vector> eps_avir_;
224 
225 public:
226  CISRHamiltonian(std::shared_ptr<JK> jk,
227  SharedMatrix Caocc,
228  SharedMatrix Cavir,
229  std::shared_ptr<Vector> eps_aocc,
230  std::shared_ptr<Vector> eps_avir,
231  std::shared_ptr<VBase> v = std::shared_ptr<VBase>());
232  virtual ~CISRHamiltonian();
233 
234  virtual void print_header() const;
235  virtual std::shared_ptr<Vector> diagonal();
236  virtual void product(const std::vector<std::shared_ptr<Vector> >& x,
237  std::vector<std::shared_ptr<Vector> >& b);
238 
239  virtual std::vector<SharedMatrix > unpack(const std::shared_ptr<Vector>& x);
240 
241  void set_singlet(bool singlet) { singlet_ = singlet; }
242 
243 };
244 
246 
247 protected:
248 
249  bool singlet_;
252  std::shared_ptr<Vector> eps_aocc_;
253  std::shared_ptr<Vector> eps_avir_;
254 
255 public:
256  TDHFRHamiltonian(std::shared_ptr<JK> jk,
257  SharedMatrix Caocc,
258  SharedMatrix Cavir,
259  std::shared_ptr<Vector> eps_aocc,
260  std::shared_ptr<Vector> eps_avir,
261  std::shared_ptr<VBase> v = std::shared_ptr<VBase>());
262  virtual ~TDHFRHamiltonian();
263 
264  virtual void print_header() const;
265  virtual std::shared_ptr<Vector> diagonal();
266  virtual void product(const std::vector<std::shared_ptr<Vector> >& x,
267  std::vector<std::shared_ptr<Vector> >& b);
268 
269  void set_singlet(bool singlet) { singlet_ = singlet; }
270 };
271 
273 
274 protected:
275 
278  std::shared_ptr<Vector> eps_aocc_;
279  std::shared_ptr<Vector> eps_avir_;
280 
281 public:
282  CPHFRHamiltonian(std::shared_ptr<JK> jk,
283  SharedMatrix Caocc,
284  SharedMatrix Cavir,
285  std::shared_ptr<Vector> eps_aocc,
286  std::shared_ptr<Vector> eps_avir,
287  std::shared_ptr<VBase> v = std::shared_ptr<VBase>());
288  virtual ~CPHFRHamiltonian();
289 
290  virtual void print_header() const;
291  virtual std::shared_ptr<Vector> diagonal();
292  virtual void product(const std::vector<std::shared_ptr<Vector> >& x,
293  std::vector<std::shared_ptr<Vector> >& b);
294 
295  virtual std::map<std::string, SharedVector> pack(const std::map<std::string, std::shared_ptr<Matrix> >& b);
296  virtual std::vector<SharedMatrix > unpack(const std::vector<SharedVector >& x);
297 };
298 
300 
301 protected:
302 
304 
305 public:
306  TDARHamiltonian(std::shared_ptr<JK> jk,
307  std::shared_ptr<VBase> v,
308  SharedMatrix Cocc,
309  SharedMatrix Caocc,
310  SharedMatrix Cavir,
311  std::shared_ptr<Vector> eps_aocc,
312  std::shared_ptr<Vector> eps_avir);
313  virtual ~TDARHamiltonian();
314 
315  virtual void print_header() const;
316  virtual void product(const std::vector<std::shared_ptr<Vector> >& x,
317  std::vector<std::shared_ptr<Vector> >& b);
318 };
319 
321 
322 protected:
323 
325 
326 public:
327  TDDFTRHamiltonian(std::shared_ptr<JK> jk,
328  std::shared_ptr<VBase> v,
329  SharedMatrix Cocc,
330  SharedMatrix Caocc,
331  SharedMatrix Cavir,
332  std::shared_ptr<Vector> eps_aocc,
333  std::shared_ptr<Vector> eps_avir);
334  virtual ~TDDFTRHamiltonian();
335 
336  virtual void print_header() const;
337  virtual void product(const std::vector<std::shared_ptr<Vector> >& x,
338  std::vector<std::shared_ptr<Vector> >& b);
339 };
340 
342 
343 protected:
344 
346 
347 public:
348  CPKSRHamiltonian(std::shared_ptr<JK> jk,
349  std::shared_ptr<VBase> v,
350  SharedMatrix Cocc,
351  SharedMatrix Caocc,
352  SharedMatrix Cavir,
353  std::shared_ptr<Vector> eps_aocc,
354  std::shared_ptr<Vector> eps_avir);
355  virtual ~CPKSRHamiltonian();
356 
357  virtual void print_header() const;
358  virtual void product(const std::vector<std::shared_ptr<Vector> >& x,
359  std::vector<std::shared_ptr<Vector> >& b);
360 };
361 
362 // "Hamiltonian" for UHF stability analysis.
364 
365 protected:
366 
371  std::shared_ptr<Vector> eps_occa_;
372  std::shared_ptr<Vector> eps_vira_;
373  std::shared_ptr<Vector> eps_occb_;
374  std::shared_ptr<Vector> eps_virb_;
375 
376 public:
377 
378 // Should really use a map of matrices here. But meh.
379  USTABHamiltonian(std::shared_ptr<JK> jk,
380  SharedMatrix Cocca,
381  SharedMatrix Cvira,
382  SharedMatrix Coccb,
383  SharedMatrix Cvirb,
384  std::shared_ptr<Vector> eps_occa,
385  std::shared_ptr<Vector> eps_vira,
386  std::shared_ptr<Vector> eps_occb,
387  std::shared_ptr<Vector> eps_virb,
388  std::shared_ptr<VBase> v = std::shared_ptr<VBase>());
389  virtual ~USTABHamiltonian();
390 
391  virtual void print_header() const;
392  virtual std::pair<std::shared_ptr<Vector>,
393  std::shared_ptr<Vector> > diagonal();
394  virtual void product(const std::vector<std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> > >& x,
395  std::vector<std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> > >& b);
396 
397 // Working with a pair is annoying, so we define a new function below
398  virtual std::vector<std::pair<SharedMatrix,SharedMatrix > > unpack(
399  const std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> >& x){} ;
400  virtual std::vector<std::pair<SharedMatrix,SharedMatrix > > unpack_paired(
401  const std::shared_ptr<Vector>& x);
402 
403 };
404 
405 }
406 #endif
void set_singlet(bool singlet)
Definition: hamiltonian.h:269
virtual void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b)
Definition: hamiltonian.cc:514
virtual std::shared_ptr< Vector > diagonal()=0
std::shared_ptr< VBase > v_
v object
Definition: hamiltonian.h:55
int print_
Print flag, defaults to 1.
Definition: hamiltonian.h:45
Definition: hamiltonian.h:215
std::shared_ptr< Vector > eps_avir_
Definition: hamiltonian.h:253
virtual void print_header() const
Definition: hamiltonian.cc:1284
void set_print(int print)
Print flag (defaults to 1)
Definition: hamiltonian.h:99
virtual ~TDHFRHamiltonian()
Definition: hamiltonian.cc:468
Definition: hamiltonian.h:272
virtual ~USTABHamiltonian()
Definition: hamiltonian.cc:1412
virtual ~MatrixRHamiltonian()
Definition: hamiltonian.cc:119
Definition: hamiltonian.h:299
MatrixRHamiltonian(SharedMatrix M)
Definition: hamiltonian.cc:115
std::shared_ptr< JK > jk_
jk object
Definition: hamiltonian.h:53
Definition: hamiltonian.h:245
void diag(void)
Definition: diag.cc:133
int debug_
Debug flag, defaults to 0.
Definition: hamiltonian.h:47
std::shared_ptr< Vector > eps_virb_
Definition: hamiltonian.h:374
std::shared_ptr< Vector > eps_aocc_
Definition: hamiltonian.h:222
void set_singlet(bool singlet)
Definition: hamiltonian.h:241
SharedMatrix explicit_hamiltonian()
Definition: hamiltonian.cc:78
virtual void print_header() const =0
virtual std::shared_ptr< Vector > diagonal()
Definition: hamiltonian.cc:477
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:1492
std::shared_ptr< VBase > v() const
Definition: hamiltonian.h:78
virtual ~CPHFRHamiltonian()
Definition: hamiltonian.cc:692
virtual void print_header() const
Definition: hamiltonian.cc:1415
void common_init()
Definition: hamiltonian.cc:59
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:207
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:276
virtual ~Hamiltonian()
Destructor.
Definition: hamiltonian.cc:56
Definition: hamiltonian.h:320
void set_V(std::shared_ptr< VBase > v)
Definition: hamiltonian.h:97
void set_exact_diagonal(bool diag)
User the exact diagonal, if available? (defaults to false)
Definition: hamiltonian.h:105
virtual std::pair< std::shared_ptr< Vector >, std::shared_ptr< Vector > > diagonal()
Definition: hamiltonian.cc:170
SharedMatrix Coccb_
Definition: hamiltonian.h:369
virtual ~TDARHamiltonian()
Definition: hamiltonian.cc:919
virtual ~TDDFTRHamiltonian()
Definition: hamiltonian.cc:1079
virtual std::vector< SharedMatrix > unpack(const std::vector< SharedVector > &x)
Definition: hamiltonian.cc:872
virtual std::vector< std::pair< SharedMatrix, SharedMatrix > > unpack(const std::pair< std::shared_ptr< Vector >, std::shared_ptr< Vector > > &x)
Definition: hamiltonian.h:398
virtual ~CPKSRHamiltonian()
Definition: hamiltonian.cc:1281
virtual void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b)
Definition: hamiltonian.cc:1088
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:459
SharedMatrix Caocc_
Definition: hamiltonian.h:276
virtual void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b)
Definition: hamiltonian.cc:142
virtual ~UHamiltonian()
Destructor.
Definition: hamiltonian.cc:111
Definition: hamiltonian.h:363
virtual ~RHamiltonian()
Destructor.
Definition: hamiltonian.cc:75
virtual void print_header() const
Definition: hamiltonian.cc:122
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:683
SharedMatrix Cocc_
Definition: hamiltonian.h:345
SharedMatrix Cavir_
Definition: hamiltonian.h:251
std::shared_ptr< Vector > eps_occb_
Definition: hamiltonian.h:373
SharedMatrix Caocc_
Definition: hamiltonian.h:220
virtual void print_header() const
Definition: hamiltonian.cc:471
UHamiltonian(std::shared_ptr< JK > jk)
Definition: hamiltonian.cc:103
SharedMatrix Cvira_
Definition: hamiltonian.h:368
SharedMatrix Cavir_
Definition: hamiltonian.h:221
std::pair< SharedMatrix, SharedMatrix > explicit_hamiltonian()
SharedMatrix Caocc_
Definition: hamiltonian.h:250
std::shared_ptr< Vector > eps_avir_
Definition: hamiltonian.h:223
MatrixUHamiltonian(std::pair< SharedMatrix, SharedMatrix > M)
Definition: hamiltonian.cc:157
Definition: hamiltonian.h:108
int bench_
Bench flag, defaults to 0.
Definition: hamiltonian.h:49
virtual std::pair< std::shared_ptr< Vector >, std::shared_ptr< Vector > > diagonal()=0
bool singlet_
Definition: hamiltonian.h:249
void set_bench(int bench)
Bench flag (defaults to 0)
Definition: hamiltonian.h:103
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:1058
virtual ~MatrixUHamiltonian()
Definition: hamiltonian.cc:161
virtual void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b)
Definition: hamiltonian.cc:1290
SharedMatrix Cvirb_
Definition: hamiltonian.h:370
std::shared_ptr< Vector > eps_aocc_
Definition: hamiltonian.h:252
virtual std::pair< std::shared_ptr< Vector >, std::shared_ptr< Vector > > diagonal()
Definition: hamiltonian.cc:1422
void set_JK(std::shared_ptr< JK > jk)
Definition: hamiltonian.h:92
std::pair< SharedMatrix, SharedMatrix > M_
Definition: hamiltonian.h:200
virtual void print_header() const
Definition: hamiltonian.cc:695
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:1260
virtual std::shared_ptr< Vector > diagonal()
Definition: hamiltonian.cc:225
Definition: hamiltonian.h:341
std::shared_ptr< Matrix > SharedMatrix
Definition: adc.h:50
Definition: hamiltonian.h:178
std::shared_ptr< Vector > eps_vira_
Definition: hamiltonian.h:372
std::shared_ptr< Vector > eps_avir_
Definition: hamiltonian.h:279
virtual void print_header() const
Definition: hamiltonian.cc:1082
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:1398
virtual void print_header() const
Definition: hamiltonian.cc:164
virtual std::vector< std::pair< SharedMatrix, SharedMatrix > > unpack_paired(const std::shared_ptr< Vector > &x)
Definition: hamiltonian.cc:1828
virtual void print_header() const
Definition: hamiltonian.cc:922
virtual std::shared_ptr< Vector > diagonal()
Definition: hamiltonian.cc:701
Definition: hamiltonian.h:142
std::shared_ptr< Vector > eps_occa_
Definition: hamiltonian.h:371
bool singlet_
Definition: hamiltonian.h:219
RHamiltonian(std::shared_ptr< JK > jk)
Definition: hamiltonian.cc:67
virtual ~CISRHamiltonian()
Definition: hamiltonian.cc:216
std::shared_ptr< JK > jk() const
Definition: hamiltonian.h:73
virtual void print_header() const
Definition: hamiltonian.cc:219
SharedMatrix Cocca_
Definition: hamiltonian.h:367
virtual std::map< std::string, SharedVector > pack(const std::map< std::string, std::shared_ptr< Matrix > > &b)
Definition: hamiltonian.cc:736
std::shared_ptr< Vector > eps_aocc_
Definition: hamiltonian.h:278
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:188
virtual void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b)
Definition: hamiltonian.cc:928
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:46
Definition: hamiltonian.h:196
SharedMatrix Cocc_
Definition: hamiltonian.h:303
virtual void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b)
Definition: hamiltonian.cc:768
Definition: hamiltonian.h:40
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:898
SharedMatrix M_
Definition: hamiltonian.h:182
SharedMatrix Cocc_
Definition: hamiltonian.h:324
void set_debug(int debug)
Debug flag (defaults to 0)
Definition: hamiltonian.h:101
SharedMatrix Cavir_
Definition: hamiltonian.h:277
bool exact_diagonal_
Use exact diagonal, if available?
Definition: hamiltonian.h:51
virtual std::shared_ptr< Vector > diagonal()
Definition: hamiltonian.cc:128
virtual std::vector< SharedMatrix > unpack(const std::shared_ptr< Vector > &x)
Definition: hamiltonian.cc:436