| [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" | 
|---|
| [cd4ccc] | 19 | #include "helpers.hpp" | 
|---|
| [f66195] | 20 | #include "lists.hpp" | 
|---|
| [e138de] | 21 | #include "log.hpp" | 
|---|
| [6ac7ee] | 22 | #include "periodentafel.hpp" | 
|---|
| [cd4ccc] | 23 | #include "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 | */ | 
|---|
| [4eb4fe] | 127 | element * const periodentafel::FindElement(const char * const 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 | /** Prints period table to given stream. | 
|---|
|  | 214 | * \param *output output stream | 
|---|
|  | 215 | * \param *checkliste elements table for this molecule | 
|---|
|  | 216 | */ | 
|---|
| [ead4e6] | 217 | bool periodentafel::Checkout(ostream * const output, const int * const checkliste) const | 
|---|
| [6ac7ee] | 218 | { | 
|---|
| [042f82] | 219 | bool result = true; | 
|---|
|  | 220 | int No = 1; | 
|---|
| [6ac7ee] | 221 |  | 
|---|
| [042f82] | 222 | if (output != NULL) { | 
|---|
|  | 223 | *output << "# Ion type data (PP = PseudoPotential, Z = atomic number)" << endl; | 
|---|
|  | 224 | *output << "#Ion_TypeNr.\tAmount\tZ\tRGauss\tL_Max(PP)L_Loc(PP)IonMass\t# chemical name, symbol" << endl; | 
|---|
| [ead4e6] | 225 | for(const_iterator iter=elements.begin(); iter!=elements.end();++iter){ | 
|---|
|  | 226 | if (((*iter).first < MAX_ELEMENTS) && (checkliste[(*iter).first])) { | 
|---|
|  | 227 | (*iter).second->No = No; | 
|---|
|  | 228 | result = result && (*iter).second->Checkout(output, No++, checkliste[(*iter).first]); | 
|---|
| [042f82] | 229 | } | 
|---|
|  | 230 | } | 
|---|
|  | 231 | return result; | 
|---|
|  | 232 | } else | 
|---|
|  | 233 | return false; | 
|---|
| [6ac7ee] | 234 | }; | 
|---|
|  | 235 |  | 
|---|
|  | 236 | /** Loads element list from file. | 
|---|
|  | 237 | * \param *path to to standard file names | 
|---|
|  | 238 | */ | 
|---|
| [989bf6] | 239 | bool periodentafel::LoadPeriodentafel(const char *path) | 
|---|
| [6ac7ee] | 240 | { | 
|---|
| [4eb4fe] | 241 | ifstream input; | 
|---|
| [042f82] | 242 | bool status = true; | 
|---|
|  | 243 | bool otherstatus = true; | 
|---|
|  | 244 | char filename[255]; | 
|---|
| [6ac7ee] | 245 |  | 
|---|
| [042f82] | 246 | // fill elements DB | 
|---|
|  | 247 | strncpy(filename, path, MAXSTRINGSIZE); | 
|---|
|  | 248 | strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); | 
|---|
|  | 249 | strncat(filename, STANDARDELEMENTSDB, MAXSTRINGSIZE-strlen(filename)); | 
|---|
| [4eb4fe] | 250 | input.open(filename); | 
|---|
| [61745cc] | 251 | if (!input.fail()) | 
|---|
|  | 252 | DoLog(0) && (Log() << Verbose(0) << "Using " << filename << " as elements database." << endl); | 
|---|
| [4eb4fe] | 253 | status = status && LoadElementsDatabase(&input); | 
|---|
| [61745cc] | 254 | input.close(); | 
|---|
|  | 255 | input.clear(); | 
|---|
| [4eb4fe] | 256 |  | 
|---|
|  | 257 | // fill valence DB per element | 
|---|
|  | 258 | strncpy(filename, path, MAXSTRINGSIZE); | 
|---|
|  | 259 | strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); | 
|---|
|  | 260 | strncat(filename, STANDARDVALENCEDB, MAXSTRINGSIZE-strlen(filename)); | 
|---|
|  | 261 | input.open(filename); | 
|---|
| [61745cc] | 262 | if (!input.fail()) | 
|---|
|  | 263 | DoLog(0) && (Log() << Verbose(0) << "Using " << filename << " as valence database." << endl); | 
|---|
| [4eb4fe] | 264 | otherstatus = otherstatus && LoadValenceDatabase(&input); | 
|---|
| [61745cc] | 265 | input.close(); | 
|---|
|  | 266 | input.clear(); | 
|---|
| [4eb4fe] | 267 |  | 
|---|
|  | 268 | // fill orbitals DB per element | 
|---|
|  | 269 | strncpy(filename, path, MAXSTRINGSIZE); | 
|---|
|  | 270 | strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); | 
|---|
|  | 271 | strncat(filename, STANDARDORBITALDB, MAXSTRINGSIZE-strlen(filename)); | 
|---|
|  | 272 | input.open(filename); | 
|---|
| [61745cc] | 273 | if (!input.fail()) | 
|---|
|  | 274 | DoLog(0) && (Log() << Verbose(0) << "Using " << filename << " as orbitals database." << endl); | 
|---|
| [4eb4fe] | 275 | otherstatus = otherstatus && LoadOrbitalsDatabase(&input); | 
|---|
| [61745cc] | 276 | input.close(); | 
|---|
|  | 277 | input.clear(); | 
|---|
| [4eb4fe] | 278 |  | 
|---|
|  | 279 | // fill H-BondAngle DB per element | 
|---|
|  | 280 | strncpy(filename, path, MAXSTRINGSIZE); | 
|---|
|  | 281 | strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); | 
|---|
|  | 282 | strncat(filename, STANDARDHBONDANGLEDB, MAXSTRINGSIZE-strlen(filename)); | 
|---|
|  | 283 | input.open(filename); | 
|---|
| [61745cc] | 284 | if (!input.fail()) | 
|---|
|  | 285 | DoLog(0) && (Log() << Verbose(0) << "Using " << filename << " as H bond angle database." << endl); | 
|---|
| [4eb4fe] | 286 | otherstatus = otherstatus && LoadHBondAngleDatabase(&input); | 
|---|
| [61745cc] | 287 | input.close(); | 
|---|
|  | 288 | input.clear(); | 
|---|
| [4eb4fe] | 289 |  | 
|---|
|  | 290 | // fill H-BondDistance DB per element | 
|---|
|  | 291 | strncpy(filename, path, MAXSTRINGSIZE); | 
|---|
|  | 292 | strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); | 
|---|
|  | 293 | strncat(filename, STANDARDHBONDDISTANCEDB, MAXSTRINGSIZE-strlen(filename)); | 
|---|
|  | 294 | input.open(filename); | 
|---|
| [61745cc] | 295 | if (!input.fail()) | 
|---|
|  | 296 | DoLog(0) && (Log() << Verbose(0) << "Using " << filename << " as H bond length database." << endl); | 
|---|
| [4eb4fe] | 297 | otherstatus = otherstatus && LoadHBondLengthsDatabase(&input); | 
|---|
| [61745cc] | 298 | input.close(); | 
|---|
|  | 299 | input.clear(); | 
|---|
| [4eb4fe] | 300 |  | 
|---|
|  | 301 | if (!otherstatus){ | 
|---|
|  | 302 | DoeLog(2) && (eLog()<< Verbose(2) << "Something went wrong while parsing the other databases!" << endl); | 
|---|
|  | 303 | } | 
|---|
|  | 304 |  | 
|---|
|  | 305 | return status; | 
|---|
|  | 306 | }; | 
|---|
|  | 307 |  | 
|---|
|  | 308 | /** load the element info. | 
|---|
|  | 309 | * \param *input stream to parse from | 
|---|
|  | 310 | * \return true - parsing successful, false - something went wrong | 
|---|
|  | 311 | */ | 
|---|
|  | 312 | bool periodentafel::LoadElementsDatabase(istream *input) | 
|---|
|  | 313 | { | 
|---|
| [ff73a2] | 314 | bool status = true; | 
|---|
|  | 315 | int counter = 0; | 
|---|
| [61745cc] | 316 | pair< std::map<atomicNumber_t,element*>::iterator, bool > InserterTest; | 
|---|
| [ff73a2] | 317 | if (!(*input).fail()) { | 
|---|
| [4eb4fe] | 318 | (*input).getline(header1, MAXSTRINGSIZE); | 
|---|
|  | 319 | (*input).getline(header2, MAXSTRINGSIZE); // skip first two header lines | 
|---|
| [a67d19] | 320 | DoLog(0) && (Log() << Verbose(0) <<  "Parsed elements:"); | 
|---|
| [4eb4fe] | 321 | while (!(*input).eof()) { | 
|---|
| [042f82] | 322 | element *neues = new element; | 
|---|
| [4eb4fe] | 323 | (*input) >> neues->name; | 
|---|
|  | 324 | //(*input) >> ws; | 
|---|
|  | 325 | (*input) >> neues->symbol; | 
|---|
|  | 326 | //(*input) >> ws; | 
|---|
|  | 327 | (*input) >> neues->period; | 
|---|
|  | 328 | //(*input) >> ws; | 
|---|
|  | 329 | (*input) >> neues->group; | 
|---|
|  | 330 | //(*input) >> ws; | 
|---|
|  | 331 | (*input) >> neues->block; | 
|---|
|  | 332 | //(*input) >> ws; | 
|---|
|  | 333 | (*input) >> neues->Z; | 
|---|
|  | 334 | //(*input) >> ws; | 
|---|
|  | 335 | (*input) >> neues->mass; | 
|---|
|  | 336 | //(*input) >> ws; | 
|---|
|  | 337 | (*input) >> neues->CovalentRadius; | 
|---|
|  | 338 | //(*input) >> ws; | 
|---|
|  | 339 | (*input) >> neues->VanDerWaalsRadius; | 
|---|
|  | 340 | //(*input) >> ws; | 
|---|
|  | 341 | (*input) >> ws; | 
|---|
| [042f82] | 342 | //neues->Output((ofstream *)&cout); | 
|---|
| [61745cc] | 343 | if ((neues->getNumber() > 0) && (neues->getNumber() < MAX_ELEMENTS)) { | 
|---|
|  | 344 | if (elements.count(neues->getNumber())) {// if element already present, remove and delete old one (i.e. replace it) | 
|---|
|  | 345 | //cout << neues->symbol << " is present already." << endl; | 
|---|
|  | 346 | element * const Elemental = FindElement(neues->getNumber()); | 
|---|
|  | 347 | ASSERT(Elemental != NULL, "element should be present but is not??"); | 
|---|
|  | 348 | *Elemental = *neues; | 
|---|
| [61b5f0] | 349 | delete(neues); | 
|---|
|  | 350 | neues = Elemental; | 
|---|
| [61745cc] | 351 | } else { | 
|---|
|  | 352 | InserterTest = elements.insert(pair <atomicNumber_t,element*> (neues->getNumber(), neues)); | 
|---|
|  | 353 | ASSERT(InserterTest.second, "Could not insert new element into periodentafel on LoadElementsDatabase()."); | 
|---|
|  | 354 | } | 
|---|
|  | 355 | DoLog(0) && (Log() << Verbose(0) << " " << elements[neues->getNumber()]->symbol); | 
|---|
| [ff73a2] | 356 | counter++; | 
|---|
|  | 357 | } else { | 
|---|
|  | 358 | DoeLog(2) && (eLog() << Verbose(2) << "Detected empty line or invalid element in elements db, discarding." << endl); | 
|---|
|  | 359 | DoLog(0) && (Log() << Verbose(0) << " <?>"); | 
|---|
| [db6bf74] | 360 | delete(neues); | 
|---|
| [042f82] | 361 | } | 
|---|
|  | 362 | } | 
|---|
| [a67d19] | 363 | DoLog(0) && (Log() << Verbose(0) << endl); | 
|---|
| [61745cc] | 364 | } else { | 
|---|
|  | 365 | DoeLog(1) && (eLog() << Verbose(1) << "Could not open the database." << endl); | 
|---|
| [ff73a2] | 366 | status = false; | 
|---|
| [61745cc] | 367 | } | 
|---|
| [ff73a2] | 368 |  | 
|---|
|  | 369 | if (counter == 0) | 
|---|
|  | 370 | status = false; | 
|---|
|  | 371 |  | 
|---|
|  | 372 | return status; | 
|---|
| [4eb4fe] | 373 | } | 
|---|
| [6ac7ee] | 374 |  | 
|---|
| [4eb4fe] | 375 | /** load the valence info. | 
|---|
|  | 376 | * \param *input stream to parse from | 
|---|
|  | 377 | * \return true - parsing successful, false - something went wrong | 
|---|
|  | 378 | */ | 
|---|
|  | 379 | bool periodentafel::LoadValenceDatabase(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]->Valence; | 
|---|
|  | 390 | (*input) >> ws; | 
|---|
| [274d45] | 391 | //Log() << Verbose(3) << "Element " << Z << " has " << FindElement(Z)->Valence << " valence electrons." << endl; | 
|---|
| [042f82] | 392 | } | 
|---|
| [4eb4fe] | 393 | return true; | 
|---|
| [042f82] | 394 | } else | 
|---|
| [4eb4fe] | 395 | return false; | 
|---|
|  | 396 | } | 
|---|
| [6ac7ee] | 397 |  | 
|---|
| [4eb4fe] | 398 | /** load the orbitals info. | 
|---|
|  | 399 | * \param *input stream to parse from | 
|---|
|  | 400 | * \return true - parsing successful, false - something went wrong | 
|---|
|  | 401 | */ | 
|---|
|  | 402 | bool periodentafel::LoadOrbitalsDatabase(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]->NoValenceOrbitals; | 
|---|
|  | 413 | (*input) >> ws; | 
|---|
| [274d45] | 414 | //Log() << Verbose(3) << "Element " << Z << " has " << FindElement(Z)->NoValenceOrbitals << " number of singly occupied valence orbitals." << endl; | 
|---|
| [042f82] | 415 | } | 
|---|
| [4eb4fe] | 416 | return true; | 
|---|
| [042f82] | 417 | } else | 
|---|
| [4eb4fe] | 418 | return false; | 
|---|
|  | 419 | } | 
|---|
| [6ac7ee] | 420 |  | 
|---|
| [4eb4fe] | 421 | /** load the hbond angles info. | 
|---|
|  | 422 | * \param *input stream to parse from | 
|---|
|  | 423 | * \return true - parsing successful, false - something went wrong | 
|---|
|  | 424 | */ | 
|---|
|  | 425 | bool periodentafel::LoadHBondAngleDatabase(istream *input) | 
|---|
|  | 426 | { | 
|---|
|  | 427 | char dummy[MAXSTRINGSIZE]; | 
|---|
| [ff73a2] | 428 | if (!(*input).fail()) { | 
|---|
| [4eb4fe] | 429 | (*input).getline(dummy, MAXSTRINGSIZE); | 
|---|
|  | 430 | while (!(*input).eof()) { | 
|---|
| [ead4e6] | 431 | atomicNumber_t Z; | 
|---|
| [4eb4fe] | 432 | (*input) >> Z; | 
|---|
|  | 433 | ASSERT(elements.count(Z), "Element not present"); | 
|---|
|  | 434 | (*input) >> ws; | 
|---|
|  | 435 | (*input) >> elements[Z]->HBondAngle[0]; | 
|---|
|  | 436 | (*input) >> elements[Z]->HBondAngle[1]; | 
|---|
|  | 437 | (*input) >> elements[Z]->HBondAngle[2]; | 
|---|
|  | 438 | (*input) >> ws; | 
|---|
|  | 439 | //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] | 440 | } | 
|---|
| [4eb4fe] | 441 | return true; | 
|---|
| [042f82] | 442 | } else | 
|---|
| [4eb4fe] | 443 | return false; | 
|---|
|  | 444 | } | 
|---|
| [6ac7ee] | 445 |  | 
|---|
| [4eb4fe] | 446 | /** load the hbond lengths info. | 
|---|
|  | 447 | * \param *input stream to parse from | 
|---|
|  | 448 | * \return true - parsing successful, false - something went wrong | 
|---|
|  | 449 | */ | 
|---|
|  | 450 | bool periodentafel::LoadHBondLengthsDatabase(istream *input) | 
|---|
|  | 451 | { | 
|---|
|  | 452 | char dummy[MAXSTRINGSIZE]; | 
|---|
| [ff73a2] | 453 | if (!(*input).fail()) { | 
|---|
| [4eb4fe] | 454 | (*input).getline(dummy, MAXSTRINGSIZE); | 
|---|
|  | 455 | while (!(*input).eof()) { | 
|---|
| [ead4e6] | 456 | atomicNumber_t Z; | 
|---|
| [4eb4fe] | 457 | (*input) >> Z; | 
|---|
|  | 458 | ASSERT(elements.count(Z), "Element not present"); | 
|---|
|  | 459 | (*input) >> ws; | 
|---|
|  | 460 | (*input) >> elements[Z]->HBondDistance[0]; | 
|---|
|  | 461 | (*input) >> elements[Z]->HBondDistance[1]; | 
|---|
|  | 462 | (*input) >> elements[Z]->HBondDistance[2]; | 
|---|
|  | 463 | (*input) >> ws; | 
|---|
|  | 464 | //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->HBondDistance[0] << " Angstrom typical distance to hydrogen." << endl; | 
|---|
| [042f82] | 465 | } | 
|---|
| [4eb4fe] | 466 | return true; | 
|---|
| [042f82] | 467 | } else | 
|---|
| [4eb4fe] | 468 | return false; | 
|---|
|  | 469 | } | 
|---|
| [6ac7ee] | 470 |  | 
|---|
|  | 471 | /** Stores element list to file. | 
|---|
|  | 472 | */ | 
|---|
| [989bf6] | 473 | bool periodentafel::StorePeriodentafel(const char *path) const | 
|---|
| [6ac7ee] | 474 | { | 
|---|
| [042f82] | 475 | bool result = true; | 
|---|
|  | 476 | ofstream f; | 
|---|
|  | 477 | char filename[MAXSTRINGSIZE]; | 
|---|
| [6ac7ee] | 478 |  | 
|---|
| [042f82] | 479 | strncpy(filename, path, MAXSTRINGSIZE); | 
|---|
|  | 480 | strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); | 
|---|
|  | 481 | strncat(filename, STANDARDELEMENTSDB, MAXSTRINGSIZE-strlen(filename)); | 
|---|
|  | 482 | f.open(filename); | 
|---|
|  | 483 | if (f != NULL) { | 
|---|
|  | 484 | f << header1 << endl; | 
|---|
|  | 485 | f << header2 << endl; | 
|---|
| [ead4e6] | 486 | for(const_iterator iter=elements.begin();iter!=elements.end();++iter){ | 
|---|
|  | 487 | result = result && (*iter).second->Output(&f); | 
|---|
| [042f82] | 488 | } | 
|---|
|  | 489 | f.close(); | 
|---|
| [4eb4fe] | 490 | return true; | 
|---|
| [042f82] | 491 | } else | 
|---|
| [4eb4fe] | 492 | return result; | 
|---|
| [6ac7ee] | 493 | }; | 
|---|