| [6ac7ee] | 1 | /** \file periodentafel.cpp
 | 
|---|
 | 2 |  *
 | 
|---|
 | 3 |  * Function implementations for the class periodentafel.
 | 
|---|
 | 4 |  *
 | 
|---|
 | 5 |  */
 | 
|---|
 | 6 | 
 | 
|---|
| [112b09] | 7 | #include "Helpers/MemDebug.hpp"
 | 
|---|
 | 8 | 
 | 
|---|
| [6ac7ee] | 9 | using namespace std;
 | 
|---|
 | 10 | 
 | 
|---|
| [cd4ccc] | 11 | #include <iomanip>
 | 
|---|
| [4eb4fe] | 12 | #include <iostream>
 | 
|---|
| [cd4ccc] | 13 | #include <fstream>
 | 
|---|
| [49e1ae] | 14 | #include <cstring>
 | 
|---|
| [cd4ccc] | 15 | 
 | 
|---|
| [4eb4fe] | 16 | #include "Helpers/Assert.hpp"
 | 
|---|
| [f66195] | 17 | #include "element.hpp"
 | 
|---|
| [4eb4fe] | 18 | #include "elements_db.hpp"
 | 
|---|
| [952f38] | 19 | #include "Helpers/helpers.hpp"
 | 
|---|
| [f66195] | 20 | #include "lists.hpp"
 | 
|---|
| [952f38] | 21 | #include "Helpers/Log.hpp"
 | 
|---|
| [6ac7ee] | 22 | #include "periodentafel.hpp"
 | 
|---|
| [952f38] | 23 | #include "Helpers/Verbose.hpp"
 | 
|---|
| [6ac7ee] | 24 | 
 | 
|---|
| [ead4e6] | 25 | using namespace std;
 | 
|---|
 | 26 | 
 | 
|---|
| [6ac7ee] | 27 | /************************************* Functions for class periodentafel ***************************/
 | 
|---|
 | 28 | 
 | 
|---|
 | 29 | /** constructor for class periodentafel
 | 
|---|
 | 30 |  * Initialises start and end of list and resets periodentafel::checkliste to false.
 | 
|---|
 | 31 |  */
 | 
|---|
| [ead4e6] | 32 | periodentafel::periodentafel()
 | 
|---|
| [4eb4fe] | 33 | {
 | 
|---|
| [f34c23] | 34 |   {
 | 
|---|
 | 35 |     stringstream input(elementsDB,ios_base::in);
 | 
|---|
 | 36 |     bool status = LoadElementsDatabase(&input);
 | 
|---|
 | 37 |     ASSERT(status,  "General element initialization failed");
 | 
|---|
 | 38 |   }
 | 
|---|
 | 39 |   {
 | 
|---|
 | 40 |     stringstream input(valenceDB,ios_base::in);
 | 
|---|
 | 41 |     bool status = LoadValenceDatabase(&input);
 | 
|---|
 | 42 |     ASSERT(status, "Valence entry of element initialization failed");
 | 
|---|
 | 43 |   }
 | 
|---|
 | 44 |   {
 | 
|---|
 | 45 |     stringstream input(orbitalsDB,ios_base::in);
 | 
|---|
 | 46 |     bool status = LoadOrbitalsDatabase(&input);
 | 
|---|
 | 47 |     ASSERT(status, "Orbitals entry of element initialization failed");
 | 
|---|
 | 48 |   }
 | 
|---|
 | 49 |   {
 | 
|---|
 | 50 |     stringstream input(HbondangleDB,ios_base::in);
 | 
|---|
 | 51 |     bool status = LoadHBondAngleDatabase(&input);
 | 
|---|
 | 52 |     ASSERT(status, "HBond angle entry of element initialization failed");
 | 
|---|
 | 53 |   }
 | 
|---|
 | 54 |   {
 | 
|---|
 | 55 |     stringstream input(HbonddistanceDB,ios_base::in);
 | 
|---|
 | 56 |     bool status = LoadHBondLengthsDatabase(&input);
 | 
|---|
 | 57 |     ASSERT(status, "HBond distance entry of element initialization failed");
 | 
|---|
 | 58 |   }
 | 
|---|
| [4eb4fe] | 59 | };
 | 
|---|
| [6ac7ee] | 60 | 
 | 
|---|
 | 61 | /** destructor for class periodentafel
 | 
|---|
 | 62 |  * Removes every element and afterwards deletes start and end of list.
 | 
|---|
| [42af9e] | 63 |  * TODO: Handle when elements have changed and store databases then
 | 
|---|
| [6ac7ee] | 64 |  */
 | 
|---|
 | 65 | periodentafel::~periodentafel()
 | 
|---|
 | 66 | {
 | 
|---|
| [042f82] | 67 |   CleanupPeriodtable();
 | 
|---|
| [6ac7ee] | 68 | };
 | 
|---|
 | 69 | 
 | 
|---|
 | 70 | /** Adds element to period table list
 | 
|---|
 | 71 |  * \param *pointer element to be added
 | 
|---|
| [4eb4fe] | 72 |  * \return iterator to added element
 | 
|---|
| [6ac7ee] | 73 |  */
 | 
|---|
| [ead4e6] | 74 | periodentafel::iterator periodentafel::AddElement(element * const pointer)
 | 
|---|
| [6ac7ee] | 75 | {
 | 
|---|
| [ead4e6] | 76 |   atomicNumber_t Z = pointer->getNumber();
 | 
|---|
| [4eb4fe] | 77 |   ASSERT(!elements.count(Z), "Element is already present.");
 | 
|---|
| [042f82] | 78 |   pointer->sort = &pointer->Z;
 | 
|---|
| [ead4e6] | 79 |   if (pointer->getNumber() < 1 && pointer->getNumber() >= MAX_ELEMENTS)
 | 
|---|
| [5f612ee] | 80 |     DoeLog(0) && (eLog() << Verbose(0) << "Invalid Z number!\n");
 | 
|---|
| [ead4e6] | 81 |   pair<iterator,bool> res = elements.insert(pair<atomicNumber_t,element*>(Z,pointer));
 | 
|---|
 | 82 |   return res.first;
 | 
|---|
| [6ac7ee] | 83 | };
 | 
|---|
 | 84 | 
 | 
|---|
 | 85 | /** Removes element from list.
 | 
|---|
 | 86 |  * \param *pointer element to be removed
 | 
|---|
 | 87 |  */
 | 
|---|
| [61745cc] | 88 | size_t periodentafel::RemoveElement(element * const pointer)
 | 
|---|
| [6ac7ee] | 89 | {
 | 
|---|
| [61745cc] | 90 |   return RemoveElement(pointer->getNumber());
 | 
|---|
| [4eb4fe] | 91 | };
 | 
|---|
 | 92 | 
 | 
|---|
 | 93 | /** Removes element from list.
 | 
|---|
 | 94 |  * \param Z element to be removed
 | 
|---|
 | 95 |  */
 | 
|---|
| [61745cc] | 96 | size_t periodentafel::RemoveElement(atomicNumber_t Z)
 | 
|---|
| [4eb4fe] | 97 | {
 | 
|---|
| [61745cc] | 98 |   return elements.erase(Z);
 | 
|---|
| [6ac7ee] | 99 | };
 | 
|---|
 | 100 | 
 | 
|---|
 | 101 | /** Removes every element from the period table.
 | 
|---|
 | 102 |  */
 | 
|---|
| [ead4e6] | 103 | void periodentafel::CleanupPeriodtable()
 | 
|---|
| [6ac7ee] | 104 | {
 | 
|---|
| [745a85] | 105 |   for(iterator iter=elements.begin();iter!=elements.end();++iter){
 | 
|---|
 | 106 |     delete(*iter).second;
 | 
|---|
 | 107 |   }
 | 
|---|
| [ead4e6] | 108 |   elements.clear();
 | 
|---|
| [6ac7ee] | 109 | };
 | 
|---|
 | 110 | 
 | 
|---|
 | 111 | /** Finds an element by its atomic number.
 | 
|---|
| [fb73b8] | 112 |  * If element is not yet in list, returns NULL.
 | 
|---|
| [6ac7ee] | 113 |  * \param Z atomic number
 | 
|---|
| [fb73b8] | 114 |  * \return pointer to element or NULL if not found
 | 
|---|
| [6ac7ee] | 115 |  */
 | 
|---|
| [4eb4fe] | 116 | element * const periodentafel::FindElement(atomicNumber_t Z) const
 | 
|---|
| [6ac7ee] | 117 | {
 | 
|---|
| [ead4e6] | 118 |   const_iterator res = elements.find(Z);
 | 
|---|
 | 119 |   return res!=elements.end()?((*res).second):0;
 | 
|---|
| [6ac7ee] | 120 | };
 | 
|---|
 | 121 | 
 | 
|---|
 | 122 | /** Finds an element by its atomic number.
 | 
|---|
 | 123 |  * If element is not yet in list, datas are asked and stored in database.
 | 
|---|
 | 124 |  * \param shorthand chemical symbol of the element, e.g. H for hydrogene
 | 
|---|
 | 125 |  * \return pointer to element
 | 
|---|
 | 126 |  */
 | 
|---|
| [f308e6] | 127 | element * const periodentafel::FindElement(const string &shorthand) const
 | 
|---|
| [6ac7ee] | 128 | {
 | 
|---|
| [ead4e6] | 129 |   element *res = 0;
 | 
|---|
 | 130 |   for(const_iterator iter=elements.begin();iter!=elements.end();++iter) {
 | 
|---|
 | 131 |     if((*iter).second->getSymbol() == shorthand){
 | 
|---|
 | 132 |       res = (*iter).second;
 | 
|---|
 | 133 |       break;
 | 
|---|
 | 134 |     }
 | 
|---|
| [042f82] | 135 |   }
 | 
|---|
| [ead4e6] | 136 |   return res;
 | 
|---|
| [6ac7ee] | 137 | };
 | 
|---|
 | 138 | 
 | 
|---|
 | 139 | /** Asks for element number and returns pointer to element
 | 
|---|
| [4eb4fe] | 140 |  * \return desired element or NULL
 | 
|---|
| [6ac7ee] | 141 |  */
 | 
|---|
| [4eb4fe] | 142 | element * const periodentafel::AskElement() const
 | 
|---|
| [6ac7ee] | 143 | {
 | 
|---|
| [4eb4fe] | 144 |   element * walker = NULL;
 | 
|---|
| [042f82] | 145 |   int Z;
 | 
|---|
 | 146 |   do {
 | 
|---|
| [a67d19] | 147 |     DoLog(0) && (Log() << Verbose(0) << "Atomic number Z: ");
 | 
|---|
| [042f82] | 148 |     cin >> Z;
 | 
|---|
 | 149 |     walker = this->FindElement(Z);  // give type
 | 
|---|
 | 150 |   } while (walker == NULL);
 | 
|---|
 | 151 |   return walker;
 | 
|---|
| [6ac7ee] | 152 | };
 | 
|---|
 | 153 | 
 | 
|---|
| [fb73b8] | 154 | /** Asks for element and if not found, presents mask to enter info.
 | 
|---|
 | 155 |  * \return pointer to either present or newly created element
 | 
|---|
 | 156 |  */
 | 
|---|
| [4eb4fe] | 157 | element * const periodentafel::EnterElement()
 | 
|---|
| [fb73b8] | 158 | {
 | 
|---|
| [ead4e6] | 159 |   atomicNumber_t Z = 0;
 | 
|---|
| [a67d19] | 160 |   DoLog(0) && (Log() << Verbose(0) << "Atomic number: " << Z << endl);
 | 
|---|
| [fb73b8] | 161 |   cin >> Z;
 | 
|---|
| [4eb4fe] | 162 |   element * const res = FindElement(Z);
 | 
|---|
| [ead4e6] | 163 |   if (!res) {
 | 
|---|
 | 164 |     // TODO: make this using the constructor
 | 
|---|
| [a67d19] | 165 |     DoLog(0) && (Log() << Verbose(0) << "Element not found in database, please enter." << endl);
 | 
|---|
| [4eb4fe] | 166 |     element *tmp = new element;
 | 
|---|
| [ead4e6] | 167 |     tmp->Z = Z;
 | 
|---|
| [a67d19] | 168 |     DoLog(0) && (Log() << Verbose(0) << "Mass: " << endl);
 | 
|---|
| [ead4e6] | 169 |     cin >> tmp->mass;
 | 
|---|
| [a67d19] | 170 |     DoLog(0) && (Log() << Verbose(0) << "Name [max 64 chars]: " << endl);
 | 
|---|
| [ead4e6] | 171 |     cin >> tmp->name;
 | 
|---|
| [a67d19] | 172 |     DoLog(0) && (Log() << Verbose(0) << "Short form [max 3 chars]: " << endl);
 | 
|---|
| [ead4e6] | 173 |     cin >> tmp->symbol;
 | 
|---|
 | 174 |     AddElement(tmp);
 | 
|---|
| [4eb4fe] | 175 |     return tmp;
 | 
|---|
| [fb73b8] | 176 |   }
 | 
|---|
| [ead4e6] | 177 |   return res;
 | 
|---|
| [fb73b8] | 178 | };
 | 
|---|
 | 179 | 
 | 
|---|
| [ead4e6] | 180 | 
 | 
|---|
 | 181 | /******************** Access to iterators ****************************/
 | 
|---|
 | 182 | periodentafel::const_iterator periodentafel::begin(){
 | 
|---|
 | 183 |   return elements.begin();
 | 
|---|
 | 184 | }
 | 
|---|
 | 185 | 
 | 
|---|
 | 186 | periodentafel::const_iterator periodentafel::end(){
 | 
|---|
 | 187 |   return elements.end();
 | 
|---|
 | 188 | }
 | 
|---|
 | 189 | 
 | 
|---|
 | 190 | periodentafel::reverse_iterator periodentafel::rbegin(){
 | 
|---|
 | 191 |   return reverse_iterator(elements.end());
 | 
|---|
 | 192 | }
 | 
|---|
 | 193 | 
 | 
|---|
 | 194 | periodentafel::reverse_iterator periodentafel::rend(){
 | 
|---|
 | 195 |   return reverse_iterator(elements.begin());
 | 
|---|
 | 196 | }
 | 
|---|
 | 197 | 
 | 
|---|
| [6ac7ee] | 198 | /** Prints period table to given stream.
 | 
|---|
 | 199 |  * \param output stream
 | 
|---|
 | 200 |  */
 | 
|---|
| [ead4e6] | 201 | bool periodentafel::Output(ostream * const output) const
 | 
|---|
| [6ac7ee] | 202 | {
 | 
|---|
| [042f82] | 203 |   bool result = true;
 | 
|---|
 | 204 |   if (output != NULL) {
 | 
|---|
| [ead4e6] | 205 |     for(const_iterator iter=elements.begin(); iter !=elements.end();++iter){
 | 
|---|
 | 206 |       result = result && (*iter).second->Output(output);
 | 
|---|
| [042f82] | 207 |     }
 | 
|---|
 | 208 |     return result;
 | 
|---|
 | 209 |   } else
 | 
|---|
 | 210 |     return false;
 | 
|---|
| [6ac7ee] | 211 | };
 | 
|---|
 | 212 | 
 | 
|---|
 | 213 | /** Loads element list from file.
 | 
|---|
 | 214 |  * \param *path to to standard file names
 | 
|---|
 | 215 |  */
 | 
|---|
| [989bf6] | 216 | bool periodentafel::LoadPeriodentafel(const char *path)
 | 
|---|
| [6ac7ee] | 217 | {
 | 
|---|
| [4eb4fe] | 218 |   ifstream input;
 | 
|---|
| [042f82] | 219 |   bool status = true;
 | 
|---|
 | 220 |   bool otherstatus = true;
 | 
|---|
 | 221 |   char filename[255];
 | 
|---|
| [6ac7ee] | 222 | 
 | 
|---|
| [042f82] | 223 |   // fill elements DB
 | 
|---|
 | 224 |   strncpy(filename, path, MAXSTRINGSIZE);
 | 
|---|
 | 225 |   strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
 | 
|---|
 | 226 |   strncat(filename, STANDARDELEMENTSDB, MAXSTRINGSIZE-strlen(filename));
 | 
|---|
| [4eb4fe] | 227 |   input.open(filename);
 | 
|---|
| [61745cc] | 228 |   if (!input.fail())
 | 
|---|
 | 229 |     DoLog(0) && (Log() << Verbose(0) << "Using " << filename << " as elements database." << endl);
 | 
|---|
| [4eb4fe] | 230 |   status = status && LoadElementsDatabase(&input);
 | 
|---|
| [61745cc] | 231 |   input.close();
 | 
|---|
 | 232 |   input.clear();
 | 
|---|
| [4eb4fe] | 233 | 
 | 
|---|
 | 234 |   // fill valence DB per element
 | 
|---|
 | 235 |   strncpy(filename, path, MAXSTRINGSIZE);
 | 
|---|
 | 236 |   strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
 | 
|---|
 | 237 |   strncat(filename, STANDARDVALENCEDB, MAXSTRINGSIZE-strlen(filename));
 | 
|---|
 | 238 |   input.open(filename);
 | 
|---|
| [61745cc] | 239 |   if (!input.fail())
 | 
|---|
 | 240 |     DoLog(0) && (Log() << Verbose(0) << "Using " << filename << " as valence database." << endl);
 | 
|---|
| [4eb4fe] | 241 |   otherstatus = otherstatus && LoadValenceDatabase(&input);
 | 
|---|
| [61745cc] | 242 |   input.close();
 | 
|---|
 | 243 |   input.clear();
 | 
|---|
| [4eb4fe] | 244 | 
 | 
|---|
 | 245 |   // fill orbitals DB per element
 | 
|---|
 | 246 |   strncpy(filename, path, MAXSTRINGSIZE);
 | 
|---|
 | 247 |   strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
 | 
|---|
 | 248 |   strncat(filename, STANDARDORBITALDB, MAXSTRINGSIZE-strlen(filename));
 | 
|---|
 | 249 |   input.open(filename);
 | 
|---|
| [61745cc] | 250 |   if (!input.fail())
 | 
|---|
 | 251 |     DoLog(0) && (Log() << Verbose(0) << "Using " << filename << " as orbitals database." << endl);
 | 
|---|
| [4eb4fe] | 252 |   otherstatus = otherstatus && LoadOrbitalsDatabase(&input);
 | 
|---|
| [61745cc] | 253 |   input.close();
 | 
|---|
 | 254 |   input.clear();
 | 
|---|
| [4eb4fe] | 255 | 
 | 
|---|
 | 256 |   // fill H-BondAngle DB per element
 | 
|---|
 | 257 |   strncpy(filename, path, MAXSTRINGSIZE);
 | 
|---|
 | 258 |   strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
 | 
|---|
 | 259 |   strncat(filename, STANDARDHBONDANGLEDB, MAXSTRINGSIZE-strlen(filename));
 | 
|---|
 | 260 |   input.open(filename);
 | 
|---|
| [61745cc] | 261 |   if (!input.fail())
 | 
|---|
 | 262 |     DoLog(0) && (Log() << Verbose(0) << "Using " << filename << " as H bond angle database." << endl);
 | 
|---|
| [4eb4fe] | 263 |   otherstatus = otherstatus && LoadHBondAngleDatabase(&input);
 | 
|---|
| [61745cc] | 264 |   input.close();
 | 
|---|
 | 265 |   input.clear();
 | 
|---|
| [4eb4fe] | 266 | 
 | 
|---|
 | 267 |   // fill H-BondDistance DB per element
 | 
|---|
 | 268 |   strncpy(filename, path, MAXSTRINGSIZE);
 | 
|---|
 | 269 |   strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
 | 
|---|
 | 270 |   strncat(filename, STANDARDHBONDDISTANCEDB, MAXSTRINGSIZE-strlen(filename));
 | 
|---|
 | 271 |   input.open(filename);
 | 
|---|
| [61745cc] | 272 |   if (!input.fail())
 | 
|---|
 | 273 |     DoLog(0) && (Log() << Verbose(0) << "Using " << filename << " as H bond length database." << endl);
 | 
|---|
| [4eb4fe] | 274 |   otherstatus = otherstatus && LoadHBondLengthsDatabase(&input);
 | 
|---|
| [61745cc] | 275 |   input.close();
 | 
|---|
 | 276 |   input.clear();
 | 
|---|
| [4eb4fe] | 277 | 
 | 
|---|
 | 278 |   if (!otherstatus){
 | 
|---|
 | 279 |     DoeLog(2) && (eLog()<< Verbose(2) << "Something went wrong while parsing the other databases!" << endl);
 | 
|---|
 | 280 |   }
 | 
|---|
 | 281 | 
 | 
|---|
 | 282 |   return status;
 | 
|---|
 | 283 | };
 | 
|---|
 | 284 | 
 | 
|---|
 | 285 | /** load the element info.
 | 
|---|
 | 286 |  * \param *input stream to parse from
 | 
|---|
 | 287 |  * \return true - parsing successful, false - something went wrong
 | 
|---|
 | 288 |  */
 | 
|---|
 | 289 | bool periodentafel::LoadElementsDatabase(istream *input)
 | 
|---|
 | 290 | {
 | 
|---|
| [ff73a2] | 291 |   bool status = true;
 | 
|---|
 | 292 |   int counter = 0;
 | 
|---|
| [61745cc] | 293 |   pair< std::map<atomicNumber_t,element*>::iterator, bool > InserterTest;
 | 
|---|
| [ff73a2] | 294 |   if (!(*input).fail()) {
 | 
|---|
| [4eb4fe] | 295 |     (*input).getline(header1, MAXSTRINGSIZE);
 | 
|---|
 | 296 |     (*input).getline(header2, MAXSTRINGSIZE); // skip first two header lines
 | 
|---|
| [a67d19] | 297 |     DoLog(0) && (Log() << Verbose(0) <<  "Parsed elements:");
 | 
|---|
| [4eb4fe] | 298 |     while (!(*input).eof()) {
 | 
|---|
| [042f82] | 299 |       element *neues = new element;
 | 
|---|
| [4eb4fe] | 300 |       (*input) >> neues->name;
 | 
|---|
 | 301 |       //(*input) >> ws;
 | 
|---|
 | 302 |       (*input) >> neues->symbol;
 | 
|---|
 | 303 |       //(*input) >> ws;
 | 
|---|
 | 304 |       (*input) >> neues->period;
 | 
|---|
 | 305 |       //(*input) >> ws;
 | 
|---|
 | 306 |       (*input) >> neues->group;
 | 
|---|
 | 307 |       //(*input) >> ws;
 | 
|---|
 | 308 |       (*input) >> neues->block;
 | 
|---|
 | 309 |       //(*input) >> ws;
 | 
|---|
 | 310 |       (*input) >> neues->Z;
 | 
|---|
 | 311 |       //(*input) >> ws;
 | 
|---|
 | 312 |       (*input) >> neues->mass;
 | 
|---|
 | 313 |       //(*input) >> ws;
 | 
|---|
 | 314 |       (*input) >> neues->CovalentRadius;
 | 
|---|
 | 315 |       //(*input) >> ws;
 | 
|---|
 | 316 |       (*input) >> neues->VanDerWaalsRadius;
 | 
|---|
 | 317 |       //(*input) >> ws;
 | 
|---|
 | 318 |       (*input) >> ws;
 | 
|---|
| [042f82] | 319 |       //neues->Output((ofstream *)&cout);
 | 
|---|
| [61745cc] | 320 |       if ((neues->getNumber() > 0) && (neues->getNumber() < MAX_ELEMENTS)) {
 | 
|---|
 | 321 |         if (elements.count(neues->getNumber())) {// if element already present, remove and delete old one (i.e. replace it)
 | 
|---|
 | 322 |           //cout << neues->symbol << " is present already." << endl;
 | 
|---|
 | 323 |           element * const Elemental = FindElement(neues->getNumber());
 | 
|---|
 | 324 |           ASSERT(Elemental != NULL, "element should be present but is not??");
 | 
|---|
 | 325 |           *Elemental = *neues;
 | 
|---|
| [61b5f0] | 326 |           delete(neues);
 | 
|---|
 | 327 |           neues = Elemental;
 | 
|---|
| [61745cc] | 328 |         } else {
 | 
|---|
 | 329 |           InserterTest = elements.insert(pair <atomicNumber_t,element*> (neues->getNumber(), neues));
 | 
|---|
 | 330 |           ASSERT(InserterTest.second, "Could not insert new element into periodentafel on LoadElementsDatabase().");
 | 
|---|
 | 331 |         }
 | 
|---|
 | 332 |         DoLog(0) && (Log() << Verbose(0) << " " << elements[neues->getNumber()]->symbol);
 | 
|---|
| [ff73a2] | 333 |         counter++;
 | 
|---|
 | 334 |       } else {
 | 
|---|
 | 335 |         DoeLog(2) && (eLog() << Verbose(2) << "Detected empty line or invalid element in elements db, discarding." << endl);
 | 
|---|
 | 336 |         DoLog(0) && (Log() << Verbose(0) << " <?>");
 | 
|---|
| [db6bf74] | 337 |         delete(neues);
 | 
|---|
| [042f82] | 338 |       }
 | 
|---|
 | 339 |     }
 | 
|---|
| [a67d19] | 340 |     DoLog(0) && (Log() << Verbose(0) << endl);
 | 
|---|
| [61745cc] | 341 |   } else {
 | 
|---|
 | 342 |     DoeLog(1) && (eLog() << Verbose(1) << "Could not open the database." << endl);
 | 
|---|
| [ff73a2] | 343 |     status = false;
 | 
|---|
| [61745cc] | 344 |   }
 | 
|---|
| [ff73a2] | 345 | 
 | 
|---|
 | 346 |   if (counter == 0)
 | 
|---|
 | 347 |     status = false;
 | 
|---|
 | 348 | 
 | 
|---|
 | 349 |   return status;
 | 
|---|
| [4eb4fe] | 350 | }
 | 
|---|
| [6ac7ee] | 351 | 
 | 
|---|
| [4eb4fe] | 352 | /** load the valence info.
 | 
|---|
 | 353 |  * \param *input stream to parse from
 | 
|---|
 | 354 |  * \return true - parsing successful, false - something went wrong
 | 
|---|
 | 355 |  */
 | 
|---|
 | 356 | bool periodentafel::LoadValenceDatabase(istream *input)
 | 
|---|
 | 357 | {
 | 
|---|
 | 358 |   char dummy[MAXSTRINGSIZE];
 | 
|---|
| [ff73a2] | 359 |   if (!(*input).fail()) {
 | 
|---|
| [4eb4fe] | 360 |     (*input).getline(dummy, MAXSTRINGSIZE);
 | 
|---|
 | 361 |     while (!(*input).eof()) {
 | 
|---|
| [ead4e6] | 362 |       atomicNumber_t Z;
 | 
|---|
| [4eb4fe] | 363 |       (*input) >> Z;
 | 
|---|
 | 364 |       ASSERT(elements.count(Z), "Element not present");
 | 
|---|
 | 365 |       (*input) >> ws;
 | 
|---|
 | 366 |       (*input) >> elements[Z]->Valence;
 | 
|---|
 | 367 |       (*input) >> ws;
 | 
|---|
| [274d45] | 368 |       //Log() << Verbose(3) << "Element " << Z << " has " << FindElement(Z)->Valence << " valence electrons." << endl;
 | 
|---|
| [042f82] | 369 |     }
 | 
|---|
| [4eb4fe] | 370 |     return true;
 | 
|---|
| [042f82] | 371 |   } else
 | 
|---|
| [4eb4fe] | 372 |                 return false;
 | 
|---|
 | 373 | }
 | 
|---|
| [6ac7ee] | 374 | 
 | 
|---|
| [4eb4fe] | 375 | /** load the orbitals info.
 | 
|---|
 | 376 |  * \param *input stream to parse from
 | 
|---|
 | 377 |  * \return true - parsing successful, false - something went wrong
 | 
|---|
 | 378 |  */
 | 
|---|
 | 379 | bool periodentafel::LoadOrbitalsDatabase(istream *input)
 | 
|---|
 | 380 | {
 | 
|---|
 | 381 |   char dummy[MAXSTRINGSIZE];
 | 
|---|
| [ff73a2] | 382 |   if (!(*input).fail()) {
 | 
|---|
| [4eb4fe] | 383 |     (*input).getline(dummy, MAXSTRINGSIZE);
 | 
|---|
 | 384 |     while (!(*input).eof()) {
 | 
|---|
| [ead4e6] | 385 |       atomicNumber_t Z;
 | 
|---|
| [4eb4fe] | 386 |       (*input) >> Z;
 | 
|---|
 | 387 |       ASSERT(elements.count(Z), "Element not present");
 | 
|---|
 | 388 |       (*input) >> ws;
 | 
|---|
 | 389 |       (*input) >> elements[Z]->NoValenceOrbitals;
 | 
|---|
 | 390 |       (*input) >> ws;
 | 
|---|
| [274d45] | 391 |       //Log() << Verbose(3) << "Element " << Z << " has " << FindElement(Z)->NoValenceOrbitals << " number of singly occupied valence orbitals." << endl;
 | 
|---|
| [042f82] | 392 |     }
 | 
|---|
| [4eb4fe] | 393 |     return true;
 | 
|---|
| [042f82] | 394 |   } else
 | 
|---|
| [4eb4fe] | 395 |     return false;
 | 
|---|
 | 396 | }
 | 
|---|
| [6ac7ee] | 397 | 
 | 
|---|
| [4eb4fe] | 398 | /** load the hbond angles info.
 | 
|---|
 | 399 |  * \param *input stream to parse from
 | 
|---|
 | 400 |  * \return true - parsing successful, false - something went wrong
 | 
|---|
 | 401 |  */
 | 
|---|
 | 402 | bool periodentafel::LoadHBondAngleDatabase(istream *input)
 | 
|---|
 | 403 | {
 | 
|---|
 | 404 |   char dummy[MAXSTRINGSIZE];
 | 
|---|
| [ff73a2] | 405 |   if (!(*input).fail()) {
 | 
|---|
| [4eb4fe] | 406 |     (*input).getline(dummy, MAXSTRINGSIZE);
 | 
|---|
 | 407 |     while (!(*input).eof()) {
 | 
|---|
| [ead4e6] | 408 |       atomicNumber_t Z;
 | 
|---|
| [4eb4fe] | 409 |       (*input) >> Z;
 | 
|---|
 | 410 |       ASSERT(elements.count(Z), "Element not present");
 | 
|---|
 | 411 |       (*input) >> ws;
 | 
|---|
 | 412 |       (*input) >> elements[Z]->HBondAngle[0];
 | 
|---|
 | 413 |       (*input) >> elements[Z]->HBondAngle[1];
 | 
|---|
 | 414 |       (*input) >> elements[Z]->HBondAngle[2];
 | 
|---|
 | 415 |       (*input) >> ws;
 | 
|---|
 | 416 |       //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->HBondAngle[0] << ", " << FindElement((int)tmp)->HBondAngle[1] << ", " << FindElement((int)tmp)->HBondAngle[2] << " degrees bond angle for one, two, three connected hydrogens." << endl;
 | 
|---|
| [042f82] | 417 |     }
 | 
|---|
| [4eb4fe] | 418 |     return true;
 | 
|---|
| [042f82] | 419 |   } else
 | 
|---|
| [4eb4fe] | 420 |                 return false;
 | 
|---|
 | 421 | }
 | 
|---|
| [6ac7ee] | 422 | 
 | 
|---|
| [4eb4fe] | 423 | /** load the hbond lengths info.
 | 
|---|
 | 424 |  * \param *input stream to parse from
 | 
|---|
 | 425 |  * \return true - parsing successful, false - something went wrong
 | 
|---|
 | 426 |  */
 | 
|---|
 | 427 | bool periodentafel::LoadHBondLengthsDatabase(istream *input)
 | 
|---|
 | 428 | {
 | 
|---|
 | 429 |   char dummy[MAXSTRINGSIZE];
 | 
|---|
| [ff73a2] | 430 |   if (!(*input).fail()) {
 | 
|---|
| [4eb4fe] | 431 |     (*input).getline(dummy, MAXSTRINGSIZE);
 | 
|---|
 | 432 |     while (!(*input).eof()) {
 | 
|---|
| [ead4e6] | 433 |       atomicNumber_t Z;
 | 
|---|
| [4eb4fe] | 434 |       (*input) >> Z;
 | 
|---|
 | 435 |       ASSERT(elements.count(Z), "Element not present");
 | 
|---|
 | 436 |       (*input) >> ws;
 | 
|---|
 | 437 |       (*input) >> elements[Z]->HBondDistance[0];
 | 
|---|
 | 438 |       (*input) >> elements[Z]->HBondDistance[1];
 | 
|---|
 | 439 |       (*input) >> elements[Z]->HBondDistance[2];
 | 
|---|
 | 440 |       (*input) >> ws;
 | 
|---|
 | 441 |       //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->HBondDistance[0] << " Angstrom typical distance to hydrogen." << endl;
 | 
|---|
| [042f82] | 442 |     }
 | 
|---|
| [4eb4fe] | 443 |     return true;
 | 
|---|
| [042f82] | 444 |   } else
 | 
|---|
| [4eb4fe] | 445 |                 return false;
 | 
|---|
 | 446 | }
 | 
|---|
| [6ac7ee] | 447 | 
 | 
|---|
 | 448 | /** Stores element list to file.
 | 
|---|
 | 449 |  */
 | 
|---|
| [989bf6] | 450 | bool periodentafel::StorePeriodentafel(const char *path) const
 | 
|---|
| [6ac7ee] | 451 | {
 | 
|---|
| [042f82] | 452 |   bool result = true;
 | 
|---|
 | 453 |   ofstream f;
 | 
|---|
 | 454 |   char filename[MAXSTRINGSIZE];
 | 
|---|
| [6ac7ee] | 455 | 
 | 
|---|
| [042f82] | 456 |   strncpy(filename, path, MAXSTRINGSIZE);
 | 
|---|
 | 457 |   strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
 | 
|---|
 | 458 |   strncat(filename, STANDARDELEMENTSDB, MAXSTRINGSIZE-strlen(filename));
 | 
|---|
 | 459 |   f.open(filename);
 | 
|---|
 | 460 |   if (f != NULL) {
 | 
|---|
 | 461 |     f << header1 << endl;
 | 
|---|
 | 462 |     f << header2 << endl;
 | 
|---|
| [ead4e6] | 463 |     for(const_iterator iter=elements.begin();iter!=elements.end();++iter){
 | 
|---|
 | 464 |          result = result && (*iter).second->Output(&f);
 | 
|---|
| [042f82] | 465 |     }
 | 
|---|
 | 466 |     f.close();
 | 
|---|
| [4eb4fe] | 467 |     return true;
 | 
|---|
| [042f82] | 468 |   } else
 | 
|---|
| [4eb4fe] | 469 |     return result;
 | 
|---|
| [6ac7ee] | 470 | };
 | 
|---|