| 1 | /* | 
|---|
| 2 | * Project: MoleCuilder | 
|---|
| 3 | * Description: creates and alters molecular systems | 
|---|
| 4 | * Copyright (C)  2010 University of Bonn. All rights reserved. | 
|---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | /** \file periodentafel.cpp | 
|---|
| 9 | * | 
|---|
| 10 | * Function implementations for the class periodentafel. | 
|---|
| 11 | * | 
|---|
| 12 | */ | 
|---|
| 13 |  | 
|---|
| 14 | // include config.h | 
|---|
| 15 | #ifdef HAVE_CONFIG_H | 
|---|
| 16 | #include <config.h> | 
|---|
| 17 | #endif | 
|---|
| 18 |  | 
|---|
| 19 | #include "CodePatterns/MemDebug.hpp" | 
|---|
| 20 |  | 
|---|
| 21 | #include <iomanip> | 
|---|
| 22 | #include <iostream> | 
|---|
| 23 | #include <fstream> | 
|---|
| 24 | #include <cstring> | 
|---|
| 25 |  | 
|---|
| 26 | #include "CodePatterns/Assert.hpp" | 
|---|
| 27 | #include "element.hpp" | 
|---|
| 28 | #include "elements_db.hpp" | 
|---|
| 29 | #include "CodePatterns/Log.hpp" | 
|---|
| 30 | #include "periodentafel.hpp" | 
|---|
| 31 | #include "CodePatterns/Verbose.hpp" | 
|---|
| 32 |  | 
|---|
| 33 | using namespace std; | 
|---|
| 34 |  | 
|---|
| 35 | /************************************* Functions for class periodentafel ***************************/ | 
|---|
| 36 |  | 
|---|
| 37 | /** constructor for class periodentafel | 
|---|
| 38 | * Initialises start and end of list and resets periodentafel::checkliste to false. | 
|---|
| 39 | */ | 
|---|
| 40 | periodentafel::periodentafel() | 
|---|
| 41 | { | 
|---|
| 42 | { | 
|---|
| 43 | stringstream input(elementsDB,ios_base::in); | 
|---|
| 44 | #ifndef NDEBUG | 
|---|
| 45 | bool status = | 
|---|
| 46 | #endif | 
|---|
| 47 | LoadElementsDatabase(input); | 
|---|
| 48 | ASSERT(status,  "General element initialization failed"); | 
|---|
| 49 | } | 
|---|
| 50 | { | 
|---|
| 51 | stringstream input(ElectronegativitiesDB,ios_base::in); | 
|---|
| 52 | #ifndef NDEBUG | 
|---|
| 53 | bool status = | 
|---|
| 54 | #endif | 
|---|
| 55 | LoadElectronegativityDatabase(input); | 
|---|
| 56 | ASSERT(status, "Electronegativities entry of element initialization failed"); | 
|---|
| 57 | } | 
|---|
| 58 | { | 
|---|
| 59 | stringstream input(valenceDB,ios_base::in); | 
|---|
| 60 | #ifndef NDEBUG | 
|---|
| 61 | bool status = | 
|---|
| 62 | #endif | 
|---|
| 63 | LoadValenceDatabase(input); | 
|---|
| 64 | ASSERT(status, "Valence entry of element initialization failed"); | 
|---|
| 65 | } | 
|---|
| 66 | { | 
|---|
| 67 | stringstream input(orbitalsDB,ios_base::in); | 
|---|
| 68 | #ifndef NDEBUG | 
|---|
| 69 | bool status = | 
|---|
| 70 | #endif | 
|---|
| 71 | LoadOrbitalsDatabase(input); | 
|---|
| 72 | ASSERT(status, "Orbitals entry of element initialization failed"); | 
|---|
| 73 | } | 
|---|
| 74 | { | 
|---|
| 75 | stringstream input(HbondangleDB,ios_base::in); | 
|---|
| 76 | #ifndef NDEBUG | 
|---|
| 77 | bool status = | 
|---|
| 78 | #endif | 
|---|
| 79 | LoadHBondAngleDatabase(input); | 
|---|
| 80 | ASSERT(status, "HBond angle entry of element initialization failed"); | 
|---|
| 81 | } | 
|---|
| 82 | { | 
|---|
| 83 | stringstream input(HbonddistanceDB,ios_base::in); | 
|---|
| 84 | #ifndef NDEBUG | 
|---|
| 85 | bool status = | 
|---|
| 86 | #endif | 
|---|
| 87 | LoadHBondLengthsDatabase(input); | 
|---|
| 88 | ASSERT(status, "HBond distance entry of element initialization failed"); | 
|---|
| 89 | } | 
|---|
| 90 | }; | 
|---|
| 91 |  | 
|---|
| 92 | /** destructor for class periodentafel | 
|---|
| 93 | * Removes every element and afterwards deletes start and end of list. | 
|---|
| 94 | * TODO: Handle when elements have changed and store databases then | 
|---|
| 95 | */ | 
|---|
| 96 | periodentafel::~periodentafel() | 
|---|
| 97 | { | 
|---|
| 98 | CleanupPeriodtable(); | 
|---|
| 99 | }; | 
|---|
| 100 |  | 
|---|
| 101 | /** Adds element to period table list | 
|---|
| 102 | * \param *pointer element to be added | 
|---|
| 103 | * \return iterator to added element | 
|---|
| 104 | */ | 
|---|
| 105 | periodentafel::iterator periodentafel::AddElement(element * pointer) | 
|---|
| 106 | { | 
|---|
| 107 | atomicNumber_t Z = pointer->getNumber(); | 
|---|
| 108 | ASSERT(!elements.count(Z), "Element is already present."); | 
|---|
| 109 | if (pointer->getNumber() < 1 && pointer->getNumber() >= MAX_ELEMENTS) | 
|---|
| 110 | DoeLog(0) && (eLog() << Verbose(0) << "Invalid Z number!\n"); | 
|---|
| 111 | pair<iterator,bool> res = elements.insert(pair<atomicNumber_t,element*>(Z,pointer)); | 
|---|
| 112 | return res.first; | 
|---|
| 113 | }; | 
|---|
| 114 |  | 
|---|
| 115 | /** Removes element from list. | 
|---|
| 116 | * \param *pointer element to be removed | 
|---|
| 117 | */ | 
|---|
| 118 | size_t periodentafel::RemoveElement(const element * pointer) | 
|---|
| 119 | { | 
|---|
| 120 | return RemoveElement(pointer->getNumber()); | 
|---|
| 121 | }; | 
|---|
| 122 |  | 
|---|
| 123 | /** Removes element from list. | 
|---|
| 124 | * \param Z element to be removed | 
|---|
| 125 | */ | 
|---|
| 126 | size_t periodentafel::RemoveElement(atomicNumber_t Z) | 
|---|
| 127 | { | 
|---|
| 128 | return elements.erase(Z); | 
|---|
| 129 | }; | 
|---|
| 130 |  | 
|---|
| 131 | /** Removes every element from the period table. | 
|---|
| 132 | */ | 
|---|
| 133 | void periodentafel::CleanupPeriodtable() | 
|---|
| 134 | { | 
|---|
| 135 | for(iterator iter=elements.begin();iter!=elements.end();++iter){ | 
|---|
| 136 | delete(*iter).second; | 
|---|
| 137 | } | 
|---|
| 138 | elements.clear(); | 
|---|
| 139 | }; | 
|---|
| 140 |  | 
|---|
| 141 | /** Finds an element by its atomic number. | 
|---|
| 142 | * If element is not yet in list, returns NULL. | 
|---|
| 143 | * \param Z atomic number | 
|---|
| 144 | * \return pointer to element or NULL if not found | 
|---|
| 145 | */ | 
|---|
| 146 | const element * periodentafel::FindElement(atomicNumber_t Z) const | 
|---|
| 147 | { | 
|---|
| 148 | const_iterator res = elements.find(Z); | 
|---|
| 149 | return res!=elements.end()?((*res).second):0; | 
|---|
| 150 | }; | 
|---|
| 151 |  | 
|---|
| 152 | /** Finds an element by its atomic number. | 
|---|
| 153 | * If element is not yet in list, datas are asked and stored in database. | 
|---|
| 154 | * \param shorthand chemical symbol of the element, e.g. H for hydrogene | 
|---|
| 155 | * \return pointer to element | 
|---|
| 156 | */ | 
|---|
| 157 | const element * periodentafel::FindElement(const string &shorthand) const | 
|---|
| 158 | { | 
|---|
| 159 | element *res = 0; | 
|---|
| 160 | for(const_iterator iter=elements.begin();iter!=elements.end();++iter) { | 
|---|
| 161 | if((*iter).second->getSymbol() == shorthand){ | 
|---|
| 162 | res = (*iter).second; | 
|---|
| 163 | break; | 
|---|
| 164 | } | 
|---|
| 165 | } | 
|---|
| 166 | return res; | 
|---|
| 167 | }; | 
|---|
| 168 |  | 
|---|
| 169 | /** Asks for element number and returns pointer to element | 
|---|
| 170 | * \return desired element or NULL | 
|---|
| 171 | */ | 
|---|
| 172 | const element * periodentafel::AskElement() const | 
|---|
| 173 | { | 
|---|
| 174 | const element * walker = NULL; | 
|---|
| 175 | int Z; | 
|---|
| 176 | do { | 
|---|
| 177 | DoLog(0) && (Log() << Verbose(0) << "Atomic number Z: "); | 
|---|
| 178 | cin >> Z; | 
|---|
| 179 | walker = this->FindElement(Z);  // give type | 
|---|
| 180 | } while (walker == NULL); | 
|---|
| 181 | return walker; | 
|---|
| 182 | }; | 
|---|
| 183 |  | 
|---|
| 184 | /** Asks for element and if not found, presents mask to enter info. | 
|---|
| 185 | * \return pointer to either present or newly created element | 
|---|
| 186 | */ | 
|---|
| 187 | const element * periodentafel::EnterElement() | 
|---|
| 188 | { | 
|---|
| 189 | atomicNumber_t Z = 0; | 
|---|
| 190 | DoLog(0) && (Log() << Verbose(0) << "Atomic number: " << Z << endl); | 
|---|
| 191 | cin >> Z; | 
|---|
| 192 | const element *res = FindElement(Z); | 
|---|
| 193 | if (!res) { | 
|---|
| 194 | // TODO: make this using the constructor | 
|---|
| 195 | DoLog(0) && (Log() << Verbose(0) << "Element not found in database, please enter." << endl); | 
|---|
| 196 | element *tmp = new element; | 
|---|
| 197 | tmp->Z = Z; | 
|---|
| 198 | DoLog(0) && (Log() << Verbose(0) << "Mass: " << endl); | 
|---|
| 199 | cin >> tmp->mass; | 
|---|
| 200 | DoLog(0) && (Log() << Verbose(0) << "Name [max 64 chars]: " << endl); | 
|---|
| 201 | cin >> tmp->getName(); | 
|---|
| 202 | DoLog(0) && (Log() << Verbose(0) << "Short form [max 3 chars]: " << endl); | 
|---|
| 203 | cin >> tmp->getSymbol(); | 
|---|
| 204 | AddElement(tmp); | 
|---|
| 205 | return tmp; | 
|---|
| 206 | } | 
|---|
| 207 | return res; | 
|---|
| 208 | }; | 
|---|
| 209 |  | 
|---|
| 210 |  | 
|---|
| 211 | /******************** Access to iterators ****************************/ | 
|---|
| 212 | periodentafel::const_iterator periodentafel::begin() const{ | 
|---|
| 213 | return elements.begin(); | 
|---|
| 214 | } | 
|---|
| 215 |  | 
|---|
| 216 | periodentafel::const_iterator periodentafel::end() const{ | 
|---|
| 217 | return elements.end(); | 
|---|
| 218 | } | 
|---|
| 219 |  | 
|---|
| 220 | periodentafel::reverse_iterator periodentafel::rbegin() const{ | 
|---|
| 221 | return reverse_iterator(elements.end()); | 
|---|
| 222 | } | 
|---|
| 223 |  | 
|---|
| 224 | periodentafel::reverse_iterator periodentafel::rend() const{ | 
|---|
| 225 | return reverse_iterator(elements.begin()); | 
|---|
| 226 | } | 
|---|
| 227 |  | 
|---|
| 228 | /** Prints period table to given stream. | 
|---|
| 229 | * \param output stream | 
|---|
| 230 | */ | 
|---|
| 231 | bool periodentafel::Output(ostream * const output) const | 
|---|
| 232 | { | 
|---|
| 233 | bool result = true; | 
|---|
| 234 | if (output != NULL) { | 
|---|
| 235 | for(const_iterator iter=elements.begin(); iter !=elements.end();++iter){ | 
|---|
| 236 | result = result && (*iter).second->Output(output); | 
|---|
| 237 | } | 
|---|
| 238 | return result; | 
|---|
| 239 | } else | 
|---|
| 240 | return false; | 
|---|
| 241 | }; | 
|---|
| 242 |  | 
|---|
| 243 | /** Loads element list from file. | 
|---|
| 244 | * \param *path to to standard file names | 
|---|
| 245 | */ | 
|---|
| 246 | bool periodentafel::LoadPeriodentafel(const char *path) | 
|---|
| 247 | { | 
|---|
| 248 | ifstream input; | 
|---|
| 249 | bool status = true; | 
|---|
| 250 | bool otherstatus = true; | 
|---|
| 251 | char filename[255]; | 
|---|
| 252 |  | 
|---|
| 253 | // fill elements DB | 
|---|
| 254 | strncpy(filename, path, MAXSTRINGSIZE); | 
|---|
| 255 | strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); | 
|---|
| 256 | strncat(filename, STANDARDELEMENTSDB, MAXSTRINGSIZE-strlen(filename)); | 
|---|
| 257 | input.open(filename); | 
|---|
| 258 | if (!input.fail()) | 
|---|
| 259 | DoLog(0) && (Log() << Verbose(0) << "Using " << filename << " as elements database." << endl); | 
|---|
| 260 | status = status && LoadElementsDatabase(input); | 
|---|
| 261 | input.close(); | 
|---|
| 262 | input.clear(); | 
|---|
| 263 |  | 
|---|
| 264 | // fill valence DB per element | 
|---|
| 265 | strncpy(filename, path, MAXSTRINGSIZE); | 
|---|
| 266 | strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); | 
|---|
| 267 | strncat(filename, STANDARDELECTRONEGATIVITYDB, MAXSTRINGSIZE-strlen(filename)); | 
|---|
| 268 | input.open(filename); | 
|---|
| 269 | if (!input.fail()) | 
|---|
| 270 | DoLog(0) && (Log() << Verbose(0) << "Using " << filename << " as electronegativity database." << endl); | 
|---|
| 271 | otherstatus = otherstatus && LoadElectronegativityDatabase(input); | 
|---|
| 272 | input.close(); | 
|---|
| 273 | input.clear(); | 
|---|
| 274 |  | 
|---|
| 275 | // fill valence DB per element | 
|---|
| 276 | strncpy(filename, path, MAXSTRINGSIZE); | 
|---|
| 277 | strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); | 
|---|
| 278 | strncat(filename, STANDARDVALENCEDB, MAXSTRINGSIZE-strlen(filename)); | 
|---|
| 279 | input.open(filename); | 
|---|
| 280 | if (!input.fail()) | 
|---|
| 281 | DoLog(0) && (Log() << Verbose(0) << "Using " << filename << " as valence database." << endl); | 
|---|
| 282 | otherstatus = otherstatus && LoadValenceDatabase(input); | 
|---|
| 283 | input.close(); | 
|---|
| 284 | input.clear(); | 
|---|
| 285 |  | 
|---|
| 286 | // fill orbitals DB per element | 
|---|
| 287 | strncpy(filename, path, MAXSTRINGSIZE); | 
|---|
| 288 | strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); | 
|---|
| 289 | strncat(filename, STANDARDORBITALDB, MAXSTRINGSIZE-strlen(filename)); | 
|---|
| 290 | input.open(filename); | 
|---|
| 291 | if (!input.fail()) | 
|---|
| 292 | DoLog(0) && (Log() << Verbose(0) << "Using " << filename << " as orbitals database." << endl); | 
|---|
| 293 | otherstatus = otherstatus && LoadOrbitalsDatabase(input); | 
|---|
| 294 | input.close(); | 
|---|
| 295 | input.clear(); | 
|---|
| 296 |  | 
|---|
| 297 | // fill H-BondAngle DB per element | 
|---|
| 298 | strncpy(filename, path, MAXSTRINGSIZE); | 
|---|
| 299 | strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); | 
|---|
| 300 | strncat(filename, STANDARDHBONDANGLEDB, MAXSTRINGSIZE-strlen(filename)); | 
|---|
| 301 | input.open(filename); | 
|---|
| 302 | if (!input.fail()) | 
|---|
| 303 | DoLog(0) && (Log() << Verbose(0) << "Using " << filename << " as H bond angle database." << endl); | 
|---|
| 304 | otherstatus = otherstatus && LoadHBondAngleDatabase(input); | 
|---|
| 305 | input.close(); | 
|---|
| 306 | input.clear(); | 
|---|
| 307 |  | 
|---|
| 308 | // fill H-BondDistance DB per element | 
|---|
| 309 | strncpy(filename, path, MAXSTRINGSIZE); | 
|---|
| 310 | strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); | 
|---|
| 311 | strncat(filename, STANDARDHBONDDISTANCEDB, MAXSTRINGSIZE-strlen(filename)); | 
|---|
| 312 | input.open(filename); | 
|---|
| 313 | if (!input.fail()) | 
|---|
| 314 | DoLog(0) && (Log() << Verbose(0) << "Using " << filename << " as H bond length database." << endl); | 
|---|
| 315 | otherstatus = otherstatus && LoadHBondLengthsDatabase(input); | 
|---|
| 316 | input.close(); | 
|---|
| 317 | input.clear(); | 
|---|
| 318 |  | 
|---|
| 319 | if (!otherstatus){ | 
|---|
| 320 | DoeLog(2) && (eLog()<< Verbose(2) << "Something went wrong while parsing the other databases!" << endl); | 
|---|
| 321 | } | 
|---|
| 322 |  | 
|---|
| 323 | return status; | 
|---|
| 324 | }; | 
|---|
| 325 |  | 
|---|
| 326 | /** load the element info. | 
|---|
| 327 | * \param *input stream to parse from | 
|---|
| 328 | * \return true - parsing successful, false - something went wrong | 
|---|
| 329 | */ | 
|---|
| 330 | bool periodentafel::LoadElementsDatabase(istream &input) | 
|---|
| 331 | { | 
|---|
| 332 | bool status = true; | 
|---|
| 333 | string header1tmp,header2tmp; | 
|---|
| 334 | // first parse into a map, so we can revert to old status in case something goes wront | 
|---|
| 335 | map<atomicNumber_t,element*> parsedElements; | 
|---|
| 336 | if (!input.fail()) { | 
|---|
| 337 | getline(input,header1tmp); | 
|---|
| 338 | getline(input,header2tmp); // skip first two header lines | 
|---|
| 339 | //cout << "First header: " << header1tmp << endl; | 
|---|
| 340 | //cout << "Second header: " << header2tmp << endl; | 
|---|
| 341 | //    DoLog(0) && (Log() << Verbose(0) <<  "Parsed elements:"); | 
|---|
| 342 | while (!input.eof()) { | 
|---|
| 343 | element *neues = new element; | 
|---|
| 344 | input >> neues->name; | 
|---|
| 345 | //input >> ws; | 
|---|
| 346 | input >> neues->symbol; | 
|---|
| 347 | //input >> ws; | 
|---|
| 348 | input >> neues->period; | 
|---|
| 349 | //input >> ws; | 
|---|
| 350 | input >> neues->group; | 
|---|
| 351 | //input >> ws; | 
|---|
| 352 | input >> neues->block; | 
|---|
| 353 | //input >> ws; | 
|---|
| 354 | input >> neues->Z; | 
|---|
| 355 | //input >> ws; | 
|---|
| 356 | input >> neues->mass; | 
|---|
| 357 | //input >> ws; | 
|---|
| 358 | input >> neues->CovalentRadius; | 
|---|
| 359 | //input >> ws; | 
|---|
| 360 | input >> neues->VanDerWaalsRadius; | 
|---|
| 361 | //input >> ws; | 
|---|
| 362 | input >> ws; | 
|---|
| 363 | //neues->Output((ofstream *)&cout); | 
|---|
| 364 | if ((neues->getNumber() > 0) && (neues->getNumber() < MAX_ELEMENTS)) { | 
|---|
| 365 | parsedElements[neues->Z] = neues; | 
|---|
| 366 | //        DoLog(0) && (Log() << Verbose(0) << " " << *neues); | 
|---|
| 367 | } else { | 
|---|
| 368 | DoeLog(2) && (eLog() << Verbose(2) << "Detected empty line or invalid element in elements db, discarding." << endl); | 
|---|
| 369 | DoLog(0) && (Log() << Verbose(0) << " <?>"); | 
|---|
| 370 | delete(neues); | 
|---|
| 371 | } | 
|---|
| 372 | // when the input is in failed state, we most likely just read garbage | 
|---|
| 373 | if(input.fail()) { | 
|---|
| 374 | DoeLog(2) && (eLog() << Verbose(2) << "Error parsing elements db." << endl); | 
|---|
| 375 | status = false; | 
|---|
| 376 | break; | 
|---|
| 377 | } | 
|---|
| 378 | } | 
|---|
| 379 | //    DoLog(0) && (Log() << Verbose(0) << endl); | 
|---|
| 380 | } else { | 
|---|
| 381 | DoeLog(1) && (eLog() << Verbose(1) << "Could not open the database." << endl); | 
|---|
| 382 | status = false; | 
|---|
| 383 | } | 
|---|
| 384 |  | 
|---|
| 385 | if (!parsedElements.size()) | 
|---|
| 386 | status = false; | 
|---|
| 387 |  | 
|---|
| 388 | if(status){ | 
|---|
| 389 | for(map<atomicNumber_t,element*>::iterator iter=parsedElements.begin(); | 
|---|
| 390 | iter!=parsedElements.end(); | 
|---|
| 391 | ++iter){ | 
|---|
| 392 | if (elements.count(iter->first)) { | 
|---|
| 393 | // if element already present, replace the old one | 
|---|
| 394 | // pointer to old element might still be in use, so we have to replace into the old element | 
|---|
| 395 | *(elements[iter->first])=*iter->second; | 
|---|
| 396 | delete(iter->second); | 
|---|
| 397 | } | 
|---|
| 398 | else { | 
|---|
| 399 | // no such element in periodentafel... we can just insert | 
|---|
| 400 | elements[iter->first] = iter->second; | 
|---|
| 401 | } | 
|---|
| 402 | } | 
|---|
| 403 | // all went well.. we now copy the header | 
|---|
| 404 | strncpy(header1,header1tmp.c_str(),MAXSTRINGSIZE); | 
|---|
| 405 | header1[MAXSTRINGSIZE-1]=0; | 
|---|
| 406 | strncpy(header2,header2tmp.c_str(),MAXSTRINGSIZE); | 
|---|
| 407 | header2[MAXSTRINGSIZE-1]=0; | 
|---|
| 408 | } | 
|---|
| 409 |  | 
|---|
| 410 | return status; | 
|---|
| 411 | } | 
|---|
| 412 |  | 
|---|
| 413 | /** load the electronegativity info. | 
|---|
| 414 | * \param *input stream to parse from | 
|---|
| 415 | * \return true - parsing successful, false - something went wrong | 
|---|
| 416 | */ | 
|---|
| 417 | bool periodentafel::LoadElectronegativityDatabase(std::istream &input) | 
|---|
| 418 | { | 
|---|
| 419 | char dummy[MAXSTRINGSIZE]; | 
|---|
| 420 | if (!input.fail()) { | 
|---|
| 421 | input.getline(dummy, MAXSTRINGSIZE); | 
|---|
| 422 | while (!input.eof()) { | 
|---|
| 423 | atomicNumber_t Z; | 
|---|
| 424 | input >> Z; | 
|---|
| 425 | ASSERT(elements.count(Z), "Element not present"); | 
|---|
| 426 | input >> ws; | 
|---|
| 427 | input >> elements[Z]->Electronegativity; | 
|---|
| 428 | input >> ws; | 
|---|
| 429 | //DoLog(1) && (Log() << Verbose(1) | 
|---|
| 430 | //  << "Element " << Z << " has " << FindElement(Z)->Electronegativity << " valence electrons." << endl); | 
|---|
| 431 | } | 
|---|
| 432 | return true; | 
|---|
| 433 | } else | 
|---|
| 434 | return false; | 
|---|
| 435 | } | 
|---|
| 436 |  | 
|---|
| 437 | /** load the valence info. | 
|---|
| 438 | * \param *input stream to parse from | 
|---|
| 439 | * \return true - parsing successful, false - something went wrong | 
|---|
| 440 | */ | 
|---|
| 441 | bool periodentafel::LoadValenceDatabase(istream &input) | 
|---|
| 442 | { | 
|---|
| 443 | char dummy[MAXSTRINGSIZE]; | 
|---|
| 444 | if (!input.fail()) { | 
|---|
| 445 | input.getline(dummy, MAXSTRINGSIZE); | 
|---|
| 446 | while (!input.eof()) { | 
|---|
| 447 | atomicNumber_t Z; | 
|---|
| 448 | input >> Z; | 
|---|
| 449 | ASSERT(elements.count(Z), "Element not present"); | 
|---|
| 450 | input >> ws; | 
|---|
| 451 | input >> elements[Z]->Valence; | 
|---|
| 452 | input >> ws; | 
|---|
| 453 | //Log() << Verbose(3) << "Element " << Z << " has " << FindElement(Z)->Valence << " valence electrons." << endl; | 
|---|
| 454 | } | 
|---|
| 455 | return true; | 
|---|
| 456 | } else | 
|---|
| 457 | return false; | 
|---|
| 458 | } | 
|---|
| 459 |  | 
|---|
| 460 | /** load the orbitals info. | 
|---|
| 461 | * \param *input stream to parse from | 
|---|
| 462 | * \return true - parsing successful, false - something went wrong | 
|---|
| 463 | */ | 
|---|
| 464 | bool periodentafel::LoadOrbitalsDatabase(istream &input) | 
|---|
| 465 | { | 
|---|
| 466 | char dummy[MAXSTRINGSIZE]; | 
|---|
| 467 | if (!input.fail()) { | 
|---|
| 468 | input.getline(dummy, MAXSTRINGSIZE); | 
|---|
| 469 | while (!input.eof()) { | 
|---|
| 470 | atomicNumber_t Z; | 
|---|
| 471 | input >> Z; | 
|---|
| 472 | ASSERT(elements.count(Z), "Element not present"); | 
|---|
| 473 | input >> ws; | 
|---|
| 474 | input >> elements[Z]->NoValenceOrbitals; | 
|---|
| 475 | input >> ws; | 
|---|
| 476 | //Log() << Verbose(3) << "Element " << Z << " has " << FindElement(Z)->NoValenceOrbitals << " number of singly occupied valence orbitals." << endl; | 
|---|
| 477 | } | 
|---|
| 478 | return true; | 
|---|
| 479 | } else | 
|---|
| 480 | return false; | 
|---|
| 481 | } | 
|---|
| 482 |  | 
|---|
| 483 | /** load the hbond angles info. | 
|---|
| 484 | * \param *input stream to parse from | 
|---|
| 485 | * \return true - parsing successful, false - something went wrong | 
|---|
| 486 | */ | 
|---|
| 487 | bool periodentafel::LoadHBondAngleDatabase(istream &input) | 
|---|
| 488 | { | 
|---|
| 489 | char dummy[MAXSTRINGSIZE]; | 
|---|
| 490 | if (!input.fail()) { | 
|---|
| 491 | input.getline(dummy, MAXSTRINGSIZE); | 
|---|
| 492 | while (!input.eof()) { | 
|---|
| 493 | atomicNumber_t Z; | 
|---|
| 494 | input >> Z; | 
|---|
| 495 | ASSERT(elements.count(Z), "Element not present"); | 
|---|
| 496 | input >> ws; | 
|---|
| 497 | input >> elements[Z]->HBondAngle[0]; | 
|---|
| 498 | input >> elements[Z]->HBondAngle[1]; | 
|---|
| 499 | input >> elements[Z]->HBondAngle[2]; | 
|---|
| 500 | input >> ws; | 
|---|
| 501 | //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; | 
|---|
| 502 | } | 
|---|
| 503 | return true; | 
|---|
| 504 | } else | 
|---|
| 505 | return false; | 
|---|
| 506 | } | 
|---|
| 507 |  | 
|---|
| 508 | /** load the hbond lengths info. | 
|---|
| 509 | * \param *input stream to parse from | 
|---|
| 510 | * \return true - parsing successful, false - something went wrong | 
|---|
| 511 | */ | 
|---|
| 512 | bool periodentafel::LoadHBondLengthsDatabase(istream &input) | 
|---|
| 513 | { | 
|---|
| 514 | char dummy[MAXSTRINGSIZE]; | 
|---|
| 515 | if (!input.fail()) { | 
|---|
| 516 | input.getline(dummy, MAXSTRINGSIZE); | 
|---|
| 517 | while (!input.eof()) { | 
|---|
| 518 | atomicNumber_t Z; | 
|---|
| 519 | input >> Z; | 
|---|
| 520 | ASSERT(elements.count(Z), "Element not present"); | 
|---|
| 521 | input >> ws; | 
|---|
| 522 | input >> elements[Z]->HBondDistance[0]; | 
|---|
| 523 | input >> elements[Z]->HBondDistance[1]; | 
|---|
| 524 | input >> elements[Z]->HBondDistance[2]; | 
|---|
| 525 | input >> ws; | 
|---|
| 526 | //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->HBondDistance[0] << " Angstrom typical distance to hydrogen." << endl; | 
|---|
| 527 | } | 
|---|
| 528 | return true; | 
|---|
| 529 | } else | 
|---|
| 530 | return false; | 
|---|
| 531 | } | 
|---|
| 532 |  | 
|---|
| 533 | /** Stores element list to file. | 
|---|
| 534 | */ | 
|---|
| 535 | bool periodentafel::StorePeriodentafel(const char *path) const | 
|---|
| 536 | { | 
|---|
| 537 | bool result = true; | 
|---|
| 538 | ofstream f; | 
|---|
| 539 | char filename[MAXSTRINGSIZE]; | 
|---|
| 540 |  | 
|---|
| 541 | strncpy(filename, path, MAXSTRINGSIZE); | 
|---|
| 542 | strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); | 
|---|
| 543 | strncat(filename, STANDARDELEMENTSDB, MAXSTRINGSIZE-strlen(filename)); | 
|---|
| 544 | f.open(filename); | 
|---|
| 545 | if (f != NULL) { | 
|---|
| 546 | f << header1 << endl; | 
|---|
| 547 | f << header2 << endl; | 
|---|
| 548 | for(const_iterator iter=elements.begin();iter!=elements.end();++iter){ | 
|---|
| 549 | result = result && (*iter).second->Output(&f); | 
|---|
| 550 | } | 
|---|
| 551 | f.close(); | 
|---|
| 552 | return true; | 
|---|
| 553 | } else | 
|---|
| 554 | return result; | 
|---|
| 555 | }; | 
|---|