v2DM-DOCI  1.0
doci_bp2.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 <cstring>
27 #include <getopt.h>
28 #include <signal.h>
29 
30 #include "include.h"
31 #include "BoundaryPoint.h"
32 #include "LocalMinimizer.h"
33 
34 // from CheMPS2
35 #include "Hamiltonian.h"
36 #include "OptIndex.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 void stopcalcsignal(int sig);
43 void stopminsignal(int sig);
44 
45 int main(int argc,char **argv)
46 {
47  using std::cout;
48  using std::endl;
49  using namespace doci2DM;
51 
52  cout.precision(10);
53 
54  std::string integralsfile = "mo-integrals.h5";
55  std::string unitary;
56  std::string rdmfile;
57  bool random = false;
58  bool localmini = false;
59  bool scan = false;
60  bool localmininoopt = false;
61 
62  struct option long_options[] =
63  {
64  {"integrals", required_argument, 0, 'i'},
65  {"unitary", required_argument, 0, 'u'},
66  {"rdm", required_argument, 0, 'd'},
67  {"random", no_argument, 0, 'r'},
68  {"scan", no_argument, 0, 's'},
69  {"local-minimizer", no_argument, 0, 'l'},
70  {"local-minimizer-no-opt", no_argument, 0, 'n'},
71  {"help", no_argument, 0, 'h'},
72  {0, 0, 0, 0}
73  };
74 
75  int i,j;
76 
77  while( (j = getopt_long (argc, argv, "d:rlhi:u:sn", long_options, &i)) != -1)
78  switch(j)
79  {
80  case 'h':
81  case '?':
82  cout << "Usage: " << argv[0] << " [OPTIONS]\n"
83  "\n"
84  " -i, --integrals=integrals-file Set the input integrals file\n"
85  " -d, --rdm=rdm-file Use this rdm as starting point\n"
86  " -u, --unitary=unitary-file Use the unitary matrix in this file\n"
87  " -r, --random Perform a random unitary transformation on the Hamiltonian\n"
88  " -l, --local-minimizer Use the local minimizer\n"
89  " -n, --local-minimizer-no-opt Use the local minimizer without optimalization\n"
90  " -h, --help Display this help\n"
91  "\n";
92  return 0;
93  break;
94  case 'i':
95  integralsfile = optarg;
96  break;
97  case 'u':
98  unitary = optarg;
99  break;
100  case 'd':
101  rdmfile = optarg;
102  break;
103  case 'r':
104  random = true;
105  break;
106  case 'l':
107  localmini = true;
108  break;
109  case 's':
110  scan = true;
111  break;
112  case 'n':
113  localmininoopt = true;
114  break;
115  }
116 
117  cout << "Reading: " << integralsfile << endl;
118 
119  // make sure we have a save path, even if it's not specify already
120  // This will not overwrite an already set SAVE_H5_PATH
121  setenv("SAVE_H5_PATH", "./", 0);
122 
123  cout << "Using save path: " << getenv("SAVE_H5_PATH") << endl;
124 
125  const auto L = 12;
126  const auto N = 12;
127 
128  cout << "Starting with L=" << L << " N=" << N << endl;
129 
130  TPM pairham(L,N);
131  pairham = 0;
132  pairham.pairing(20.0);
133 
134 
135  BoundaryPoint method(pairham);
136 // method.getHam() = pairham;
137  method.set_tol_PD(1e-7);
138 // method.getLineq() = Lineq(L,N,true);
139 
140  method.Run();
141 
142  cout << "The optimal energy is " << method.evalEnergy() << std::endl;
143 
144 
145 
146 
147 /* // for(int k_in=0;k_in<L;k_in++)
148  * // for(int l_in=k_in+1;l_in<L;l_in++)
149  * int k_in = 2;
150  * int l_in = 3;
151  * if(ham.getOrbitalIrrep(k_in) == ham.getOrbitalIrrep(l_in))
152  * {
153  * std::fstream fs;
154  * std::string filename = "orbs-scan-" + std::to_string(k_in) + "-" + std::to_string(l_in) + ".txt";
155  * fs.open(filename, std::fstream::out | std::fstream::trunc);
156  *
157  * fs.precision(10);
158  *
159  * fs << "# theta\trot\trot+v2dm" << endl;
160  *
161  * auto found = rdm.find_min_angle(k_in,l_in,0.3,getT3,getV3);
162  *
163  * cout << "Min:\t" << k_in << "\t" << l_in << "\t" << found.first << "\t" << found.second << endl;
164  *
165  * cout << "######################" << endl;
166  *
167  * int Na = 200;
168  * #pragma omp parallel for
169  * for(int a=0;a<=Na;a++)
170  * {
171  * double theta = 2.0*M_PI/(1.0*Na) * a;
172  *
173  * BoundaryPoint mymethod(ham);
174  *
175  * mymethod.getRDM() = orig_rdm;
176  * mymethod.getHam() = orig_ham;
177  * mymethod.getHam().rotate(k_in, l_in, theta, getT3, getV3);
178  *
179  * simanneal::OrbitalTransform orbtrans2(ham2);
180  * orbtrans2.DoJacobiRotation(ham, k_in, l_in, theta);
181  * orbtrans2.get_unitary().jacobi_rotation(ham2.getOrbitalIrrep(k_in), k_in, l_in, theta);
182  * //orbtrans2.fillHamCI(ham);
183  *
184  * mymethod.BuildHam(new_ham);
185  *
186  * double new_en = orig_rdm.ddot(mymethod.getHam());
187  *
188  * mymethod.Run();
189  *
190  * #pragma omp critical
191  * fs << theta << "\t" << new_en << "\t" << mymethod.getEnergy() << endl;
192  * }
193  * fs.close();
194  * }
195  */
196 
197 
198  std::string h5_name = getenv("SAVE_H5_PATH");
199  h5_name += "/optimal-rdm.h5";
200 
201  method.getRDM().WriteToFile(h5_name);
202 
203  return 0;
204 }
205 
206 void stopcalcsignal(int sig)
207 {
208  stopping=1;
209 }
210 
211 void stopminsignal(int sig)
212 {
213  stopping_min=1;
214 }
215 
216 /* vim: set ts=3 sw=3 expandtab :*/
int main(int argc, char **argv)
Definition: doci_bp2.cpp:45
sig_atomic_t stopping_min
Definition: doci_bp2.cpp:40
void pairing(double)
Definition: TPM.cpp:1087
void stopcalcsignal(int sig)
Definition: doci_bp2.cpp:206
double evalEnergy() const
void WriteToFile(hid_t &group_id) const
Definition: TPM.cpp:304
sig_atomic_t stopping
Definition: doci_bp2.cpp:39
void stopminsignal(int sig)
Definition: doci_bp2.cpp:211