-
Notifications
You must be signed in to change notification settings - Fork 1
/
components.h
309 lines (294 loc) · 7.36 KB
/
components.h
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
#ifndef FILE_COMP
#define FILE_COMP
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstring>
using namespace std;
class components
{
public:
int Nat;
int Nbasis;
int NBsUse; //The number of MOs produced (may differ from AOs if basis has been collapsed)
double ** MOs;
double ** S;
double * Evls;
string * Atypes;
components(){
Nat=0;
Nbasis=0;
}
~components(){
if (Nbasis != 0 ){
for (int i=0; i <Nbasis;i++) {
delete [] MOs[i];
delete [] S[i];
}
delete [] S;
delete [] MOs;
delete [] Evls;
//delete [] Atypes;
}
MOs=0;
S=0;
Atypes=0;
Evls=0;
Nbasis=0;
}
void readS(char * namefile){
//read all the info from a punch file
char infile[256];
strcpy(infile,namefile);
strcat(infile,".log");
ifstream in(infile);
if (!in) {cerr << "***Error*** : " << infile << " doesn't exist.\n";}
string word;
while( in ){
getline(in, word);
if ( word == " Two-electron integral symmetry is turned off."
|| word == " Two-electron integral symmetry is turned on.") {
in >> word;
sscanf(word.c_str(), "%i", &Nbasis);
cerr << "NBasis = " << Nbasis << endl;
}
if (word.find("*** Overlap")!=string::npos) {
S = new double * [Nbasis];
for (int m=0;m<Nbasis;m++) {S[m] = new double[Nbasis];}
for (int j=0; j<Nbasis; j+=5) {
getline(in,word); //Get labels
int line=0;
for (int i=j; i<Nbasis; i++) {
in >> word; //Get label
if (line<4) { //Don't have all fields
for (int l=0; l<=line; l++) {
in >> word;
size_t pos=word.find("D");
word=word.substr(0,pos)+"e"+word.substr(pos+1);
S[i][j+l]=S[j+l][i]=atof(word.c_str());
}
}
else{ //Have 5 fields
for (int l=0; l<=4; l++) {
in >> word;
size_t pos=word.find("D");
word=word.substr(0,pos)+"e"+word.substr(pos+1);
S[i][j+l]=S[j+l][i]=atof(word.c_str());
}
}
line++;
}//for(i)
getline(in,word); //Appears to be necessary to finish line
}//for(j)
}//if(*** Overlap)
}//while(in)
cerr << "Read in S... ";
}//components(char * namefile)
void readMOs(char * namefile) {
char infile[256];
//TIDY
char logfile[256];
strcpy(logfile,namefile);
strcat(logfile,".log");
ifstream logIn(logfile);
string word;
while (logfile) {
getline(logIn,word);
if (word.find("NBsUse=")!=string::npos) {
NBsUse=atoi(word.substr(8,6).c_str());
cerr << "NBsUse = " << NBsUse << endl;
break;
}
}
if (Nbasis==0 || NBsUse==0) {cerr << "***Error*** : Trying to read MOs without knowing the number of basis sets\n";}
strcpy(infile,namefile);
strcat(infile,".pun");
ifstream in(infile);
if (!in) {cerr << "***Error*** : " << infile << " doesn't exist.\n";}
getline(in,word); //First line of rubbish
MOs = new double * [Nbasis];
for (int i=0; i<Nbasis; i++) {MOs[i] = new double [NBsUse];}
Evls = new double [NBsUse];
//N.B. MOs[i][j] = <Basis_i | MO_j>
for (int i=0; i<NBsUse; i++) {
getline(in,word); //MO label and energy
size_t pos=word.find("OE=");
word=word.substr(pos+3);
pos=word.find("D");
word=word.substr(0,pos)+"e"+word.substr(pos+1);
Evls[i]=27.211396*atof(word.c_str()); //eV
for (int j=0; j<Nbasis; j+=5) {
getline(in,word);
if (Nbasis-j>=5) {
for (int k=0; k<5; k++) {
string f=word.substr(15*k, 15*(k+1));
f=f.substr(0,(f.find("D")))+"e"+f.substr(f.find("D")+1);
MOs[j+k][i]=atof(f.c_str());
}//for(k)
}//if(Nbasis-j>5)
else {
for (int k=0; k<Nbasis-j; k++) {
string f=word.substr(15*k, 15*(k+1));
f=f.substr(0,(f.find("D")))+"e"+f.substr(f.find("D")+1);
MOs[j+k][i]=atof(f.c_str());
}//for(k)
}//else
}//for(Nbasis)
}//for(Nbasis)
cerr << "Read in MOs\n";
}//readMOs(char * namefile)
void checkOrthNorm() {
for (int psi1=0; psi1<NBsUse; psi1++) {
for (int psi2=psi1; psi2<NBsUse; psi2++) {
double dotProd=0.0;
for (int basis=0; basis<Nbasis; basis++) {
dotProd+=MOs[basis][psi1]*MOs[basis][psi2];
}
if (dotProd>1e-2) cerr << "MO_" << psi1 << ".MO_" << psi2 << " = " << dotProd << endl;
}
}
}
void normaliseMOs() {
for (int psi=0; psi<Nbasis; psi++) {
double N_sqd=0.0;
for (int basis=0; basis<Nbasis; basis++) {
N_sqd+=MOs[basis][psi]*MOs[basis][psi];
}
double N=sqrt(N_sqd); cout << N << '\t' ;
for (int basis=0; basis<Nbasis; basis++) {
MOs[basis][psi]/=N;
}
}
}//normaliseMOs()
void set (char * namefile){
//read all the info from a punch file
ifstream in(namefile);
if (!in) {cerr << "Error file non existant" <<endl;}
string word;
while( in ){
in >> word;
if ( word == "(Angstroms)"){
getline(in, word);
getline(in, word);
in >> word;
Atypes = new string[Nat];
in >> word;
in >> word;
in >> word;
for (int i=0; i< Nat;i++)
{
in >> Atypes[i];
in >> word;
in >> word;
in >> word;
}
}
if ( word == "Overlap" ){
in >> word;
in >> word;
in >> word;
in >> word;
in >> word;
in >> word;
sscanf(word.c_str(), "%i", &Nbasis);
S = new double * [Nbasis];
for (int m=0;m<Nbasis;m++)
{
S[m] = new double[Nbasis];
}
int i=0;
int j=0;
while ( i< Nbasis){
in >>word;
sscanf(word.c_str(), "%lf", &S[i][j]);
j++;
if(j==Nbasis) {
j=0;
i++;
}
}
}
if ( word == "vectors" ){
in >> word;
in >> word;
in >> word;
in >> word;
in >> word;
in >> word;
in >> word;
in >> word;
in >> word;
sscanf(word.c_str(), "%i", &Nbasis);
MOs = new double * [Nbasis];
for (int m=0;m<Nbasis;m++)
{
MOs[m] = new double[Nbasis];
}
getline(in, word); //skip the rest of the line
int i=0;
int j=0;
while ( i< Nbasis){
in >>word;
sscanf(word.c_str(), "%lf", &MOs[i][j]);
j++;
if(j==Nbasis) {
j=0;
i++;
}
}
}
}
}
void justPrintS(char * namefile) {
ofstream out(namefile);
if (!out) {
cerr << "***ERROR*** : Can't open " << namefile << endl;
exit(-1);
}
for (int i=0; i<Nbasis; i++) {
for (int j=0; j<Nbasis; j++) {
out << scientific << setprecision(8) << S[i][j] << " ";
}
out << endl;
}
}
void justPrintMOs(char * namefile) {
ofstream out(namefile);
if (!out) {
cerr << "***ERROR*** : Can't open " << namefile << endl;
exit(-1);
}
for (int i=0; i<Nbasis; i++) {
for (int j=0; j<Nbasis; j++) {
out << scientific << setprecision(8) << MOs[i][j] << " ";
}
out << endl;
}
}
void justPrintEvls(char * namefile) {
ofstream out(namefile);
if (!out) {
cerr << "***ERROR*** : Can't open " << namefile << endl;
exit(-1);
}
for (int i=0; i<Nbasis; i++ )
out << scientific << setprecision(8) << Evls[i] << endl;
}
void print_S(){
int i,j,k,l;
double test_S;
for (i=0; i<Nbasis;i++){
for( j=0;j<Nbasis;j++){
test_S=0.0;
for (k=0;k<Nbasis;k++){
for (l=0;l<Nbasis;l++){
test_S+= S[k][l] * MOs[i][l] * MOs[j][k] ;
}
}
cout << "test_S" << '\t' << test_S <<'\t' ;
}
cout <<endl;
}
}
};
#endif // FILE_COMP