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