v2DM-DOCI  1.0
Hamiltonian.h
Go to the documentation of this file.
1 /*
2  CheMPS2: a spin-adapted implementation of DMRG for ab initio quantum chemistry
3  Copyright (C) 2013, 2014 Sebastian Wouters
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 
20 #ifndef HAMILTONIAN_CHEMPS2_H
21 #define HAMILTONIAN_CHEMPS2_H
22 
23 #include <string>
24 #include <memory>
25 
26 #include "Irreps.h"
27 #include "TwoIndex.h"
28 #include "FourIndex.h"
29 #include "Options.h"
30 
31 using std::string;
32 
33 namespace simanneal { class OptIndex; }
34 
35 namespace CheMPS2{
56  class Hamiltonian{
57 
58  friend class simanneal::OptIndex;
59 
60  public:
61 
63 
66  Hamiltonian(const int Norbitals, const int nGroup, const int * OrbIrreps);
67 
69 
70  Hamiltonian(const string file_psi4text);
71 
73 
77  Hamiltonian(const bool fileh5, const string main_file=HAMILTONIAN_ParentStorageName, const string file_tmat=HAMILTONIAN_TmatStorageName, const string file_vmat=HAMILTONIAN_VmatStorageName);
78 
79  Hamiltonian(const Hamiltonian &);
80 
81  Hamiltonian(Hamiltonian &&) = default;
82 
84 
85  Hamiltonian& operator=(Hamiltonian &&) = default;
86 
88  virtual ~Hamiltonian() = default;
89 
91 
92  int getL() const;
93 
95 
96  int getNGroup() const;
97 
99 
101  int getOrbitalIrrep(const int nOrb) const;
102 
104 
105  void setEconst(const double val);
106 
108 
111  void setTmat(const int index1, const int index2, const double val);
112 
114 
119  void setVmat(const int index1, const int index2, const int index3, const int index4, const double val);
120 
122 
127  void addToVmat(const int index1, const int index2, const int index3, const int index4, const double val);
128 
130 
131  double getEconst() const;
132 
134 
137  double getTmat(const int index1, const int index2) const;
138 
140 
145  double getVmat(const int index1, const int index2, const int index3, const int index4) const;
146 
148 
151  void save(const string file_parent=HAMILTONIAN_ParentStorageName, const string file_tmat=HAMILTONIAN_TmatStorageName, const string file_vmat=HAMILTONIAN_VmatStorageName) const;
152 
154 
157  void read(const string file_parent=HAMILTONIAN_ParentStorageName, const string file_tmat=HAMILTONIAN_TmatStorageName, const string file_vmat=HAMILTONIAN_VmatStorageName);
158 
159  void save2(const string filename) const;
160 
161  void read2(const string filename);
162 
163  void setNe(int);
164 
165  int getNe() const;
166 
168  void debugcheck() const;
169 
170  static Hamiltonian CreateFromH5(const string filename);
171 
173  void reset();
174 
175  private:
176 
177  //number of orbitals
178  int L;
179 
180  //number of electrons
181  int Ne;
182 
183  //symmetry info
185 
186  //irrep of each orbital
187  std::unique_ptr<int []> orb2irrep;
188 
189  //number of orbitals per irrep
190  std::unique_ptr<int []> irrep2num_orb;
191 
192  //index of an orbital within irrep block
193  std::unique_ptr<int []> orb2indexSy;
194 
195  //1-particle matrix elements
196  std::unique_ptr<TwoIndex> Tmat;
197 
198  //2-particle matrix elements
199  std::unique_ptr<FourIndex> Vmat;
200 
201  //Constant part of the Hamiltonian
202  double Econst;
203 
204  //If filename=="LOADH5" in Hamiltonian::Hamiltonian then the HDF5 Hamiltonian is loaded
205  void CreateAndFillFromH5(const string file_parent, const string file_tmat, const string file_vmat);
206 
207  //If filename!="LOADH5" in Hamiltonian::Hamiltonian then a Psi4 dump in the file with name "filename" is loaded
208  void CreateAndFillFromPsi4dump(const string filename);
209 
210  };
211 }
212 
213 #endif
static Hamiltonian CreateFromH5(const string filename)
void reset()
set everything to zero
std::unique_ptr< int[]> orb2indexSy
Definition: Hamiltonian.h:193
void setTmat(const int index1, const int index2, const double val)
Set a Tmat element.
int getOrbitalIrrep(const int nOrb) const
Get an orbital irrep number.
double getVmat(const int index1, const int index2, const int index3, const int index4) const
Get a Vmat element.
void debugcheck() const
Debug check certain elements and sums.
void setVmat(const int index1, const int index2, const int index3, const int index4, const double val)
Set a Vmat element.
void save(const string file_parent=HAMILTONIAN_ParentStorageName, const string file_tmat=HAMILTONIAN_TmatStorageName, const string file_vmat=HAMILTONIAN_VmatStorageName) const
Save the Hamiltonian.
void setEconst(const double val)
Set the constant energy.
std::unique_ptr< FourIndex > Vmat
Definition: Hamiltonian.h:199
void read(const string file_parent=HAMILTONIAN_ParentStorageName, const string file_tmat=HAMILTONIAN_TmatStorageName, const string file_vmat=HAMILTONIAN_VmatStorageName)
Load the Hamiltonian.
void save2(const string filename) const
double getTmat(const int index1, const int index2) const
Get a Tmat element.
const string HAMILTONIAN_ParentStorageName
Definition: Options.h:58
std::unique_ptr< TwoIndex > Tmat
Definition: Hamiltonian.h:196
void CreateAndFillFromH5(const string file_parent, const string file_tmat, const string file_vmat)
void addToVmat(const int index1, const int index2, const int index3, const int index4, const double val)
Add to Vmat element.
void CreateAndFillFromPsi4dump(const string filename)
virtual ~Hamiltonian()=default
Destructor.
Hamiltonian & operator=(const Hamiltonian &)
Definition: Hamiltonian.cpp:84
std::unique_ptr< int[]> orb2irrep
Definition: Hamiltonian.h:187
void read2(const string filename)
const string HAMILTONIAN_VmatStorageName
Definition: Options.h:57
int getNGroup() const
Get the group number.
double getEconst() const
Get the constant energy.
Hamiltonian(const int Norbitals, const int nGroup, const int *OrbIrreps)
Constructor.
Definition: Hamiltonian.cpp:38
int getL() const
Get the number of orbitals.
const string HAMILTONIAN_TmatStorageName
Definition: Options.h:56
std::unique_ptr< int[]> irrep2num_orb
Definition: Hamiltonian.h:190