v2DM-DOCI  1.0
print.cpp
Go to the documentation of this file.
1 /*
2  * @BEGIN LICENSE
3  *
4  * Copyright (C) 2014-2015 Ward Poelmans
5  *
6  * This file is part of v2DM-DOCI.
7  *
8  * v2DM-DOCI is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * Foobar is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
20  *
21  * @END LICENSE
22  */
23 
24 #include <iostream>
25 #include <fstream>
26 #include <getopt.h>
27 #include <signal.h>
28 
29 #include "include.h"
30 #include "BoundaryPoint.h"
31 
32 // from CheMPS2
33 #include "Hamiltonian.h"
34 #include "OptIndex.h"
35 #include "OrbitalTransform.h"
36 #include "UnitaryMatrix.h"
37 
38 // if set, the signal has been given to stop the calculation and write current step to file
39 sig_atomic_t stopping = 0;
40 sig_atomic_t stopping_min = 0;
41 
42 int main(int argc,char **argv)
43 {
44  using std::cout;
45  using std::endl;
46  using namespace doci2DM;
47 
48  cout.precision(10);
49 
50  std::string inputfile = "rdm.h5";
51  std::string integralsfile;
52  std::string unitary;
53  bool dm2 = false;
54  bool dm1 = false;
55  bool sorted = false;
56 
57  struct option long_options[] =
58  {
59  {"integrals", required_argument, 0, 'i'},
60  {"unitary", required_argument, 0, 'u'},
61  {"rdm", required_argument, 0, 'r'},
62  {"2dm", no_argument, 0, '2'},
63  {"1dm", no_argument, 0, '1'},
64  {"sort", no_argument, 0, 's'},
65  {"help", no_argument, 0, 'h'},
66  {0, 0, 0, 0}
67  };
68 
69  int i,j;
70 
71  while( (j = getopt_long (argc, argv, "h12si:u:r:", long_options, &i)) != -1)
72  switch(j)
73  {
74  case 'h':
75  case '?':
76  cout << "Usage: " << argv[0] << " [OPTIONS]\n"
77  "\n"
78  " -r, --rdm=rdm-file Read this RDM\n"
79  " -i, --integrals=integrals-file Set the input integrals file\n"
80  " -u, --unitary=unitary-file Use the unitary matrix in this file\n"
81  " -1, --1dm Print the 1DM\n"
82  " -2, --2dm Print the 2DM\n"
83  " -s, --sort Sort the 1DM elements\n"
84  " -h, --help Display this help\n"
85  "\n";
86  return 0;
87  break;
88  case 'i':
89  integralsfile = optarg;
90  break;
91  case 'u':
92  unitary = optarg;
93  break;
94  case 'r':
95  inputfile = optarg;
96  break;
97  case '1':
98  dm1 = true;
99  break;
100  case '2':
101  dm2 = true;
102  break;
103  case 's':
104  sorted = true;
105  break;
106  }
107 
108  cout << "Reading: " << inputfile << endl;
109 
110  int N, L;
111 
112  std::unique_ptr<CheMPS2::Hamiltonian> ham;
113 
114  if(!integralsfile.empty())
115  {
116  cout << "Reading ham: " << integralsfile << endl;
117  ham.reset(new CheMPS2::Hamiltonian(CheMPS2::Hamiltonian::CreateFromH5(integralsfile)));
118 
119  L = ham->getL(); //dim sp hilbert space
120  N = ham->getNe(); //nr of particles
121 
122  cout << "Found L=" << L << " N=" << N << endl;
123  }
124 
125  TPM rdm = TPM::CreateFromFile(inputfile);
126  L = rdm.gL();
127  N = rdm.gN();
128 
129  cout << "Read: L=" << L << " N=" << N << endl;
130 
131  if(!integralsfile.empty() && !unitary.empty())
132  {
133  simanneal::OrbitalTransform orbtrans(*ham);
134 
135  orbtrans.get_unitary().loadU(unitary);
136  orbtrans.fillHamCI(*ham);
137 
138  doci2DM::BoundaryPoint method(*ham);
139  method.getRDM() = rdm;
140 
141  method.energyperirrep(*ham, true);
142 
143  if(dm1)
144  {
145  SPM spm(rdm);
146  simanneal::OptIndex index(*ham);
147 
148  spm.Particlesperirrep(index);
149  }
150 
151  return 0;
152  }
153 
154  if(dm2)
155  {
156  cout << "2DM:" << endl;
157  cout << rdm << endl;
158  cout << "Trace: " << rdm.trace() << endl;
159  cout << "Block: " << rdm.getMatrix(0).trace() << endl;
160  cout << "vec: " << rdm.getVector(0).trace() << endl;
161  }
162 
163  SPM spm(rdm);
164 
165  if(dm1)
166  {
167  cout << "1DM:" << endl;
168 
169  if(sorted)
170  spm.PrintSorted();
171  else
172  cout << spm << endl;
173 
174  cout << "Trace: " << spm.trace() << endl;
175  }
176 
177  return 0;
178 }
179 
180 
181 /* vim: set ts=3 sw=3 expandtab :*/
int gN() const
Definition: TPM.cpp:110
double trace() const
Definition: Container.cpp:250
static Hamiltonian CreateFromH5(const string filename)
Matrix & getMatrix(int)
Definition: Container.cpp:174
double trace() const
Definition: Matrix.cpp:244
void PrintSorted() const
Definition: SPM.cpp:173
static TPM CreateFromFile(std::string filename)
Definition: TPM.cpp:1825
Vector & getVector(int)
Definition: Container.cpp:184
std::vector< double > energyperirrep(const CheMPS2::Hamiltonian &, bool print=false)
void fillHamCI(CheMPS2::Hamiltonian &HamCI)
std::vector< double > Particlesperirrep(const simanneal::OptIndex &index, bool print=true) const
Definition: SPM.cpp:196
UnitaryMatrix & get_unitary()
int gL() const
Definition: TPM.cpp:115
double trace() const
Definition: Vector.cpp:255
int getL() const
Get the number of orbitals.