Debian Codegraph @

avogadro/quantumio/gamessukout.cpp

raw
1 /******************************************************************************
2 This source file is part of the Avogadro project.
3 This source code is released under the 3-Clause BSD License, (see "LICENSE").
4 ******************************************************************************/
5
6 #include "gamessukout.h"
7 #include <fstream>
8 #include <iostream>
9
10 #include <QtCore/QRegularExpression>
11 #include <QtCore/QString>
12 #include <QtCore/QStringList>
13
14 using Eigen::Vector3d;
15 using std::vector;
16
17 namespace Avogadro {
18 namespace QuantumIO {
19
20 using Quantum::D;
21 using Quantum::F;
22 using Quantum::P;
23 using Quantum::S;
24 using Quantum::SP;
25 using Quantum::UU;
26
27 using Quantum::orbital;
28
29 //! Break a string (supplied as the second argument) into tokens, returned
30 //! in the first argument. Tokens are determined by the delimiters supplied
31 bool tokenize(std::vector<std::string>& vcr, const char* buf,
32 const char* delimstr)
33 {
34 // Not the most efficient way to do this, but this avoids using GPL code
35 // from openbabel.
36 if (!buf || !delimstr)
37 return false;
38
39 QString tmp(buf);
40 tmp += "\n"; // for compatibility with old behavior
41 vcr.clear();
42 QString splitString("[");
43 splitString += QString(delimstr);
44 splitString += QString("]");
45 QRegularExpression splitter(splitString);
46 foreach (const QString& str, tmp.split(splitter, Qt::SkipEmptyParts))
47 vcr.push_back(str.toStdString());
48
49 return true;
50 }
51
52 //! Removes white space from front and back of string
53 std::string& Trim(std::string& txt)
54 {
55 // Not the most efficient way to do this, but this avoids using GPL code
56 // from openbabel.
57 txt = QString::fromStdString(txt).trimmed().toStdString();
58 return txt;
59 }
60
61 /**
62 * This purloined from: http://www.codeguru.com/forum/showthread.php?t=231054
63 */
64 template <class T>
65 bool from_string(T& t, const std::string& s,
66 std::ios_base& (*f)(std::ios_base&))
67 {
68 std::istringstream iss(s);
69 return !(iss >> f >> t).fail();
70 }
71
72 void GUKBasisSet::outputCoord()
73 {
74 std::cout << "Coordinates:\n";
75 for (unsigned int i = 0; i < coordinates.size(); i++) {
76 printf("%d: %3s %10f %10f %10f\n", i, atomLabels[i].c_str(),
77 coordinates[i][0], coordinates[i][1], coordinates[i][2]);
78 }
79 } // end outputCoord
80
81 void GUKBasisSet::outputBasis()
82 {
83 std::cout << "Basis functions" << std::endl;
84
85 int prev;
86 for (unsigned int i = 0; i < shellLabels.size(); i++) {
87 std::cout << "Atom(" << i << "): " << shellLabels.at(i) << std::endl;
88 // std::cout << "shells at(i).size() " << shells.at(i).size() << std::endl;
89 for (unsigned int j = 0; j < shells.at(i).size(); j++) {
90 // The first indexes are different as they are the indexes held at the
91 // end of the last shell or 0 for the first one
92 if (i == 0 && j == 0)
93 prev = 0;
94 else if (j == 0)
95 prev = gtoIndicies.at(i - 1).back();
96 else
97 prev = gtoIndicies.at(i).at(j - 1);
98 std::cout << "shell type " << shells.at(i).at(j) << std::endl;
99 for (unsigned int k = prev; k < gtoIndicies.at(i).at(j); k++) {
100 std::cout << " e = " << gtoExponents.at(k)
101 << " c = " << gtoCoefficients.at(k) << std::endl;
102 }
103 }
104 }
105
106 std::cout << "Read in nShell " << nShell << std::endl;
107 std::cout << "Read in nBasisFunctions " << nBasisFunctions << std::endl;
108 std::cout << "Read in nElectrons " << nElectrons << std::endl;
109
110 } // end outputBasis
111
112 bool GUKBasisSet::labelIndex(std::string label)
113 {
114 for (unsigned int i = 0; i < shellLabels.size(); i++)
115 if (shellLabels.at(i) == label)
116 return true;
117 return false;
118 } // end labelIndex
119
120 orbital GUKBasisSet::shellTypeFromString(std::string label)
121 {
122 /**
123 * Return the enum from basis.h for the supplied label as a string
124 * basisset.h: enum orbital { S, SP, P, D, D5, F, F7, UU };
125
126 * The label is from the GAMESS-UK basis set label, which is printed as shown
127 below:
128
129 * shell type prim exponents contraction coefficients
130 * 1 1s 3 5.533350 1.801737 ( 0.700713 )
131 * or
132 * 2 2sp 4 3.664980 -0.747384 ( -0.395897 )
133 1.709178 ( 0.236460 )
134
135 */
136
137 // Could be e.g. 's', 'l', '2sp' or '1s'.
138 // We assume that if it is longer then 1 character long, the rest is the label
139 if (label.size() > 1) {
140 // Remove the shell number
141 label = label.substr(1, std::string::npos);
142 }
143
144 // Check for sp
145 if (label.size() == 2) {
146 if (label.compare(0, 2, "sp") == 0)
147 return SP;
148 }
149
150 if (label.size() == 1) {
151 if (label == "l")
152 return SP;
153 if (label == "s")
154 return S;
155 if (label == "p")
156 return P;
157 if (label == "d")
158 return D;
159 } // end label of length 1
160
161 // if we get here, it's all gone wrong...
162 std::cerr << "ERROR: shellTypeFromString with label: " << label << std::endl;
163 return UU;
164 }
165
166 GamessukOut::GamessukOut(const QString& qtfilename, GaussianSet* basis)
167 {
168 std::string filename;
169 filename = qtfilename.toStdString();
170 GamessukOutNoQt(filename, basis);
171 } // end GamessukOut
172
173 GamessukOut::~GamessukOut() {} // end ~GamessukOut
174
175 void GamessukOut::GamessukOutNoQt(const std::string& filename,
176 GaussianSet* basis)
177 {
178
179 bool ok;
180 std::ifstream ifs;
181
182 ifs.open(filename.c_str());
183 if (!ifs) {
184 std::cerr << "Cannot open: " << filename << "\n";
185 return;
186 }
187
188 // Initialise the basis set object that holds the parsed data before we
189 // convert
190 // it into Avogadro form
191 gukBasis = GUKBasisSet();
192
193 // Now read the file
194 ok = parseFile(ifs);
195
196 ifs.close();
197
198 if (ok) {
199 // outputParsedData();
200 // Create the Avogadro basis set object
201 load(basis);
202 } else
203 std::cerr << "ERROR READING ORBITALS FROM FILE: " << filename << std::endl;
204
205 } // end GamessukOutNoQt
206
207 void GamessukOut::outputParsedData()
208 {
209 gukBasis.outputCoord();
210 gukBasis.outputBasis();
211 } // end outputParsedData
212
213 bool GamessukOut::parseFile(std::ifstream& ifs)
214 {
215
216 /**
217 * Loop through the file, calling routines that read in the data of interest
218 * into the GUKBasisSet object
219 * Is currently pretty rudimentary - could do with lots of error trapping to
220 * check all o.k.
221 */
222
223 bool gotMOs = false; // used as return value - indicates if we have valid
224 // orbitals for the coordinates we've read in
225
226 while (ifs.good() && ifs.getline(buffer, BUFF_SIZE)) {
227
228 // First find oriented geometry - use this for single-point calculations
229 if (strstr(buffer,
230 " * atom atomic coordinates") !=
231 nullptr) {
232 readInitialCoordinates(ifs);
233 }
234
235 // The basis set definition
236 if (strstr(buffer, " atom shell type prim exponents "
237 " contraction coefficients") != nullptr) {
238 readBasisSet(ifs);
239 }
240
241 // Determine the scftype - can't do uhf yet
242 if (strstr(buffer, " * SCF TYPE") != nullptr) {
243 tokenize(tokens, buffer, " \t\n");
244 if (tokens[3].compare(0, 6, "rhf") != 0) {
245 std::cerr << "ERROR: can currently only do rhf!\n";
246 return false;
247 }
248 }
249
250 // The converged geometry
251 if (strstr(buffer, "optimization converged") != nullptr) {
252 readOptimisedCoordinates(ifs);
253 if (gotMOs)
254 gotMOs = false; // If we read in some MOs they are now redundant
255 }
256
257 // The molecular orbitals
258 if (strstr(
259 buffer,
260 " eigenvectors") !=
261 nullptr ||
262 strstr(buffer, " molecular orbitals") != nullptr) {
263 readMOs(ifs);
264 gotMOs = true;
265 }
266 }
267
268 return gotMOs;
269 }
270
271 void GamessukOut::readInitialCoordinates(std::ifstream& ifs)
272 {
273 // string to mark end of the coordinates
274 char coordEnd[86] = " "
275 "********************************************************"
276 "********************";
277 double x = 0.0, y = 0.0, z = 0.0;
278
279 // skip five lines
280 ifs.getline(buffer, BUFF_SIZE) && ifs.getline(buffer, BUFF_SIZE) &&
281 ifs.getline(buffer, BUFF_SIZE) && ifs.getline(buffer, BUFF_SIZE) &&
282 ifs.getline(buffer, BUFF_SIZE);
283
284 while (strstr(buffer, coordEnd) == nullptr) {
285 // std::cout << "COORD line" << buffer << std::endl;
286 // ifs.getline(buffer, BUFF_SIZE);
287 tokenize(tokens, buffer, " \t\n");
288
289 if (tokens.size() == 8) {
290 // std::cout << "Coord line" << buffer << std::endl;
291 gukBasis.atomLabels.push_back(tokens.at(1));
292
293 from_string<double>(x, tokens.at(3), std::dec);
294 from_string<double>(y, tokens.at(4), std::dec);
295 from_string<double>(z, tokens.at(5), std::dec);
296 gukBasis.coordinates.push_back(
297 Eigen::Vector3d(x, y, z)); // Want coordinates in Bohr
298 }
299
300 ifs.getline(buffer, BUFF_SIZE);
301 }
302 }
303
304 void GamessukOut::readBasisSet(std::ifstream& ifs)
305 {
306
307 // std::cout << "readBasisSet\n";
308
309 bool newAtom = true, gotAtom = false, firstAtom = true;
310 std::string atomLabel;
311 double exponent, coefficient;
312 orbital stype;
313 int nshell = -1;
314 int lastNshell = -1; // the last shell number - is same as nshell when looping
315 // through a shell
316 int lastStype = -1; // need to keep track of sp shells as we split into s & p
317
318 // For separating sp-shells
319 std::vector<double> s_coeff;
320 std::vector<double> p_coeff;
321 std::vector<double> sp_exponents;
322
323 // skip 2 lines to be just before the first atom label
324 ifs.getline(buffer, BUFF_SIZE) && ifs.getline(buffer, BUFF_SIZE);
325
326 // now loop through the basis sets till we hit the end
327 while (!ifs.eof()) {
328 ifs.getline(buffer, BUFF_SIZE);
329 line = buffer;
330
331 if (line.compare(0, 10, " =========") == 0) {
332 // End of basis - add indicies of where the coffecients and exponents of
333 // the GTOs for the last shell end
334 gukBasis.gtoIndicies.at(gukBasis.shellLabels.size() - 1)
335 .push_back(static_cast<unsigned int>(gukBasis.gtoExponents.size()));
336 break;
337 }
338
339 // Remove blank space
340 line = Trim(line);
341
342 // skip blank lines
343 if (line.size() == 0)
344 continue;
345
346 // Separate into tokens
347 if (!tokenize(tokens, line.c_str(), " \t\n") || tokens.size() == 0) {
348 // If the string couldn't be tokenised, set tokens[0] to the entire string
349 tokens.clear();
350 tokens.push_back(line);
351 }
352
353 if (tokens.size() == 1) {
354 // This means a new atomLabel
355 newAtom = true;
356 if (firstAtom)
357 firstAtom = false;
358 else {
359 // Check if the last shell was sp - if so add the temp sp data
360 // structures
361 // to the main ones
362 if (lastStype == SP) {
363 addSpBasis(s_coeff, p_coeff, sp_exponents);
364
365 // Clear the temp data structures for separating out sp into s & p
366 s_coeff.clear();
367 p_coeff.clear();
368 sp_exponents.clear();
369 lastStype = -1;
370 } else {
371 // Add the index for where the GTO coffecients and exponents for the
372 // previous shell start
373 gukBasis.gtoIndicies.at(gukBasis.shellLabels.size() - 1)
374 .push_back(static_cast<unsigned int>(gukBasis.gtoExponents.size()));
375 }
376
377 } // end firstAtom
378
379 // Check if we've already processed an atom of this type
380 if (!gukBasis.labelIndex(tokens.at(0))) {
381 // std::cout << "Processing atom label: " << tokens.at(0) << std::endl;
382 gotAtom = false; // we'll be processing this atom
383 gukBasis.shellLabels.push_back(tokens.at(0));
384 gukBasis.shells.push_back(std::vector<orbital>());
385 gukBasis.gtoIndicies.push_back(std::vector<unsigned int>());
386 } else
387 gotAtom = true;
388 continue;
389
390 } // End new atomLabel
391
392 // if we're not processing an atom we can skip this line
393 if (gotAtom)
394 continue;
395
396 /* Here we are reading in a line of the format:
397 shell type prim exponents contraction coefficients
398 1 1s 3 5.533350 1.801737 ( 0.700713 )
399 or
400 2 2sp 4 3.664980 -0.747384 ( -0.395897 )
401 1.709178 ( 0.236460 )
402 */
403
404 from_string<int>(nshell, tokens.at(0), std::dec);
405
406 if (nshell != lastNshell) {
407 // Reading a new shell
408
409 if (!newAtom) {
410 // Add the data for the last shell processed
411
412 // First check if last shell was sp & we need to add the data we've
413 // gathered to the main structures
414 if (lastStype == SP) {
415
416 addSpBasis(s_coeff, p_coeff, sp_exponents);
417
418 // Clear the temp data structures for separating out sp into s & p
419 s_coeff.clear();
420 p_coeff.clear();
421 sp_exponents.clear();
422 } else {
423 // Add the index for where the primitives for the last shell finish
424 gukBasis.gtoIndicies.at(gukBasis.shellLabels.size() - 1)
425 .push_back(static_cast<unsigned int>(gukBasis.gtoExponents.size()));
426
427 } // end sp shell
428
429 } // end newAtom
430
431 // need to determine type
432 stype = gukBasis.shellTypeFromString(tokens.at(1));
433 // std::cout << "Reading new shell of type " << stype << std::endl;
434
435 if (stype != SP) {
436 // Add shell to symmetry list and AtomToShellIndex if not sp shell as we
437 // do that separately
438 gukBasis.shells.at(gukBasis.shellLabels.size() - 1).push_back(stype);
439 }
440
441 } // end new shell
442
443 // Now check for coefficients - we take the second lot to match Gaussian
444 from_string<double>(exponent, tokens.at(3), std::dec);
445
446 if (stype == SP) {
447 if (tokens.size() != 12)
448 std::cerr << "PROBLEM READING SP LINE!\n";
449 from_string<double>(coefficient, tokens.at(6), std::dec);
450 s_coeff.push_back(coefficient);
451 from_string<double>(coefficient, tokens.at(10), std::dec);
452 p_coeff.push_back(coefficient);
453 sp_exponents.push_back(exponent);
454 } else {
455 // std::cout << "Adding exponent " << exponent << std::endl;
456 gukBasis.gtoExponents.push_back(exponent);
457 from_string<double>(coefficient, tokens.at(6), std::dec);
458 gukBasis.gtoCoefficients.push_back(coefficient);
459 } // end type == SP
460
461 lastNshell = nshell;
462 lastStype = stype;
463 newAtom = false;
464
465 } // end while
466
467 // Finished reading the basis data - now just collect some data from the
468 // summary - mainly for checking
469
470 ifs.getline(buffer, BUFF_SIZE); // blank
471
472 // nShell
473 ifs.getline(buffer, BUFF_SIZE);
474 if (strstr(buffer, " total number of shells") == nullptr)
475 std::cerr << "Error reading nShell!: " << line << std::endl;
476 // reuse nshell from above as temporary variable
477 tokenize(tokens, buffer, " \t\n");
478 from_string<int>(nshell, tokens.at(4), std::dec);
479 gukBasis.nShell = nshell;
480
481 // nBasisFunctions
482 ifs.getline(buffer, BUFF_SIZE);
483 if (strstr(buffer, " total number of basis") == nullptr)
484 std::cerr << "Error reading nBasisFunctions!: " << line << std::endl;
485 tokenize(tokens, buffer, " \t\n");
486 // reuse nshell from above as temporary variable
487 from_string<int>(nshell, tokens.at(5), std::dec);
488 gukBasis.nBasisFunctions = nshell;
489
490 // nElectrons
491 ifs.getline(buffer, BUFF_SIZE);
492 if (strstr(buffer, " number of electrons") == nullptr)
493 std::cerr << "Error reading nElectrons!: " << line << std::endl;
494 tokenize(tokens, buffer, " \t\n");
495 // reuse nshell from above as temporary variable
496 from_string<int>(nshell, tokens.at(3), std::dec);
497 gukBasis.nElectrons = nshell;
498
499 } // end readBasisSet
500
501 inline void GamessukOut::addSpBasis(std::vector<double> s_coeff,
502 std::vector<double> p_coeff,
503 std::vector<double> sp_exponents)
504 {
505
506 // Convenience function for adding separated sp basis
507
508 // Add s
509 gukBasis.shells.at(gukBasis.shellLabels.size() - 1).push_back(S);
510
511 for (unsigned int i = 0; i < s_coeff.size(); i++) {
512 gukBasis.gtoExponents.push_back(sp_exponents[i]);
513 gukBasis.gtoCoefficients.push_back(s_coeff[i]);
514 }
515 gukBasis.gtoIndicies.at(gukBasis.shellLabels.size() - 1)
516 .push_back(static_cast<unsigned int>(gukBasis.gtoExponents.size()));
517
518 // Add p
519 gukBasis.shells.at(gukBasis.shellLabels.size() - 1).push_back(P);
520
521 for (unsigned int i = 0; i < p_coeff.size(); i++) {
522 gukBasis.gtoExponents.push_back(sp_exponents[i]);
523 gukBasis.gtoCoefficients.push_back(p_coeff[i]);
524 }
525 gukBasis.gtoIndicies.at(gukBasis.shellLabels.size() - 1)
526 .push_back(static_cast<unsigned int>(gukBasis.gtoExponents.size()));
527
528 } // end addSpBasis
529
530 void GamessukOut::readOptimisedCoordinates(std::ifstream& ifs)
531 {
532
533 // std::cout << "readOptimisedCoordinates\n";
534
535 double x, y, z;
536
537 // Nuke the old coordinates
538 gukBasis.atomLabels.clear();
539 gukBasis.coordinates.clear();
540
541 ifs.getline(buffer, BUFF_SIZE);
542 while (!ifs.eof()) {
543
544 // This for some optimize runtypes
545 if (strstr(
546 buffer,
547 " x y z chg tag") !=
548 nullptr) {
549 // std::cout << "start of opt coord\n";
550 // Skip 2 lines - should then be at the coordinates
551 ifs.getline(buffer, BUFF_SIZE) && ifs.getline(buffer, BUFF_SIZE);
552
553 while (!ifs.eof()) {
554 // End of geometry block
555 if (strstr(buffer, " "
556 "==================================================="
557 "=========") != nullptr)
558 return;
559
560 tokenize(tokens, buffer, " \t\n");
561
562 from_string<double>(x, tokens.at(0), std::dec);
563 from_string<double>(y, tokens.at(1), std::dec);
564 from_string<double>(z, tokens.at(2), std::dec);
565
566 gukBasis.coordinates.push_back(Eigen::Vector3d(x, y, z));
567 gukBasis.atomLabels.push_back(tokens.at(4));
568
569 ifs.getline(buffer, BUFF_SIZE);
570 } // end while
571 } else if (strstr(buffer,
572 "atom znuc x y z") !=
573 nullptr) {
574
575 // print "start of opt coord 2"
576
577 // Skip 3 lines - should then be at the coordinates
578 ifs.getline(buffer, BUFF_SIZE) && ifs.getline(buffer, BUFF_SIZE) &&
579 ifs.getline(buffer, BUFF_SIZE);
580
581 while (!ifs.eof()) {
582 // End of geometry block
583 if (strstr(buffer, "*************************") != nullptr)
584 return;
585
586 tokenize(tokens, buffer, " \t\n");
587
588 gukBasis.atomLabels.push_back(tokens.at(0));
589 from_string<double>(x, tokens.at(3), std::dec);
590 from_string<double>(y, tokens.at(4), std::dec);
591 from_string<double>(z, tokens.at(5), std::dec);
592
593 gukBasis.coordinates.push_back(Eigen::Vector3d(x, y, z));
594
595 ifs.getline(buffer, BUFF_SIZE);
596 } // end of while
597 }
598
599 ifs.getline(buffer, BUFF_SIZE);
600 } // end of read loop
601
602 } // end readOptimisedCoordinates
603
604 void GamessukOut::readMOs(std::ifstream& ifs)
605 {
606 /*
607 Read the Molecular Orbitals as printed out by util1.m subroutine prev
608 */
609
610 int orbitalsRead, orbitalsRead1;
611
612 // Nuke any old set - fix when look at alpha & beta
613 gukBasis.moVectors.clear();
614
615 // Skip 3 lines to be just before first header
616 ifs.getline(buffer, BUFF_SIZE) && ifs.getline(buffer, BUFF_SIZE) &&
617 ifs.getline(buffer, BUFF_SIZE);
618
619 orbitalsRead1 = readMOVectors(ifs);
620 orbitalsRead = orbitalsRead1;
621 while (orbitalsRead == orbitalsRead1 || orbitalsRead != 0)
622 orbitalsRead = readMOVectors(ifs);
623
624 } // end readMos
625
626 int GamessukOut::readMOVectors(std::ifstream& ifs)
627 {
628 /*
629 Loop through a series of columns of printed MO vectors & return the
630 number of orbitals read in
631 */
632
633 unsigned int norbitals, norbitalsRead;
634 double energy;
635
636 ifs.getline(buffer, BUFF_SIZE);
637 // std::cout << "HeaderLine " << buffer << std::endl;
638
639 // Check we're not at the end
640 if (strstr(buffer, "end of") != 0)
641 return 0;
642
643 tokenize(tokens, buffer, " \t\n");
644 // How many orbital columns:
645 norbitals = static_cast<unsigned int>(tokens.size());
646
647 for (unsigned int i = 0; i < tokens.size(); i++) {
648 from_string<double>(energy, tokens.at(i), std::dec);
649 // std::cout << "adding e " << energy << std::endl;
650 gukBasis.moEnergies.push_back(energy);
651 }
652
653 // Add the lists to hold this set of coefficients
654 // How many were read in previously:
655 norbitalsRead = static_cast<unsigned int>(gukBasis.moVectors.size());
656
657 // Create the arrays to hold the coefficients for each orbital
658 for (unsigned int i = 0; i < norbitals; i++)
659 gukBasis.moVectors.push_back(std::vector<double>());
660
661 // skip 5 lines to just before where first set of orbitals are printed
662 ifs.getline(buffer, BUFF_SIZE) && ifs.getline(buffer, BUFF_SIZE) &&
663 ifs.getline(buffer, BUFF_SIZE) && ifs.getline(buffer, BUFF_SIZE) &&
664 ifs.getline(buffer, BUFF_SIZE);
665
666 // loop nBasisFunctions times to read in up to norbitals coefficients
667 for (int i = 0; i < gukBasis.nBasisFunctions; i++) {
668 ifs.getline(buffer, BUFF_SIZE);
669 // std::cout << "MO line " << buffer << std::endl;
670
671 tokenize(tokens, buffer, " \t\n");
672
673 for (unsigned int j = 0; j < norbitals; j++) {
674 // reuse variable energy to hold coefficient
675 from_string<double>(energy, tokens.at(j + 4), std::dec);
676 gukBasis.moVectors.at(norbitalsRead + j).push_back(energy);
677 // std::cout << "Adding " << energy << " to vector " << norbitalsRead+j <<
678 // std::endl;
679 }
680 }
681
682 // skip 2 lines to where the next set of headers are printed
683 ifs.getline(buffer, BUFF_SIZE);
684 ifs.getline(buffer, BUFF_SIZE);
685
686 // If we are printed out after an optimisation under the control of "iprint
687 // vectors",
688 // the next line with be filled with " =================" if we've finished
689 if (strstr(buffer, " ===============================") != 0)
690 return 0;
691
692 return norbitals;
693
694 } // end readMOVectors
695
696 void GamessukOut::addBasisForLabel(unsigned int atomIndex, std::string label,
697 GaussianSet* basis)
698 {
699 /*
700 Add the basis functions for the atom label
701 */
702
703 unsigned int s;
704 int prev;
705 for (unsigned int i = 0; i < gukBasis.shellLabels.size(); i++) {
706 if (gukBasis.shellLabels.at(i) != label)
707 continue;
708
709 for (unsigned int j = 0; j < gukBasis.shells.at(i).size(); j++) {
710 s = basis->addBasis(atomIndex, gukBasis.shells.at(i).at(j));
711
712 // The first indexes are different as they are the indexes held at the end
713 // of the last shell or
714 // 0 for the first one
715 if (i == 0 && j == 0)
716 prev = 0;
717 else if (j == 0)
718 prev = gukBasis.gtoIndicies.at(i - 1).back();
719 else
720 prev = gukBasis.gtoIndicies.at(i).at(j - 1);
721
722 for (unsigned int k = prev; k < gukBasis.gtoIndicies.at(i).at(j); k++) {
723 basis->addGTO(s, gukBasis.gtoCoefficients.at(k),
724 gukBasis.gtoExponents.at(k));
725 }
726 }
727 }
728 return;
729
730 } // end addBasisForLabel
731
732 void GamessukOut::load(GaussianSet* basis)
733 {
734 /*
735 We will only have read in a basis set for atoms of each type
736 Loop through the list of all the atoms & add the basis functions for each
737 individual atom
738
739 */
740
741 basis->setNumElectrons(gukBasis.nElectrons);
742
743 // Add the basis for each atom
744 for (unsigned int i = 0; i < gukBasis.atomLabels.size(); i++) {
745 basis->addAtom(gukBasis.coordinates.at(i));
746 addBasisForLabel(i, gukBasis.atomLabels.at(i), basis);
747 }
748
749 // Now to load in the MO coefficients
750 // This currently a dirty hack - basisset addMO just expects a long vector of
751 // doubles, which
752 // it then converts into a square matrix.
753 // For this test, we convert our vector of vectors to a single vector and fill
754 // the remaining
755 // virtual orbitals with zeros.
756
757 std::vector<double> MOs;
758 unsigned int moEnd,
759 nBasis = static_cast<unsigned int>(gukBasis.nBasisFunctions);
760
761 for (unsigned int i = 0; i < nBasis; i++) {
762 if (i >= gukBasis.moVectors.size()) {
763 // std::cout << "Adding blank vectors for non-printed MOs " << i <<
764 // std::endl;
765 moEnd = static_cast<unsigned int>(MOs.size()) + nBasis;
766 for (unsigned int j = static_cast<unsigned int>(MOs.size()); j < moEnd;
767 j++)
768 MOs.push_back(0.0);
769 } else {
770 // std::cout << "Adding actual vector " << i << std::endl;
771 MOs.insert(MOs.end(), gukBasis.moVectors.at(i).begin(),
772 gukBasis.moVectors.at(i).end());
773 }
774 }
775
776 // Need to multiply by -1 to bring into accordance with Gaussian.
777 // for( unsigned int i=0; i <MOs.size(); i++ ) MOs.at(i)=MOs.at(i)*-1;
778
779 basis->addMOs(MOs);
780
781 // basis->initCalculation();
782
783 } // end load
784
785 } // namespace QuantumIO
786 } // namespace Avogadro