Psi4
integraltransform.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-2017 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_LIBTRANS_INTEGRALTRANSFORM_H_
30 #define _PSI_SRC_LIB_LIBTRANS_INTEGRALTRANSFORM_H_
31 
32 #include <map>
33 #include <vector>
34 #include <string>
36 #include "psi4/libmints/typedefs.h"
37 #include "mospace.h"
38 
39 #ifndef INDEX
40  #define INDEX(i,j) (((i)>(j)) ? (((i)*((i)+1)/2)+(j)) : (((j)*((j)+1)/2)+(i)))
41 #endif
42 
43 namespace psi{
44 
45 struct dpdbuf4;
46 class Matrix;
47 class Dimension;
48 class Wavefunction;
49 class PSIO;
50 
51 typedef std::vector<std::shared_ptr< MOSpace> > SpaceVec;
52 
59 // TODO check usage of restricted, to make sure that it's correct everywhere
60  public:
70 
117  enum SpinType {Alpha, Beta};
135  IntegralTransform(std::shared_ptr<Wavefunction> wfn,
136  SpaceVec spaces,
137  TransformationType transformationType = Restricted,
138  OutputType outputType = DPDOnly,
139  MOOrdering moOrdering = QTOrder,
140  FrozenOrbitals frozenOrbitals = OccAndVir,
141  bool initialize = true);
142 
144  SharedMatrix c,
145  SharedMatrix i,
146  SharedMatrix a,
147  SharedMatrix v,
148  SpaceVec spaces,
149  TransformationType transformationType = Restricted,
150  OutputType outputType = DPDOnly,
151  MOOrdering moOrdering = QTOrder,
152  FrozenOrbitals frozenOrbitals = OccAndVir,
153  bool initialize = true);
154 
156 
157  void initialize();
158  void presort_so_tei();
159  void generate_oei();
160  void update_orbitals();
161  void transform_oei(const std::shared_ptr<MOSpace> s1, const std::shared_ptr<MOSpace> s2, const char *label);
162  void transform_tei(const std::shared_ptr<MOSpace> s1, const std::shared_ptr<MOSpace> s2,
163  const std::shared_ptr<MOSpace> s3, const std::shared_ptr<MOSpace> s4,
165  void transform_tei_first_half(const std::shared_ptr<MOSpace> s1, const std::shared_ptr<MOSpace> s2);
166  void transform_tei_second_half(const std::shared_ptr<MOSpace> s1, const std::shared_ptr<MOSpace> s2,
167  const std::shared_ptr<MOSpace> s3, const std::shared_ptr<MOSpace> s4);
168  void backtransform_density();
171  void print_dpd_lookup();
172  std::vector<SharedMatrix> compute_fock_like_matrices(SharedMatrix Hcore, std::vector<SharedMatrix> Cmats);
173 
174  int DPD_ID(const char c);
175  int DPD_ID(char *str);
176  int DPD_ID(const char *str);
177  int DPD_ID(const std::string &str);
178  int DPD_ID(const std::shared_ptr<MOSpace> s1, const std::shared_ptr<MOSpace> s2, SpinType spin, bool pack);
179 
180  /*===== The set/get accessor functions =====*/
181 
183  void set_so_tei_file(int so_tei_file) { soIntTEIFile_ = so_tei_file; }
185  void set_write_dpd_so_tpdm(bool t_f) { write_dpd_so_tpdm_ = t_f; }
187  void set_print(int n) {print_ = n;}
190  void set_orbitals(SharedMatrix C);
191 
193  int get_print() const {return print_;}
194 
196  double get_frozen_core_energy() const { return frozen_core_energy_; }
197 
199  void set_keep_ht_ints(bool val) {keepHtInts_ = val;}
201  bool get_keep_ht_ints() const {return keepHtInts_;}
202 
204  void set_keep_dpd_so_ints(bool val) {keepDpdSoInts_ = val;}
206  bool get_keep_dpd_so_ints() const {return keepDpdSoInts_;}
207 
209  void set_keep_iwl_so_ints(bool val) {keepIwlSoInts_ = val;}
211  bool get_keep_iwl_so_ints() const {return keepIwlSoInts_;}
214 
218 
220  void set_memory(size_t memory) {memory_ = memory;}
222  size_t get_memory() const {return memory_;}
223 
225  void set_dpd_id(int n) {myDPDNum_ = n;}
227  int get_dpd_id() const {return myDPDNum_;}
228 
230  std::shared_ptr<PSIO> get_psio() const;
232  void set_psio(std::shared_ptr<PSIO> psio);
233 
235  void set_dpd_int_file(int file) { dpdIntFile_ = file; }
238  void set_aa_int_name(const std::string& name) { aaIntName_ = name; }
241  void set_ab_int_name(const std::string& name) { abIntName_ = name; }
244  void set_bb_int_name(const std::string& name) { bbIntName_ = name; }
245 
247  const int *alpha_corr_to_pitzer() const { return aCorrToPitzer_; }
249  const int *beta_corr_to_pitzer() const { return bCorrToPitzer_; }
250 
251  int nirrep() const { return nirreps_; }
252 
253  void reset_so_int() { alreadyPresorted_ = false; }
254 
255  protected:
256  void check_initialized();
257  void common_initialize();
258 
259  void process_eigenvectors();
260  void process_spaces();
263  void setup_tpdm_buffer(const dpdbuf4 *D);
264  void sort_so_tpdm(const dpdbuf4 *B, int irrep, size_t first_row, size_t num_rows, bool first_run);
265 
266  void trans_one(int m, int n, double *input, double *output, double **C, int soOffset,
267  int *order, bool backtransform = false, double scale = 0.0);
268 
269  // Has this instance been initialized yet?
271 
272  // The number of SO tpdm elements in each SO shell quartet
273  std::vector<size_t> tpdm_buffer_sizes_;
274  // The buffer used in sorting the SO basis tpdm
275  double *tpdm_buffer_;
276  // Frozen core energy
278  // The wavefunction object, containing the orbital infomation
279  std::shared_ptr<Wavefunction> wfn_;
280  // Pointer to the PSIO object to use for file I/O
281  std::shared_ptr<PSIO> psio_;
282  // The type of transformation
284  // The unique MO spaces provided to this object's constructor
286  // The ordering of the resulting integrals
288  // The format of the outputted integrals
290  // How to handle frozen orbitals
292  // The unique orbital spaces involved in this transformation
293  std::vector <char> spacesUsed_;
294  // A list of the arrays to pass into libDPD
295  std::vector<int*> spaceArray_;
296  // The alpha orbitals per irrep for each space
297  std::map<char, int* > aOrbsPI_;
298  // The beta orbitals per irrep for each space
299  std::map<char, int* > bOrbsPI_;
300  // The alpha MO coefficients for all unique spaces needed
301  std::map<char, SharedMatrix> aMOCoefficients_;
302  // The beta MO coefficients for all unique spaces needed
303  std::map<char, SharedMatrix> bMOCoefficients_;
304  // The alpha orbital indexing arrays
305  std::map<char, int* > aIndices_;
306  // The beta orbital indexing arrays
307  std::map<char, int* > bIndices_;
308  // The lookup table for DPD indexing
309  std::map<std::string, int> dpdLookup_;
310  // Whether the SO integrals have already been presorted
312  // Whether to also write DPD formatted SO TPDMs after density transformations
314  // The file to which DPD formatted integrals are written
316  // The file from which IWL SO TEIs are read
318  // The file containing alpha half-transformed integrals in DPD format
320  // The file containing beta half-transformed integrals in DPD format
322  // The file containing alpha-alpha IWL formatted integrals
324  // The file containing alpha-beta IWL formatted integrals
326  // The file containing beta-beta IWL formatted integrals
328  // The number of irreps
329  int nirreps_;
330  // The number of molecular orbitals
331  int nmo_;
332  // The number of symmetrized atomic orbitals
333  int nso_;
334  // The number of pairs of symmetrized atomic orbitals
335  int nTriSo_;
336  // The number of pairs of molecular orbitals
337  int nTriMo_;
338  // The number of frozen doubly occupied orbitals
339  int nfzc_;
340  // The number of frozen virtual orbitals
341  int nfzv_;
342  // The name of the alpha-alpha DPD integral buffer
343  std::string aaIntName_;
344  // The name of the alpha-beta DPD integral buffer
345  std::string abIntName_;
346  // The name of the beta-beta DPD integral buffer
347  std::string bbIntName_;
348  // A string describing the spaces in which the integrals are to be transformed
349  char *spaces_;
350  // An array containing labels for each irrep
351  char **labels_;
352  // The definition of zero
353  double tolerance_;
354  // The amount of memory, in MB
355  size_t memory_;
356  // The PSI file number for the alpha-alpha integrals
358  // The PSI file number for the alpha-beta integrals
360  // The PSI file number for the beta-beta integrals
362  // The DPD id to use internally
364  // The amount of information to print
365  int print_;
366  // Just an array of zeros! Used in the null MOSpace "transforms"
367  int *zeros_;
368  // The alpha Pitzer->QT reordering array
369  int *aQT_;
370  // The alpha Pitzer->QT reordering array
371  int *bQT_;
372  // The alpha correlated to Pitzer ordering arrays, used in backtransforms
374  // The beta correlated to Pitzer ordering arrays, used in backtransforms
376  // The number of symmetrized orbitals per irrep
378  // The symmetry (irrep number) of each symmetrized atomic orbital
379  int *sosym_;
380  // The symmetry (irrep number) of each molecular orbital
381  int *mosym_;
382  // The number of molecular orbitals per irrep
384  // The number of doubly-occupied orbitals per irrep
386  // The number of singly-occupied orbitals per irrep
388  // The number of frozen doubly occupied orbitals per irrep
390  // The number of frozen virtual orbitals per irrep
392  // The number of alpha electrons per irrep
394  // The number of beta electrons per irrep
396  // The cache files used by libDPD
398  // The alpha MO coefficients for each irrep
399  std::shared_ptr<Matrix> Ca_;
400  // The alpha MO coefficients for each irrep
401  std::shared_ptr<Matrix> Cb_;
402  // The one electron Hamiltonian matrix for each irrep
403  std::shared_ptr<Matrix> H_;
404  // Whether to keep the IWL SO integral file after processing
406  // Whether to keep the IWL MO two particle density matrix
408  // Whether to keep the DPD SO integral file after processing
410  // Whether to keep the DPD MO to particle density matrix after processing
412  // Whether to keep the half-transformed two electron integrals
414  // Whether to keep the half-transformed TPDM
416  // Whether to print the two-electron integrals or not
417  bool printTei_;
418  // Whether to output the results to an IWL buffer
419  bool useIWL_;
420  // Whether to output the results to a DPD buffer
421  bool useDPD_;
422  // Has this object already pre-sorted?
424  // This keeps track of which labels have been assigned by other spaces
425  std::map<char, int> labelsUsed_;
426 };
427 
428 } // End namespaces
429 
430 #endif // Header guard
void set_memory(size_t memory)
Set the memory (in MB) available to the library.
Definition: integraltransform.h:220
bool keepHtInts_
Definition: integraltransform.h:413
bool write_dpd_so_tpdm_
Definition: integraltransform.h:313
bool keepIwlSoInts_
Definition: integraltransform.h:405
std::map< char, int * > aIndices_
Definition: integraltransform.h:305
void setup_tpdm_buffer(const dpdbuf4 *D)
Definition: integraltransform_sort_so_tpdm.cc:45
std::vector< char > spacesUsed_
Definition: integraltransform.h:293
void set_so_tei_file(int so_tei_file)
Sets the SO IWL file to read the TEIs from.
Definition: integraltransform.h:183
size_t get_memory() const
The amount of memory (in MB) available to the library.
Definition: integraltransform.h:222
int * sosym_
Definition: integraltransform.h:379
Definition: integraltransform.h:109
Dimension nalphapi_
Definition: integraltransform.h:393
bool keepDpdMoTpdm_
Definition: integraltransform.h:411
std::string abIntName_
Definition: integraltransform.h:345
void print_dpd_lookup()
Definition: integraltransform_moinfo.cc:741
std::map< std::string, int > dpdLookup_
Definition: integraltransform.h:309
void set_tei_already_presorted(bool val)
Definition: integraltransform.h:217
Definition: integraltransform.h:109
int nfzc_
Definition: integraltransform.h:339
bool alreadyPresorted_
Definition: integraltransform.h:311
void set_keep_dpd_so_ints(bool val)
Set the library to keep or delete the SO integrals in DPD form after processing.
Definition: integraltransform.h:204
int get_print() const
The level of printing used during transformations.
Definition: integraltransform.h:193
bool get_tei_already_presorted()
Whether SO intergals are already presorted.
Definition: integraltransform.h:216
void backtransform_tpdm_unrestricted()
Definition: integraltransform_tpdm_unrestricted.cc:46
Dimension nbetapi_
Definition: integraltransform.h:395
Definition: integraltransform.h:97
int * cacheFiles_
Definition: integraltransform.h:397
int * aCorrToPitzer_
Definition: integraltransform.h:373
void process_spaces()
Definition: integraltransform_moinfo.cc:89
double * tpdm_buffer_
Definition: integraltransform.h:275
const int * alpha_corr_to_pitzer() const
Get the alpha correlated to Pitzer ordering array, used in backtransforms.
Definition: integraltransform.h:247
OutputType
Definition: integraltransform.h:97
int * bCorrToPitzer_
Definition: integraltransform.h:375
void set_keep_iwl_so_ints(bool val)
Set the library to keep or delete the SO integrals in IWL form after processing.
Definition: integraltransform.h:209
std::map< char, int * > aOrbsPI_
Definition: integraltransform.h:297
double get_frozen_core_energy() const
Returns the frozen-core energy.
Definition: integraltransform.h:196
Dimension sopi_
Definition: integraltransform.h:377
void set_dpd_int_file(int file)
The file to output DPD integrals to.
Definition: integraltransform.h:235
bool get_keep_dpd_so_ints() const
Whether the library will keep or delete the SO integrals in DPD form after processing.
Definition: integraltransform.h:206
std::string bbIntName_
Definition: integraltransform.h:347
std::vector< SharedMatrix > compute_fock_like_matrices(SharedMatrix Hcore, std::vector< SharedMatrix > Cmats)
Computes Fock matrices, frozen core operators and other Fock-like quantities. This shouldn&#39;t be neede...
Definition: integraltransform_sort_so_tei.cc:55
SpinType
Definition: integraltransform.h:117
bool useIWL_
Definition: integraltransform.h:419
void initialize()
Definition: integraltransform.cc:213
Definition: pointgrp.h:106
std::shared_ptr< Matrix > Ca_
Definition: integraltransform.h:399
Definition: integraltransform.h:97
int soIntTEIFile_
Definition: integraltransform.h:317
Definition: integraltransform.h:88
Definition: integraltransform.h:117
std::map< char, SharedMatrix > bMOCoefficients_
Definition: integraltransform.h:303
std::vector< int * > spaceArray_
Definition: integraltransform.h:295
int get_dpd_id() const
The number of the DPD instance used in the transformation.
Definition: integraltransform.h:227
bool initialized_
Definition: integraltransform.h:270
int nirrep() const
Definition: integraltransform.h:251
std::shared_ptr< PSIO > psio_
Definition: integraltransform.h:281
double frozen_core_energy_
Definition: integraltransform.h:277
MOOrdering
Definition: integraltransform.h:88
Definition: integraltransform.h:69
void set_write_dpd_so_tpdm(bool t_f)
Set whether to write a DPD formatted SO basis TPDM to disk after density transformations.
Definition: integraltransform.h:185
void set_ab_int_name(const std::string &name)
Definition: integraltransform.h:241
std::string aaIntName_
Definition: integraltransform.h:343
size_t memory_
Definition: integraltransform.h:355
void backtransform_tpdm_restricted()
Definition: integraltransform_tpdm_restricted.cc:46
Dimension clsdpi_
Definition: integraltransform.h:385
std::map< char, int * > bIndices_
Definition: integraltransform.h:307
int nmo_
Definition: integraltransform.h:331
void transform_oei(const std::shared_ptr< MOSpace > s1, const std::shared_ptr< MOSpace > s2, const char *label)
Definition: integraltransform_oei.cc:54
void set_psio(std::shared_ptr< PSIO > psio)
Set the psio object to be used. You must delay initialization in the ctor for this to work...
Definition: integraltransform.cc:313
Definition: integraltransform.h:109
MOOrdering moOrdering_
Definition: integraltransform.h:287
int moIntFileBB_
Definition: integraltransform.h:361
void trans_one(int m, int n, double *input, double *output, double **C, int soOffset, int *order, bool backtransform=false, double scale=0.0)
Definition: integraltransform_oei.cc:136
Dimension frzvpi_
Definition: integraltransform.h:391
std::vector< std::shared_ptr< MOSpace > > SpaceVec
Definition: integraltransform.h:49
void set_aa_int_name(const std::string &name)
Definition: integraltransform.h:238
std::shared_ptr< Matrix > Cb_
Definition: integraltransform.h:401
int * mosym_
Definition: integraltransform.h:381
std::map< char, int > labelsUsed_
Definition: integraltransform.h:425
void transform_tei(const std::shared_ptr< MOSpace > s1, const std::shared_ptr< MOSpace > s2, const std::shared_ptr< MOSpace > s3, const std::shared_ptr< MOSpace > s4, HalfTrans=MakeAndNuke)
Definition: integraltransform_tei.cc:54
Definition: integraltransform.h:88
const int * beta_corr_to_pitzer() const
Get the beta correlated to Pitzer ordering array, used in backtransforms.
Definition: integraltransform.h:249
void backtransform_density()
Definition: integraltransform_tpdm.cc:49
void set_tpdm_already_presorted(bool val)
Whether TPDM has already presorted.
Definition: integraltransform.h:213
void set_keep_ht_ints(bool val)
Set the library to keep or delete the half-transformed integrals in DPD form after processing...
Definition: integraltransform.h:199
Definition: integraltransform.h:80
std::map< char, SharedMatrix > aMOCoefficients_
Definition: integraltransform.h:301
int * zeros_
Definition: integraltransform.h:367
int nfzv_
Definition: integraltransform.h:341
int iwlBBIntFile_
Definition: integraltransform.h:327
int dpdIntFile_
Definition: integraltransform.h:315
void update_orbitals()
Definition: integraltransform_moinfo.cc:571
void check_initialized()
Definition: integraltransform.cc:336
Definition: dimension.h:38
~IntegralTransform()
Definition: integraltransform.cc:318
void process_eigenvectors()
Definition: integraltransform_moinfo.cc:598
void reset_so_int()
Definition: integraltransform.h:253
void transform_tei_first_half(const std::shared_ptr< MOSpace > s1, const std::shared_ptr< MOSpace > s2)
Definition: integraltransform_tei_1st_half.cc:47
int aHtIntFile_
Definition: integraltransform.h:319
bool printTei_
Definition: integraltransform.h:417
TransformationType transformationType_
Definition: integraltransform.h:283
int bHtIntFile_
Definition: integraltransform.h:321
bool useDPD_
Definition: integraltransform.h:421
bool keepHtTpdm_
Definition: integraltransform.h:415
void set_print(int n)
Set the level of printing used during transformations (0 -&gt; 6)
Definition: integraltransform.h:187
char ** labels_
Definition: integraltransform.h:351
int nTriMo_
Definition: integraltransform.h:337
IntegralTransform(std::shared_ptr< Wavefunction > wfn, SpaceVec spaces, TransformationType transformationType=Restricted, OutputType outputType=DPDOnly, MOOrdering moOrdering=QTOrder, FrozenOrbitals frozenOrbitals=OccAndVir, bool initialize=true)
Definition: integraltransform.cc:45
int iwlAAIntFile_
Definition: integraltransform.h:323
int nso_
Definition: integraltransform.h:333
FrozenOrbitals
Definition: integraltransform.h:109
bool get_keep_iwl_so_ints() const
Whether the library will keep or delete the SO integrals in IWL form after processing.
Definition: integraltransform.h:211
int ** cacheList_
Definition: integraltransform.h:397
void set_bb_int_name(const std::string &name)
Definition: integraltransform.h:244
Definition: integraltransform.h:80
int myDPDNum_
Definition: integraltransform.h:363
bool get_keep_ht_ints() const
Whether the library will keep or delete the half-transformed integrals in DPD form after processing...
Definition: integraltransform.h:201
std::shared_ptr< Matrix > SharedMatrix
Definition: adc.h:49
std::shared_ptr< Matrix > H_
Definition: integraltransform.h:403
std::shared_ptr< Wavefunction > wfn
Definition: dx_write.cc:60
std::shared_ptr< PSIO > get_psio() const
Get the psio object being used by this object.
Definition: integraltransform.cc:307
int moIntFileAA_
Definition: integraltransform.h:357
int moIntFileAB_
Definition: integraltransform.h:359
OutputType outputType_
Definition: integraltransform.h:289
std::map< char, int * > bOrbsPI_
Definition: integraltransform.h:299
int nirreps_
Definition: integraltransform.h:329
int nTriSo_
Definition: integraltransform.h:335
char * spaces_
Definition: integraltransform.h:349
Definition: libdpd/dpd.h:105
std::shared_ptr< Wavefunction > wfn_
Definition: integraltransform.h:279
bool tpdmAlreadyPresorted_
Definition: integraltransform.h:423
Definition: integraltransform.h:80
int * aQT_
Definition: integraltransform.h:369
SpaceVec uniqueSpaces_
Definition: integraltransform.h:285
bool keepIwlMoTpdm_
Definition: integraltransform.h:407
Dimension mopi_
Definition: integraltransform.h:383
void common_initialize()
Definition: integraltransform_moinfo.cc:41
Definition: integraltransform.h:97
Definition: integraltransform.h:117
void presort_mo_tpdm_restricted()
Definition: integraltransform_sort_mo_tpdm.cc:47
int DPD_ID(const char c)
Definition: integraltransform_dpd_id.cc:92
void set_orbitals(SharedMatrix C)
Definition: integraltransform_moinfo.cc:585
void transform_tei_second_half(const std::shared_ptr< MOSpace > s1, const std::shared_ptr< MOSpace > s2, const std::shared_ptr< MOSpace > s3, const std::shared_ptr< MOSpace > s4)
Definition: integraltransform_tei_2nd_half.cc:47
std::vector< size_t > tpdm_buffer_sizes_
Definition: integraltransform.h:273
HalfTrans
Definition: integraltransform.h:69
void sort_so_tpdm(const dpdbuf4 *B, int irrep, size_t first_row, size_t num_rows, bool first_run)
Definition: integraltransform_sort_so_tpdm.cc:134
Definition: integraltransform.h:109
void presort_so_tei()
Definition: integraltransform_sort_so_tei.cc:179
void generate_oei()
Definition: integraltransform_oei.cc:190
bool keepDpdSoInts_
Definition: integraltransform.h:409
Definition: integraltransform.h:69
double tolerance_
Definition: integraltransform.h:353
Definition: integraltransform.h:58
FrozenOrbitals frozenOrbitals_
Definition: integraltransform.h:291
int print_
Definition: integraltransform.h:365
void presort_mo_tpdm_unrestricted()
Definition: integraltransform_sort_mo_tpdm.cc:216
void set_dpd_id(int n)
Set the number of the DPD instance to be used in the transformation.
Definition: integraltransform.h:225
Dimension frzcpi_
Definition: integraltransform.h:389
int * bQT_
Definition: integraltransform.h:371
Definition: integraltransform.h:69
int iwlABIntFile_
Definition: integraltransform.h:325
Definition: integraltransform.h:69
TransformationType
Definition: integraltransform.h:80
Definition: psio.hpp:197
Dimension openpi_
Definition: integraltransform.h:387