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