Psi4
wavefunction.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 _psi_src_lib_libmints_wavefunction_h
30 #define _psi_src_lib_libmints_wavefunction_h
31 
32 #include "typedefs.h"
35 
36 #include <stddef.h>
37 #include <vector>
38 #include <array>
39 #include <memory>
40 #include <map>
41 
42 #define MAX_IOFF 30000
43 extern size_t ioff[MAX_IOFF];
44 
45 #define MAX_DF 500
46 extern double df[MAX_DF];
47 
48 #define MAX_BC 20
49 extern double bc[MAX_BC][MAX_BC];
50 
51 #define MAX_FAC 100
52 extern double fac[MAX_FAC];
53 
54 #if !defined( EXPLICIT_IOFF )
55 # define EXPLICIT_IOFF(i) ( (i) * ((i) + 1) / 2 )
56 #endif
57 
58 #if !defined( INDEX2 )
59 # define INDEX2(i, j) ( (i) >= (j) ? EXPLICIT_IOFF(i) + (j) : EXPLICIT_IOFF(j) + (i) )
60 #endif
61 
62 #if !defined( INDEX4 )
63 # define INDEX4(i, j, k, l) ( INDEX2( INDEX2((i), (j)), INDEX2((k), (l)) ) )
64 #endif
65 
66 
67 namespace psi {
68 
69 class Molecule;
70 class BasisSet;
71 class IntegralFactory;
72 class Matrix;
73 class Vector;
74 class MatrixFactory;
75 class Options;
76 class SOBasisSet;
77 class PSIO;
78 class OrbitalSpace;
79 class ExternalPotential;
80 
85 class PSI_API Wavefunction : public std::enable_shared_from_this<Wavefunction>
86 {
87 protected:
89  std::string name_;
90 
92  std::map<std::string, std::shared_ptr<BasisSet>> basissets_;
93 
95  std::shared_ptr<BasisSet> basisset_;
96 
98  std::shared_ptr<SOBasisSet> sobasisset_;
99 
102 
104  std::shared_ptr<Molecule> molecule_;
105 
108 
109  // PSI file access variables
110  std::shared_ptr<PSIO> psio_;
111 
113  std::shared_ptr<IntegralFactory> integral_;
114 
116  std::shared_ptr<MatrixFactory> factory_;
117 
118  std::shared_ptr<Wavefunction> reference_wavefunction_;
119 
121  long int memory_;
122 
126  enum FieldType { nothing, dipole_x, dipole_y, dipole_z, dipole, embpot, dx, sphere };
129  std::array<double,3> dipole_field_strength_;
130 
131 
133  size_t debug_;
135  size_t print_;
136 
138  int nalpha_, nbeta_;
139 
141  int nfrzc_;
142 
155 
160 
161 
164 
166  double energy_;
167 
169  double efzc_;
170 
172  int nso_;
174  int nmo_;
176  int nirrep_;
177 
180 
183 
188 
193 
196 
201 
206 
209 
212 
214  SharedMatrix C_subset_helper(SharedMatrix C, const Dimension& noccpi, SharedVector epsilon,
215  const std::string& basis, const std::string& subset) const;
216  SharedVector epsilon_subset_helper(SharedVector epsilon, const Dimension& noccpi,
217  const std::string& basis, const std::string& subset) const;
218  std::vector<std::vector<int>> subset_occupation(const Dimension& noccpi,
219  const std::string& subset) const;
220 
222  std::shared_ptr<std::vector<double>> esp_at_nuclei_;
223 
225  std::vector<SharedVector> mo_extents_;
226 
228  std::shared_ptr<std::vector<double>> atomic_point_charges_;
229 
231  std::vector<std::vector< std::tuple<double, int, int> >> no_occupations_;
232 
235 
239 
240  // The external potential
241  std::shared_ptr<ExternalPotential> external_pot_;
242 
243  // Collection of variables
244  std::map<std::string, double> variables_;
245  std::map<std::string, SharedMatrix> arrays_;
246 
247 private:
248  // Wavefunction() {}
249  void common_init();
250 
251 public:
252 
254  Wavefunction(std::shared_ptr<Molecule> molecule,
255  std::shared_ptr<BasisSet> basis,
256  Options& options);
257 
259  Wavefunction(std::shared_ptr<Molecule> molecule,
260  std::shared_ptr<BasisSet> basis);
261 
263  Wavefunction(Options & options);
264 
273  void shallow_copy(SharedWavefunction other);
274  void shallow_copy(const Wavefunction* other);
275 
283  void deep_copy(SharedWavefunction other);
284  void deep_copy(const Wavefunction* other);
285 
293  std::shared_ptr <Wavefunction> c1_deep_copy(std::shared_ptr<BasisSet> basis);
294 
295  virtual ~Wavefunction();
296 
298  virtual double compute_energy() {throw PSIEXCEPTION("Compute energy has not been implemented for this wavefunction.");}
299 
301  virtual SharedMatrix compute_gradient() {throw PSIEXCEPTION("Analytic gradients are not available for this wavefunction.");}
302 
304  virtual SharedMatrix compute_hessian() {throw PSIEXCEPTION("Analytic Hessians are not available for this wavefunction.");}
305 
307  bool same_a_b_orbs() const { return same_a_b_orbs_; }
308  bool same_a_b_dens() const { return same_a_b_dens_; }
309 
312  Dimension map_irreps(const Dimension &dimpi);
313 
315  std::shared_ptr<Molecule> molecule() const;
316  std::shared_ptr<PSIO> psio() const;
317  Options& options() const;
318 
320  std::shared_ptr<IntegralFactory> integral() const;
322  std::shared_ptr<BasisSet> basisset() const;
324  std::shared_ptr<SOBasisSet> sobasisset() const;
325 
327  std::shared_ptr<BasisSet> get_basisset(std::string label);
328  void set_basisset(std::string label, std::shared_ptr<BasisSet> basis);
329  bool basisset_exists(std::string label);
330 
331 
333  std::shared_ptr<MatrixFactory> matrix_factory() const;
335  std::shared_ptr<Wavefunction> reference_wavefunction() const;
337  void set_reference_wavefunction(const std::shared_ptr<Wavefunction> wfn);
338 
340  bool density_fitted() const { return density_fitted_; }
341 
343  int get_print() const { return print_; }
344  static void initialize_singletons();
345 
347  const Dimension& doccpi() const { return doccpi_; }
349  const Dimension& soccpi() const { return soccpi_; }
351  const Dimension& nsopi() const { return nsopi_; }
353  const Dimension& nmopi() const { return nmopi_; }
355  const Dimension& nalphapi() const { return nalphapi_; }
357  const Dimension& nbetapi() const { return nbetapi_; }
359  const Dimension& frzcpi() const { return frzcpi_; }
361  const Dimension& frzvpi() const { return frzvpi_; }
362 
363  /* Return the magnitude of the dipole perturbation strength in the x,y,z direction */
364  std::array<double,3> get_dipole_field_strength() const;
365  FieldType get_dipole_perturbation_type() const;
366 
371  void force_doccpi(const Dimension& doccpi);
376  void force_soccpi(const Dimension& soccpi);
377 
379  void set_frzvpi(const Dimension& frzvpi);
380 
382  int nfrzc() const { return nfrzc_; }
384  int nalpha() const { return nalpha_; }
386  int nbeta() const { return nbeta_; }
388  int nso() const { return nso_; }
390  int nmo() const { return nmo_; }
392  int nirrep() const { return nirrep_; }
394  double reference_energy () const { return energy_; }
396  double efzc() const { return efzc_; }
398  void set_efzc(double efzc) { efzc_ = efzc; }
399 
401  SharedMatrix S() const { return S_; }
402 
404  SharedMatrix H() const { return H_; }
405 
407  SharedMatrix Ca() const;
409  SharedMatrix Cb() const;
411  SharedMatrix Fa() const;
413  SharedMatrix Fb() const;
415  SharedVector epsilon_a() const;
417  SharedVector epsilon_b() const;
419  SharedMatrix Lagrangian() const;
420 
421  SharedMatrix aotoso() const { return AO2SO_; }
422 
424  const SharedMatrix Da() const;
426  SharedMatrix Db() const;
427 
436  SharedMatrix Ca_subset(const std::string& basis = "SO", const std::string& subset = "ALL") const;
437 
446  SharedMatrix Cb_subset(const std::string& basis = "SO", const std::string& subset = "ALL") const;
447 
457  OrbitalSpace alpha_orbital_space(const std::string& id, const std::string& basis = "SO", const std::string& subset = "ALL");
467  OrbitalSpace beta_orbital_space(const std::string& id, const std::string& basis = "SO", const std::string& subset = "ALL");
468 
475  SharedMatrix Da_subset(const std::string& basis = "SO") const;
476 
483  SharedMatrix Db_subset(const std::string& basis = "SO") const;
484 
493  SharedMatrix D_subset_helper(SharedMatrix D, SharedMatrix C, const std::string& basis) const;
494 
501  SharedMatrix Fa_subset(const std::string& basis = "SO") const;
502 
509  SharedMatrix Fb_subset(const std::string& basis = "SO") const;
510 
519  SharedMatrix F_subset_helper(SharedMatrix F, SharedMatrix C, const std::string& basis) const;
520 
521 
530  SharedMatrix matrix_subset_helper(SharedMatrix M,
531  SharedMatrix C, const std::string &basis,
532  const std::string matrix_basename) const;
533 
541  SharedVector epsilon_a_subset(const std::string& basis = "SO", const std::string& subset = "ALL") const;
542 
550  SharedVector epsilon_b_subset(const std::string& basis = "SO", const std::string& subset = "ALL") const;
551 
560  SharedMatrix basis_projection(SharedMatrix Cold, Dimension noccpi,
561  std::shared_ptr<BasisSet> old_basis,
562  std::shared_ptr<BasisSet> new_basis);
563 
565  SharedMatrix X() const;
566 
568  SharedMatrix gradient() const;
570  void set_gradient(SharedMatrix& grad);
571 
573  SharedMatrix hessian() const;
575  void set_hessian(SharedMatrix& hess);
576 
578  std::shared_ptr<std::vector<double>> esp_at_nuclei()const{
579  return esp_at_nuclei_;
580  }
581 
583  std::shared_ptr<Vector> get_esp_at_nuclei() const;
584 
586  void set_esp_at_nuclei(const std::shared_ptr<std::vector<double>>& nesps){
587  esp_at_nuclei_=nesps;
588  }
589 
591  std::vector<SharedVector> mo_extents()const{
592  return mo_extents_;
593  }
594 
596  std::vector<SharedVector> get_mo_extents() const;
597 
599  void set_mo_extents(const std::vector<SharedVector> mo_es){
600  mo_extents_ = mo_es;
601  }
602 
604  std::shared_ptr<std::vector<double>> atomic_point_charges()const{
605  return atomic_point_charges_;
606  }
608  SharedVector get_atomic_point_charges() const;
609 
611  void set_atomic_point_charges(const std::shared_ptr<std::vector<double>>& apcs){
612  atomic_point_charges_=apcs;
613  }
614 
616  std::vector<std::vector< std::tuple<double, int, int> >> no_occupations()const{
617  return no_occupations_;
618  }
619 
621  std::vector<std::vector< std::tuple<double, int, int> >> get_no_occupations() const;
622 
624  void set_no_occupations(const std::vector<std::vector< std::tuple<double, int, int> >> no_ocs){
625  no_occupations_=no_ocs;
626  }
627 
629  SharedVector frequencies() const;
631  void set_frequencies(std::shared_ptr<Vector>& freqs);
632 
634  void set_name(const std::string& name) { name_ = name; }
635 
637  const std::string& name() const { return name_; }
638 
639  // Set the print flag level
640  void set_print(size_t print) { print_ = print; }
641 
642  // Set the debug flag level
643  void set_debug(size_t debug) { debug_ = debug; }
644 
646  virtual void save() const;
647 
648  // Set the external potential
649  void set_external_potential(std::shared_ptr<ExternalPotential> external) { external_pot_ = external; }
650 
652  double get_variable(const std::string key);
653  void set_variable(const std::string key, double value) { variables_[key] = value; }
654  std::map<std::string, double> variables(void) { return variables_; }
655 
657  SharedMatrix get_array(const std::string key);
658  void set_array(const std::string key, SharedMatrix value) { arrays_[key] = value; }
659  std::map<std::string, SharedMatrix> arrays(void) { return arrays_; }
660 };
661 
662 }
663 
664 #endif
FieldType dipole_field_type_
Definition: wavefunction.h:127
#define MAX_BC
Definition: wavefunction.h:48
double reference_energy() const
Returns the reference energy.
Definition: wavefunction.h:394
SharedVector epsilon_a_
Alpha orbital eneriges.
Definition: wavefunction.h:203
SharedMatrix S_
Overlap matrix.
Definition: wavefunction.h:179
const Dimension & frzvpi() const
Returns the frozen virtual orbitals per irrep array.
Definition: wavefunction.h:361
const Dimension & nsopi() const
Returns the number of SOs per irrep array.
Definition: wavefunction.h:351
std::shared_ptr< std::vector< double > > esp_at_nuclei() const
Returns electrostatic potentials at nuclei.
Definition: wavefunction.h:578
SharedMatrix AO2SO_
AO2SO conversion matrix (AO in rows, SO in cols)
Definition: wavefunction.h:101
std::shared_ptr< PSIO > psio_
Definition: wavefunction.h:110
SharedMatrix S() const
Returns the overlap matrix.
Definition: wavefunction.h:401
int nmo_
Total number of MOs.
Definition: wavefunction.h:174
Dimension soccpi_
Number of singly occupied per irrep.
Definition: wavefunction.h:146
int nbeta_
Definition: wavefunction.h:138
std::shared_ptr< BasisSet > basis
Definition: dx_write.cc:59
SharedMatrix H_
Core Hamiltonian matrix.
Definition: wavefunction.h:182
void set_name(const std::string &name)
Set the wavefunction name (e.g. &quot;RHF&quot;, &quot;ROHF&quot;, &quot;UHF&quot;, &quot;CCEnergyWavefunction&quot;)
Definition: wavefunction.h:634
void set_print(size_t print)
Definition: wavefunction.h:640
Dimension frzcpi_
Number of frozen core per irrep.
Definition: wavefunction.h:148
void set_array(const std::string key, SharedMatrix value)
Definition: wavefunction.h:658
std::vector< std::vector< std::tuple< double, int, int > > > no_occupations_
Should natural orbital occupations be available, they will be here.
Definition: wavefunction.h:231
bool same_a_b_dens() const
Definition: wavefunction.h:308
std::shared_ptr< MatrixFactory > factory_
Matrix factory for creating standard sized matrices.
Definition: wavefunction.h:116
double efzc_
Frozen-core energy associated with this wavefunction.
Definition: wavefunction.h:169
double df[MAX_DF]
Definition: wavefunction.cc:64
const Dimension & soccpi() const
Returns the SOCC per irrep array.
Definition: wavefunction.h:349
size_t print_
Print flag.
Definition: wavefunction.h:135
std::shared_ptr< std::vector< double > > atomic_point_charges() const
Returns the atomic point charges.
Definition: wavefunction.h:604
SharedMatrix Lagrangian_
Lagrangian matrix.
Definition: wavefunction.h:195
double efzc() const
Returns the frozen-core energy.
Definition: wavefunction.h:396
long int memory_
How much memory you have access to.
Definition: wavefunction.h:121
std::shared_ptr< IntegralFactory > integral_
Integral factory.
Definition: wavefunction.h:113
void set_debug(size_t debug)
Definition: wavefunction.h:643
void set_efzc(double efzc)
Sets the frozen-core energy.
Definition: wavefunction.h:398
double energy_
The energy associated with this wavefunction.
Definition: wavefunction.h:166
#define MAX_FAC
Definition: wavefunction.h:51
int get_print() const
Returns the print level.
Definition: wavefunction.h:343
std::map< std::string, double > variables_
Definition: wavefunction.h:244
int perturb_h_
Perturb the Hamiltonian?
Definition: wavefunction.h:124
std::vector< SharedVector > mo_extents() const
Returns Molecular orbital extents.
Definition: wavefunction.h:591
double bc[MAX_BC][MAX_BC]
Definition: wavefunction.cc:65
bool same_a_b_dens_
Same orbs or dens.
Definition: wavefunction.h:237
const Dimension & nmopi() const
Returns the number of MOs per irrep array.
Definition: wavefunction.h:353
#define MAX_DF
Definition: wavefunction.h:45
std::map< std::string, double > variables(void)
Definition: wavefunction.h:654
int nfrzc_
Total frozen core orbitals.
Definition: wavefunction.h:141
std::vector< std::vector< std::tuple< double, int, int > > > no_occupations() const
Returns NO occupations.
Definition: wavefunction.h:616
int nalpha() const
Return the number of alpha electrons.
Definition: wavefunction.h:384
int nso_
Total number of SOs.
Definition: wavefunction.h:172
std::shared_ptr< std::vector< double > > atomic_point_charges_
If atomic point charges are available they will be here.
Definition: wavefunction.h:228
FieldType
With what...
Definition: wavefunction.h:126
SharedMatrix Ca_
Alpha MO coefficients.
Definition: wavefunction.h:185
SharedMatrix Cb_
Beta MO coefficients.
Definition: wavefunction.h:187
size_t debug_
Debug flag.
Definition: wavefunction.h:133
std::string name_
Name of the wavefunction.
Definition: wavefunction.h:89
const Dimension & doccpi() const
Returns the DOCC per irrep array.
Definition: wavefunction.h:347
bool density_fitted_
Whether this wavefunction was obtained using density fitting.
Definition: wavefunction.h:163
SharedMatrix hessian_
Hessian, if available, as natom_*3 x natom_*3 SharedMatrix (NOT mass-weighted!)
Definition: wavefunction.h:211
std::shared_ptr< Wavefunction > reference_wavefunction_
Definition: wavefunction.h:118
Options & options_
Options object.
Definition: wavefunction.h:107
Definition: dimension.h:40
std::shared_ptr< Molecule > molecule
Definition: dx_write.cc:58
virtual SharedMatrix compute_hessian()
Compute Hessian. Subclasses override this function to compute the Hessian.
Definition: wavefunction.h:304
SharedMatrix H() const
Returns the core Hamiltonian matrix.
Definition: wavefunction.h:404
Definition: liboptions.h:355
std::array< double, 3 > dipole_field_strength_
How big of a field perturbation to apply.
Definition: wavefunction.h:129
int nso() const
Returns the number of SOs.
Definition: wavefunction.h:388
virtual double compute_energy()
Compute energy. Subclasses override this function to compute its energy.
Definition: wavefunction.h:298
common_init()
std::shared_ptr< BasisSet > basisset_
The ORBITAL basis.
Definition: wavefunction.h:95
void set_external_potential(std::shared_ptr< ExternalPotential > external)
Definition: wavefunction.h:649
std::shared_ptr< Matrix > SharedMatrix
Definition: adc.h:49
std::shared_ptr< Wavefunction > wfn
Definition: dx_write.cc:60
double fac[MAX_FAC]
Definition: wavefunction.cc:66
Simple wavefunction base class.
Definition: wavefunction.h:85
#define PSI_API
Definition: pragma.h:128
bool same_a_b_orbs_
Definition: wavefunction.h:238
#define MAX_IOFF
Definition: wavefunction.h:42
std::map< std::string, std::shared_ptr< BasisSet > > basissets_
DF/RI/F12/etc basis sets.
Definition: wavefunction.h:92
Dimension frzvpi_
Number of frozen virtuals per irrep.
Definition: wavefunction.h:150
std::shared_ptr< Molecule > molecule_
Molecule that this wavefunction is run on.
Definition: wavefunction.h:104
int nfrzc() const
Return the number of frozen core orbitals.
Definition: wavefunction.h:382
int nmo() const
Returns the number of MOs.
Definition: wavefunction.h:390
SharedMatrix Fa_
Alpha Fock matrix.
Definition: wavefunction.h:198
void set_variable(const std::string key, double value)
Definition: wavefunction.h:653
std::shared_ptr< SOBasisSet > sobasisset_
Primary basis set for SO integrals.
Definition: wavefunction.h:98
const Dimension & nbetapi() const
Returns the number of beta electrons per irrep array.
Definition: wavefunction.h:357
SharedMatrix Da_
Alpha density matrix.
Definition: wavefunction.h:190
std::shared_ptr< ExternalPotential > external_pot_
Definition: wavefunction.h:241
void set_mo_extents(const std::vector< SharedVector > mo_es)
Sets molecular orbital extents.
Definition: wavefunction.h:599
const std::string & name() const
Returns the wavefunction name.
Definition: wavefunction.h:637
The OrbitalSpace class.
Definition: orbitalspace.h:48
SharedVector frequencies_
If frequencies are available, they will be here:
Definition: wavefunction.h:234
int nbeta() const
Return the number of beta electrons.
Definition: wavefunction.h:386
void set_atomic_point_charges(const std::shared_ptr< std::vector< double >> &apcs)
Sets the atomic point charges.
Definition: wavefunction.h:611
bool density_fitted() const
Returns whether this wavefunction was obtained using density fitting or not.
Definition: wavefunction.h:340
SharedVector epsilon_b_
Beta orbital energies.
Definition: wavefunction.h:205
int nirrep_
Number of irreps.
Definition: wavefunction.h:176
EXTERN int * ioff
Definition: ccresponse/globals.h:48
SharedMatrix aotoso() const
Definition: wavefunction.h:421
bool same_a_b_orbs() const
Is this a restricted wavefunction?
Definition: wavefunction.h:307
const Dimension & nalphapi() const
Returns the number of alpha electrons per irrep array.
Definition: wavefunction.h:355
SharedMatrix Db_
Beta density matrix.
Definition: wavefunction.h:192
const Dimension & frzcpi() const
Returns the frozen core orbitals per irrep array.
Definition: wavefunction.h:359
Dimension nmopi_
Number of mo per irrep.
Definition: wavefunction.h:159
std::shared_ptr< Wavefunction > SharedWavefunction
Definition: typedefs.h:54
std::map< std::string, SharedMatrix > arrays_
Definition: wavefunction.h:245
SharedMatrix Fb_
Beta Fock matrix.
Definition: wavefunction.h:200
Dimension nbetapi_
Number of beta electrons per irrep.
Definition: wavefunction.h:154
void set_no_occupations(const std::vector< std::vector< std::tuple< double, int, int > >> no_ocs)
Sets the NO occupations.
Definition: wavefunction.h:624
#define PSIEXCEPTION(message)
Definition: exception.h:50
void set_esp_at_nuclei(const std::shared_ptr< std::vector< double >> &nesps)
Sets the electrostatic potentials at nuclei.
Definition: wavefunction.h:586
Dimension nalphapi_
Number of alpha electrons per irrep.
Definition: wavefunction.h:152
int nirrep() const
Returns the number of irreps.
Definition: wavefunction.h:392
virtual SharedMatrix compute_gradient()
Compute gradient. Subclasses override this function to compute the gradient.
Definition: wavefunction.h:301
std::shared_ptr< Vector > SharedVector
Definition: adc.h:51
Dimension nsopi_
Number of so per irrep.
Definition: wavefunction.h:157
std::shared_ptr< std::vector< double > > esp_at_nuclei_
Should nuclear electrostatic potentials be available, they will be here.
Definition: wavefunction.h:222
std::map< std::string, SharedMatrix > arrays(void)
Definition: wavefunction.h:659
SharedMatrix gradient_
gradient, if available, as natom_ x 3 SharedMatrix
Definition: wavefunction.h:208
std::vector< SharedVector > mo_extents_
Should molecular orbital extents be available, they will be here.
Definition: wavefunction.h:225
Dimension doccpi_
Number of doubly occupied per irrep.
Definition: wavefunction.h:144