MPQC  3.0.0-alpha
psiwfn.h
1 //
2 // psiwfn.h
3 //
4 // Copyright (C) 2002 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 _chemistry_qc_psi_psiwfn_h
29 #define _chemistry_qc_psi_psiwfn_h
30 
31 #include <chemistry/qc/wfn/wfn.h>
32 #include <chemistry/qc/wfn/obwfn.h>
33 #include <chemistry/qc/psi/psiexenv.h>
34 #include <chemistry/qc/wfn/spin.h>
35 #include <chemistry/qc/wfn/orbitalspace.h>
36 #include <chemistry/qc/mbptr12/mbptr12.h>
37 
38 namespace sc {
39 
41 
46  class PsiWavefunction : public Wavefunction {
47 
48  Ref<PsiExEnv> exenv_;
50  int value_implemented() const {
51  return 1;
52  }
53 
54  protected:
55  Ref<PsiWavefunction> prerequisite_;
56  int nirrep_;
57  size_t memory_;
58  char *memory_str_;
59  bool compute_1rdm_;
60  char *dertype_;
62  virtual void write_input(int conv) =0;
63 
64  std::vector<unsigned int> read_occ(const Ref<KeyVal> &keyval, const char *name,
65  size_t nirrep);
66 
68  int debug() const;
69 
70  public:
93  ~PsiWavefunction();
94 
96 
99 
102  virtual void write_basic_input(int conv);
103  void compute();
104  void print(std::ostream&o=ExEnv::out0()) const;
105  int nirrep() const { return nirrep_; }
106 
107  virtual RefSymmSCMatrix density();
109  virtual RefSymmSCMatrix mo_density(SpinCase1 spin = AnySpinCase1) =0;
110 
113  return exenv_;
114  }
115 
118  return exenv_->get_psi_input();
119  }
120 
121 #if 0
122  std::vector< std::pair<unsigned int,unsigned int> > shell_map();
125  std::vector<unsigned int> ao_map();
126 #endif
127 
129  double nuclear_repulsion_energy();
130 
131  void obsolete();
132  void symmetry_changed();
133  };
134 
135  class PsiSCF;
136 
139 
141  protected:
142  Ref<PsiSCF> reference_;
143  unsigned int nfzc_;
144  unsigned int nfzv_;
145  mutable std::vector<unsigned int> frozen_docc_;
146  mutable std::vector<unsigned int> frozen_uocc_;
147  RefSymmSCMatrix mo_density_[NSpinCases1];
148 
149  void write_input(int conv);
150  // set fz2restr to use RESTRICTED instead of FROZEN keywords
151  void write_input_frozen2restricted(int conv, bool fz2restr);
152 
153  double valacc_to_refacc() const { return 100.0; }
154 
160  virtual std::vector<unsigned int> map_density_to_sb();
161 
162  public:
196  void save_data_state(StateOut&);
197 
198  void print(std::ostream& os) const;
199  double magnetic_moment() const;
201  void set_desired_value_accuracy(double acc);
202 
203  void compute(); // compute is overloaded because reference object needs to be marked computed
204  void obsolete();
205  void symmetry_changed();
208 
209  const Ref<PsiSCF>& reference() const;
211  int nelectron();
212 
213 #if 0 // these should be implemented in PsiCC classes
214  const Ref<OrbitalSpace>& occ_act_sb(SpinCase1);
217  const Ref<OrbitalSpace>& vir_act_sb(SpinCase1);
218 #endif
219  unsigned int nfzc() const;
222  unsigned int nfzv() const;
226  virtual const Ref<OrbitalSpace>& orbs_sb(SpinCase1 spin);
227 
229  const std::vector<unsigned int>& frozen_docc() const;
231  const std::vector<unsigned int>& frozen_uocc() const;
233  const std::vector<unsigned int> docc_act();
234  const std::vector<unsigned int> socc();
235  const std::vector<unsigned int> uocc_act();
236  const std::vector<unsigned int> docc();
237  const std::vector<unsigned int> uocc();
238 
240  virtual double reference_energy();
241 
243  RefSymmSCMatrix mo_density(SpinCase1 spin);
244 #if 0
245  RefSymmSCMatrix onepdm(const SpinCase1 &spin);
247  RefSymmSCMatrix onepdm();
250  RefSymmSCMatrix twopdm();
253  RefSymmSCMatrix twopdm_dirac_from_components();
254 #endif
255  RefSymmSCMatrix twopdm_dirac(const SpinCase2 &pairspin);
259  void print_onepdm_vec(FILE *output,const RefSCVector &opdm,double TOL);
260  void print_onepdm_mat(FILE *output,const RefSymmSCMatrix &opdm,double TOL);
261  void print_twopdm_mat(FILE *output,const RefSymmSCMatrix &tpdm, double TOL);
262  void print_twopdm_arr(FILE *output,double *tpdm,double TOL);
263  };
264 
265 
268 
269  class PsiSCF : public PsiWavefunction {
270  Ref<OrbitalSpace> orbs_sb_[NSpinCases1];
271  RefDiagSCMatrix evals_[NSpinCases1];
272  RefSCMatrix coefs_[NSpinCases1];
273  RefSymmSCMatrix mo_density_[NSpinCases1];
274  std::vector<unsigned int> occpi_[NSpinCases1];
275  std::vector<unsigned int> uoccpi_[NSpinCases1];
276  std::vector<unsigned int> mopi_;
277  std::vector<double> occupation_[NSpinCases1];
278  void compute_occupations(SpinCase1 spin);
279 
280  // PsiCorrWavefunction needs to be able to set value of PsiSCF
281  friend void PsiCorrWavefunction::compute();
282  protected:
283  std::vector<unsigned int> docc_;
284  std::vector<unsigned int> socc_;
285  int multp_;
286  int charge_;
287  int maxiter_;
288  double diisdamp_;
289  double levelshift_;
290  bool diis_;
291  static const int default_maxiter = 200;
293  static double guess_acc_ratio() { return 1e4; }
294 
297 
298  public:
313  PsiSCF(const Ref<KeyVal>&);
314  PsiSCF(StateIn&);
315  ~PsiSCF();
316  void save_data_state(StateOut&);
317 
318  double magnetic_moment() const;
319 
322  void import_occupations(const Ref<OneBodyWavefunction>& obwfn);
323  enum RefType {rhf, hsoshf, uhf};
325  virtual PsiSCF::RefType reftype() const =0;
327  virtual const RefDiagSCMatrix& evals(SpinCase1 spin = AnySpinCase1);
329  virtual const RefSCMatrix& coefs(SpinCase1 spin = AnySpinCase1);
331  const std::vector<unsigned int>& occpi(SpinCase1 S);
333  const std::vector<unsigned int>& uoccpi(SpinCase1 S);
335  const std::vector<unsigned int>& mopi();
337  const Ref<OrbitalSpace>& orbs_sb(SpinCase1 spin);
339  int nelectron();
341  double occupation(int mo);
343  double alpha_occupation(int mo);
345  double beta_occupation(int mo);
346 
352 
354  RefSymmSCMatrix ao_density(SpinCase1);
357  RefSymmSCMatrix mo_density(SpinCase1 spin = AnySpinCase1);
358 
360  unsigned int nmo();
362  unsigned int nocc(SpinCase1 spin);
364  unsigned int multiplicity() const { return multp_; }
365 
366  void obsolete();
367  void symmetry_changed();
368  };
369 
372 
373  class PsiCLHF : public PsiSCF {
374  protected:
375  void write_input(int conv);
376  public:
377  PsiCLHF(const Ref<KeyVal>&);
378  PsiCLHF(StateIn&);
379  ~PsiCLHF();
380  void print(std::ostream& os = ExEnv::out0()) const;
381 
382  void write_basic_input(int conv);
384  return true;
385  }
386  PsiSCF::RefType reftype() const {
387  return rhf;
388  }
389  };
390 
393 
394  class PsiHSOSHF : public PsiSCF {
395  protected:
396  void write_input(int conv);
397  public:
398  PsiHSOSHF(const Ref<KeyVal>&);
399  PsiHSOSHF(StateIn&);
400  ~PsiHSOSHF();
401  void print(std::ostream& os = ExEnv::out0()) const;
402 
403  void write_basic_input(int conv);
405  return true;
406  }
407  PsiSCF::RefType reftype() const {
408  return hsoshf;
409  }
410 
412  const RefSCMatrix& coefs_semicanonical(SpinCase1 s);
414  const RefDiagSCMatrix& evals_semicanonical(SpinCase1 s);
415 
416  private:
417  RefSCMatrix coefs_sc_[NSpinCases1];
418  RefDiagSCMatrix evals_sc_[NSpinCases1];
419 
421  void semicanonical();
422 
423  void obsolete();
424  };
425 
428 
429  class PsiUHF : public PsiSCF {
430  protected:
431  void write_input(int conv);
432  public:
433  PsiUHF(const Ref<KeyVal>&);
434  PsiUHF(StateIn&);
435  ~PsiUHF();
436  void print(std::ostream& os = ExEnv::out0()) const;
437 
438  void write_basic_input(int conv);
440  return true;
441  }
442  PsiSCF::RefType reftype() const {
443  return uhf;
444  }
445  };
446 
447  namespace detail {
456  RefSymmSCMatrix rdopdm(SpinCase1 spin,
457  const std::vector<unsigned int>& mopi,
458  const std::vector<unsigned int>& dmap,
459  Ref<SCMatrixKit> kit = 0);
464  RefSymmSCMatrix rdtpdm(SpinCase2 pairspin,
465  const std::vector<unsigned int>& dmap,
466  bool spinfree = false,
467  Ref<SCMatrixKit> kit = 0);
468  }
469 }
470 #endif
sc::PsiCLHF::write_basic_input
void write_basic_input(int conv)
Writes out Psi input file entries specific to this PsiWavefunction.
sc::PsiSCF::multiplicity
unsigned int multiplicity() const
spin multiplicity
Definition: psiwfn.h:364
sc::PsiCLHF::print
void print(std::ostream &os=ExEnv::out0()) const
Print information about the object.
sc::PsiCorrWavefunction::nfzc
unsigned int nfzc() const
total # of frozen doubly-occupied orbitals
sc::PsiHSOSHF::print
void print(std::ostream &os=ExEnv::out0()) const
Print information about the object.
sc::PsiHSOSHF::write_input
void write_input(int conv)
Prepares a complete Psi input file. The input file is assumed to have been opened.
sc::PsiSCF::uoccpi
const std::vector< unsigned int > & uoccpi(SpinCase1 S)
Number of unoccupied orbitals of spin S per irrep.
sc::PsiWavefunction::PsiWavefunction
PsiWavefunction(const Ref< KeyVal > &)
The KeyVal constructor.
sc::PsiHSOSHF::coefs_semicanonical
const RefSCMatrix & coefs_semicanonical(SpinCase1 s)
returns the semicanonical MO coefficients in AO basis
sc::PsiSCF::save_data_state
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
sc::PsiHSOSHF::evals_semicanonical
const RefDiagSCMatrix & evals_semicanonical(SpinCase1 s)
returns the eigenvalues of semicanonical MOs in AO basis
sc::RefSymmSCMatrix
The RefSymmSCMatrix class is a smart pointer to an SCSymmSCMatrix specialization.
Definition: matrix.h:265
sc::PsiWavefunction::obsolete
void obsolete()
Marks all results as being out of date.
sc::PsiCorrWavefunction::set_desired_value_accuracy
void set_desired_value_accuracy(double acc)
sets the desired value accuracy
sc::PsiSCF::guess_wfn_
Ref< OneBodyWavefunction > guess_wfn_
guess wave function is only used to get the occupations
Definition: psiwfn.h:296
sc::RefSCMatrix
The RefSCMatrix class is a smart pointer to an SCMatrix specialization.
Definition: matrix.h:135
sc::Ref
A template class that maintains references counts.
Definition: ref.h:361
sc::PsiUHF::write_input
void write_input(int conv)
Prepares a complete Psi input file. The input file is assumed to have been opened.
sc::PsiCorrWavefunction::docc_act
const std::vector< unsigned int > docc_act()
sc::PsiSCF::beta_occupation
double beta_occupation(int mo)
Returns the occupation for beta orbitals.
sc::PsiCorrWavefunction::frozen_docc
const std::vector< unsigned int > & frozen_docc() const
sc::PsiUHF::reftype
PsiSCF::RefType reftype() const
Returns the PsiSCF::RefType of this particular Psi SCF wave function.
Definition: psiwfn.h:442
sc::PsiCorrWavefunction::map_density_to_sb
virtual std::vector< unsigned int > map_density_to_sb()
returns the index map that transforms indices in which densities are reported in Psi to the symmetry-...
sc::PsiHSOSHF::analytic_gradient_implemented
bool analytic_gradient_implemented() const
must overload this in a derived class if analytic gradient can be computed
Definition: psiwfn.h:404
sc::PsiCorrWavefunction::PsiCorrWavefunction
PsiCorrWavefunction(const Ref< KeyVal > &)
A KeyVal constructor is used to generate a PsiCorrWavefunction object from the input.
sc::PsiWavefunction
PsiWavefunction is an abstract base for all Psi wave functions.
Definition: psiwfn.h:46
sc::PsiSCF::density
RefSymmSCMatrix density()
Returns the SO density.
sc::PsiSCF::magnetic_moment
double magnetic_moment() const
Computes the S (or J) magnetic moment of the target state(s), in units of .
sc::PsiWavefunction::symmetry_changed
void symmetry_changed()
Call this if you have changed the molecular symmetry of the molecule contained by this MolecularEnerg...
sc::PsiSCF::occpi
const std::vector< unsigned int > & occpi(SpinCase1 S)
Number of occupied orbitals of spin S per irrep.
sc::Integral::CartesianOrdering
CartesianOrdering
Describes the ordering of the cartesian functions in a shell.
Definition: integral.h:175
sc::PsiCorrWavefunction::orbs_sb
virtual const Ref< OrbitalSpace > & orbs_sb(SpinCase1 spin)
symmetry-blocked space of MO's from Psi3 the default implementation returns the orbitals from referen...
sc::Wavefunction
A Wavefunction is a MolecularEnergy that utilizies a GaussianBasisSet.
Definition: wfn.h:52
sc::PsiSCF::beta_density
RefSymmSCMatrix beta_density()
Return beta electron densities in the SO basis.
sc::RefDiagSCMatrix
The RefDiagSCMatrix class is a smart pointer to an DiagSCMatrix specialization.
Definition: matrix.h:389
sc::PsiHSOSHF
PsiHSOSHF is a concrete implementation of Psi ROHF wave function.
Definition: psiwfn.h:394
sc::PsiCorrWavefunction::reference_energy
virtual double reference_energy()
reference energy
sc::PsiSCF::mopi
const std::vector< unsigned int > & mopi()
Number of orbitals per irrep.
sc::PsiCorrWavefunction::compute
void compute()
Recompute at least the results that have compute true and are not already computed.
sc::StateIn
Definition: statein.h:79
sc::PsiWavefunction::cartesian_ordering
static Integral::CartesianOrdering cartesian_ordering()
returns the Psi3 convention for the ordering of the cartesian functions
sc::PsiCorrWavefunction::nelectron
int nelectron()
Number of electrons.
sc::PsiSCF::nelectron
int nelectron()
Number of electrons.
sc::PsiSCF::mo_density
RefSymmSCMatrix mo_density(SpinCase1 spin=AnySpinCase1)
MO-basis density.
sc::PsiSCF::guess_acc_ratio
static double guess_acc_ratio()
how much lower is the desired accuracy of the guess?
Definition: psiwfn.h:293
sc::PsiSCF::obsolete
void obsolete()
Marks all results as being out of date.
sc::PsiUHF
PsiUHF is a concrete implementation of Psi UHF wave function.
Definition: psiwfn.h:429
sc::PsiWavefunction::mo_density
virtual RefSymmSCMatrix mo_density(SpinCase1 spin=AnySpinCase1)=0
Returns the MO basis density (blocked by symmetry)
sc::PsiSCF::coefs
virtual const RefSCMatrix & coefs(SpinCase1 spin=AnySpinCase1)
Returns the coefficient matrix in AO basis.
sc::PsiSCF
PsiSCF is an abstract base for all Psi SCF wave functions.
Definition: psiwfn.h:269
sc::PsiUHF::print
void print(std::ostream &os=ExEnv::out0()) const
Print information about the object.
sc::PsiCorrWavefunction::frozen_uocc
const std::vector< unsigned int > & frozen_uocc() const
sc::PsiCorrWavefunction::symmetry_changed
void symmetry_changed()
Call this if you have changed the molecular symmetry of the molecule contained by this MolecularEnerg...
sc::PsiWavefunction::print
void print(std::ostream &o=ExEnv::out0()) const
Print information about the object.
sc::PsiCorrWavefunction::twopdm_dirac
RefSymmSCMatrix twopdm_dirac()
produces spin-free 2-RDM
sc::PsiHSOSHF::reftype
PsiSCF::RefType reftype() const
Returns the PsiSCF::RefType of this particular Psi SCF wave function.
Definition: psiwfn.h:407
sc::PsiCLHF::analytic_gradient_implemented
bool analytic_gradient_implemented() const
must overload this in a derived class if analytic gradient can be computed
Definition: psiwfn.h:383
sc::PsiUHF::write_basic_input
void write_basic_input(int conv)
Writes out Psi input file entries specific to this PsiWavefunction.
sc::PsiSCF::symmetry_changed
void symmetry_changed()
Call this if you have changed the molecular symmetry of the molecule contained by this MolecularEnerg...
sc::RefSCVector
The RefSCVector class is a smart pointer to an SCVector specialization.
Definition: matrix.h:55
sc::PsiCorrWavefunction::mo_density
RefSymmSCMatrix mo_density(SpinCase1 spin)
return one-particel density matrix in symmetry-blocked orbitals
sc::StateOut
Definition: stateout.h:71
sc::PsiWavefunction::nuclear_repulsion_energy
double nuclear_repulsion_energy()
return Psi3 nuclear repulsion energy
sc::PsiCLHF::reftype
PsiSCF::RefType reftype() const
Returns the PsiSCF::RefType of this particular Psi SCF wave function.
Definition: psiwfn.h:386
sc::PsiWavefunction::write_basic_input
virtual void write_basic_input(int conv)
Writes out Psi input file entries specific to this PsiWavefunction.
sc::PsiWavefunction::save_data_state
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
sc::PsiCorrWavefunction::print
void print(std::ostream &os) const
Print information about the object.
sc::PsiCorrWavefunction::nfzv
unsigned int nfzv() const
total # of frozen unoccupied orbitals
sc::PsiSCF::nmo
unsigned int nmo()
number of MOs
sc::ExEnv::out0
static std::ostream & out0()
Return an ostream that writes from node 0.
sc::PsiCorrWavefunction::obsolete
void obsolete()
Marks all results as being out of date.
sc::PsiCLHF
PsiCLHF is a concrete implementation of Psi RHF wave function.
Definition: psiwfn.h:373
sc::PsiHSOSHF::write_basic_input
void write_basic_input(int conv)
Writes out Psi input file entries specific to this PsiWavefunction.
sc::PsiUHF::analytic_gradient_implemented
bool analytic_gradient_implemented() const
must overload this in a derived class if analytic gradient can be computed
Definition: psiwfn.h:439
sc::PsiSCF::evals
virtual const RefDiagSCMatrix & evals(SpinCase1 spin=AnySpinCase1)
Returns the eigenvalues matrix.
sc::PsiWavefunction::compute
void compute()
Recompute at least the results that have compute true and are not already computed.
sc::PsiSCF::orbs_sb
const Ref< OrbitalSpace > & orbs_sb(SpinCase1 spin)
symmetry-blocked space
sc::PsiSCF::ao_density
RefSymmSCMatrix ao_density()
Returns the AO density.
sc::PsiSCF::nocc
unsigned int nocc(SpinCase1 spin)
number of occupied MOs of spin
sc::PsiSCF::occupation
double occupation(int mo)
Returns the total occupation for orbital mo.
sc::PsiWavefunction::debug
int debug() const
return the debug level
sc::PsiWavefunction::get_psi_input
Ref< PsiInput > get_psi_input() const
Return an associated PsiInput object.
Definition: psiwfn.h:117
sc::PsiWavefunction::exenv
Ref< PsiExEnv > exenv() const
Return an associated PsiExEnv object.
Definition: psiwfn.h:112
sc::PsiCorrWavefunction
PsiCorrWavefunction is a Psi correlated wave function.
Definition: psiwfn.h:140
sc::PsiWavefunction::density
virtual RefSymmSCMatrix density()
Returns the SO density.
sc::PsiSCF::alpha_density
RefSymmSCMatrix alpha_density()
Return alpha electron densities in the SO basis.
sc::PsiCorrWavefunction::density
RefSymmSCMatrix density()
reimplementation of PsiWavefunction::density()
sc::PsiSCF::import_occupations
void import_occupations(const Ref< OneBodyWavefunction > &obwfn)
imports occupations from obwfn.
sc::PsiCorrWavefunction::save_data_state
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14
sc::PsiCLHF::write_input
void write_input(int conv)
Prepares a complete Psi input file. The input file is assumed to have been opened.
sc::PsiCorrWavefunction::magnetic_moment
double magnetic_moment() const
Computes the S (or J) magnetic moment of the target state(s), in units of .
sc::PsiSCF::reftype
virtual PsiSCF::RefType reftype() const =0
Returns the PsiSCF::RefType of this particular Psi SCF wave function.
sc::PsiSCF::PsiSCF
PsiSCF(const Ref< KeyVal > &)
The KeyVal constructor uses all keywords of PsiWavefunction class and the following additional keywor...
sc::PsiCorrWavefunction::write_input
void write_input(int conv)
Prepares a complete Psi input file. The input file is assumed to have been opened.
sc::PsiSCF::alpha_occupation
double alpha_occupation(int mo)
Returns the occupation for alpha orbitals.
sc::PsiWavefunction::write_input
virtual void write_input(int conv)=0
Prepares a complete Psi input file. The input file is assumed to have been opened.

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