forked from susilehtola/erkale
/
main.cpp
147 lines (127 loc) · 3.61 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
* This source code is part of
*
* E R K A L E
* -
* HF/DFT from Hel
*
* Written by Susi Lehtola, 2010-2011
* Copyright (c) 2010-2011, Susi Lehtola
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*/
#include "basislibrary.h"
#include "basis.h"
#include "checkpoint.h"
#include "dftfuncs.h"
#include "elements.h"
#include "emd/emd.h"
#include "find_molecules.h"
#include "linalg.h"
#include "mathf.h"
#include "xyzutils.h"
#include "properties.h"
#include "scf.h"
#include "settings.h"
#include "stringutil.h"
#include "timer.h"
// Needed for libint init
#include "eriworker.h"
#include <armadillo>
#include <cstdio>
#include <cstdlib>
#include <cfloat>
#ifdef _OPENMP
#include <omp.h>
#endif
#ifdef SVNRELEASE
#include "version.h"
#endif
int main(int argc, char **argv) {
#ifdef _OPENMP
printf("ERKALE - HF/DFT from Hel, OpenMP version, running on %i cores.\n",omp_get_max_threads());
#else
printf("ERKALE - HF/DFT from Hel, serial version.\n");
#endif
print_copyright();
print_license();
#ifdef SVNRELEASE
printf("At svn revision %s.\n\n",SVNREVISION);
#endif
print_hostname();
if(argc!=2) {
printf("Usage: $ %s runfile\n",argv[0]);
return 0;
}
// Initialize libint
init_libint_base();
Timer t;
t.print_time();
// Parse settings
Settings set;
set.add_scf_settings();
set.add_string("SaveChk","File to use as checkpoint","erkale.chk");
set.add_string("LoadChk","File to load old results from","");
set.add_bool("ForcePol","Force polarized calculation",false);
set.add_bool("FreezeCore","Freeze the atomic cores?",false);
set.parse(std::string(argv[1]),true);
set.print();
// Redirect output?
std::string logfile=set.get_string("Logfile");
if(stricmp(logfile,"stdout")!=0) {
// Redirect stdout to file
FILE *outstream=freopen(logfile.c_str(),"w",stdout);
if(outstream==NULL) {
ERROR_INFO();
throw std::runtime_error("Unable to redirect output!\n");
} else
fprintf(stderr,"\n");
}
// Basis set
BasisSet basis;
std::string basfile(set.get_string("Basis"));
if(stricmp(basfile,"Read")==0) {
// Get checkpoint file
std::string chkf(set.get_string("LoadChk"));
if(!chkf.size())
throw std::runtime_error("Must specify LoadChk for Basis Read\n");
if(!file_exists(chkf))
throw std::runtime_error("Can't find LoadChk!\n");
Checkpoint chk(chkf,false);
chk.read(basis);
printf("Basis set read in from checkpoint.\n\n");
} else {
// Read in atoms.
std::vector<atom_t> atoms;
std::string atomfile=set.get_string("System");
if(file_exists(atomfile))
atoms=load_xyz(atomfile);
else {
// Check if a directory has been set
char * libloc=getenv("ERKALE_SYSDIR");
if(libloc) {
std::string filename=std::string(libloc)+"/"+atomfile;
if(file_exists(filename))
atoms=load_xyz(filename);
else
throw std::runtime_error("Unable to open xyz input file!\n");
} else
throw std::runtime_error("Unable to open xyz input file!\n");
}
// Read in basis set
BasisSetLibrary baslib;
baslib.load_basis(basfile);
// Construct basis set
construct_basis(basis,atoms,baslib,set);
}
// Do the calculation
calculate(basis,set);
if(set.get_bool("Verbose")) {
printf("\nRunning program took %s.\n",t.elapsed().c_str());
t.print_time();
}
return 0;
}