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-2019 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  const 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; }
182  void set_build_mo_fock(bool t_f) { buildMOFock_ = t_f; }
185  void set_orbitals(SharedMatrix C);
186 
188  int get_print() const { return print_; }
189 
191  double get_frozen_core_energy() const { return frozen_core_energy_; }
192 
194  void set_keep_ht_ints(bool val) { keepHtInts_ = val; }
196  bool get_keep_ht_ints() const { return keepHtInts_; }
197 
199  void set_keep_dpd_so_ints(bool val) { keepDpdSoInts_ = val; }
201  bool get_keep_dpd_so_ints() const { return keepDpdSoInts_; }
202 
204  void set_keep_iwl_so_ints(bool val) { keepIwlSoInts_ = val; }
206  bool get_keep_iwl_so_ints() const { return keepIwlSoInts_; }
208  void set_tpdm_already_presorted(bool val) { tpdmAlreadyPresorted_ = val; }
209 
211  bool get_tei_already_presorted() { return alreadyPresorted_; }
212  void set_tei_already_presorted(bool val) { alreadyPresorted_ = val; }
213 
215  void set_memory(size_t memory) { memory_ = memory; }
217  size_t get_memory() const { return memory_; }
218 
220  void set_dpd_id(int n) { myDPDNum_ = n; }
222  int get_dpd_id() const { return myDPDNum_; }
223 
225  std::shared_ptr<PSIO> get_psio() const;
227  void set_psio(std::shared_ptr<PSIO> psio);
228 
230  void set_dpd_int_file(int file) { dpdIntFile_ = file; }
233  void set_aa_int_name(const std::string &name) { aaIntName_ = name; }
236  void set_ab_int_name(const std::string &name) { abIntName_ = name; }
239  void set_bb_int_name(const std::string &name) { bbIntName_ = name; }
240 
242  const int *alpha_corr_to_pitzer() const { return aCorrToPitzer_; }
244  const int *beta_corr_to_pitzer() const { return bCorrToPitzer_; }
245 
246  int nirrep() const { return nirreps_; }
247 
248  void reset_so_int() { alreadyPresorted_ = false; }
249 
250  protected:
251  void check_initialized();
252  void common_initialize();
253 
254  void process_eigenvectors();
255  void process_spaces();
256  void presort_mo_tpdm_restricted();
257  void presort_mo_tpdm_unrestricted();
258  void setup_tpdm_buffer(const dpdbuf4 *D);
259  void sort_so_tpdm(const dpdbuf4 *B, int irrep, size_t first_row, size_t num_rows, bool first_run);
260 
261  void transform_oei_restricted(const std::shared_ptr<MOSpace> s1, const std::shared_ptr<MOSpace> s2,
262  const std::vector<double> &soInts, std::string label);
263  void transform_oei_unrestricted(const std::shared_ptr<MOSpace> s1, const std::shared_ptr<MOSpace> s2,
264  const std::vector<double> &soInts, std::string A_label, std::string B_label);
265  void trans_one(int m, int n, double *input, double *output, double **C, int soOffset, int *order,
266  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  std::vector<std::string> 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
396  int *cacheFiles_, **cacheList_;
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  // The one electron Hamiltonian matrix for each irrep
402  std::shared_ptr<Matrix> H_;
403  // Whether to keep the IWL SO integral file after processing
405  // Whether to keep the IWL MO two particle density matrix
407  // Whether to keep the DPD SO integral file after processing
409  // Whether to keep the DPD MO to particle density matrix after processing
411  // Whether to keep the half-transformed two electron integrals
413  // Whether to keep the half-transformed TPDM
415  // Whether to print the two-electron integrals or not
416  bool printTei_;
417  // Whether to output the results to an IWL buffer
418  bool useIWL_;
419  // Whether to output the results to a DPD buffer
420  bool useDPD_;
421  // Has this object already pre-sorted?
423  // Whether to form the MO basis Fock matrix during TEI presort
425  // This keeps track of which labels have been assigned by other spaces
426  std::map<char, int> labelsUsed_;
427 };
428 
429 } // namespace psi
430 
431 #endif // Header guard
void set_memory(size_t memory)
Set the memory (in MB) available to the library.
Definition: integraltransform.h:215
bool keepHtInts_
Definition: integraltransform.h:412
bool write_dpd_so_tpdm_
Definition: integraltransform.h:312
bool keepIwlSoInts_
Definition: integraltransform.h:404
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:176
size_t get_memory() const
The amount of memory (in MB) available to the library.
Definition: integraltransform.h:217
int * sosym_
Definition: integraltransform.h:378
Dimension nalphapi_
Definition: integraltransform.h:392
bool keepDpdMoTpdm_
Definition: integraltransform.h:410
std::string abIntName_
Definition: integraltransform.h:344
std::map< std::string, int > dpdLookup_
Definition: integraltransform.h:308
void set_tei_already_presorted(bool val)
Definition: integraltransform.h:212
int nfzc_
Definition: integraltransform.h:338
bool alreadyPresorted_
Definition: integraltransform.h:310
bool buildMOFock_
Definition: integraltransform.h:424
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:199
int get_print() const
The level of printing used during transformations.
Definition: integraltransform.h:188
bool get_tei_already_presorted()
Whether SO intergals are already presorted.
Definition: integraltransform.h:211
Dimension nbetapi_
Definition: integraltransform.h:394
int * aCorrToPitzer_
Definition: integraltransform.h:372
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:242
OutputType
Definition: integraltransform.h:98
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:204
double get_frozen_core_energy() const
Returns the frozen-core energy.
Definition: integraltransform.h:191
Dimension sopi_
Definition: integraltransform.h:376
void set_dpd_int_file(int file)
The file to output DPD integrals to.
Definition: integraltransform.h:230
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:201
std::string bbIntName_
Definition: integraltransform.h:346
SpinType
Definition: integraltransform.h:118
bool useIWL_
Definition: integraltransform.h:418
Definition: pointgrp.h:104
std::shared_ptr< Matrix > Ca_
Definition: integraltransform.h:398
int soIntTEIFile_
Definition: integraltransform.h:316
std::map< char, SharedMatrix > bMOCoefficients_
Definition: integraltransform.h:302
int get_dpd_id() const
The number of the DPD instance used in the transformation.
Definition: integraltransform.h:222
bool initialized_
Definition: integraltransform.h:269
int nirrep() const
Definition: integraltransform.h:246
std::shared_ptr< PSIO > psio_
Definition: integraltransform.h:280
double frozen_core_energy_
Definition: integraltransform.h:276
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:342
void set_ab_int_name(const std::string &name)
Definition: integraltransform.h:236
size_t memory_
Definition: integraltransform.h:354
Dimension clsdpi_
Definition: integraltransform.h:384
int nmo_
Definition: integraltransform.h:330
MOOrdering moOrdering_
Definition: integraltransform.h:286
int moIntFileBB_
Definition: integraltransform.h:360
Dimension frzvpi_
Definition: integraltransform.h:390
std::map< char, int * > bIndices_
Definition: integraltransform.h:306
void set_aa_int_name(const std::string &name)
Definition: integraltransform.h:233
std::shared_ptr< Matrix > Cb_
Definition: integraltransform.h:400
int * mosym_
Definition: integraltransform.h:380
std::map< char, int > labelsUsed_
Definition: integraltransform.h:426
const int * beta_corr_to_pitzer() const
Get the beta correlated to Pitzer ordering array, used in backtransforms.
Definition: integraltransform.h:244
void set_tpdm_already_presorted(bool val)
Whether TPDM has already presorted.
Definition: integraltransform.h:208
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:194
std::map< char, SharedMatrix > aMOCoefficients_
Definition: integraltransform.h:300
int * zeros_
Definition: integraltransform.h:366
std::map< char, int * > aIndices_
Definition: integraltransform.h:304
int nfzv_
Definition: integraltransform.h:340
int iwlBBIntFile_
Definition: integraltransform.h:326
void set_build_mo_fock(bool t_f)
Whether to build the Fock matrix in the MO basis during integral presort.
Definition: integraltransform.h:182
int dpdIntFile_
Definition: integraltransform.h:314
Definition: dimension.h:40
void reset_so_int()
Definition: integraltransform.h:248
int aHtIntFile_
Definition: integraltransform.h:318
bool printTei_
Definition: integraltransform.h:416
std::vector< std::shared_ptr< MOSpace > > SpaceVec
Definition: integraltransform.h:50
TransformationType transformationType_
Definition: integraltransform.h:282
std::map< char, int * > bOrbsPI_
Definition: integraltransform.h:298
int bHtIntFile_
Definition: integraltransform.h:320
bool useDPD_
Definition: integraltransform.h:420
const char * labels[]
Definition: petitelist.cc:942
bool keepHtTpdm_
Definition: integraltransform.h:414
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:336
int iwlAAIntFile_
Definition: integraltransform.h:322
std::vector< std::string > labels_
Definition: integraltransform.h:350
int nso_
Definition: integraltransform.h:332
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:206
int ** cacheList_
Definition: integraltransform.h:396
std::vector< int * > spaceArray_
Definition: integraltransform.h:294
void set_bb_int_name(const std::string &name)
Definition: integraltransform.h:239
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:196
std::shared_ptr< Matrix > SharedMatrix
Definition: adc.h:49
std::shared_ptr< Matrix > H_
Definition: integraltransform.h:402
std::shared_ptr< Wavefunction > wfn
Definition: dx_write.cc:60
int moIntFileAA_
Definition: integraltransform.h:356
int moIntFileAB_
Definition: integraltransform.h:358
OutputType outputType_
Definition: integraltransform.h:288
#define PSI_API
Definition: pragma.h:155
int nirreps_
Definition: integraltransform.h:328
int nTriSo_
Definition: integraltransform.h:334
char * spaces_
Definition: integraltransform.h:348
Definition: libdpd/dpd.h:105
std::shared_ptr< Wavefunction > wfn_
Definition: integraltransform.h:278
bool tpdmAlreadyPresorted_
Definition: integraltransform.h:422
int * aQT_
Definition: integraltransform.h:368
SpaceVec uniqueSpaces_
Definition: integraltransform.h:284
bool keepIwlMoTpdm_
Definition: integraltransform.h:406
Dimension mopi_
Definition: integraltransform.h:382
std::vector< size_t > tpdm_buffer_sizes_
Definition: integraltransform.h:272
HalfTrans
Definition: integraltransform.h:70
std::map< char, int * > aOrbsPI_
Definition: integraltransform.h:296
bool keepDpdSoInts_
Definition: integraltransform.h:408
double tolerance_
Definition: integraltransform.h:352
Definition: integraltransform.h:59
FrozenOrbitals frozenOrbitals_
Definition: integraltransform.h:290
int print_
Definition: integraltransform.h:364
void set_dpd_id(int n)
Set the number of the DPD instance to be used in the transformation.
Definition: integraltransform.h:220
Dimension frzcpi_
Definition: integraltransform.h:388
int * bQT_
Definition: integraltransform.h:370
int iwlABIntFile_
Definition: integraltransform.h:324
TransformationType
Definition: integraltransform.h:81
Definition: psio.hpp:195
Dimension openpi_
Definition: integraltransform.h:386