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