[0b990d] | 1 | //
|
---|
| 2 | // moindexspace.h
|
---|
| 3 | //
|
---|
| 4 | // Copyright (C) 2004 Edward Valeev
|
---|
| 5 | //
|
---|
| 6 | // Author: Edward Valeev <edward.valeev@chemistry.gatech.edu>
|
---|
| 7 | // Maintainer: EV
|
---|
| 8 | //
|
---|
| 9 | // This file is part of the SC Toolkit.
|
---|
| 10 | //
|
---|
| 11 | // The SC Toolkit is free software; you can redistribute it and/or modify
|
---|
| 12 | // it under the terms of the GNU Library General Public License as published by
|
---|
| 13 | // the Free Software Foundation; either version 2, or (at your option)
|
---|
| 14 | // any later version.
|
---|
| 15 | //
|
---|
| 16 | // The SC Toolkit 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 Library General Public License for more details.
|
---|
| 20 | //
|
---|
| 21 | // You should have received a copy of the GNU Library General Public License
|
---|
| 22 | // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
|
---|
| 23 | // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 24 | //
|
---|
| 25 | // The U.S. Government is granted a limited license as per AL 91-7.
|
---|
| 26 | //
|
---|
| 27 |
|
---|
| 28 | #ifdef __GNUG__
|
---|
| 29 | #pragma interface
|
---|
| 30 | #endif
|
---|
| 31 |
|
---|
| 32 | #ifndef _chemistry_qc_mbptr12_moindexspace_h
|
---|
| 33 | #define _chemistry_qc_mbptr12_moindexspace_h
|
---|
| 34 |
|
---|
| 35 | #include <vector>
|
---|
| 36 | #include <util/ref/ref.h>
|
---|
| 37 | #include <util/state/statein.h>
|
---|
| 38 | #include <util/state/stateout.h>
|
---|
| 39 | #include <math/scmat/abstract.h>
|
---|
| 40 | #include <util/state/statein.h>
|
---|
| 41 | #include <chemistry/qc/basis/basis.h>
|
---|
| 42 |
|
---|
| 43 | using namespace std;
|
---|
| 44 |
|
---|
| 45 | namespace sc {
|
---|
| 46 |
|
---|
| 47 | /** Class MOIndexSpace describes a range of molecular orbitals or
|
---|
| 48 | similar objects that are linear combinations of basis functions
|
---|
| 49 | (e.g. atomic orbitals). In general, such sets are subspaces of
|
---|
| 50 | a full space of orbitals supported by the given basis. Orbitals
|
---|
| 51 | can be symmetry-blocked, ordered by energy, etc.
|
---|
| 52 | Examples of sets that can be described
|
---|
| 53 | using MOIndexSpace are occupied MOs and virtual MOs. */
|
---|
| 54 |
|
---|
| 55 | class MOIndexSpace : virtual public SavableState {
|
---|
| 56 |
|
---|
| 57 | public:
|
---|
| 58 |
|
---|
| 59 | /// Describes the ordering of indices
|
---|
| 60 | enum IndexOrder { symmetry = 0, energy = 1, undefined = 2 };
|
---|
| 61 |
|
---|
| 62 | MOIndexSpace(StateIn&);
|
---|
| 63 | /** This function constructs an MOIndexSpace from (blocked) space full_coefs.
|
---|
| 64 | Block i will contain vectors [ offsets[i], offsets[i]+nmopi[i]-1 ] . By default,
|
---|
| 65 | the space maintains the same blocked structure and the same order within blocks
|
---|
| 66 | as the original space (moorder=symmetry). If moorder=energy and eigenvalues
|
---|
| 67 | evals are provided, then all vectors will be put in one block and
|
---|
| 68 | sorted according to ascending evals.
|
---|
| 69 |
|
---|
| 70 | \param name -- the name of this MOIndexSpace
|
---|
| 71 | \param full_coefs -- symmetry-blocked transformation coefficient matrix
|
---|
| 72 | (AO by MO) for the full space
|
---|
| 73 | \param basis -- basis set
|
---|
| 74 | \param integral -- integral factory
|
---|
| 75 | \param offsets -- block offsets
|
---|
| 76 | \param nmopi -- new block sizes
|
---|
| 77 | \param moorder -- specifies new ordering of vectors
|
---|
| 78 | \param evals -- used to sort the vectors
|
---|
| 79 | */
|
---|
| 80 | MOIndexSpace(std::string name, const RefSCMatrix& full_coefs,
|
---|
| 81 | const Ref<GaussianBasisSet> basis, const Ref<Integral>& integral,
|
---|
| 82 | const vector<int>& offsets, const vector<int>& nmopi,
|
---|
| 83 | IndexOrder moorder = symmetry,
|
---|
| 84 | const RefDiagSCMatrix& evals = 0);
|
---|
| 85 | /** This constructor should be used when the MOIndexSpace object is a subspace of a full orbital space.
|
---|
| 86 | Similarly to the previous constructor, it constructs an MOIndexSpace object using a symmetry-blocked
|
---|
| 87 | transformation coefficient matrix (AO by MO) for the full space,
|
---|
| 88 | basis set, "eigenvalues" and the number of orbitals with lowest (nfzc) and highest (nfzv) eigenvalues
|
---|
| 89 | to be dropped. The orbitals in the constructed space are ordered by energy. */
|
---|
| 90 | MOIndexSpace(std::string name, const RefSCMatrix& full_coefs,
|
---|
| 91 | const Ref<GaussianBasisSet> basis, const Ref<Integral>& integral,
|
---|
| 92 | const RefDiagSCMatrix& evals, int nfzc, int nfzv, IndexOrder moorder = energy);
|
---|
| 93 | /** This constructor should be used when the MOIndexSpace object is the full orbital space.
|
---|
| 94 | The orbitals will be symmetry-blocked. */
|
---|
| 95 | MOIndexSpace(std::string name, const RefSCMatrix& full_coefs,
|
---|
| 96 | const Ref<GaussianBasisSet> basis, const Ref<Integral>& integral);
|
---|
| 97 |
|
---|
| 98 | /** This constructor is a true hack introduced because I have no idea how to construct what I need.
|
---|
| 99 | It will copy orig_space but replace it's coefs with new_coefs, and its basis with new_basis. */
|
---|
| 100 | MOIndexSpace(std::string name, const Ref<MOIndexSpace>& orig_space,
|
---|
| 101 | const RefSCMatrix& new_coefs,
|
---|
| 102 | const Ref<GaussianBasisSet>& new_basis);
|
---|
| 103 | ~MOIndexSpace();
|
---|
| 104 |
|
---|
| 105 | void save_data_state(StateOut&);
|
---|
| 106 |
|
---|
| 107 | /// Returns the name of this MOIndexSpace.
|
---|
| 108 | const std::string name() const;
|
---|
| 109 | /// Returns the AO basis set
|
---|
| 110 | const Ref<GaussianBasisSet> basis() const;
|
---|
| 111 | /// Returns the integral factory used to instantiate the coefficient matrix
|
---|
| 112 | Ref<Integral> integral() const;
|
---|
| 113 | /// Returns the coefficient matrix
|
---|
| 114 | const RefSCMatrix coefs() const;
|
---|
| 115 | /// Returns the "eigenvalues" matrix
|
---|
| 116 | const RefDiagSCMatrix evals() const;
|
---|
| 117 | /// Returns the orbital symmetry array
|
---|
| 118 | vector<int> mosym() const;
|
---|
| 119 | /// Returns the order of the orbitals
|
---|
| 120 | IndexOrder moorder() const;
|
---|
| 121 | /// Returns the rank of the space
|
---|
| 122 | int rank() const;
|
---|
| 123 | /// Returns the rank of the full space
|
---|
| 124 | int full_rank() const;
|
---|
| 125 | /// Returns the number of blocks
|
---|
| 126 | int nblocks() const;
|
---|
| 127 | /// Returns the number of orbitals in each block
|
---|
| 128 | vector<int> nmo() const;
|
---|
| 129 | /// Returns the full-space index of the first orbital in each block
|
---|
| 130 | vector<int> offsets() const;
|
---|
| 131 | /// Returns the full-space index
|
---|
| 132 | int to_full_space(const int i) const;
|
---|
| 133 |
|
---|
| 134 | /// Returns how much "significant" (i.e. O^2) memory this object uses
|
---|
| 135 | size_t memory_in_use() const;
|
---|
| 136 |
|
---|
| 137 | /// Prints out this
|
---|
| 138 | void print(std::ostream&o=ExEnv::out0()) const;
|
---|
| 139 | /// Produces a short summary
|
---|
| 140 | void print_summary(std::ostream& os) const;
|
---|
| 141 |
|
---|
| 142 | private:
|
---|
| 143 | std::string name_; // String identifier for the orbital space
|
---|
| 144 |
|
---|
| 145 | Ref<GaussianBasisSet> basis_; // The AO basis
|
---|
| 146 | Ref<Integral> integral_; // The integral factory
|
---|
| 147 | RefSCMatrix coefs_; // AO->MO transformation coefficients (nao by nmo matrix)
|
---|
| 148 | RefDiagSCMatrix evals_; // "eigenvalues" associated with the MOs
|
---|
| 149 | RefSCDimension modim_; // The MO dimension
|
---|
| 150 | vector<int> mosym_; // irrep of each orbital
|
---|
| 151 |
|
---|
| 152 | int rank_; // The rank of this space
|
---|
| 153 | int full_rank_; // Rank of the full space, i.e. number of MOs
|
---|
| 154 | int nblocks_; // Number of blocks
|
---|
| 155 | vector<int> nmo_; // Number of MOs in each block
|
---|
| 156 | vector<int> offsets_; // Index of the first MO in each block relative to the first MO of that block in full space
|
---|
| 157 | vector<int> map_to_full_space_; // Full-space index
|
---|
| 158 |
|
---|
| 159 | IndexOrder moorder_;
|
---|
| 160 |
|
---|
| 161 | // checks mosym_ for irrep indices outside of the allowed range
|
---|
| 162 | void check_mosym() const;
|
---|
| 163 |
|
---|
| 164 | // determines offsets_ and nmo_ from nfzc, nfzv, and evals
|
---|
| 165 | void frozen_to_blockinfo(const int nfzc, const int nfzv, const RefDiagSCMatrix& evals);
|
---|
| 166 |
|
---|
| 167 | // computes coefficient matrix from the full coefficient matrix. If moorder_ == energy
|
---|
| 168 | // then the MO vectors will be sorted by their eigenvalues
|
---|
| 169 | void full_coefs_to_coefs(const RefSCMatrix& full_coefs, const RefDiagSCMatrix& evals);
|
---|
| 170 |
|
---|
| 171 | // initialize the object
|
---|
| 172 | void init();
|
---|
| 173 |
|
---|
| 174 | // sorting functions borrowed from mbpt.cc
|
---|
| 175 | static void dquicksort(double *item,int *index,int n);
|
---|
| 176 | static void dqs(double *item,int *index,int left,int right);
|
---|
| 177 |
|
---|
| 178 | };
|
---|
| 179 |
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | #endif
|
---|
| 183 |
|
---|
| 184 | // Local Variables:
|
---|
| 185 | // mode: c++
|
---|
| 186 | // c-file-style: "CLJ"
|
---|
| 187 | // End:
|
---|
| 188 |
|
---|
| 189 |
|
---|