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