MPQC  3.0.0-alpha
rdm.h
1 //
2 // rdm.h
3 //
4 // Copyright (C) 2009 Edward Valeev
5 //
6 // Author: Edward Valeev <evaleev@vt.edu>
7 // Maintainer: EV
8 //
9 // This file is part of the SC Toolkit.
10 //
11 // The SC Toolkit is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU Library General Public License as published by
13 // the Free Software Foundation; either version 2, or (at your option)
14 // any later version.
15 //
16 // The SC Toolkit 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 Library General Public License for more details.
20 //
21 // You should have received a copy of the GNU Library General Public License
22 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 //
25 // The U.S. Government is granted a limited license as per AL 91-7.
26 //
27 
28 #ifndef _mpqc_src_lib_chemistry_qc_mbptr12_rdm_h
29 #define _mpqc_src_lib_chemistry_qc_mbptr12_rdm_h
30 
31 #include <chemistry/qc/wfn/wfn.h>
32 #include <chemistry/qc/wfn/obwfn.h>
33 #include <chemistry/qc/wfn/spin.h>
34 #include <math/distarray4/distarray4.h>
35 
36 namespace sc {
37 
39  typedef enum {Zero=0, One = 1, Two = 2, Three = 3, Four = 4} Rank;
40 
43 
44  namespace {
45  template <Rank R> struct __spincase;
46  template <> struct __spincase<One> {
47  typedef SpinCase1 type;
48  };
49  template <> struct __spincase<Two> {
50  typedef SpinCase2 type;
51  };
52 
53  template <Rank R> struct __nspincases;
54  template <> struct __nspincases<One> {
55  static const int value = NSpinCases1;
56  };
57  template <> struct __nspincases<Two> {
58  static const int value = NSpinCases2;
59  };
60 
61  }
62 
63  template <Rank R> class RDMCumulant;
64  class OrbitalSpace;
65 
68  template <Rank R>
69  class RDM : public Compute, virtual public SavableState {
70  typedef RDM<R> this_type;
71  typedef typename __spincase<R>::type spincase;
72  public:
85  RDM(const Ref<KeyVal>& kv) {
86  wfn_ = require_dynamic_cast<Wavefunction*>(
87  kv->describedclassvalue("wfn").pointer(),
88  "RDM<R>::RDM\n"
89  );
90  }
91  RDM(StateIn& si) : SavableState(si) {
92  wfn_ << SavableState::restore_state(si);
93  }
94  RDM(const Ref<Wavefunction>& wfn) : wfn_(wfn) {
95  }
96  ~RDM() {
97  }
99  SavableState::save_state(wfn_.pointer(), so);
100  }
101 
102  virtual void obsolete() {
103  wfn_->obsolete();
104  for(int s=0; s<__nspincases<R>::value; ++s)
105  scmat_[s] = 0;
106  }
107 
109  Ref<Wavefunction> wfn() const { return wfn_; }
110  virtual void compute() {
111  const double energy = wfn_->value();
112  }
114  virtual Ref<OrbitalSpace> orbs(SpinCase1 s) const =0;
116  virtual size_t ndim(spincase spincase) const;
118  virtual const double* obtain_block(spincase spin, size_t bra) const {
119  throw ProgrammingError("RDM<R>::obtain_block() is not yet implemented",
120  __FILE__,
121  __LINE__);
122  }
124  virtual void release_block(spincase spin, size_t bra, double*) const {
125  throw ProgrammingError("RDM<R>::release_block() is not yet implemented",
126  __FILE__,
127  __LINE__);
128  }
130  virtual RefSymmSCMatrix scmat(spincase spin) const;
131 
133  virtual Ref< RDMCumulant<R> > cumulant() const;
135  virtual Ref< RDM< static_cast<Rank>(R-1) > > rdm_m_1() const;
136 
137  private:
138  static ClassDesc class_desc_;
139  Ref<Wavefunction> wfn_;
140 
141  protected:
142  mutable RefSymmSCMatrix scmat_[__nspincases<R>::value];
143  };
144 
145  template <Rank R>
146  ClassDesc
147  RDM<R>::class_desc_(typeid(this_type),
148  (std::string("RDM<") +
149  char('1' + R - 1) +
150  std::string(">")
151  ).c_str(), 1,
152  "virtual public SavableState", 0, 0, 0 );
153 
155  template <> class RDM<Zero> : public RefCount {};
156 
158 
161  template <Rank R>
162  class RDMCumulant : public Compute, virtual public SavableState {
163  typedef RDMCumulant<R> this_type;
164  typedef RDM<R> density_type;
165  typedef typename __spincase<R>::type spincase;
166  public:
167  RDMCumulant(const Ref<density_type>& density) : density_(density) {
168  }
169  RDMCumulant(StateIn& si) : SavableState(si) {
170  density_ << SavableState::restore_state(si);
171  }
172  ~RDMCumulant() {
173  }
175  SavableState::save_state(density_.pointer(), so);
176  }
177  void obsolete() {
178  density_->obsolete();
179  for(int s=0; s<__nspincases<R>::value; ++s)
180  scmat_[s] = 0;
181  }
182 
184  Ref<Wavefunction> wfn() const { return density_->wfn(); }
185  void compute() { density_->compute(); }
187  Ref<density_type> density() const { return density_; }
189  size_t ndim(spincase spincase) const { return density_->ndim(); }
191  virtual const double* obtain_block(spincase spin, size_t bra) const {
192  throw ProgrammingError("RDMCumulant<R>::obtain_block() is not yet implemented",
193  __FILE__,
194  __LINE__);
195  }
197  virtual void release_block(spincase spin, size_t bra, double*) const {
198  throw ProgrammingError("RDMCumulant<R>::release_block() is not yet implemented",
199  __FILE__,
200  __LINE__);
201  }
203  virtual RefSymmSCMatrix scmat(spincase spin) const;
204 
205  private:
206  static ClassDesc class_desc_;
207  Ref<density_type> density_;
208 
209  protected:
210  mutable RefSymmSCMatrix scmat_[__nspincases<R>::value];
211  };
212 
213  template <Rank R>
214  ClassDesc
215  RDMCumulant<R>::class_desc_(typeid(this_type),
216  (std::string("RDMCumulant<") +
217  char('1' + R - 1) +
218  std::string(">")
219  ).c_str(), 1,
220  "virtual public SavableState", 0, 0, 0 );
221 
222 
225  template <Rank R>
226  class SpinFreeRDM : public Compute, virtual public SavableState {
227  typedef SpinFreeRDM<R> this_type;
228  typedef typename __spincase<R>::type spincase;
229  public:
243  wfn_ = require_dynamic_cast<Wavefunction*>(
244  kv->describedclassvalue("wfn").pointer(),
245  "RDM<R>::RDM\n"
246  );
247  }
248  SpinFreeRDM(StateIn& si) : SavableState(si) {
249  wfn_ << SavableState::restore_state(si);
250  }
251  SpinFreeRDM(const Ref<Wavefunction>& wfn) : wfn_(wfn) {
252  }
253  ~SpinFreeRDM() {
254  }
256  SavableState::save_state(wfn_.pointer(), so);
257  }
258 
259  virtual void obsolete() {
260  wfn_->obsolete();
261  scmat_ = 0;
262  da4_ = 0;
263  }
264 
266  Ref<Wavefunction> wfn() const { return wfn_; }
267  virtual void compute() {
268  const double energy = wfn_->value();
269  }
271  virtual Ref<OrbitalSpace> orbs() const =0;
273  virtual size_t ndim() const;
275  virtual const double* obtain_block(spincase spin, size_t bra) const {
276  throw ProgrammingError("SpinFreeRDM<R>::obtain_block() is not yet implemented",
277  __FILE__,
278  __LINE__);
279  }
281  virtual void release_block(spincase spin, size_t bra, double*) const {
282  throw ProgrammingError("SpinFreeRDM<R>::release_block() is not yet implemented",
283  __FILE__,
284  __LINE__);
285  }
287  virtual RefSymmSCMatrix scmat() const;
291  virtual const Ref<DistArray4>& da4() const;
292 
294  virtual Ref< SpinFreeRDM< static_cast<Rank>(R-1) > > rdm_m_1() const;
295 
296  private:
297  static ClassDesc class_desc_;
298  Ref<Wavefunction> wfn_;
299 
300  protected:
301  // used for R=1 (and for now for R=2)
302  mutable RefSymmSCMatrix scmat_;
303  // (will be) used for R=2
304  mutable Ref<DistArray4> da4_;
305  };
306 
307  template <Rank R>
308  ClassDesc
309  SpinFreeRDM<R>::class_desc_(typeid(this_type),
310  (std::string("SpinFreeRDM<") +
311  char('1' + R - 1) +
312  std::string(">")
313  ).c_str(), 1,
314  "virtual public SavableState", 0, 0, 0 );
315 
317  template <> class SpinFreeRDM<Zero> : public RefCount {};
318 
320 
321  class OrbitalSpace;
322 
324  class OBWfnRDMTwo : public RDM<Two> {
326  typedef RDM<One> rdm_m_1_type;
327  public:
340  OBWfnRDMTwo(const Ref<KeyVal>& kv);
341  OBWfnRDMTwo(StateIn& si);
343  virtual ~OBWfnRDMTwo();
344  void save_data_state(StateOut& so);
345 
346  Ref<OneBodyWavefunction> wfn() const { return wfn_; }
347  Ref<OrbitalSpace> orbs(SpinCase1 s) const;
348  RefSymmSCMatrix scmat(SpinCase2 spincase) const;
350  Ref<rdm_m_1_type> rdm_m_1() const;
351 
352  private:
354  mutable RefSymmSCMatrix scmat_[NSpinCases2];
355  mutable Ref<OrbitalSpace> orbs_[NSpinCases1];
356 
357  static ClassDesc class_desc_;
358  };
359 
361  class OBWfnRDMCumulantTwo : public RDMCumulant<Two> {
362  public:
365  virtual ~OBWfnRDMCumulantTwo();
366  void save_data_state(StateOut& so);
367 
368  void compute();
369  const double* obtain_block(SpinCase2 spin, size_t bra) const;
370  void release_block(SpinCase2, size_t bra, double*) const;
371  RefSymmSCMatrix scmat(SpinCase2 spincase) const;
372 
373  private:
374  Ref<OBWfnRDMTwo> density_;
375  mutable RefSymmSCMatrix scmat_[NSpinCases2];
376 
377  static ClassDesc class_desc_;
378  };
379 
380 #if 0
381  class WfnRDMOne : public RDM<One> {
384  typedef RDMCumulant<One> cumulant_type;
385  public:
398  WfnRDMOne(const Ref<KeyVal>& kv);
399  WfnRDMOne(StateIn& si);
400  WfnRDMOne(const Ref<Wavefunction>& wfn);
401  ~WfnRDMOne();
402  void save_data_state(StateOut& so);
403 
404  Ref<Wavefunction> wfn() const { return wfn_; }
405  void compute();
406  size_t ndim(SpinCase1 spincase) const;
407  const double* obtain_block(SpinCase1 spin, size_t bra) const;
408  void release_block(SpinCase1, size_t bra, double*) const;
409  RefSymmSCMatrix scmat(SpinCase1 spincase) const;
410  Ref<cumulant_type> cumulant() const;
411  Ref< RDM<Zero> > rdm_m_1() const;
412 
413  private:
414  Ref<Wavefunction> wfn_;
415  mutable RefSymmSCMatrix scmat_[NSpinCases1];
416 
417  static ClassDesc class_desc_;
418  };
419 
421  class WfnRDMCumulantOne : public RDMCumulant<One> {
422  public:
423  WfnRDMCumulantOne(const Ref<WfnRDMOne>& density);
424  WfnRDMCumulantOne(StateIn& si);
425  ~WfnRDMCumulantOne();
426  void save_data_state(StateOut& so);
427 
428  void compute();
429  const double* obtain_block(SpinCase1 spin, size_t bra) const;
430  void release_block(SpinCase1, size_t bra, double*) const;
431  RefSymmSCMatrix scmat(SpinCase1 spincase) const;
432 
433  private:
434  Ref<WfnRDMOne> density_;
435  mutable RefSymmSCMatrix scmat_[NSpinCases1];
436 
437  static ClassDesc class_desc_;
438  };
439 #endif
440 
442  class OBWfnRDMOne : public RDM<One> {
443  public:
456  OBWfnRDMOne(const Ref<KeyVal>& kv);
457  OBWfnRDMOne(StateIn& si);
459  virtual ~OBWfnRDMOne();
460  void save_data_state(StateOut& so);
461 
462  Ref<OneBodyWavefunction> wfn() const { return wfn_; }
463  Ref<OrbitalSpace> orbs(SpinCase1 s) const;
464 
465  private:
467  mutable Ref<OrbitalSpace> orbs_[NSpinCases1];
468 
469  static ClassDesc class_desc_;
470  };
471 
473  // end of addtogroup ChemistryElectronicStructure
474 
475 } // end of namespace sc
476 
477 #endif // end of header guard
478 
479 
480 // Local Variables:
481 // mode: c++
482 // c-file-style: "CLJ-CONDENSED"
483 // End:
sc::SpinFreeRDM::SpinFreeRDM
SpinFreeRDM(const Ref< KeyVal > &kv)
A KeyVal constructor is used to generate a SpinFreeRDM<R> object from the input.
Definition: rdm.h:242
sc::RDMCumulant::ndim
size_t ndim(spincase spincase) const
bra/ket dimension
Definition: rdm.h:189
sc::OBWfnRDMTwo::save_data_state
void save_data_state(StateOut &so)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
sc::SpinFreeRDM::release_block
virtual void release_block(spincase spin, size_t bra, double *) const
releases the ket block
Definition: rdm.h:281
sc::SpinFreeRDM::da4
virtual const Ref< DistArray4 > & da4() const
should only be used for R=2
sc::RDM::release_block
virtual void release_block(spincase spin, size_t bra, double *) const
releases the ket block
Definition: rdm.h:124
sc::RDMCumulant::density
Ref< density_type > density() const
the corresponding Density
Definition: rdm.h:187
sc::RDM::RDM
RDM(const Ref< KeyVal > &kv)
A KeyVal constructor is used to generate a RDM<R> object from the input.
Definition: rdm.h:85
sc::SpinFreeRDM::ndim
virtual size_t ndim() const
bra/ket dimension
sc::RefSymmSCMatrix
The RefSymmSCMatrix class is a smart pointer to an SCSymmSCMatrix specialization.
Definition: matrix.h:265
sc::RDM::rdm_m_1
virtual Ref< RDM< static_cast< Rank >R-1) > > rdm_m_1() const
RDM of rank decreased by 1.
sc::RDMCumulant::obsolete
void obsolete()
Marks all results as being out of date.
Definition: rdm.h:177
sc::Ref
A template class that maintains references counts.
Definition: ref.h:361
sc::OBWfnRDMTwo::OBWfnRDMTwo
OBWfnRDMTwo(const Ref< KeyVal > &kv)
A KeyVal constructor is used to generate a OBWfnRDMTwo object from the input.
sc::OBWfnRDMTwo::orbs
Ref< OrbitalSpace > orbs(SpinCase1 s) const
the orbital space of spincase s in which the density is reported
sc::OBWfnRDMOne::save_data_state
void save_data_state(StateOut &so)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
sc::RDM::wfn
Ref< Wavefunction > wfn() const
the corresponding Wavefunction
Definition: rdm.h:109
sc::SpinFreeRDM::obsolete
virtual void obsolete()
Marks all results as being out of date.
Definition: rdm.h:259
sc::RDMCumulant::wfn
Ref< Wavefunction > wfn() const
the corresponding Wavefunction
Definition: rdm.h:184
sc::RDMCumulant::obtain_block
virtual const double * obtain_block(spincase spin, size_t bra) const
returns the ket block for the given bra index
Definition: rdm.h:191
sc::OBWfnRDMCumulantTwo
OBWfnRDMCumulantTwo is the cumulant of OBWfnRDMTwo.
Definition: rdm.h:361
sc::OBWfnRDMTwo::cumulant
Ref< cumulant_type > cumulant() const
cumulant of rank R
sc::Ref::pointer
T * pointer() const
Returns a pointer the reference counted object.
Definition: ref.h:413
sc::OBWfnRDMOne::orbs
Ref< OrbitalSpace > orbs(SpinCase1 s) const
the orbital space of spincase s in which the density is reported
sc::RDM
RDM<R> is a reduced density matrix of rank R.
Definition: rdm.h:69
sc::RDMCumulant::release_block
virtual void release_block(spincase spin, size_t bra, double *) const
releases the ket block
Definition: rdm.h:197
sc::SpinFreeRDM::save_data_state
void save_data_state(StateOut &so)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
Definition: rdm.h:255
sc::RDMCumulant::scmat
virtual RefSymmSCMatrix scmat(spincase spin) const
full cumulant matrix
sc::StateIn
Definition: statein.h:79
sc::ClassDesc
This class is used to contain information about classes.
Definition: class.h:147
sc::SpinFreeRDM::scmat
virtual RefSymmSCMatrix scmat() const
full density matrix, can be used for RDM of any rank
sc::OrbitalSpace
Class OrbitalSpace describes a range of orbitals that are linear combinations of Gaussian basis funct...
Definition: orbitalspace.h:342
sc::RDM::compute
virtual void compute()
Recompute at least the results that have compute true and are not already computed.
Definition: rdm.h:110
sc::SavableState::restore_state
static SavableState * restore_state(StateIn &si)
Restores objects saved with save_state.
sc::RDM::obsolete
virtual void obsolete()
Marks all results as being out of date.
Definition: rdm.h:102
sc::OBWfnRDMOne
OBWfnRDMOne is a 1-RDM from a OneBodyWavefunction.
Definition: rdm.h:442
sc::Rank
Rank
Rank of the RDM.
Definition: rdm.h:39
sc::OBWfnRDMOne::OBWfnRDMOne
OBWfnRDMOne(const Ref< KeyVal > &kv)
A KeyVal constructor is used to generate a OBWfnRDMOne object from the input.
sc::SpinFreeRDM
SpinFreeRDM<R> is a spin-free reduced density matrix of rank R.
Definition: rdm.h:226
sc::OBWfnRDMCumulantTwo::save_data_state
void save_data_state(StateOut &so)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
sc::RDM::ndim
virtual size_t ndim(spincase spincase) const
bra/ket dimension
sc::StateOut
Definition: stateout.h:71
sc::SpinFreeRDM::rdm_m_1
virtual Ref< SpinFreeRDM< static_cast< Rank >R-1) > > rdm_m_1() const
RDM of rank decreased by 1.
sc::SpinFreeRDM::compute
virtual void compute()
Recompute at least the results that have compute true and are not already computed.
Definition: rdm.h:267
sc::RDMCumulant
RDMCumulant<R> is a reduced density matrix cumulant of rank R.
Definition: rdm.h:63
sc::RDMCumulant::compute
void compute()
Recompute at least the results that have compute true and are not already computed.
Definition: rdm.h:185
sc::Compute
The Compute class provides a means of keeping results up to date.
Definition: compute.h:51
sc::RDM::save_data_state
void save_data_state(StateOut &so)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
Definition: rdm.h:98
sc::SavableState::save_state
void save_state(StateOut &)
Save the state of the object as specified by the StateOut object.
sc::ProgrammingError
This is thrown when a situations arises that should be impossible.
Definition: scexception.h:92
sc::SpinFreeRDM::orbs
virtual Ref< OrbitalSpace > orbs() const =0
the orbital space of spincase s in which the density is reported
sc::RDM::scmat
virtual RefSymmSCMatrix scmat(spincase spin) const
full density matrix
sc::RDM::orbs
virtual Ref< OrbitalSpace > orbs(SpinCase1 s) const =0
the orbital space of spincase s in which the density is reported
sc::RDM::obtain_block
virtual const double * obtain_block(spincase spin, size_t bra) const
returns the ket block for the given bra index
Definition: rdm.h:118
sc::SpinFreeRDM::wfn
Ref< Wavefunction > wfn() const
the corresponding Wavefunction
Definition: rdm.h:266
sc::OBWfnRDMTwo::rdm_m_1
Ref< rdm_m_1_type > rdm_m_1() const
RDM of rank decreased by 1.
sc::RDM::cumulant
virtual Ref< RDMCumulant< R > > cumulant() const
cumulant of rank R
sc::SpinFreeRDM::obtain_block
virtual const double * obtain_block(spincase spin, size_t bra) const
returns the ket block for the given bra index
Definition: rdm.h:275
sc::SavableState
Base class for objects that can save/restore state.
Definition: state.h:45
sc::OBWfnRDMCumulantTwo::compute
void compute()
Recompute at least the results that have compute true and are not already computed.
sc::RefCount
The base class for all reference counted objects.
Definition: ref.h:192
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14
sc::RDMCumulant::save_data_state
void save_data_state(StateOut &so)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
Definition: rdm.h:174
sc::OBWfnRDMTwo
OBWfnRDMTwo is a 2-RDM from a OneBodyWavefunction.
Definition: rdm.h:324

Generated at Sun Jan 26 2020 23:24:00 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.