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 namespace psi {
33 
34 class Matrix;
35 class Vector;
36 class JK;
37 class VBase;
38 
39 // => BASE CLASSES <= //
40 
41 class Hamiltonian {
42 
43 protected:
44 
46  int print_;
48  int debug_;
50  int bench_;
54  std::shared_ptr<JK> jk_;
56  std::shared_ptr<VBase> v_;
57 
58  void common_init();
59 
60 public:
61  // => Constructors < = //
62 
63  Hamiltonian(std::shared_ptr<JK> jk);
64  Hamiltonian(std::shared_ptr<JK> jk, std::shared_ptr<VBase> v);
66  virtual ~Hamiltonian();
67 
68  // => Accessors <= //
69 
74  std::shared_ptr<JK> jk() const { return jk_; }
79  std::shared_ptr<VBase> v() const { return v_; }
80 
85  virtual void print_header() const = 0;
86 
87  // => Knobs <= //
88 
93  void set_JK(std::shared_ptr<JK> jk) { jk_ = jk; }
98  void set_V(std::shared_ptr<VBase> v) { v_ = v; }
100  void set_print(int print) { print_ = print; }
102  void set_debug(int debug) { debug_ = debug; }
104  void set_bench(int bench) { bench_ = bench; }
107 };
108 
109 class RHamiltonian : public Hamiltonian {
110 
111 public:
112  // => Constructors < = //
113 
114  RHamiltonian(std::shared_ptr<JK> jk);
115  RHamiltonian(std::shared_ptr<JK> jk, std::shared_ptr<VBase> v);
117  virtual ~RHamiltonian();
118 
119  // => Required Methods <= //
120 
127  virtual std::shared_ptr<Vector> diagonal() = 0;
133  virtual void product(const std::vector<std::shared_ptr<Vector> >& x,
134  std::vector<std::shared_ptr<Vector> >& b) = 0;
135 
140 
141 };
142 
143 class UHamiltonian : public Hamiltonian {
144 
145 public:
146  // => Constructors < = //
147 
148  UHamiltonian(std::shared_ptr<JK> jk);
149  UHamiltonian(std::shared_ptr<JK> jk, std::shared_ptr<VBase> v);
151  virtual ~UHamiltonian();
152 
153  // => Required Methods <= //
154 
162  virtual std::pair<std::shared_ptr<Vector>,
163  std::shared_ptr<Vector> > diagonal() = 0;
169  virtual void product(const std::vector<std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> > >& x,
170  std::vector<std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> > >& b) = 0;
174  std::pair<SharedMatrix, SharedMatrix > explicit_hamiltonian();
175 };
176 
177 // => APPLIED CLASSES <= //
178 
180 
181 protected:
182 
184 
185 public:
186 
188  virtual ~MatrixRHamiltonian();
189 
190  virtual void print_header() const;
191  virtual std::shared_ptr<Vector> diagonal();
192  virtual void product(const std::vector<std::shared_ptr<Vector> >& x,
193  std::vector<std::shared_ptr<Vector> >& b);
194 
195 };
196 
198 
199 protected:
200 
201  std::pair<SharedMatrix, SharedMatrix > M_;
202 
203 public:
204 
205  MatrixUHamiltonian(std::pair<SharedMatrix, SharedMatrix > M);
206  virtual ~MatrixUHamiltonian();
207 
208  virtual void print_header() const;
209  virtual std::pair<std::shared_ptr<Vector>,
210  std::shared_ptr<Vector> > diagonal();
211  virtual void product(const std::vector<std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> > >& x,
212  std::vector<std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> > >& b);
213 
214 };
215 
217 
218 protected:
219 
220  bool singlet_;
223  std::shared_ptr<Vector> eps_aocc_;
224  std::shared_ptr<Vector> eps_avir_;
225 
226 public:
227  CISRHamiltonian(std::shared_ptr<JK> jk,
228  SharedMatrix Caocc,
229  SharedMatrix Cavir,
230  std::shared_ptr<Vector> eps_aocc,
231  std::shared_ptr<Vector> eps_avir,
232  std::shared_ptr<VBase> v = std::shared_ptr<VBase>());
233  virtual ~CISRHamiltonian();
234 
235  virtual void print_header() const;
236  virtual std::shared_ptr<Vector> diagonal();
237  virtual void product(const std::vector<std::shared_ptr<Vector> >& x,
238  std::vector<std::shared_ptr<Vector> >& b);
239 
240  virtual std::vector<SharedMatrix > unpack(const std::shared_ptr<Vector>& x);
241 
242  void set_singlet(bool singlet) { singlet_ = singlet; }
243 
244 };
245 
247 
248 protected:
249 
250  bool singlet_;
253  std::shared_ptr<Vector> eps_aocc_;
254  std::shared_ptr<Vector> eps_avir_;
255 
256 public:
257  TDHFRHamiltonian(std::shared_ptr<JK> jk,
258  SharedMatrix Caocc,
259  SharedMatrix Cavir,
260  std::shared_ptr<Vector> eps_aocc,
261  std::shared_ptr<Vector> eps_avir,
262  std::shared_ptr<VBase> v = std::shared_ptr<VBase>());
263  virtual ~TDHFRHamiltonian();
264 
265  virtual void print_header() const;
266  virtual std::shared_ptr<Vector> diagonal();
267  virtual void product(const std::vector<std::shared_ptr<Vector> >& x,
268  std::vector<std::shared_ptr<Vector> >& b);
269 
270  void set_singlet(bool singlet) { singlet_ = singlet; }
271 };
272 
274 
275 protected:
276 
279  std::shared_ptr<Vector> eps_aocc_;
280  std::shared_ptr<Vector> eps_avir_;
281 
282 public:
283  CPHFRHamiltonian(std::shared_ptr<JK> jk,
284  SharedMatrix Caocc,
285  SharedMatrix Cavir,
286  std::shared_ptr<Vector> eps_aocc,
287  std::shared_ptr<Vector> eps_avir,
288  std::shared_ptr<VBase> v = std::shared_ptr<VBase>());
289  virtual ~CPHFRHamiltonian();
290 
291  virtual void print_header() const;
292  virtual std::shared_ptr<Vector> diagonal();
293  virtual void product(const std::vector<std::shared_ptr<Vector> >& x,
294  std::vector<std::shared_ptr<Vector> >& b);
295 
296  virtual std::map<std::string, SharedVector> pack(const std::map<std::string, std::shared_ptr<Matrix> >& b);
297  virtual std::vector<SharedMatrix > unpack(const std::vector<SharedVector >& x);
298 };
299 
301 
302 protected:
303 
305 
306 public:
307  TDARHamiltonian(std::shared_ptr<JK> jk,
308  std::shared_ptr<VBase> v,
309  SharedMatrix Cocc,
310  SharedMatrix Caocc,
311  SharedMatrix Cavir,
312  std::shared_ptr<Vector> eps_aocc,
313  std::shared_ptr<Vector> eps_avir);
314  virtual ~TDARHamiltonian();
315 
316  virtual void print_header() const;
317  virtual void product(const std::vector<std::shared_ptr<Vector> >& x,
318  std::vector<std::shared_ptr<Vector> >& b);
319 };
320 
322 
323 protected:
324 
326 
327 public:
328  TDDFTRHamiltonian(std::shared_ptr<JK> jk,
329  std::shared_ptr<VBase> v,
330  SharedMatrix Cocc,
331  SharedMatrix Caocc,
332  SharedMatrix Cavir,
333  std::shared_ptr<Vector> eps_aocc,
334  std::shared_ptr<Vector> eps_avir);
335  virtual ~TDDFTRHamiltonian();
336 
337  virtual void print_header() const;
338  virtual void product(const std::vector<std::shared_ptr<Vector> >& x,
339  std::vector<std::shared_ptr<Vector> >& b);
340 };
341 
343 
344 protected:
345 
347 
348 public:
349  CPKSRHamiltonian(std::shared_ptr<JK> jk,
350  std::shared_ptr<VBase> v,
351  SharedMatrix Cocc,
352  SharedMatrix Caocc,
353  SharedMatrix Cavir,
354  std::shared_ptr<Vector> eps_aocc,
355  std::shared_ptr<Vector> eps_avir);
356  virtual ~CPKSRHamiltonian();
357 
358  virtual void print_header() const;
359  virtual void product(const std::vector<std::shared_ptr<Vector> >& x,
360  std::vector<std::shared_ptr<Vector> >& b);
361 };
362 
363 // "Hamiltonian" for UHF stability analysis.
365 
366 protected:
367 
372  std::shared_ptr<Vector> eps_occa_;
373  std::shared_ptr<Vector> eps_vira_;
374  std::shared_ptr<Vector> eps_occb_;
375  std::shared_ptr<Vector> eps_virb_;
376 
377 public:
378 
379 // Should really use a map of matrices here. But meh.
380  USTABHamiltonian(std::shared_ptr<JK> jk,
381  SharedMatrix Cocca,
382  SharedMatrix Cvira,
383  SharedMatrix Coccb,
384  SharedMatrix Cvirb,
385  std::shared_ptr<Vector> eps_occa,
386  std::shared_ptr<Vector> eps_vira,
387  std::shared_ptr<Vector> eps_occb,
388  std::shared_ptr<Vector> eps_virb,
389  std::shared_ptr<VBase> v = std::shared_ptr<VBase>());
390  virtual ~USTABHamiltonian();
391 
392  virtual void print_header() const;
393  virtual std::pair<std::shared_ptr<Vector>,
394  std::shared_ptr<Vector> > diagonal();
395  virtual void product(const std::vector<std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> > >& x,
396  std::vector<std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> > >& b);
397 
398 // Working with a pair is annoying, so we define a new function below
399  virtual std::vector<std::pair<SharedMatrix,SharedMatrix > > unpack(
400  const std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> >& x){} ;
401  virtual std::vector<std::pair<SharedMatrix,SharedMatrix > > unpack_paired(
402  const std::shared_ptr<Vector>& x);
403 
404 };
405 
406 }
407 #endif
void set_singlet(bool singlet)
Definition: hamiltonian.h:270
virtual void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b)
Definition: hamiltonian.cc:515
virtual std::shared_ptr< Vector > diagonal()=0
std::shared_ptr< VBase > v_
v object
Definition: hamiltonian.h:56
int print_
Print flag, defaults to 1.
Definition: hamiltonian.h:46
Definition: hamiltonian.h:216
std::shared_ptr< Vector > eps_avir_
Definition: hamiltonian.h:254
virtual void print_header() const
Definition: hamiltonian.cc:1285
void set_print(int print)
Print flag (defaults to 1)
Definition: hamiltonian.h:100
virtual ~TDHFRHamiltonian()
Definition: hamiltonian.cc:469
Definition: hamiltonian.h:273
virtual ~USTABHamiltonian()
Definition: hamiltonian.cc:1413
virtual ~MatrixRHamiltonian()
Definition: hamiltonian.cc:120
Definition: hamiltonian.h:300
MatrixRHamiltonian(SharedMatrix M)
Definition: hamiltonian.cc:116
std::shared_ptr< JK > jk_
jk object
Definition: hamiltonian.h:54
Definition: hamiltonian.h:246
void diag(void)
Definition: diag.cc:134
int debug_
Debug flag, defaults to 0.
Definition: hamiltonian.h:48
std::shared_ptr< Vector > eps_virb_
Definition: hamiltonian.h:375
std::shared_ptr< Vector > eps_aocc_
Definition: hamiltonian.h:223
void set_singlet(bool singlet)
Definition: hamiltonian.h:242
SharedMatrix explicit_hamiltonian()
Definition: hamiltonian.cc:79
virtual void print_header() const =0
virtual std::shared_ptr< Vector > diagonal()
Definition: hamiltonian.cc:478
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:1493
std::shared_ptr< VBase > v() const
Definition: hamiltonian.h:79
virtual ~CPHFRHamiltonian()
Definition: hamiltonian.cc:693
virtual void print_header() const
Definition: hamiltonian.cc:1416
void common_init()
Definition: hamiltonian.cc:60
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:208
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:277
virtual ~Hamiltonian()
Destructor.
Definition: hamiltonian.cc:57
Definition: hamiltonian.h:321
void set_V(std::shared_ptr< VBase > v)
Definition: hamiltonian.h:98
void set_exact_diagonal(bool diag)
User the exact diagonal, if available? (defaults to false)
Definition: hamiltonian.h:106
virtual std::pair< std::shared_ptr< Vector >, std::shared_ptr< Vector > > diagonal()
Definition: hamiltonian.cc:171
SharedMatrix Coccb_
Definition: hamiltonian.h:370
virtual ~TDARHamiltonian()
Definition: hamiltonian.cc:920
virtual ~TDDFTRHamiltonian()
Definition: hamiltonian.cc:1080
virtual std::vector< SharedMatrix > unpack(const std::vector< SharedVector > &x)
Definition: hamiltonian.cc:873
virtual std::vector< std::pair< SharedMatrix, SharedMatrix > > unpack(const std::pair< std::shared_ptr< Vector >, std::shared_ptr< Vector > > &x)
Definition: hamiltonian.h:399
virtual ~CPKSRHamiltonian()
Definition: hamiltonian.cc:1282
virtual void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b)
Definition: hamiltonian.cc:1089
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:460
SharedMatrix Caocc_
Definition: hamiltonian.h:277
virtual void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b)
Definition: hamiltonian.cc:143
virtual ~UHamiltonian()
Destructor.
Definition: hamiltonian.cc:112
Definition: hamiltonian.h:364
virtual ~RHamiltonian()
Destructor.
Definition: hamiltonian.cc:76
virtual void print_header() const
Definition: hamiltonian.cc:123
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:684
SharedMatrix Cocc_
Definition: hamiltonian.h:346
SharedMatrix Cavir_
Definition: hamiltonian.h:252
std::shared_ptr< Vector > eps_occb_
Definition: hamiltonian.h:374
SharedMatrix Caocc_
Definition: hamiltonian.h:221
virtual void print_header() const
Definition: hamiltonian.cc:472
UHamiltonian(std::shared_ptr< JK > jk)
Definition: hamiltonian.cc:104
SharedMatrix Cvira_
Definition: hamiltonian.h:369
SharedMatrix Cavir_
Definition: hamiltonian.h:222
std::pair< SharedMatrix, SharedMatrix > explicit_hamiltonian()
SharedMatrix Caocc_
Definition: hamiltonian.h:251
std::shared_ptr< Vector > eps_avir_
Definition: hamiltonian.h:224
MatrixUHamiltonian(std::pair< SharedMatrix, SharedMatrix > M)
Definition: hamiltonian.cc:158
Definition: hamiltonian.h:109
int bench_
Bench flag, defaults to 0.
Definition: hamiltonian.h:50
virtual std::pair< std::shared_ptr< Vector >, std::shared_ptr< Vector > > diagonal()=0
bool singlet_
Definition: hamiltonian.h:250
void set_bench(int bench)
Bench flag (defaults to 0)
Definition: hamiltonian.h:104
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:1059
virtual ~MatrixUHamiltonian()
Definition: hamiltonian.cc:162
virtual void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b)
Definition: hamiltonian.cc:1291
SharedMatrix Cvirb_
Definition: hamiltonian.h:371
std::shared_ptr< Vector > eps_aocc_
Definition: hamiltonian.h:253
virtual std::pair< std::shared_ptr< Vector >, std::shared_ptr< Vector > > diagonal()
Definition: hamiltonian.cc:1423
void set_JK(std::shared_ptr< JK > jk)
Definition: hamiltonian.h:93
std::pair< SharedMatrix, SharedMatrix > M_
Definition: hamiltonian.h:201
virtual void print_header() const
Definition: hamiltonian.cc:696
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:1261
virtual std::shared_ptr< Vector > diagonal()
Definition: hamiltonian.cc:226
Definition: hamiltonian.h:342
std::shared_ptr< Matrix > SharedMatrix
Definition: adc.h:49
Definition: hamiltonian.h:179
std::shared_ptr< Vector > eps_vira_
Definition: hamiltonian.h:373
std::shared_ptr< Vector > eps_avir_
Definition: hamiltonian.h:280
virtual void print_header() const
Definition: hamiltonian.cc:1083
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:1399
virtual void print_header() const
Definition: hamiltonian.cc:165
virtual std::vector< std::pair< SharedMatrix, SharedMatrix > > unpack_paired(const std::shared_ptr< Vector > &x)
Definition: hamiltonian.cc:1829
virtual void print_header() const
Definition: hamiltonian.cc:923
virtual std::shared_ptr< Vector > diagonal()
Definition: hamiltonian.cc:702
Definition: hamiltonian.h:143
std::shared_ptr< Vector > eps_occa_
Definition: hamiltonian.h:372
bool singlet_
Definition: hamiltonian.h:220
RHamiltonian(std::shared_ptr< JK > jk)
Definition: hamiltonian.cc:68
virtual ~CISRHamiltonian()
Definition: hamiltonian.cc:217
std::shared_ptr< JK > jk() const
Definition: hamiltonian.h:74
virtual void print_header() const
Definition: hamiltonian.cc:220
SharedMatrix Cocca_
Definition: hamiltonian.h:368
virtual std::map< std::string, SharedVector > pack(const std::map< std::string, std::shared_ptr< Matrix > > &b)
Definition: hamiltonian.cc:737
std::shared_ptr< Vector > eps_aocc_
Definition: hamiltonian.h:279
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:189
virtual void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b)
Definition: hamiltonian.cc:929
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:47
Definition: hamiltonian.h:197
SharedMatrix Cocc_
Definition: hamiltonian.h:304
virtual void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b)
Definition: hamiltonian.cc:769
Definition: hamiltonian.h:41
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:899
SharedMatrix M_
Definition: hamiltonian.h:183
SharedMatrix Cocc_
Definition: hamiltonian.h:325
void set_debug(int debug)
Debug flag (defaults to 0)
Definition: hamiltonian.h:102
SharedMatrix Cavir_
Definition: hamiltonian.h:278
bool exact_diagonal_
Use exact diagonal, if available?
Definition: hamiltonian.h:52
virtual std::shared_ptr< Vector > diagonal()
Definition: hamiltonian.cc:129
virtual std::vector< SharedMatrix > unpack(const std::shared_ptr< Vector > &x)
Definition: hamiltonian.cc:437