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-2018 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  protected:
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  public:
111  // => Constructors < = //
112 
113  RHamiltonian(std::shared_ptr<JK> jk);
114  RHamiltonian(std::shared_ptr<JK> jk, std::shared_ptr<VBase> v);
116  ~RHamiltonian() override;
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, std::vector<std::shared_ptr<Vector> >& b) = 0;
133 
138 };
139 
140 class UHamiltonian : public Hamiltonian {
141  public:
142  // => Constructors < = //
143 
144  UHamiltonian(std::shared_ptr<JK> jk);
145  UHamiltonian(std::shared_ptr<JK> jk, std::shared_ptr<VBase> v);
147  ~UHamiltonian() override;
148 
149  // => Required Methods <= //
150 
158  virtual std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> > diagonal() = 0;
164  virtual void product(const std::vector<std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> > >& x,
165  std::vector<std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> > >& b) = 0;
169  std::pair<SharedMatrix, SharedMatrix> explicit_hamiltonian();
170 };
171 
172 // => APPLIED CLASSES <= //
173 
175  protected:
177 
178  public:
180  ~MatrixRHamiltonian() override;
181 
182  void print_header() const override;
183  std::shared_ptr<Vector> diagonal() override;
184  void product(const std::vector<std::shared_ptr<Vector> >& x, std::vector<std::shared_ptr<Vector> >& b) override;
185 };
186 
188  protected:
189  std::pair<SharedMatrix, SharedMatrix> M_;
190 
191  public:
192  MatrixUHamiltonian(std::pair<SharedMatrix, SharedMatrix> M);
193  ~MatrixUHamiltonian() override;
194 
195  void print_header() const override;
196  std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> > diagonal() override;
197  void product(const std::vector<std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> > >& x,
198  std::vector<std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> > >& b) override;
199 };
200 
202  protected:
203  bool singlet_;
206  std::shared_ptr<Vector> eps_aocc_;
207  std::shared_ptr<Vector> eps_avir_;
208 
209  public:
210  CISRHamiltonian(std::shared_ptr<JK> jk, SharedMatrix Caocc, SharedMatrix Cavir, std::shared_ptr<Vector> eps_aocc,
211  std::shared_ptr<Vector> eps_avir, std::shared_ptr<VBase> v = std::shared_ptr<VBase>());
212  ~CISRHamiltonian() override;
213 
214  void print_header() const override;
215  std::shared_ptr<Vector> diagonal() override;
216  void product(const std::vector<std::shared_ptr<Vector> >& x, std::vector<std::shared_ptr<Vector> >& b) override;
217 
218  virtual std::vector<SharedMatrix> unpack(const std::shared_ptr<Vector>& x);
219 
220  void set_singlet(bool singlet) { singlet_ = singlet; }
221 };
222 
224  protected:
225  bool singlet_;
228  std::shared_ptr<Vector> eps_aocc_;
229  std::shared_ptr<Vector> eps_avir_;
230 
231  public:
232  TDHFRHamiltonian(std::shared_ptr<JK> jk, SharedMatrix Caocc, SharedMatrix Cavir, std::shared_ptr<Vector> eps_aocc,
233  std::shared_ptr<Vector> eps_avir, std::shared_ptr<VBase> v = std::shared_ptr<VBase>());
234  ~TDHFRHamiltonian() override;
235 
236  void print_header() const override;
237  std::shared_ptr<Vector> diagonal() override;
238  void product(const std::vector<std::shared_ptr<Vector> >& x, std::vector<std::shared_ptr<Vector> >& b) override;
239 
240  void set_singlet(bool singlet) { singlet_ = singlet; }
241 };
242 
244  protected:
247  std::shared_ptr<Vector> eps_aocc_;
248  std::shared_ptr<Vector> eps_avir_;
249 
250  public:
251  CPHFRHamiltonian(std::shared_ptr<JK> jk, SharedMatrix Caocc, SharedMatrix Cavir, std::shared_ptr<Vector> eps_aocc,
252  std::shared_ptr<Vector> eps_avir, std::shared_ptr<VBase> v = std::shared_ptr<VBase>());
253  ~CPHFRHamiltonian() override;
254 
255  void print_header() const override;
256  std::shared_ptr<Vector> diagonal() override;
257  void product(const std::vector<std::shared_ptr<Vector> >& x, std::vector<std::shared_ptr<Vector> >& b) override;
258 
259  virtual std::map<std::string, SharedVector> pack(const std::map<std::string, std::shared_ptr<Matrix> >& b);
260  virtual std::vector<SharedMatrix> unpack(const std::vector<SharedVector>& x);
261 };
262 
264  protected:
266 
267  public:
268  TDARHamiltonian(std::shared_ptr<JK> jk, std::shared_ptr<VBase> v, SharedMatrix Cocc, SharedMatrix Caocc,
269  SharedMatrix Cavir, std::shared_ptr<Vector> eps_aocc, std::shared_ptr<Vector> eps_avir);
270  ~TDARHamiltonian() override;
271 
272  void print_header() const override;
273  void product(const std::vector<std::shared_ptr<Vector> >& x, std::vector<std::shared_ptr<Vector> >& b) override;
274 };
275 
277  protected:
279 
280  public:
281  TDDFTRHamiltonian(std::shared_ptr<JK> jk, std::shared_ptr<VBase> v, SharedMatrix Cocc, SharedMatrix Caocc,
282  SharedMatrix Cavir, std::shared_ptr<Vector> eps_aocc, std::shared_ptr<Vector> eps_avir);
283  ~TDDFTRHamiltonian() override;
284 
285  void print_header() const override;
286  void product(const std::vector<std::shared_ptr<Vector> >& x, std::vector<std::shared_ptr<Vector> >& b) override;
287 };
288 
290  protected:
292 
293  public:
294  CPKSRHamiltonian(std::shared_ptr<JK> jk, std::shared_ptr<VBase> v, SharedMatrix Cocc, SharedMatrix Caocc,
295  SharedMatrix Cavir, std::shared_ptr<Vector> eps_aocc, std::shared_ptr<Vector> eps_avir);
296  ~CPKSRHamiltonian() override;
297 
298  void print_header() const override;
299  void product(const std::vector<std::shared_ptr<Vector> >& x, std::vector<std::shared_ptr<Vector> >& b) override;
300 };
301 
302 // "Hamiltonian" for UHF stability analysis.
304  protected:
309  std::shared_ptr<Vector> eps_occa_;
310  std::shared_ptr<Vector> eps_vira_;
311  std::shared_ptr<Vector> eps_occb_;
312  std::shared_ptr<Vector> eps_virb_;
313 
314  public:
315  // Should really use a map of matrices here. But meh.
316  USTABHamiltonian(std::shared_ptr<JK> jk, SharedMatrix Cocca, SharedMatrix Cvira, SharedMatrix Coccb,
317  SharedMatrix Cvirb, std::shared_ptr<Vector> eps_occa, std::shared_ptr<Vector> eps_vira,
318  std::shared_ptr<Vector> eps_occb, std::shared_ptr<Vector> eps_virb,
319  std::shared_ptr<VBase> v = std::shared_ptr<VBase>());
320  ~USTABHamiltonian() override;
321 
322  void print_header() const override;
323  std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> > diagonal() override;
324  void product(const std::vector<std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> > >& x,
325  std::vector<std::pair<std::shared_ptr<Vector>, std::shared_ptr<Vector> > >& b) override;
326 
327  // Working with a pair is annoying, so we define a new function below
328  virtual std::vector<std::pair<SharedMatrix, SharedMatrix> > unpack_paired(const std::shared_ptr<Vector>& x);
329 };
330 }
331 #endif
void set_singlet(bool singlet)
Definition: hamiltonian.h:240
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:201
std::shared_ptr< Vector > eps_avir_
Definition: hamiltonian.h:229
void set_print(int print)
Print flag (defaults to 1)
Definition: hamiltonian.h:100
Definition: hamiltonian.h:243
Definition: hamiltonian.h:263
~CPHFRHamiltonian() override
Definition: hamiltonian.cc:616
MatrixRHamiltonian(SharedMatrix M)
Definition: hamiltonian.cc:89
std::shared_ptr< Vector > diagonal() override
Definition: hamiltonian.cc:413
std::pair< SharedMatrix, SharedMatrix > M_
Definition: hamiltonian.h:189
std::shared_ptr< JK > jk_
jk object
Definition: hamiltonian.h:54
Definition: hamiltonian.h:223
int debug_
Debug flag, defaults to 0.
Definition: hamiltonian.h:48
std::shared_ptr< Vector > eps_virb_
Definition: hamiltonian.h:312
void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b) override
Definition: hamiltonian.cc:109
~MatrixRHamiltonian() override
Definition: hamiltonian.cc:90
std::shared_ptr< Vector > eps_aocc_
Definition: hamiltonian.h:206
void set_singlet(bool singlet)
Definition: hamiltonian.h:220
SharedMatrix explicit_hamiltonian()
Definition: hamiltonian.cc:61
virtual void print_header() const =0
std::shared_ptr< VBase > v() const
Definition: hamiltonian.h:79
void print_header() const override
Definition: hamiltonian.cc:828
std::pair< std::shared_ptr< Vector >, std::shared_ptr< Vector > > diagonal() override
Definition: hamiltonian.cc:131
~USTABHamiltonian() override
Definition: hamiltonian.cc:1286
void common_init()
Definition: hamiltonian.cc:51
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:166
void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b) override
Definition: hamiltonian.cc:225
virtual void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b)=0
virtual ~Hamiltonian()
Destructor.
Definition: hamiltonian.cc:50
Definition: hamiltonian.h:276
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
void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b) override
Definition: hamiltonian.cc:833
SharedMatrix Coccb_
Definition: hamiltonian.h:307
std::shared_ptr< Vector > diagonal() override
Definition: hamiltonian.cc:96
virtual std::vector< SharedMatrix > unpack(const std::vector< SharedVector > &x)
Definition: hamiltonian.cc:785
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) override
Definition: hamiltonian.cc:1361
void print_header() const override
Definition: hamiltonian.cc:408
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:403
~RHamiltonian() override
Destructor.
Definition: hamiltonian.cc:60
SharedMatrix Caocc_
Definition: hamiltonian.h:245
Definition: hamiltonian.h:303
void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b) override
Definition: hamiltonian.cc:449
~TDDFTRHamiltonian() override
Definition: hamiltonian.cc:975
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:612
SharedMatrix Cocc_
Definition: hamiltonian.h:291
void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b) override
Definition: hamiltonian.cc:981
SharedMatrix Cavir_
Definition: hamiltonian.h:227
~UHamiltonian() override
Destructor.
Definition: hamiltonian.cc:87
std::shared_ptr< Vector > eps_occb_
Definition: hamiltonian.h:311
SharedMatrix Caocc_
Definition: hamiltonian.h:204
UHamiltonian(std::shared_ptr< JK > jk)
Definition: hamiltonian.cc:85
SharedMatrix Cvira_
Definition: hamiltonian.h:306
SharedMatrix Cavir_
Definition: hamiltonian.h:205
void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b) override
Definition: hamiltonian.cc:1169
SharedMatrix Caocc_
Definition: hamiltonian.h:226
void print_header() const override
Definition: hamiltonian.cc:1164
std::shared_ptr< Vector > eps_avir_
Definition: hamiltonian.h:207
MatrixUHamiltonian(std::pair< SharedMatrix, SharedMatrix > M)
Definition: hamiltonian.cc:123
Definition: hamiltonian.h:109
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) override
Definition: hamiltonian.cc:148
void print_header() const override
Definition: hamiltonian.cc:91
std::shared_ptr< Vector > diagonal() override
Definition: hamiltonian.cc:622
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:225
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:959
SharedMatrix Cvirb_
Definition: hamiltonian.h:308
std::shared_ptr< Vector > diagonal() override
Definition: hamiltonian.cc:176
void print_header() const override
Definition: hamiltonian.cc:617
std::pair< std::shared_ptr< Vector >, std::shared_ptr< Vector > > diagonal() override
Definition: hamiltonian.cc:1293
std::shared_ptr< Vector > eps_aocc_
Definition: hamiltonian.h:228
void set_JK(std::shared_ptr< JK > jk)
Definition: hamiltonian.h:93
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:1147
void print_header() const override
Definition: hamiltonian.cc:1287
std::pair< SharedMatrix, SharedMatrix > explicit_hamiltonian()
Definition: hamiltonian.h:289
std::shared_ptr< Matrix > SharedMatrix
Definition: adc.h:49
~MatrixUHamiltonian() override
Definition: hamiltonian.cc:125
Definition: hamiltonian.h:174
std::shared_ptr< Vector > eps_vira_
Definition: hamiltonian.h:310
std::shared_ptr< Vector > eps_avir_
Definition: hamiltonian.h:248
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:1273
void product(const std::vector< std::shared_ptr< Vector > > &x, std::vector< std::shared_ptr< Vector > > &b) override
Definition: hamiltonian.cc:685
virtual std::vector< std::pair< SharedMatrix, SharedMatrix > > unpack_paired(const std::shared_ptr< Vector > &x)
Definition: hamiltonian.cc:1689
Definition: hamiltonian.h:140
std::shared_ptr< Vector > eps_occa_
Definition: hamiltonian.h:309
bool singlet_
Definition: hamiltonian.h:203
RHamiltonian(std::shared_ptr< JK > jk)
Definition: hamiltonian.cc:58
~CPKSRHamiltonian() override
Definition: hamiltonian.cc:1163
std::shared_ptr< JK > jk() const
Definition: hamiltonian.h:74
SharedMatrix Cocca_
Definition: hamiltonian.h:305
virtual std::map< std::string, SharedVector > pack(const std::map< std::string, std::shared_ptr< Matrix > > &b)
Definition: hamiltonian.cc:656
std::shared_ptr< Vector > eps_aocc_
Definition: hamiltonian.h:247
void print_header() const override
Definition: hamiltonian.cc:171
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
void diag()
Definition: diag.cc:134
Definition: hamiltonian.h:187
SharedMatrix Cocc_
Definition: hamiltonian.h:265
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:811
SharedMatrix M_
Definition: hamiltonian.h:176
SharedMatrix Cocc_
Definition: hamiltonian.h:278
void set_debug(int debug)
Debug flag (defaults to 0)
Definition: hamiltonian.h:102
~TDHFRHamiltonian() override
Definition: hamiltonian.cc:407
~CISRHamiltonian() override
Definition: hamiltonian.cc:170
void print_header() const override
Definition: hamiltonian.cc:126
void print_header() const override
Definition: hamiltonian.cc:976
~TDARHamiltonian() override
Definition: hamiltonian.cc:827
SharedMatrix Cavir_
Definition: hamiltonian.h:246
bool exact_diagonal_
Use exact diagonal, if available?
Definition: hamiltonian.h:52
virtual std::vector< SharedMatrix > unpack(const std::shared_ptr< Vector > &x)
Definition: hamiltonian.cc:381