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-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_LIBTRANS_INTEGRALTRANSFORM_H_
30 #define _PSI_SRC_LIB_LIBTRANS_INTEGRALTRANSFORM_H_
31 
32 #include <array>
33 #include <map>
34 #include <vector>
35 #include <string>
37 #include "psi4/libmints/typedefs.h"
38 #include "mospace.h"
39 
40 #ifndef INDEX
41 #define INDEX(i, j) (((i) > (j)) ? (((i) * ((i) + 1) / 2) + (j)) : (((j) * ((j) + 1) / 2) + (i)))
42 #endif
43 
44 namespace psi {
45 
46 struct dpdbuf4;
47 class Matrix;
48 class Dimension;
49 class Wavefunction;
50 class PSIO;
51 
52 typedef std::vector<std::shared_ptr<MOSpace> > SpaceVec;
53 
60  // TODO check usage of restricted, to make sure that it's correct everywhere
61  public:
70  enum class HalfTrans { MakeAndKeep, ReadAndKeep, MakeAndNuke, ReadAndNuke };
71 
81  enum class TransformationType { Restricted, Unrestricted, SemiCanonical };
89  enum class MOOrdering { QTOrder, PitzerOrder };
98  enum class OutputType { DPDOnly, IWLOnly, IWLAndDPD };
110  enum class FrozenOrbitals { None, OccOnly, VirOnly, OccAndVir };
118  enum class SpinType { Alpha, Beta };
136  IntegralTransform(std::shared_ptr<Wavefunction> wfn, SpaceVec spaces,
137  TransformationType transformationType = TransformationType::Restricted,
138  OutputType outputType = OutputType::DPDOnly, MOOrdering moOrdering = MOOrdering::QTOrder,
139  FrozenOrbitals frozenOrbitals = FrozenOrbitals::OccAndVir, bool initialize = true);
140 
142  TransformationType transformationType = TransformationType::Restricted,
143  OutputType outputType = OutputType::DPDOnly, MOOrdering moOrdering = MOOrdering::QTOrder,
144  FrozenOrbitals frozenOrbitals = FrozenOrbitals::OccAndVir, bool initialize = true);
145 
147 
148  void initialize();
149  void presort_so_tei();
150  void generate_oei();
151  void update_orbitals();
152  void transform_T_plus_V(const std::shared_ptr<MOSpace> s1, const std::shared_ptr<MOSpace> s2);
153  void transform_oei(const std::shared_ptr<MOSpace> s1, const std::shared_ptr<MOSpace> s2,
154  std::array<std::string, 4> labels);
155  void transform_tei(const std::shared_ptr<MOSpace> s1, const std::shared_ptr<MOSpace> s2,
156  const std::shared_ptr<MOSpace> s3, const std::shared_ptr<MOSpace> s4,
157  HalfTrans = HalfTrans::MakeAndNuke);
158  void transform_tei_first_half(const std::shared_ptr<MOSpace> s1, const std::shared_ptr<MOSpace> s2);
159  void transform_tei_second_half(const std::shared_ptr<MOSpace> s1, const std::shared_ptr<MOSpace> s2,
160  const std::shared_ptr<MOSpace> s3, const std::shared_ptr<MOSpace> s4);
161  void backtransform_density();
162  void backtransform_tpdm_restricted();
163  void backtransform_tpdm_unrestricted();
164  void print_dpd_lookup();
165  std::vector<SharedMatrix> compute_fock_like_matrices(SharedMatrix Hcore, std::vector<SharedMatrix> Cmats);
166 
167  int DPD_ID(const char c);
168  int DPD_ID(char *str);
169  int DPD_ID(const char *str);
170  int DPD_ID(const std::string &str);
171  int DPD_ID(const std::shared_ptr<MOSpace> s1, const std::shared_ptr<MOSpace> s2, SpinType spin, bool pack);
172 
173  /*===== The set/get accessor functions =====*/
174 
176  void set_so_tei_file(int so_tei_file) { soIntTEIFile_ = so_tei_file; }
178  void set_write_dpd_so_tpdm(bool t_f) { write_dpd_so_tpdm_ = t_f; }
180  void set_print(int n) { print_ = n; }
183  void set_orbitals(SharedMatrix C);
184 
186  int get_print() const { return print_; }
187 
189  double get_frozen_core_energy() const { return frozen_core_energy_; }
190 
192  void set_keep_ht_ints(bool val) { keepHtInts_ = val; }
194  bool get_keep_ht_ints() const { return keepHtInts_; }
195 
197  void set_keep_dpd_so_ints(bool val) { keepDpdSoInts_ = val; }
199  bool get_keep_dpd_so_ints() const { return keepDpdSoInts_; }
200 
202  void set_keep_iwl_so_ints(bool val) { keepIwlSoInts_ = val; }
204  bool get_keep_iwl_so_ints() const { return keepIwlSoInts_; }
206  void set_tpdm_already_presorted(bool val) { tpdmAlreadyPresorted_ = val; }
207 
209  bool get_tei_already_presorted() { return alreadyPresorted_; }
210  void set_tei_already_presorted(bool val) { alreadyPresorted_ = val; }
211 
213  void set_memory(size_t memory) { memory_ = memory; }
215  size_t get_memory() const { return memory_; }
216 
218  void set_dpd_id(int n) { myDPDNum_ = n; }
220  int get_dpd_id() const { return myDPDNum_; }
221 
223  std::shared_ptr<PSIO> get_psio() const;
225  void set_psio(std::shared_ptr<PSIO> psio);
226 
228  void set_dpd_int_file(int file) { dpdIntFile_ = file; }
231  void set_aa_int_name(const std::string &name) { aaIntName_ = name; }
234  void set_ab_int_name(const std::string &name) { abIntName_ = name; }
237  void set_bb_int_name(const std::string &name) { bbIntName_ = name; }
238 
240  const int *alpha_corr_to_pitzer() const { return aCorrToPitzer_; }
242  const int *beta_corr_to_pitzer() const { return bCorrToPitzer_; }
243 
244  int nirrep() const { return nirreps_; }
245 
246  void reset_so_int() { alreadyPresorted_ = false; }
247 
248  protected:
249  void check_initialized();
250  void common_initialize();
251 
252  void process_eigenvectors();
253  void process_spaces();
254  void presort_mo_tpdm_restricted();
255  void presort_mo_tpdm_unrestricted();
256  void setup_tpdm_buffer(const dpdbuf4 *D);
257  void sort_so_tpdm(const dpdbuf4 *B, int irrep, size_t first_row, size_t num_rows, bool first_run);
258 
259  void transform_oei_restricted(const std::shared_ptr<MOSpace> s1, const std::shared_ptr<MOSpace> s2,
260  const std::vector<double> &soInts, std::string label);
261  void transform_oei_unrestricted(const std::shared_ptr<MOSpace> s1, const std::shared_ptr<MOSpace> s2,
262  const std::vector<double> &soInts, std::string A_label, std::string B_label);
263  void trans_one(int m, int n, double *input, double *output, double **C, int soOffset, int *order,
264  bool backtransform = false, double scale = 0.0);
265 
266  // Has this instance been initialized yet?
268 
269  // The number of SO tpdm elements in each SO shell quartet
270  std::vector<size_t> tpdm_buffer_sizes_;
271  // The buffer used in sorting the SO basis tpdm
272  double *tpdm_buffer_;
273  // Frozen core energy
275  // The wavefunction object, containing the orbital infomation
276  std::shared_ptr<Wavefunction> wfn_;
277  // Pointer to the PSIO object to use for file I/O
278  std::shared_ptr<PSIO> psio_;
279  // The type of transformation
281  // The unique MO spaces provided to this object's constructor
283  // The ordering of the resulting integrals
285  // The format of the outputted integrals
287  // How to handle frozen orbitals
289  // The unique orbital spaces involved in this transformation
290  std::vector<char> spacesUsed_;
291  // A list of the arrays to pass into libDPD
292  std::vector<int *> spaceArray_;
293  // The alpha orbitals per irrep for each space
294  std::map<char, int *> aOrbsPI_;
295  // The beta orbitals per irrep for each space
296  std::map<char, int *> bOrbsPI_;
297  // The alpha MO coefficients for all unique spaces needed
298  std::map<char, SharedMatrix> aMOCoefficients_;
299  // The beta MO coefficients for all unique spaces needed
300  std::map<char, SharedMatrix> bMOCoefficients_;
301  // The alpha orbital indexing arrays
302  std::map<char, int *> aIndices_;
303  // The beta orbital indexing arrays
304  std::map<char, int *> bIndices_;
305  // The lookup table for DPD indexing
306  std::map<std::string, int> dpdLookup_;
307  // Whether the SO integrals have already been presorted
309  // Whether to also write DPD formatted SO TPDMs after density transformations
311  // The file to which DPD formatted integrals are written
313  // The file from which IWL SO TEIs are read
315  // The file containing alpha half-transformed integrals in DPD format
317  // The file containing beta half-transformed integrals in DPD format
319  // The file containing alpha-alpha IWL formatted integrals
321  // The file containing alpha-beta IWL formatted integrals
323  // The file containing beta-beta IWL formatted integrals
325  // The number of irreps
326  int nirreps_;
327  // The number of molecular orbitals
328  int nmo_;
329  // The number of symmetrized atomic orbitals
330  int nso_;
331  // The number of pairs of symmetrized atomic orbitals
332  int nTriSo_;
333  // The number of pairs of molecular orbitals
334  int nTriMo_;
335  // The number of frozen doubly occupied orbitals
336  int nfzc_;
337  // The number of frozen virtual orbitals
338  int nfzv_;
339  // The name of the alpha-alpha DPD integral buffer
340  std::string aaIntName_;
341  // The name of the alpha-beta DPD integral buffer
342  std::string abIntName_;
343  // The name of the beta-beta DPD integral buffer
344  std::string bbIntName_;
345  // A string describing the spaces in which the integrals are to be transformed
346  char *spaces_;
347  // An array containing labels for each irrep
348  std::vector<std::string> labels_;
349  // The definition of zero
350  double tolerance_;
351  // The amount of memory, in MB
352  size_t memory_;
353  // The PSI file number for the alpha-alpha integrals
355  // The PSI file number for the alpha-beta integrals
357  // The PSI file number for the beta-beta integrals
359  // The DPD id to use internally
361  // The amount of information to print
362  int print_;
363  // Just an array of zeros! Used in the null MOSpace "transforms"
364  int *zeros_;
365  // The alpha Pitzer->QT reordering array
366  int *aQT_;
367  // The alpha Pitzer->QT reordering array
368  int *bQT_;
369  // The alpha correlated to Pitzer ordering arrays, used in backtransforms
371  // The beta correlated to Pitzer ordering arrays, used in backtransforms
373  // The number of symmetrized orbitals per irrep
375  // The symmetry (irrep number) of each symmetrized atomic orbital
376  int *sosym_;
377  // The symmetry (irrep number) of each molecular orbital
378  int *mosym_;
379  // The number of molecular orbitals per irrep
381  // The number of doubly-occupied orbitals per irrep
383  // The number of singly-occupied orbitals per irrep
385  // The number of frozen doubly occupied orbitals per irrep
387  // The number of frozen virtual orbitals per irrep
389  // The number of alpha electrons per irrep
391  // The number of beta electrons per irrep
393  // The cache files used by libDPD
394  int *cacheFiles_, **cacheList_;
395  // The alpha MO coefficients for each irrep
396  std::shared_ptr<Matrix> Ca_;
397  // The alpha MO coefficients for each irrep
398  std::shared_ptr<Matrix> Cb_;
399  // The one electron Hamiltonian matrix for each irrep
400  std::shared_ptr<Matrix> H_;
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:213
bool keepHtInts_
Definition: integraltransform.h:410
bool write_dpd_so_tpdm_
Definition: integraltransform.h:310
bool keepIwlSoInts_
Definition: integraltransform.h:402
std::vector< char > spacesUsed_
Definition: integraltransform.h:290
void set_so_tei_file(int so_tei_file)
Sets the SO IWL file to read the TEIs from.
Definition: integraltransform.h:176
size_t get_memory() const
The amount of memory (in MB) available to the library.
Definition: integraltransform.h:215
int * sosym_
Definition: integraltransform.h:376
Dimension nalphapi_
Definition: integraltransform.h:390
bool keepDpdMoTpdm_
Definition: integraltransform.h:408
std::string abIntName_
Definition: integraltransform.h:342
std::map< std::string, int > dpdLookup_
Definition: integraltransform.h:306
void set_tei_already_presorted(bool val)
Definition: integraltransform.h:210
int nfzc_
Definition: integraltransform.h:336
bool alreadyPresorted_
Definition: integraltransform.h:308
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:197
int get_print() const
The level of printing used during transformations.
Definition: integraltransform.h:186
bool get_tei_already_presorted()
Whether SO intergals are already presorted.
Definition: integraltransform.h:209
Dimension nbetapi_
Definition: integraltransform.h:392
int * aCorrToPitzer_
Definition: integraltransform.h:370
double * tpdm_buffer_
Definition: integraltransform.h:272
const int * alpha_corr_to_pitzer() const
Get the alpha correlated to Pitzer ordering array, used in backtransforms.
Definition: integraltransform.h:240
OutputType
Definition: integraltransform.h:98
int * bCorrToPitzer_
Definition: integraltransform.h:372
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:202
double get_frozen_core_energy() const
Returns the frozen-core energy.
Definition: integraltransform.h:189
Dimension sopi_
Definition: integraltransform.h:374
void set_dpd_int_file(int file)
The file to output DPD integrals to.
Definition: integraltransform.h:228
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:199
std::string bbIntName_
Definition: integraltransform.h:344
SpinType
Definition: integraltransform.h:118
bool useIWL_
Definition: integraltransform.h:416
Definition: pointgrp.h:106
std::shared_ptr< Matrix > Ca_
Definition: integraltransform.h:396
int soIntTEIFile_
Definition: integraltransform.h:314
std::map< char, SharedMatrix > bMOCoefficients_
Definition: integraltransform.h:300
int get_dpd_id() const
The number of the DPD instance used in the transformation.
Definition: integraltransform.h:220
bool initialized_
Definition: integraltransform.h:267
int nirrep() const
Definition: integraltransform.h:244
std::shared_ptr< PSIO > psio_
Definition: integraltransform.h:278
double frozen_core_energy_
Definition: integraltransform.h:274
MOOrdering
Definition: integraltransform.h:89
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:178
std::string aaIntName_
Definition: integraltransform.h:340
void set_ab_int_name(const std::string &name)
Definition: integraltransform.h:234
size_t memory_
Definition: integraltransform.h:352
Dimension clsdpi_
Definition: integraltransform.h:382
int nmo_
Definition: integraltransform.h:328
MOOrdering moOrdering_
Definition: integraltransform.h:284
int moIntFileBB_
Definition: integraltransform.h:358
Dimension frzvpi_
Definition: integraltransform.h:388
std::map< char, int * > bIndices_
Definition: integraltransform.h:304
void set_aa_int_name(const std::string &name)
Definition: integraltransform.h:231
std::shared_ptr< Matrix > Cb_
Definition: integraltransform.h:398
int * mosym_
Definition: integraltransform.h:378
std::map< char, int > labelsUsed_
Definition: integraltransform.h:422
const int * beta_corr_to_pitzer() const
Get the beta correlated to Pitzer ordering array, used in backtransforms.
Definition: integraltransform.h:242
void set_tpdm_already_presorted(bool val)
Whether TPDM has already presorted.
Definition: integraltransform.h:206
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:192
std::map< char, SharedMatrix > aMOCoefficients_
Definition: integraltransform.h:298
int * zeros_
Definition: integraltransform.h:364
std::map< char, int * > aIndices_
Definition: integraltransform.h:302
int nfzv_
Definition: integraltransform.h:338
int iwlBBIntFile_
Definition: integraltransform.h:324
int dpdIntFile_
Definition: integraltransform.h:312
Definition: dimension.h:40
void reset_so_int()
Definition: integraltransform.h:246
int aHtIntFile_
Definition: integraltransform.h:316
bool printTei_
Definition: integraltransform.h:414
std::vector< std::shared_ptr< MOSpace > > SpaceVec
Definition: integraltransform.h:50
TransformationType transformationType_
Definition: integraltransform.h:280
std::map< char, int * > bOrbsPI_
Definition: integraltransform.h:296
int bHtIntFile_
Definition: integraltransform.h:318
bool useDPD_
Definition: integraltransform.h:418
const char * labels[]
Definition: petitelist.cc:961
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:180
int nTriMo_
Definition: integraltransform.h:334
int iwlAAIntFile_
Definition: integraltransform.h:320
std::vector< std::string > labels_
Definition: integraltransform.h:348
int nso_
Definition: integraltransform.h:330
FrozenOrbitals
Definition: integraltransform.h:110
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:204
int ** cacheList_
Definition: integraltransform.h:394
std::vector< int * > spaceArray_
Definition: integraltransform.h:292
void set_bb_int_name(const std::string &name)
Definition: integraltransform.h:237
int myDPDNum_
Definition: integraltransform.h:360
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:194
std::shared_ptr< Matrix > SharedMatrix
Definition: adc.h:49
std::shared_ptr< Matrix > H_
Definition: integraltransform.h:400
std::shared_ptr< Wavefunction > wfn
Definition: dx_write.cc:60
int moIntFileAA_
Definition: integraltransform.h:354
int moIntFileAB_
Definition: integraltransform.h:356
OutputType outputType_
Definition: integraltransform.h:286
#define PSI_API
Definition: pragma.h:153
int nirreps_
Definition: integraltransform.h:326
int nTriSo_
Definition: integraltransform.h:332
char * spaces_
Definition: integraltransform.h:346
Definition: libdpd/dpd.h:105
std::shared_ptr< Wavefunction > wfn_
Definition: integraltransform.h:276
bool tpdmAlreadyPresorted_
Definition: integraltransform.h:420
int * aQT_
Definition: integraltransform.h:366
SpaceVec uniqueSpaces_
Definition: integraltransform.h:282
bool keepIwlMoTpdm_
Definition: integraltransform.h:404
Dimension mopi_
Definition: integraltransform.h:380
std::vector< size_t > tpdm_buffer_sizes_
Definition: integraltransform.h:270
HalfTrans
Definition: integraltransform.h:70
std::map< char, int * > aOrbsPI_
Definition: integraltransform.h:294
bool keepDpdSoInts_
Definition: integraltransform.h:406
double tolerance_
Definition: integraltransform.h:350
Definition: integraltransform.h:59
FrozenOrbitals frozenOrbitals_
Definition: integraltransform.h:288
int print_
Definition: integraltransform.h:362
void set_dpd_id(int n)
Set the number of the DPD instance to be used in the transformation.
Definition: integraltransform.h:218
Dimension frzcpi_
Definition: integraltransform.h:386
int * bQT_
Definition: integraltransform.h:368
int iwlABIntFile_
Definition: integraltransform.h:322
TransformationType
Definition: integraltransform.h:81
Definition: psio.hpp:195
Dimension openpi_
Definition: integraltransform.h:384