25 #include "Permutation.h"
27 #include "DOCIHamtilonian.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;
124 if(getenv(
"SAVE_H5_PATH"))
126 h5name = getenv(
"SAVE_H5_PATH");
131 setenv(
"SAVE_H5_PATH",
"./", 0);
133 cout <<
"Reading: " << integralsfile << endl;
140 cout <<
"Overriding the input unitary " << unitary <<
" with a random unitary!" << endl;
147 cout <<
"U=exp(X), X=" << endl;
153 std::string filename = getenv(
"SAVE_H5_PATH");
154 filename +=
"/random-start-unitary.h5";
158 cout <<
"Saving random start point to " << filename << endl;
162 if(!simanneal && !jacobirots)
166 cout <<
"Reading unitary " << unitary << endl;
176 auto start = std::chrono::high_resolution_clock::now();
178 auto end = std::chrono::high_resolution_clock::now();
180 cout <<
"Building took: " << std::fixed << std::chrono::duration_cast<std::chrono::duration<double,std::ratio<1>>>(end-start).count() <<
" s" << endl;
182 start = std::chrono::high_resolution_clock::now();
185 end = std::chrono::high_resolution_clock::now();
187 cout <<
"Diagonalization took: " << std::chrono::duration_cast<std::chrono::duration<double,std::ratio<1>>>(end-start).count() <<
" s" << endl;
193 cout <<
"E = " << eig2.first + mol.
get_nucl_rep() << endl;
197 start = std::chrono::high_resolution_clock::now();
198 rdm.
Build(perm, eig2.second);
199 end = std::chrono::high_resolution_clock::now();
201 cout <<
"Building 2DM took: " << std::chrono::duration_cast<std::chrono::duration<double,std::ratio<1>>>(end-start).count() <<
" s" << endl;
207 cout <<
"DM2 Energy = " << rdm.
Dot(rdm_ham) + mol.
get_nucl_rep() << endl;
208 cout <<
"DM2 Trace = " << rdm.
Trace() << endl;
210 cout <<
"Writing 2DM to " << h5name << endl;
223 cout <<
"Reading unitary " << unitary << endl;
232 auto start = std::chrono::high_resolution_clock::now();
236 auto end = std::chrono::high_resolution_clock::now();
238 cout <<
"The optimal energy is " << opt.
get_energy() << std::endl;
240 cout <<
"Optimization took: " << std::fixed << std::chrono::duration_cast<std::chrono::duration<double,std::ratio<1>>>(end-start).count() <<
" s" << endl;
247 auto eigs = ham.Diagonalize();
248 cout <<
"E = " << eigs.first + mol.
get_nucl_rep() << endl;
251 auto perm = ham.getPermutation();
252 start = std::chrono::high_resolution_clock::now();
253 rdm.
Build(perm, eigs.second);
254 end = std::chrono::high_resolution_clock::now();
256 cout <<
"Building 2DM took: " << std::chrono::duration_cast<std::chrono::duration<double,std::ratio<1>>>(end-start).count() <<
" s" << endl;
258 DM2 rdm_ham(opt_mol);
261 cout <<
"DM2 Energy = " << rdm.
Dot(rdm_ham) + mol.
get_nucl_rep() << endl;
262 cout <<
"DM2 Trace = " << rdm.
Trace() << endl;
273 cout <<
"Reading unitary " << unitary << endl;
279 cout <<
"The optimal energy is " << opt.
get_energy() << std::endl;
285 cout <<
"DM2 Energy = " << rdm.
Dot(rdm_ham) + mol.
get_nucl_rep() << endl;
286 cout <<
"DM2 Trace = " << rdm.
Trace() << endl;
289 cout <<
"Writing 2DM to " << h5name << 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
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()