MPQC  3.0.0-alpha
pt2r12.h
1 //
2 // pt2r12.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_pt2r12_h
29 #define _mpqc_src_lib_chemistry_qc_mbptr12_pt2r12_h
30 
31 #include <chemistry/qc/wfn/wfn.h>
32 #include <chemistry/qc/wfn/spin.h>
33 #include <chemistry/qc/mbptr12/r12wfnworld.h>
34 #include <chemistry/qc/mbptr12/r12int_eval.h>
35 #include <chemistry/qc/wfn/rdm.h>
36 
37 
38 #if defined(MPQC_NEW_FEATURES)
39 #include <chemistry/qc/mbptr12/sr_r12intermediates.h>
40 #include <chemistry/qc/mbptr12/singles_casscf.h>
41 #endif
42 
43 namespace sc {
44 
47  public:
75  SpinOrbitalPT2R12(const Ref<KeyVal> &keyval);
78  void save_data_state(StateOut &s);
79 
80  void compute();
81  void print(std::ostream& os =ExEnv::out0()) const;
83  double magnetic_moment() const;
84  int value_implemented() const { return 1; }
85  void set_desired_value_accuracy(double acc);
86 
88  const Ref<R12WavefunctionWorld>& r12world() const { return r12world_; }
89  Ref<R12IntEval>& get_r12eval() {return r12eval_;}
90  RefSCMatrix transform_MO(); // when using screening, we rotate (occ_act) orbitals; row: new orbs, col: old MO
91  // new orbs differ from old orbs in that the occ_act part is rotated to natural orbs.
92  // this is used to get RDM in new orbitals spaces so that later on the orbital space comparison with ggspace()
93  // can be done (since ggspace etc already use rotated and screened orbitals).
94 
95  void obsolete();
96  int nelectron();
97  static double zero_occupancy() { return sc::PopulatedOrbitalSpace::zero_occupancy(); }
98 
99  private:
100  enum Tensor4_Permute {Permute23 =1, Permute34 = 2, Permute14 = 3};
101  static double ref_to_pt2r12_acc() { return 0.01; }
102 
103  Ref< RDM<Two> > rdm2_;
104  Ref< RDM<One> > rdm1_;
105  Ref<R12IntEval> r12eval_;
106  Ref<R12WavefunctionWorld> r12world_;
107 
108  unsigned int nfzc_;
109  bool omit_uocc_;
110  bool pt2_correction_; // for testing purposes only, set to false to skip the [2]_R12 computation
111  bool cabs_singles_;
112  std::string cabs_singles_h0_; // specify zeroth order H; options: 'fock',
113  // 'dyall'
114  bool cabs_singles_coupling_; // if set to true, we include the coupling between cabs and OBS virtual orbitals. This should be preferred choice,
115  // as explained in the paper.
116  bool rotate_core_; // if set to false, when doing rasscf cabs_singles correction, don't include excitation from core orbitals to cabs orbitals in
117  // first-order Hamiltonian. (this may be used when using frozen core orbitals which
118  // are not optimized (does not satisfy Brillouin condition)). Currently, we suggest set it to 'true'
119  int debug_;
120  std::vector<double> B_;
121  std::vector<double> X_;
122  std::vector<double> V_; // store the values for different spins
123 
125  RefSymmSCMatrix rdm1(SpinCase1 spin);
127  RefSymmSCMatrix rdm2(SpinCase2 spin);
129  RefSymmSCMatrix lambda2(SpinCase2 spin);
131  RefSymmSCMatrix rdm1_gg(SpinCase1 spin);
133  RefSymmSCMatrix rdm2_gg(SpinCase2 spin);
135  RefSymmSCMatrix lambda2_gg(SpinCase2 spin);
136  // the above 2 functions are implemented using this function
137  RefSymmSCMatrix _rdm2_to_gg(SpinCase2 spin,
138  RefSymmSCMatrix input);
139 
141  RefSCMatrix C(SpinCase2 S);
142 
143  RefSCMatrix V_genref_projector2(SpinCase2 pairspin);
144  RefSCMatrix V_transformed_by_C(SpinCase2 pairspin);
145  RefSymmSCMatrix X_transformed_by_C(SpinCase2 pairspin);
146  RefSymmSCMatrix B_transformed_by_C(SpinCase2 pairspin);
148  double compute_DC_energy_GenRefansatz2();
149 
151  double energy_PT2R12_projector1(SpinCase2 pairspin);
152  double energy_PT2R12_projector2(SpinCase2 pairspin);
153 
155  template<Tensor4_Permute HowPermute>
156  RefSCMatrix RefSCMAT4_permu(RefSCMatrix rdm2_4space_int,
157  const Ref<OrbitalSpace> b1space,
158  const Ref<OrbitalSpace> b2space,
159  const Ref<OrbitalSpace> k1space,
160  const Ref<OrbitalSpace> k2space);
161 
162 
163 
165  double cabs_singles_Fock(SpinCase1 spin);
167  double cabs_singles_Dyall();
168 
170  RefSymmSCMatrix hcore_mo();
171  RefSymmSCMatrix hcore_mo(SpinCase1 spin);
173  RefSCMatrix moints(SpinCase2 pairspin = AlphaBeta);
175  RefSCMatrix g(SpinCase2 pairspin,
176  const Ref<OrbitalSpace>& space1,
177  const Ref<OrbitalSpace>& space2);
179  RefSCMatrix g(SpinCase2 pairspin,
180  const Ref<OrbitalSpace>& bra1,
181  const Ref<OrbitalSpace>& bra2,
182  const Ref<OrbitalSpace>& ket1,
183  const Ref<OrbitalSpace>& ket2);
187  RefSCMatrix f(SpinCase1 spin);
188 
189  /*
190  * phi truncated in lambda: terms with three-particle lambda's or higher or terms with
191  * squares (or higher) of two-particle lambda's are neglected.
192  * this version does not uses the 2-body cumulant (2-lambda).
193  *
194  * phi is reported in the same space as given by rdm2()
195  */
196  RefSymmSCMatrix phi_cumulant(SpinCase2 pairspin);
198  RefSymmSCMatrix phi_gg(SpinCase2 spin);
199 
201  double energy_recomputed_from_densities();
202 
204  void brillouin_matrix();
205 
210  double compute_energy(const RefSCMatrix &hmat,
211  SpinCase2 pairspin,
212  bool print_pair_energies = true,
213  std::ostream& os = ExEnv::out0());
214 
215  };
216 
218  class PT2R12 : public Wavefunction {
219  public:
251  PT2R12(const Ref<KeyVal> &keyval);
252  PT2R12(StateIn &s);
253  ~PT2R12();
254  void save_data_state(StateOut &s);
255 
256  void compute();
257  void print(std::ostream& os =ExEnv::out0()) const;
259  double magnetic_moment() const;
260  int value_implemented() const { return 1; }
261  void set_desired_value_accuracy(double acc);
262 
264  const Ref<R12WavefunctionWorld>& r12world() const { return r12world_; }
265  Ref<R12IntEval>& get_r12eval() {return r12eval_;}
266  RefSCMatrix transform_MO(); // when using screening, we rotate (occ_act) orbitals; row: new orbs, col: old MO
267  // new orbs differ from old orbs in that the occ_act part is rotated to natural orbs.
268  // this is used to get RDM in new orbitals spaces so that later on the orbital space comparison with ggspace()
269  // can be done (since ggspace etc already use rotated and screened orbitals).
270 
271  void obsolete();
272  int nelectron();
273  static double zero_occupancy() { return sc::PopulatedOrbitalSpace::zero_occupancy(); }
274 
275  private:
276  enum Tensor4_Permute {Permute23 =1, Permute34 = 2, Permute14 = 3};
277  static double ref_to_pt2r12_acc() { return 0.01; }
278 
279  Ref< SpinFreeRDM<Two> > rdm2_;
280  Ref< SpinFreeRDM<One> > rdm1_;
281  Ref<R12IntEval> r12eval_;
282  Ref<R12WavefunctionWorld> r12world_;
283  unsigned int nfzc_;
284  bool omit_uocc_;
285  bool pt2_correction_; // for testing purposes only, set to false to skip the [2]_R12 computation
286 
287 #if defined(MPQC_NEW_FEATURES)
288  bool cabs_singles_;
289  std::string cabs_singles_h0_; // specify zeroth order H; options: 'CI'
290  // 'dyall_1', 'dyall_2', 'complete'; '1' and '2'
291  // in dyall_sf options
292  // represent whether use 1-body Fock or including 2-b op
293  // in H(1).
294  bool cabs_singles_coupling_; // if set to true, we include the coupling between cabs and OBS virtual orbitals. This should be preferred choice,
295  // as explained in the paper.
296  std::shared_ptr<CabsSingles> cabs_singles_engine_;
297 #endif
298  bool rotate_core_; // if set to false, when doing rasscf cabs_singles correction, don't include excitation from core orbitals to cabs orbitals in
299  // first-order Hamiltonian. (this may be used when using frozen core orbitals which
300  // are not optimized (does not satisfy Brillouin condition)). Currently, we suggest set it to 'true'
301  int debug_;
302  std::vector<double> B_;
303  std::vector<double> X_;
304  std::vector<double> V_; // store the values for different spins
305 
306 
307 
308 
310  RefSymmSCMatrix rdm1();
312  RefSymmSCMatrix rdm2();
314  RefSymmSCMatrix rdm1_gg();
316  RefSymmSCMatrix rdm2_gg();
317  // the above 2 functions are implemented using this function
318  RefSymmSCMatrix _rdm2_to_gg(RefSymmSCMatrix input);
319 
321  RefSCMatrix C();
322 
324  double compute_DC_energy_GenRefansatz2();
325 
327  double energy_PT2R12_projector2();
328  RefSCMatrix V_genref_projector2();
330  RefSCMatrix X_term_Gamma_F_T();
331  RefSymmSCMatrix X_transformed_by_C();
332  RefSCMatrix B_others();
333 
334  // TODO reimplement using native spin-free densities from Psi3
335  RefSCMatrix rdm1_gg_sf(); // return spin-free 1/2 rdm
336  RefSymmSCMatrix rdm1_sf();
337  RefSymmSCMatrix rdm1_sf_transform();
338  RefSCMatrix rdm1_sf_2spaces(const Ref<OrbitalSpace> bspace, const Ref<OrbitalSpace> kspace);
339 
340  RefSymmSCMatrix rdm2_sf();
341  // return 2-RDM in certain spaces; all the spaces should be subsets of 1-RDM/2-RDM orbital space
342  RefSCMatrix rdm2_sf_4spaces(const Ref<OrbitalSpace> b1space, const Ref<OrbitalSpace> b2space, const Ref<OrbitalSpace> k1space, const Ref<OrbitalSpace> k2space);
344  RefSCMatrix rdm2_sf_4spaces_int(const double a, const double b, double const c,
345  const Ref<OrbitalSpace> b1space,
346  const Ref<OrbitalSpace> b2space,
347  const Ref<OrbitalSpace> k1space,
348  const Ref<OrbitalSpace> k2space);
349 
351  template<Tensor4_Permute HowPermute>
352  RefSCMatrix RefSCMAT4_permu(RefSCMatrix rdm2_4space_int,
353  const Ref<OrbitalSpace> b1space,
354  const Ref<OrbitalSpace> b2space,
355  const Ref<OrbitalSpace> k1space,
356  const Ref<OrbitalSpace> k2space);
357 
358 
360  RefSymmSCMatrix hcore_mo();
362  RefSCMatrix moints();
364  RefSCMatrix g(const Ref<OrbitalSpace>& space1,
365  const Ref<OrbitalSpace>& space2);
367  RefSCMatrix g(const Ref<OrbitalSpace>& bra1,
368  const Ref<OrbitalSpace>& bra2,
369  const Ref<OrbitalSpace>& ket1,
370  const Ref<OrbitalSpace>& ket2);
374  RefSCMatrix f();
375 
377  double energy_recomputed_from_densities();
378 
380  void brillouin_matrix();
381 
385  double compute_energy(const RefSCMatrix &hmat,
386  bool print_pair_energies = true,
387  std::ostream& os = ExEnv::out0());
388 
389 
391  std::pair<double,double> energy_PT2R12_projector2_mpqc3();
392 #if defined(MPQC_NEW_FEATURES)
393  // r12 intermediates are computed by this engine
394  std::shared_ptr< SingleReference_R12Intermediates<double> > srr12intrmds_;
395 
397  void bootup_mpqc3();
399  void shutdown_mpqc3();
400 
402  auto _Tg(const std::string& key) -> decltype(srr12intrmds_->_Tg(key)) {
403  return srr12intrmds_->_Tg(key);
404  }
405  auto _4(const std::string& key) -> decltype(srr12intrmds_->_4(key)) {
406  return srr12intrmds_->_4(key);
407  }
408  auto _2(const std::string& key) -> decltype(srr12intrmds_->_2(key)) {
409  return srr12intrmds_->_2(key);
410  }
411  auto V_sf(bool b) -> decltype(srr12intrmds_->V_spinfree(b)) {
412  return srr12intrmds_->V_spinfree(b);
413  }
414  auto X_sf(bool b) -> decltype(srr12intrmds_->X_spinfree(b)) {
415  return srr12intrmds_->X_spinfree(b);
416  }
417  auto B_sf(bool b) -> decltype(srr12intrmds_->B_spinfree(b)) {
418  return srr12intrmds_->B_spinfree(b);
419  }
420 
422  SingleReference_R12Intermediates<double>::TArray4d __4(const std::string& key) {
424 
425  ParsedTwoBodyFourCenterIntKey pkey(key);
426  const std::string annotation = pkey.bra1() + "," + pkey.bra2() + "," + pkey.ket1() + "," + pkey.ket2();
427 
428  return srr12intrmds_->ijxy(key);
429  }
430 
432  SingleReference_R12Intermediates<double>::TArray2 __2(const std::string& key) {
434 
435  ParsedOneBodyIntKey pkey(key);
436  const std::string annotation = pkey.bra() + "," + pkey.ket();
437 
438  return srr12intrmds_->xy(key);
439  }
440 
441 
442 #endif
443 
444  };
445 
446 
447 } // end of namespace sc
448 
449 #endif // end of header guard
450 
451 
452 // Local Variables:
453 // mode: c++
454 // c-file-style: "CLJ-CONDENSED"
455 // End:
sc::PT2R12::PT2R12
PT2R12(const Ref< KeyVal > &keyval)
A KeyVal constructor is used to generate a PT2R12 object from the input.
sc::PT2R12::density
RefSymmSCMatrix density()
Returns the SO density.
sc::PT2R12
PT2R12: a universal spin-free second-order R12 correction.
Definition: pt2r12.h:218
sc::RefSymmSCMatrix
The RefSymmSCMatrix class is a smart pointer to an SCSymmSCMatrix specialization.
Definition: matrix.h:265
sc::SpinOrbitalPT2R12::r12world
const Ref< R12WavefunctionWorld > & r12world() const
SpinOrbitalPT2R12 is an R12 Wavefunction.
Definition: pt2r12.h:88
sc::SpinOrbitalPT2R12::compute
void compute()
Recompute at least the results that have compute true and are not already computed.
sc::Ref
A template class that maintains references counts.
Definition: ref.h:361
sc::SpinOrbitalPT2R12
SpinOrbitalPT2R12: a universal second-order R12 correction.
Definition: pt2r12.h:46
sc::SingleReference_R12Intermediates::TArray4d
TA::Array< T, 4, DA4_Tile< T > > TArray4d
4-index tensor with lazy tiles
Definition: sr_r12intermediates.h:224
sc::SpinOrbitalPT2R12::magnetic_moment
double magnetic_moment() const
Computes the S (or J) magnetic moment of the target state(s), in units of .
sc::Wavefunction
A Wavefunction is a MolecularEnergy that utilizies a GaussianBasisSet.
Definition: wfn.h:52
sc::PopulatedOrbitalSpace::zero_occupancy
static double zero_occupancy()
an orbital is occupied if its occupancy is greater than this
Definition: ref.h:80
sc::SingleReference_R12Intermediates::TArray2
TA::Array< T, 2 > TArray2
standard 2-index tensor
Definition: sr_r12intermediates.h:226
sc::SpinOrbitalPT2R12::value_implemented
int value_implemented() const
Definition: pt2r12.h:84
sc::PT2R12::r12world
const Ref< R12WavefunctionWorld > & r12world() const
PT2R12 is an R12 Wavefunction.
Definition: pt2r12.h:264
sc::StateIn
Definition: statein.h:79
sc::PT2R12::magnetic_moment
double magnetic_moment() const
Computes the S (or J) magnetic moment of the target state(s), in units of .
sc::SpinOrbitalPT2R12::set_desired_value_accuracy
void set_desired_value_accuracy(double acc)
Set the accuracy to which the value is to be computed.
sc::SpinOrbitalPT2R12::obsolete
void obsolete()
Marks all results as being out of date.
sc::SpinOrbitalPT2R12::save_data_state
void save_data_state(StateOut &s)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
sc::PT2R12::nelectron
int nelectron()
Returns the number of electrons.
sc::PT2R12::obsolete
void obsolete()
Marks all results as being out of date.
sc::PT2R12::print
void print(std::ostream &os=ExEnv::out0()) const
Print information about the object.
sc::StateOut
Definition: stateout.h:71
sc::PT2R12::set_desired_value_accuracy
void set_desired_value_accuracy(double acc)
Set the accuracy to which the value is to be computed.
sc::SpinOrbitalPT2R12::nelectron
int nelectron()
Returns the number of electrons.
sc::SpinOrbitalPT2R12::SpinOrbitalPT2R12
SpinOrbitalPT2R12(const Ref< KeyVal > &keyval)
A KeyVal constructor is used to generate a SpinOrbitalPT2R12 object from the input.
sc::PT2R12::save_data_state
void save_data_state(StateOut &s)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
sc::SpinOrbitalPT2R12::print
void print(std::ostream &os=ExEnv::out0()) const
Print information about the object.
sc::ExEnv::out0
static std::ostream & out0()
Return an ostream that writes from node 0.
sc::PT2R12::value_implemented
int value_implemented() const
Definition: pt2r12.h:260
sc::PT2R12::compute
void compute()
Recompute at least the results that have compute true and are not already computed.
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14
sc::SpinOrbitalPT2R12::density
RefSymmSCMatrix density()
Returns the SO density.

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