25 #include "Permutation.h"
31 #include "SymMolecule.h"
32 #include "SimulatedAnnealing.h"
33 #include "Hamiltonian.h"
34 #include "OrbitalTransform.h"
35 #include "UnitaryMatrix.h"
36 #include "LocalMinimizer.h"
50 int main(
int argc,
char **argv)
58 std::string integralsfile =
"mo-integrals.h5";
59 std::string h5name =
"rdm.h5";
62 bool jacobirots =
false;
65 struct option long_options[] =
67 {
"integrals", required_argument, 0,
'i'},
68 {
"output", required_argument, 0,
'o'},
69 {
"unitary", required_argument, 0,
'u'},
70 {
"simulated-annealing", no_argument, 0,
's'},
71 {
"jacobi-rotations", no_argument, 0,
'j'},
72 {
"random", no_argument, 0,
'r'},
73 {
"help", no_argument, 0,
'h'},
79 while( (j = getopt_long (argc, argv,
"hi:o:su:jr", long_options, &i)) != -1)
84 cout <<
"Usage: " << argv[0] <<
" [OPTIONS]\n"
86 " -i, --integrals=integrals-file Set the input integrals file\n"
87 " -o, --output=h5-file Set the output filename for the RDM\n"
88 " -s, --simulated-annealing Use stimulated Annealing to find lowest energy\n"
89 " -j, --jacobi-rotations Use Jacobi Rotations to find lowest energy\n"
90 " -u, --unitary Use this unitary to calc energy\n"
91 " -r, --random Use a random unitary as start point\n"
92 " -h, --help Display this help\n"
97 integralsfile = optarg;
116 if(simanneal && jacobirots)
118 cout <<
"Cannot do both simulated annealing and jacobi rotations, you have to choose!" << endl;
125 setenv(
"SAVE_H5_PATH",
"./", 0);
127 cout <<
"Reading: " << integralsfile << endl;
134 cout <<
"Overriding the input unitary " << unitary <<
" with a random unitary!" << endl;
141 cout <<
"U=exp(X), X=" << endl;
147 std::string filename = getenv(
"SAVE_H5_PATH");
148 filename +=
"/random-start-unitary.h5";
152 cout <<
"Saving random start point to " << filename << endl;
156 if(!simanneal && !jacobirots)
160 cout <<
"Reading unitary " << unitary << endl;
170 auto start = std::chrono::high_resolution_clock::now();
172 auto end = std::chrono::high_resolution_clock::now();
174 cout <<
"Building took: " << std::fixed << std::chrono::duration_cast<std::chrono::duration<double,std::ratio<1>>>(end-start).count() <<
" s" << endl;
176 start = std::chrono::high_resolution_clock::now();
178 end = std::chrono::high_resolution_clock::now();
180 cout <<
"Diagonalization took: " << std::chrono::duration_cast<std::chrono::duration<double,std::ratio<1>>>(end-start).count() <<
" s" << endl;
182 cout <<
"E = " << eig2.first + mol.
get_nucl_rep() << endl;
186 start = std::chrono::high_resolution_clock::now();
187 rdm.
Build(perm, eig2.second);
188 end = std::chrono::high_resolution_clock::now();
190 cout <<
"Building 2DM took: " << std::chrono::duration_cast<std::chrono::duration<double,std::ratio<1>>>(end-start).count() <<
" s" << endl;
196 cout <<
"DM2 Energy = " << rdm.
Dot(rdm_ham) + mol.
get_nucl_rep() << endl;
197 cout <<
"DM2 Trace = " << rdm.
Trace() << endl;
199 std::string h5_name = getenv(
"SAVE_H5_PATH");
200 h5_name +=
"/rdm.h5";
202 cout <<
"Writing 2DM to " << h5_name << endl;
215 cout <<
"Reading unitary " << unitary << endl;
224 auto start = std::chrono::high_resolution_clock::now();
228 auto end = std::chrono::high_resolution_clock::now();
230 cout <<
"The optimal energy is " << opt.
get_energy() << std::endl;
232 cout <<
"Optimization took: " << std::fixed << std::chrono::duration_cast<std::chrono::duration<double,std::ratio<1>>>(end-start).count() <<
" s" << endl;
239 auto eigs = ham.Diagonalize();
240 cout <<
"E = " << eigs.first + mol.
get_nucl_rep() << endl;
243 auto perm = ham.getPermutation();
244 start = std::chrono::high_resolution_clock::now();
245 rdm.
Build(perm, eigs.second);
246 end = std::chrono::high_resolution_clock::now();
248 cout <<
"Building 2DM took: " << std::chrono::duration_cast<std::chrono::duration<double,std::ratio<1>>>(end-start).count() <<
" s" << endl;
250 DM2 rdm_ham(opt_mol);
253 cout <<
"DM2 Energy = " << rdm.
Dot(rdm_ham) + mol.
get_nucl_rep() << endl;
254 cout <<
"DM2 Trace = " << rdm.
Trace() << endl;
265 cout <<
"Reading unitary " << unitary << endl;
272 cout <<
"The optimal energy is " << opt.
get_energy() << std::endl;
278 cout <<
"DM2 Energy = " << rdm.
Dot(rdm_ham) + mol.
get_nucl_rep() << endl;
279 cout <<
"DM2 Trace = " << rdm.
Trace() << endl;
281 std::string h5_name = getenv(
"SAVE_H5_PATH");
282 h5_name +=
"/rdm.h5";
284 cout <<
"Writing 2DM to " << h5_name << endl;
double get_energy() const
simanneal::OrbitalTransform & getOrbitalTf() const
void Minimize(bool dist_choice=false)
std::pair< double, std::vector< double > > Diagonalize() const
doci::DOCIHamiltonian & getHam() const
int main(int argc, char **argv)
void Set_delta_angle(double)
void print_unitary() const
void Set_start_temp(double)
void WriteToFile(const std::string) const
Molecule const & getMolecule() const
simanneal::OrbitalTransform & getOrbitaltf() const
void set_conv_crit(double)
const doci::DM2 & get_DM2() const
void Build(Permutation &, std::vector< double > &)
void BuildHamiltonian(const Molecule &)
void Set_max_angle(double)
void saveU(std::string savename) const
Save the unitary to disk.
void Set_delta_temp(double)
doci::Sym_Molecule & getHam() const
void loadU(std::string loadname)
Load the unitary from disk.
double get_energy() const
double get_nucl_rep() const
CheMPS2::Hamiltonian & getHamObject() const
double Dot(const DM2 &) const
Permutation const & getPermutation() const
void make_skew_symmetric()