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 program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program 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 General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  *
25  * @END LICENSE
26  */
27 
28 #ifndef _PSI_SRC_LIB_LIBTRANS_INTEGRALTRANSFORM_H_
29 #define _PSI_SRC_LIB_LIBTRANS_INTEGRALTRANSFORM_H_
30 
31 #include <map>
32 #include <vector>
33 #include <string>
35 #include "psi4/libmints/typedefs.h"
36 #include "mospace.h"
37 
38 #ifndef INDEX
39  #define INDEX(i,j) (((i)>(j)) ? (((i)*((i)+1)/2)+(j)) : (((j)*((j)+1)/2)+(i)))
40 #endif
41 
42 namespace psi{
43 
44 struct dpdfile4;
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 i,
145  SharedMatrix a,
146  SharedMatrix v,
147  SpaceVec spaces,
148  TransformationType transformationType = Restricted,
149  OutputType outputType = DPDOnly,
150  MOOrdering moOrdering = QTOrder,
151  FrozenOrbitals frozenOrbitals = OccAndVir,
152  bool initialize = true);
153 
155 
156  void initialize();
157  void presort_so_tei();
158  void generate_oei();
159  void update_orbitals();
160  void transform_oei(const std::shared_ptr<MOSpace> s1, const std::shared_ptr<MOSpace> s2, const char *label);
161  void transform_tei(const std::shared_ptr<MOSpace> s1, const std::shared_ptr<MOSpace> s2,
162  const std::shared_ptr<MOSpace> s3, const std::shared_ptr<MOSpace> s4,
164  void transform_tei_first_half(const std::shared_ptr<MOSpace> s1, const std::shared_ptr<MOSpace> s2);
165  void transform_tei_second_half(const std::shared_ptr<MOSpace> s1, const std::shared_ptr<MOSpace> s2,
166  const std::shared_ptr<MOSpace> s3, const std::shared_ptr<MOSpace> s4);
167  void backtransform_density();
170  void print_dpd_lookup();
171  std::vector<SharedMatrix> compute_fock_like_matrices(SharedMatrix Hcore, std::vector<SharedMatrix> Cmats);
172 
173  int DPD_ID(const char c);
174  int DPD_ID(char *str);
175  int DPD_ID(const char *str);
176  int DPD_ID(const std::string &str);
177  int DPD_ID(const std::shared_ptr<MOSpace> s1, const std::shared_ptr<MOSpace> s2, SpinType spin, bool pack);
178 
179  /*===== The set/get accessor functions =====*/
180 
182  void set_so_tei_file(int so_tei_file) { soIntTEIFile_ = so_tei_file; }
184  void set_write_dpd_so_tpdm(bool t_f) { write_dpd_so_tpdm_ = t_f; }
186  void set_print(int n) {print_ = n;}
189  void set_orbitals(SharedMatrix C);
190 
192  int get_print() const {return print_;}
193 
195  double get_frozen_core_energy() const { return frozen_core_energy_; }
196 
198  void set_keep_ht_ints(bool val) {keepHtInts_ = val;}
200  bool get_keep_ht_ints() const {return keepHtInts_;}
201 
203  void set_keep_dpd_so_ints(bool val) {keepDpdSoInts_ = val;}
205  bool get_keep_dpd_so_ints() const {return keepDpdSoInts_;}
206 
208  void set_keep_iwl_so_ints(bool val) {keepIwlSoInts_ = val;}
210  bool get_keep_iwl_so_ints() const {return keepIwlSoInts_;}
213 
217 
219  void set_memory(size_t memory) {memory_ = memory;}
221  size_t get_memory() const {return memory_;}
222 
224  void set_dpd_id(int n) {myDPDNum_ = n;}
226  int get_dpd_id() const {return myDPDNum_;}
227 
229  std::shared_ptr<PSIO> get_psio() const;
231  void set_psio(std::shared_ptr<PSIO> psio);
232 
234  void set_dpd_int_file(int file) { dpdIntFile_ = file; }
237  void set_aa_int_name(const std::string& name) { aaIntName_ = name; }
240  void set_ab_int_name(const std::string& name) { abIntName_ = name; }
243  void set_bb_int_name(const std::string& name) { bbIntName_ = name; }
244 
246  const int *alpha_corr_to_pitzer() const { return aCorrToPitzer_; }
248  const int *beta_corr_to_pitzer() const { return bCorrToPitzer_; }
249 
250  int nirrep() const { return nirreps_; }
251 
252  void reset_so_int() { alreadyPresorted_ = false; }
253 
254  protected:
255  void check_initialized();
256  void common_initialize();
257 
258  void process_eigenvectors();
259  void process_spaces();
262  void setup_tpdm_buffer(const dpdbuf4 *D);
263  void sort_so_tpdm(const dpdbuf4 *B, int irrep, size_t first_row, size_t num_rows, bool first_run);
264 
265  void trans_one(int m, int n, double *input, double *output, double **C, int soOffset,
266  int *order, bool backtransform = false, double scale = 0.0);
267 
268  // Has this instance been initialized yet?
270 
271  // The number of SO tpdm elements in each SO shell quartet
272  std::vector<size_t> tpdm_buffer_sizes_;
273  // The buffer used in sorting the SO basis tpdm
274  double *tpdm_buffer_;
275  // Frozen core energy
277  // The wavefunction object, containing the orbital infomation
278  std::shared_ptr<Wavefunction> wfn_;
279  // Pointer to the PSIO object to use for file I/O
280  std::shared_ptr<PSIO> psio_;
281  // The type of transformation
283  // The unique MO spaces provided to this object's constructor
285  // The ordering of the resulting integrals
287  // The format of the outputted integrals
289  // How to handle frozen orbitals
291  // The unique orbital spaces involved in this transformation
292  std::vector <char> spacesUsed_;
293  // A list of the arrays to pass into libDPD
294  std::vector<int*> spaceArray_;
295  // The alpha orbitals per irrep for each space
296  std::map<char, int* > aOrbsPI_;
297  // The beta orbitals per irrep for each space
298  std::map<char, int* > bOrbsPI_;
299  // The alpha MO coefficients for all unique spaces needed
300  std::map<char, SharedMatrix> aMOCoefficients_;
301  // The beta MO coefficients for all unique spaces needed
302  std::map<char, SharedMatrix> bMOCoefficients_;
303  // The alpha orbital indexing arrays
304  std::map<char, int* > aIndices_;
305  // The beta orbital indexing arrays
306  std::map<char, int* > bIndices_;
307  // The lookup table for DPD indexing
308  std::map<std::string, int> dpdLookup_;
309  // Whether the SO integrals have already been presorted
311  // Whether to also write DPD formatted SO TPDMs after density transformations
313  // The file to which DPD formatted integrals are written
315  // The file from which IWL SO TEIs are read
317  // The file containing alpha half-transformed integrals in DPD format
319  // The file containing beta half-transformed integrals in DPD format
321  // The file containing alpha-alpha IWL formatted integrals
323  // The file containing alpha-beta IWL formatted integrals
325  // The file containing beta-beta IWL formatted integrals
327  // The number of irreps
328  int nirreps_;
329  // The number of molecular orbitals
330  int nmo_;
331  // The number of symmetrized atomic orbitals
332  int nso_;
333  // The number of pairs of symmetrized atomic orbitals
334  int nTriSo_;
335  // The number of pairs of molecular orbitals
336  int nTriMo_;
337  // The number of frozen doubly occupied orbitals
338  int nfzc_;
339  // The number of frozen virtual orbitals
340  int nfzv_;
341  // The name of the alpha-alpha DPD integral buffer
342  std::string aaIntName_;
343  // The name of the alpha-beta DPD integral buffer
344  std::string abIntName_;
345  // The name of the beta-beta DPD integral buffer
346  std::string bbIntName_;
347  // A string describing the spaces in which the integrals are to be transformed
348  char *spaces_;
349  // An array containing labels for each irrep
350  char **labels_;
351  // The definition of zero
352  double tolerance_;
353  // The amount of memory, in MB
354  size_t memory_;
355  // The PSI file number for the alpha-alpha integrals
357  // The PSI file number for the alpha-beta integrals
359  // The PSI file number for the beta-beta integrals
361  // The DPD id to use internally
363  // The amount of information to print
364  int print_;
365  // Just an array of zeros! Used in the null MOSpace "transforms"
366  int *zeros_;
367  // The alpha Pitzer->QT reordering array
368  int *aQT_;
369  // The alpha Pitzer->QT reordering array
370  int *bQT_;
371  // The alpha correlated to Pitzer ordering arrays, used in backtransforms
373  // The beta correlated to Pitzer ordering arrays, used in backtransforms
375  // The number of symmetrized orbitals per irrep
377  // The symmetry (irrep number) of each symmetrized atomic orbital
378  int *sosym_;
379  // The symmetry (irrep number) of each molecular orbital
380  int *mosym_;
381  // The number of molecular orbitals per irrep
383  // The number of doubly-occupied orbitals per irrep
385  // The number of singly-occupied orbitals per irrep
387  // The number of frozen doubly occupied orbitals per irrep
389  // The number of frozen virtual orbitals per irrep
391  // The number of alpha electrons per irrep
393  // The number of beta electrons per irrep
395  // The cache files used by libDPD
397  // The alpha MO coefficients for each irrep
398  std::shared_ptr<Matrix> Ca_;
399  // The alpha MO coefficients for each irrep
400  std::shared_ptr<Matrix> Cb_;
401  // Whether to keep the IWL SO integral file after processing
403  // Whether to keep the IWL MO two particle density matrix
405  // Whether to keep the DPD SO integral file after processing
407  // Whether to keep the DPD MO to particle density matrix after processing
409  // Whether to keep the half-transformed two electron integrals
411  // Whether to keep the half-transformed TPDM
413  // Whether to print the two-electron integrals or not
414  bool printTei_;
415  // Whether to output the results to an IWL buffer
416  bool useIWL_;
417  // Whether to output the results to a DPD buffer
418  bool useDPD_;
419  // Has this object already pre-sorted?
421  // This keeps track of which labels have been assigned by other spaces
422  std::map<char, int> labelsUsed_;
423 };
424 
425 } // End namespaces
426 
427 #endif // Header guard
void set_memory(size_t memory)
Set the memory (in MB) available to the library.
Definition: integraltransform.h:219
bool keepHtInts_
Definition: integraltransform.h:410
bool write_dpd_so_tpdm_
Definition: integraltransform.h:312
bool keepIwlSoInts_
Definition: integraltransform.h:402
std::map< char, int * > aIndices_
Definition: integraltransform.h:304
void setup_tpdm_buffer(const dpdbuf4 *D)
Definition: integraltransform_sort_so_tpdm.cc:44
std::vector< char > spacesUsed_
Definition: integraltransform.h:292
void set_so_tei_file(int so_tei_file)
Sets the SO IWL file to read the TEIs from.
Definition: integraltransform.h:182
size_t get_memory() const
The amount of memory (in MB) available to the library.
Definition: integraltransform.h:221
int * sosym_
Definition: integraltransform.h:378
Definition: integraltransform.h:109
Dimension nalphapi_
Definition: integraltransform.h:392
bool keepDpdMoTpdm_
Definition: integraltransform.h:408
std::string abIntName_
Definition: integraltransform.h:344
void print_dpd_lookup()
Definition: integraltransform_moinfo.cc:753
std::map< std::string, int > dpdLookup_
Definition: integraltransform.h:308
void set_tei_already_presorted(bool val)
Definition: integraltransform.h:216
Definition: integraltransform.h:109
int nfzc_
Definition: integraltransform.h:338
bool alreadyPresorted_
Definition: integraltransform.h:310
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:203
int get_print() const
The level of printing used during transformations.
Definition: integraltransform.h:192
bool get_tei_already_presorted()
Whether SO intergals are already presorted.
Definition: integraltransform.h:215
void backtransform_tpdm_unrestricted()
Definition: integraltransform_tpdm_unrestricted.cc:45
Dimension nbetapi_
Definition: integraltransform.h:394
Definition: integraltransform.h:97
int * cacheFiles_
Definition: integraltransform.h:396
int * aCorrToPitzer_
Definition: integraltransform.h:372
void process_spaces()
Definition: integraltransform_moinfo.cc:89
double * tpdm_buffer_
Definition: integraltransform.h:274
const int * alpha_corr_to_pitzer() const
Get the alpha correlated to Pitzer ordering array, used in backtransforms.
Definition: integraltransform.h:246
OutputType
Definition: integraltransform.h:97
int * bCorrToPitzer_
Definition: integraltransform.h:374
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:208
std::map< char, int * > aOrbsPI_
Definition: integraltransform.h:296
double get_frozen_core_energy() const
Returns the frozen-core energy.
Definition: integraltransform.h:195
Dimension sopi_
Definition: integraltransform.h:376
void set_dpd_int_file(int file)
The file to output DPD integrals to.
Definition: integraltransform.h:234
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:205
std::string bbIntName_
Definition: integraltransform.h:346
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:54
SpinType
Definition: integraltransform.h:117
bool useIWL_
Definition: integraltransform.h:416
void initialize()
Definition: integraltransform.cc:209
Definition: pointgrp.h:105
std::shared_ptr< Matrix > Ca_
Definition: integraltransform.h:398
Definition: integraltransform.h:97
int soIntTEIFile_
Definition: integraltransform.h:316
Definition: integraltransform.h:88
Definition: integraltransform.h:117
std::map< char, SharedMatrix > bMOCoefficients_
Definition: integraltransform.h:302
std::vector< int * > spaceArray_
Definition: integraltransform.h:294
int get_dpd_id() const
The number of the DPD instance used in the transformation.
Definition: integraltransform.h:226
bool initialized_
Definition: integraltransform.h:269
int nirrep() const
Definition: integraltransform.h:250
std::shared_ptr< PSIO > psio_
Definition: integraltransform.h:280
double frozen_core_energy_
Definition: integraltransform.h:276
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:184
void set_ab_int_name(const std::string &name)
Definition: integraltransform.h:240
std::string aaIntName_
Definition: integraltransform.h:342
size_t memory_
Definition: integraltransform.h:354
void backtransform_tpdm_restricted()
Definition: integraltransform_tpdm_restricted.cc:45
Dimension clsdpi_
Definition: integraltransform.h:384
std::map< char, int * > bIndices_
Definition: integraltransform.h:306
int nmo_
Definition: integraltransform.h:330
void transform_oei(const std::shared_ptr< MOSpace > s1, const std::shared_ptr< MOSpace > s2, const char *label)
Definition: integraltransform_oei.cc:53
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:309
Definition: integraltransform.h:109
MOOrdering moOrdering_
Definition: integraltransform.h:286
int moIntFileBB_
Definition: integraltransform.h:360
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:135
Dimension frzvpi_
Definition: integraltransform.h:390
std::vector< std::shared_ptr< MOSpace > > SpaceVec
Definition: integraltransform.h:49
void set_aa_int_name(const std::string &name)
Definition: integraltransform.h:237
std::shared_ptr< Matrix > Cb_
Definition: integraltransform.h:400
int * mosym_
Definition: integraltransform.h:380
std::map< char, int > labelsUsed_
Definition: integraltransform.h:422
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:53
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:248
void backtransform_density()
Definition: integraltransform_tpdm.cc:48
void set_tpdm_already_presorted(bool val)
Whether TPDM has already presorted.
Definition: integraltransform.h:212
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:198
Definition: integraltransform.h:80
std::map< char, SharedMatrix > aMOCoefficients_
Definition: integraltransform.h:300
int * zeros_
Definition: integraltransform.h:366
int nfzv_
Definition: integraltransform.h:340
int iwlBBIntFile_
Definition: integraltransform.h:326
int dpdIntFile_
Definition: integraltransform.h:314
void update_orbitals()
Definition: integraltransform_moinfo.cc:571
void check_initialized()
Definition: integraltransform.cc:332
Definition: dimension.h:39
~IntegralTransform()
Definition: integraltransform.cc:314
void process_eigenvectors()
Definition: integraltransform_moinfo.cc:598
void reset_so_int()
Definition: integraltransform.h:252
void transform_tei_first_half(const std::shared_ptr< MOSpace > s1, const std::shared_ptr< MOSpace > s2)
Definition: integraltransform_tei_1st_half.cc:46
int aHtIntFile_
Definition: integraltransform.h:318
bool printTei_
Definition: integraltransform.h:414
TransformationType transformationType_
Definition: integraltransform.h:282
int bHtIntFile_
Definition: integraltransform.h:320
bool useDPD_
Definition: integraltransform.h:418
bool keepHtTpdm_
Definition: integraltransform.h:412
void set_print(int n)
Set the level of printing used during transformations (0 -&gt; 6)
Definition: integraltransform.h:186
char ** labels_
Definition: integraltransform.h:350
int nTriMo_
Definition: integraltransform.h:336
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:44
int iwlAAIntFile_
Definition: integraltransform.h:322
int nso_
Definition: integraltransform.h:332
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:210
int ** cacheList_
Definition: integraltransform.h:396
void set_bb_int_name(const std::string &name)
Definition: integraltransform.h:243
Definition: integraltransform.h:80
int myDPDNum_
Definition: integraltransform.h:362
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:200
std::shared_ptr< Matrix > SharedMatrix
Definition: adc.h:50
std::shared_ptr< Wavefunction > wfn
Definition: dx_write.cc:59
std::shared_ptr< PSIO > get_psio() const
Get the psio object being used by this object.
Definition: integraltransform.cc:303
int moIntFileAA_
Definition: integraltransform.h:356
int moIntFileAB_
Definition: integraltransform.h:358
OutputType outputType_
Definition: integraltransform.h:288
std::map< char, int * > bOrbsPI_
Definition: integraltransform.h:298
int nirreps_
Definition: integraltransform.h:328
int nTriSo_
Definition: integraltransform.h:334
char * spaces_
Definition: integraltransform.h:348
Definition: libdpd/dpd.h:104
std::shared_ptr< Wavefunction > wfn_
Definition: integraltransform.h:278
bool tpdmAlreadyPresorted_
Definition: integraltransform.h:420
Definition: integraltransform.h:80
int * aQT_
Definition: integraltransform.h:368
SpaceVec uniqueSpaces_
Definition: integraltransform.h:284
bool keepIwlMoTpdm_
Definition: integraltransform.h:404
Dimension mopi_
Definition: integraltransform.h:382
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:46
int DPD_ID(const char c)
Definition: integraltransform_dpd_id.cc:91
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:46
std::vector< size_t > tpdm_buffer_sizes_
Definition: integraltransform.h:272
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:133
Definition: integraltransform.h:109
void presort_so_tei()
Definition: integraltransform_sort_so_tei.cc:178
void generate_oei()
Definition: integraltransform_oei.cc:189
bool keepDpdSoInts_
Definition: integraltransform.h:406
Definition: integraltransform.h:69
double tolerance_
Definition: integraltransform.h:352
Definition: integraltransform.h:58
FrozenOrbitals frozenOrbitals_
Definition: integraltransform.h:290
int print_
Definition: integraltransform.h:364
void presort_mo_tpdm_unrestricted()
Definition: integraltransform_sort_mo_tpdm.cc:215
void set_dpd_id(int n)
Set the number of the DPD instance to be used in the transformation.
Definition: integraltransform.h:224
Dimension frzcpi_
Definition: integraltransform.h:388
int * bQT_
Definition: integraltransform.h:370
Definition: integraltransform.h:69
int iwlABIntFile_
Definition: integraltransform.h:324
Definition: integraltransform.h:69
TransformationType
Definition: integraltransform.h:80
Definition: psio.hpp:196
Dimension openpi_
Definition: integraltransform.h:386