| [bcf653] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
| [0aa122] | 4 |  * Copyright (C)  2010-2012 University of Bonn. All rights reserved.
 | 
|---|
| [94d5ac6] | 5 |  * 
 | 
|---|
 | 6 |  *
 | 
|---|
 | 7 |  *   This file is part of MoleCuilder.
 | 
|---|
 | 8 |  *
 | 
|---|
 | 9 |  *    MoleCuilder is free software: you can redistribute it and/or modify
 | 
|---|
 | 10 |  *    it under the terms of the GNU General Public License as published by
 | 
|---|
 | 11 |  *    the Free Software Foundation, either version 2 of the License, or
 | 
|---|
 | 12 |  *    (at your option) any later version.
 | 
|---|
 | 13 |  *
 | 
|---|
 | 14 |  *    MoleCuilder is distributed in the hope that it will be useful,
 | 
|---|
 | 15 |  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
 | 16 |  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
 | 17 |  *    GNU General Public License for more details.
 | 
|---|
 | 18 |  *
 | 
|---|
 | 19 |  *    You should have received a copy of the GNU General Public License
 | 
|---|
 | 20 |  *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
 | 
|---|
| [bcf653] | 21 |  */
 | 
|---|
 | 22 | 
 | 
|---|
| [6ac7ee] | 23 | /** \file periodentafel.cpp
 | 
|---|
 | 24 |  *
 | 
|---|
 | 25 |  * Function implementations for the class periodentafel.
 | 
|---|
 | 26 |  *
 | 
|---|
 | 27 |  */
 | 
|---|
 | 28 | 
 | 
|---|
| [bf3817] | 29 | // include config.h
 | 
|---|
 | 30 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 31 | #include <config.h>
 | 
|---|
 | 32 | #endif
 | 
|---|
| [112b09] | 33 | 
 | 
|---|
| [9eb71b3] | 34 | //#include "CodePatterns/MemDebug.hpp"
 | 
|---|
| [6ac7ee] | 35 | 
 | 
|---|
| [47d041] | 36 | #include <cstring>
 | 
|---|
 | 37 | #include <fstream>
 | 
|---|
| [cd4ccc] | 38 | #include <iomanip>
 | 
|---|
| [4eb4fe] | 39 | #include <iostream>
 | 
|---|
| [47d041] | 40 | #include <sstream>
 | 
|---|
| [cd4ccc] | 41 | 
 | 
|---|
| [ad011c] | 42 | #include "CodePatterns/Assert.hpp"
 | 
|---|
| [47d041] | 43 | #include "CodePatterns/Log.hpp"
 | 
|---|
| [f66195] | 44 | #include "element.hpp"
 | 
|---|
| [4eb4fe] | 45 | #include "elements_db.hpp"
 | 
|---|
| [76096d] | 46 | #include "Helpers/defs.hpp"
 | 
|---|
| [37ef6d] | 47 | #include "ion.hpp"
 | 
|---|
| [6ac7ee] | 48 | #include "periodentafel.hpp"
 | 
|---|
 | 49 | 
 | 
|---|
| [ead4e6] | 50 | using namespace std;
 | 
|---|
 | 51 | 
 | 
|---|
| [6ac7ee] | 52 | /************************************* Functions for class periodentafel ***************************/
 | 
|---|
 | 53 | 
 | 
|---|
 | 54 | /** constructor for class periodentafel
 | 
|---|
 | 55 |  * Initialises start and end of list and resets periodentafel::checkliste to false.
 | 
|---|
 | 56 |  */
 | 
|---|
| [4ae823] | 57 | periodentafel::periodentafel(const bool DoLoad)
 | 
|---|
| [4eb4fe] | 58 | {
 | 
|---|
| [4ae823] | 59 |   if (DoLoad) {
 | 
|---|
 | 60 |     ScanPeriodentafel();
 | 
|---|
| [064178] | 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 | {
 | 
|---|
| [ed26ae] | 79 |   atomicNumber_t Z = pointer->getAtomicNumber();
 | 
|---|
| [4eb4fe] | 80 |   ASSERT(!elements.count(Z), "Element is already present.");
 | 
|---|
| [ed26ae] | 81 |   if (pointer->getAtomicNumber() < 1 && pointer->getAtomicNumber() >= MAX_ELEMENTS)
 | 
|---|
| [47d041] | 82 |     ELOG(0, "Invalid Z number!");
 | 
|---|
| [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 | {
 | 
|---|
| [ed26ae] | 92 |   return RemoveElement(pointer->getAtomicNumber());
 | 
|---|
| [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 | 
 | 
|---|
| [37ef6d] | 124 | /** Returns the desired ion to a specific element.
 | 
|---|
 | 125 |  *
 | 
|---|
 | 126 |  * If the respective element is not in the list, we return
 | 
|---|
 | 127 |  * NULL.
 | 
|---|
 | 128 |  * \return pointer to an element or NULL if not found
 | 
|---|
 | 129 |  */
 | 
|---|
 | 130 | const element * periodentafel::FindElement(atomicNumber_t Z, const int ionization)
 | 
|---|
 | 131 | {
 | 
|---|
 | 132 |   // if not ionization given, fall back to other function
 | 
|---|
 | 133 |   if (ionization == 0) {
 | 
|---|
 | 134 |     return FindElement(Z);
 | 
|---|
 | 135 |   }
 | 
|---|
 | 136 |   // element present?
 | 
|---|
 | 137 |   const_iterator elementiter = elements.find(Z);
 | 
|---|
 | 138 |   if (elementiter == elements.end())
 | 
|---|
 | 139 |     return NULL;
 | 
|---|
 | 140 |   const element & element_base = *(elementiter->second);
 | 
|---|
 | 141 |         
 | 
|---|
 | 142 |   // element has already got ions?
 | 
|---|
 | 143 |   IonsPerElement::iterator setiter =
 | 
|---|
 | 144 |       ions.find(Z);
 | 
|---|
 | 145 |   if (setiter != ions.end()) {
 | 
|---|
 | 146 |     // yes, found ion list
 | 
|---|
 | 147 |     ionSet::const_iterator res = setiter->second.find(ionization);
 | 
|---|
 | 148 |         
 | 
|---|
 | 149 |         if (res != setiter->second.end()) {
 | 
|---|
 | 150 |           // ion present already
 | 
|---|
 | 151 |           element * const _ion = res->second;
 | 
|---|
 | 152 |           return _ion;
 | 
|---|
 | 153 |         } else {
 | 
|---|
 | 154 |           // ion not present yet
 | 
|---|
 | 155 |           ion * const _ion = new ion(element_base, ionization);
 | 
|---|
 | 156 |           // insert ion
 | 
|---|
 | 157 |           setiter->second.insert( std::make_pair( ionization, _ion) );
 | 
|---|
 | 158 |           return _ion;
 | 
|---|
 | 159 |         }
 | 
|---|
 | 160 |   } else {
 | 
|---|
 | 161 |     // no ions yet, create map
 | 
|---|
 | 162 |     ion * const _ion = new ion(element_base, ionization);
 | 
|---|
 | 163 |     std::pair<IonsPerElement::iterator,bool> inserter =
 | 
|---|
 | 164 |         ions.insert( std::make_pair(Z, ionSet()) );
 | 
|---|
 | 165 |     // insert ion
 | 
|---|
 | 166 |     ASSERT( inserter.second,
 | 
|---|
 | 167 |         "periodentafel::FindElement() - could not insert new ionSet to element.");
 | 
|---|
 | 168 |     inserter.first->second.insert( std::make_pair( ionization, _ion) );
 | 
|---|
 | 169 |     return _ion;
 | 
|---|
 | 170 |   }
 | 
|---|
 | 171 |   return NULL;
 | 
|---|
 | 172 | }
 | 
|---|
 | 173 | 
 | 
|---|
| [6ac7ee] | 174 | /** Finds an element by its atomic number.
 | 
|---|
 | 175 |  * If element is not yet in list, datas are asked and stored in database.
 | 
|---|
 | 176 |  * \param shorthand chemical symbol of the element, e.g. H for hydrogene
 | 
|---|
 | 177 |  * \return pointer to element
 | 
|---|
 | 178 |  */
 | 
|---|
| [e5c0a1] | 179 | const element * periodentafel::FindElement(const string &shorthand) const
 | 
|---|
| [6ac7ee] | 180 | {
 | 
|---|
| [ead4e6] | 181 |   element *res = 0;
 | 
|---|
 | 182 |   for(const_iterator iter=elements.begin();iter!=elements.end();++iter) {
 | 
|---|
 | 183 |     if((*iter).second->getSymbol() == shorthand){
 | 
|---|
 | 184 |       res = (*iter).second;
 | 
|---|
 | 185 |       break;
 | 
|---|
 | 186 |     }
 | 
|---|
| [042f82] | 187 |   }
 | 
|---|
| [ead4e6] | 188 |   return res;
 | 
|---|
| [6ac7ee] | 189 | };
 | 
|---|
 | 190 | 
 | 
|---|
 | 191 | /** Asks for element number and returns pointer to element
 | 
|---|
| [4eb4fe] | 192 |  * \return desired element or NULL
 | 
|---|
| [6ac7ee] | 193 |  */
 | 
|---|
| [e5c0a1] | 194 | const element * periodentafel::AskElement() const
 | 
|---|
| [6ac7ee] | 195 | {
 | 
|---|
| [e5c0a1] | 196 |   const element * walker = NULL;
 | 
|---|
| [042f82] | 197 |   int Z;
 | 
|---|
 | 198 |   do {
 | 
|---|
| [47d041] | 199 |     std::cout << "Atomic number Z: ";
 | 
|---|
 | 200 |     std::cin >> Z;
 | 
|---|
| [042f82] | 201 |     walker = this->FindElement(Z);  // give type
 | 
|---|
 | 202 |   } while (walker == NULL);
 | 
|---|
 | 203 |   return walker;
 | 
|---|
| [6ac7ee] | 204 | };
 | 
|---|
 | 205 | 
 | 
|---|
| [fb73b8] | 206 | /** Asks for element and if not found, presents mask to enter info.
 | 
|---|
 | 207 |  * \return pointer to either present or newly created element
 | 
|---|
 | 208 |  */
 | 
|---|
| [e5c0a1] | 209 | const element * periodentafel::EnterElement()
 | 
|---|
| [fb73b8] | 210 | {
 | 
|---|
| [ead4e6] | 211 |   atomicNumber_t Z = 0;
 | 
|---|
| [47d041] | 212 |   std::cout << "Atomic number: " << Z;
 | 
|---|
| [fb73b8] | 213 |   cin >> Z;
 | 
|---|
| [e5c0a1] | 214 |   const element *res = FindElement(Z);
 | 
|---|
| [ead4e6] | 215 |   if (!res) {
 | 
|---|
 | 216 |     // TODO: make this using the constructor
 | 
|---|
| [47d041] | 217 |     std::cout << "Element not found in database, please enter." << std::endl;
 | 
|---|
| [4eb4fe] | 218 |     element *tmp = new element;
 | 
|---|
| [ead4e6] | 219 |     tmp->Z = Z;
 | 
|---|
| [47d041] | 220 |     std::cout << "Mass: ";
 | 
|---|
| [ead4e6] | 221 |     cin >> tmp->mass;
 | 
|---|
| [47d041] | 222 |     std::cout << "Name [max 64 chars]: ";
 | 
|---|
| [bae8b0] | 223 |     cin >> tmp->name;
 | 
|---|
| [47d041] | 224 |     std::cout << "Short form [max 3 chars]: ";
 | 
|---|
| [bae8b0] | 225 |     cin >> tmp->symbol;
 | 
|---|
| [ead4e6] | 226 |     AddElement(tmp);
 | 
|---|
| [4eb4fe] | 227 |     return tmp;
 | 
|---|
| [fb73b8] | 228 |   }
 | 
|---|
| [ead4e6] | 229 |   return res;
 | 
|---|
| [fb73b8] | 230 | };
 | 
|---|
 | 231 | 
 | 
|---|
| [ead4e6] | 232 | 
 | 
|---|
 | 233 | /******************** Access to iterators ****************************/
 | 
|---|
| [e5c0a1] | 234 | periodentafel::const_iterator periodentafel::begin() const{
 | 
|---|
| [ead4e6] | 235 |   return elements.begin();
 | 
|---|
 | 236 | }
 | 
|---|
 | 237 | 
 | 
|---|
| [e5c0a1] | 238 | periodentafel::const_iterator periodentafel::end() const{
 | 
|---|
| [ead4e6] | 239 |   return elements.end();
 | 
|---|
 | 240 | }
 | 
|---|
 | 241 | 
 | 
|---|
| [e5c0a1] | 242 | periodentafel::reverse_iterator periodentafel::rbegin() const{
 | 
|---|
| [ead4e6] | 243 |   return reverse_iterator(elements.end());
 | 
|---|
 | 244 | }
 | 
|---|
 | 245 | 
 | 
|---|
| [e5c0a1] | 246 | periodentafel::reverse_iterator periodentafel::rend() const{
 | 
|---|
| [ead4e6] | 247 |   return reverse_iterator(elements.begin());
 | 
|---|
 | 248 | }
 | 
|---|
 | 249 | 
 | 
|---|
| [47ed3d] | 250 | /** Prints element data to \a *out.
 | 
|---|
 | 251 |  * \param *out outstream
 | 
|---|
 | 252 |  */
 | 
|---|
 | 253 | void periodentafel::OutputElement(ostream * const out, const element *elem) const
 | 
|---|
 | 254 | {
 | 
|---|
 | 255 |   *out << elem->getName() << "\t";
 | 
|---|
 | 256 |   *out << elem->getSymbol() << "\t";
 | 
|---|
 | 257 |   *out << elem->getAtomicNumber() << "\t";
 | 
|---|
 | 258 |   *out << elem->getMass() << "\t";
 | 
|---|
 | 259 |   *out << elem->getCovalentRadius() << "\t";
 | 
|---|
 | 260 |   *out << elem->getVanDerWaalsRadius() << std::endl;
 | 
|---|
 | 261 |   //*out << elem->getSymbol() << "\t"  << fixed << setprecision(11) << showpoint << elem->getMass() << "g/mol\t" << elem->getName() << "\t" << elem->getSymbol() << "\t" << endl;
 | 
|---|
 | 262 | };
 | 
|---|
 | 263 | 
 | 
|---|
 | 264 | 
 | 
|---|
| [6ac7ee] | 265 | /** Prints period table to given stream.
 | 
|---|
 | 266 |  * \param output stream
 | 
|---|
 | 267 |  */
 | 
|---|
| [ead4e6] | 268 | bool periodentafel::Output(ostream * const output) const
 | 
|---|
| [6ac7ee] | 269 | {
 | 
|---|
| [042f82] | 270 |   if (output != NULL) {
 | 
|---|
| [47ed3d] | 271 |     for(elementSet::const_iterator iter = elements.begin(); iter != elements.end(); ++iter) {
 | 
|---|
 | 272 |       OutputElement(output, iter->second);
 | 
|---|
| [042f82] | 273 |     }
 | 
|---|
| [47ed3d] | 274 |     return true;
 | 
|---|
 | 275 |   }
 | 
|---|
 | 276 |   return false;
 | 
|---|
 | 277 | }
 | 
|---|
| [6ac7ee] | 278 | 
 | 
|---|
| [4ae823] | 279 | /** Scan periodentafel contents from internal databases.
 | 
|---|
 | 280 |  *
 | 
|---|
 | 281 |  */
 | 
|---|
 | 282 | void periodentafel::ScanPeriodentafel()
 | 
|---|
 | 283 | {
 | 
|---|
 | 284 |   {
 | 
|---|
 | 285 |     stringstream input(elementsDB,ios_base::in);
 | 
|---|
 | 286 | #ifndef NDEBUG
 | 
|---|
 | 287 |     bool status =
 | 
|---|
 | 288 | #endif
 | 
|---|
 | 289 |         LoadElementsDatabase(input);
 | 
|---|
 | 290 |     ASSERT(status,  "General element initialization failed");
 | 
|---|
 | 291 |   }
 | 
|---|
 | 292 |   {
 | 
|---|
 | 293 |     stringstream input(ElectronegativitiesDB,ios_base::in);
 | 
|---|
 | 294 | #ifndef NDEBUG
 | 
|---|
 | 295 |     bool status =
 | 
|---|
 | 296 | #endif
 | 
|---|
 | 297 |         LoadElectronegativityDatabase(input);
 | 
|---|
 | 298 |     ASSERT(status, "Electronegativities entry of element initialization failed");
 | 
|---|
 | 299 |   }
 | 
|---|
 | 300 |   {
 | 
|---|
 | 301 |     stringstream input(valenceDB,ios_base::in);
 | 
|---|
 | 302 | #ifndef NDEBUG
 | 
|---|
 | 303 |     bool status =
 | 
|---|
 | 304 | #endif
 | 
|---|
 | 305 |         LoadValenceDatabase(input);
 | 
|---|
 | 306 |     ASSERT(status, "Valence entry of element initialization failed");
 | 
|---|
 | 307 |   }
 | 
|---|
 | 308 |   {
 | 
|---|
 | 309 |     stringstream input(orbitalsDB,ios_base::in);
 | 
|---|
 | 310 | #ifndef NDEBUG
 | 
|---|
 | 311 |     bool status =
 | 
|---|
 | 312 | #endif
 | 
|---|
 | 313 |         LoadOrbitalsDatabase(input);
 | 
|---|
 | 314 |     ASSERT(status, "Orbitals entry of element initialization failed");
 | 
|---|
 | 315 |   }
 | 
|---|
 | 316 |   {
 | 
|---|
 | 317 |     stringstream input(HbondangleDB,ios_base::in);
 | 
|---|
 | 318 | #ifndef NDEBUG
 | 
|---|
 | 319 |     bool status =
 | 
|---|
 | 320 | #endif
 | 
|---|
 | 321 |         LoadHBondAngleDatabase(input);
 | 
|---|
 | 322 |     ASSERT(status, "HBond angle entry of element initialization failed");
 | 
|---|
 | 323 |   }
 | 
|---|
 | 324 |   {
 | 
|---|
 | 325 |     stringstream input(HbonddistanceDB,ios_base::in);
 | 
|---|
 | 326 | #ifndef NDEBUG
 | 
|---|
 | 327 |     bool status =
 | 
|---|
 | 328 | #endif
 | 
|---|
 | 329 |         LoadHBondLengthsDatabase(input);
 | 
|---|
 | 330 |     ASSERT(status, "HBond distance entry of element initialization failed");
 | 
|---|
 | 331 |   }
 | 
|---|
 | 332 |   {
 | 
|---|
 | 333 |     stringstream input(ColorDB,ios_base::in);
 | 
|---|
 | 334 | #ifndef NDEBUG
 | 
|---|
 | 335 |     bool status =
 | 
|---|
 | 336 | #endif
 | 
|---|
 | 337 |         LoadColorDatabase(input);
 | 
|---|
 | 338 |     ASSERT(status, "color entry of element initialization failed");
 | 
|---|
 | 339 |   }
 | 
|---|
 | 340 | }
 | 
|---|
 | 341 | 
 | 
|---|
| [6ac7ee] | 342 | /** Loads element list from file.
 | 
|---|
 | 343 |  * \param *path to to standard file names
 | 
|---|
 | 344 |  */
 | 
|---|
| [989bf6] | 345 | bool periodentafel::LoadPeriodentafel(const char *path)
 | 
|---|
| [6ac7ee] | 346 | {
 | 
|---|
| [4eb4fe] | 347 |   ifstream input;
 | 
|---|
| [042f82] | 348 |   bool status = true;
 | 
|---|
 | 349 |   bool otherstatus = true;
 | 
|---|
| [76096d] | 350 |   char filename[MAXSTRINGSIZE];
 | 
|---|
| [6ac7ee] | 351 | 
 | 
|---|
| [042f82] | 352 |   // fill elements DB
 | 
|---|
| [76096d] | 353 |   if (strlen(path)+1+strlen(STANDARDELEMENTSDB) > MAXSTRINGSIZE-1)
 | 
|---|
 | 354 |     ELOG(2, "Generated path '" << path << "' will be too long.");
 | 
|---|
 | 355 |   filename[0] = '\0';
 | 
|---|
 | 356 |   strncat(filename, path, MAXSTRINGSIZE);
 | 
|---|
| [042f82] | 357 |   strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
 | 
|---|
 | 358 |   strncat(filename, STANDARDELEMENTSDB, MAXSTRINGSIZE-strlen(filename));
 | 
|---|
| [4eb4fe] | 359 |   input.open(filename);
 | 
|---|
| [61745cc] | 360 |   if (!input.fail())
 | 
|---|
| [47d041] | 361 |     LOG(0, "Using " << filename << " as elements database.");
 | 
|---|
| [e5c0a1] | 362 |   status = status && LoadElementsDatabase(input);
 | 
|---|
| [61745cc] | 363 |   input.close();
 | 
|---|
 | 364 |   input.clear();
 | 
|---|
| [4eb4fe] | 365 | 
 | 
|---|
| [67c92b] | 366 |   // fill valence DB per element
 | 
|---|
 | 367 |   strncpy(filename, path, MAXSTRINGSIZE);
 | 
|---|
 | 368 |   strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
 | 
|---|
 | 369 |   strncat(filename, STANDARDELECTRONEGATIVITYDB, MAXSTRINGSIZE-strlen(filename));
 | 
|---|
 | 370 |   input.open(filename);
 | 
|---|
 | 371 |   if (!input.fail())
 | 
|---|
| [47d041] | 372 |     LOG(0, "Using " << filename << " as electronegativity database.");
 | 
|---|
| [67c92b] | 373 |   otherstatus = otherstatus && LoadElectronegativityDatabase(input);
 | 
|---|
 | 374 |   input.close();
 | 
|---|
 | 375 |   input.clear();
 | 
|---|
 | 376 | 
 | 
|---|
| [4eb4fe] | 377 |   // fill valence DB per element
 | 
|---|
 | 378 |   strncpy(filename, path, MAXSTRINGSIZE);
 | 
|---|
 | 379 |   strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
 | 
|---|
 | 380 |   strncat(filename, STANDARDVALENCEDB, MAXSTRINGSIZE-strlen(filename));
 | 
|---|
 | 381 |   input.open(filename);
 | 
|---|
| [61745cc] | 382 |   if (!input.fail())
 | 
|---|
| [47d041] | 383 |     LOG(0, "Using " << filename << " as valence database.");
 | 
|---|
| [67c92b] | 384 |   otherstatus = otherstatus && LoadValenceDatabase(input);
 | 
|---|
| [61745cc] | 385 |   input.close();
 | 
|---|
 | 386 |   input.clear();
 | 
|---|
| [4eb4fe] | 387 | 
 | 
|---|
 | 388 |   // fill orbitals DB per element
 | 
|---|
 | 389 |   strncpy(filename, path, MAXSTRINGSIZE);
 | 
|---|
 | 390 |   strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
 | 
|---|
 | 391 |   strncat(filename, STANDARDORBITALDB, MAXSTRINGSIZE-strlen(filename));
 | 
|---|
 | 392 |   input.open(filename);
 | 
|---|
| [61745cc] | 393 |   if (!input.fail())
 | 
|---|
| [47d041] | 394 |     LOG(0, "Using " << filename << " as orbitals database.");
 | 
|---|
| [67c92b] | 395 |   otherstatus = otherstatus && LoadOrbitalsDatabase(input);
 | 
|---|
| [61745cc] | 396 |   input.close();
 | 
|---|
 | 397 |   input.clear();
 | 
|---|
| [4eb4fe] | 398 | 
 | 
|---|
 | 399 |   // fill H-BondAngle DB per element
 | 
|---|
 | 400 |   strncpy(filename, path, MAXSTRINGSIZE);
 | 
|---|
 | 401 |   strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
 | 
|---|
 | 402 |   strncat(filename, STANDARDHBONDANGLEDB, MAXSTRINGSIZE-strlen(filename));
 | 
|---|
 | 403 |   input.open(filename);
 | 
|---|
| [61745cc] | 404 |   if (!input.fail())
 | 
|---|
| [47d041] | 405 |     LOG(0, "Using " << filename << " as H bond angle database.");
 | 
|---|
| [67c92b] | 406 |   otherstatus = otherstatus && LoadHBondAngleDatabase(input);
 | 
|---|
| [61745cc] | 407 |   input.close();
 | 
|---|
 | 408 |   input.clear();
 | 
|---|
| [4eb4fe] | 409 | 
 | 
|---|
 | 410 |   // fill H-BondDistance DB per element
 | 
|---|
 | 411 |   strncpy(filename, path, MAXSTRINGSIZE);
 | 
|---|
 | 412 |   strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
 | 
|---|
 | 413 |   strncat(filename, STANDARDHBONDDISTANCEDB, MAXSTRINGSIZE-strlen(filename));
 | 
|---|
 | 414 |   input.open(filename);
 | 
|---|
| [61745cc] | 415 |   if (!input.fail())
 | 
|---|
| [47d041] | 416 |     LOG(0, "Using " << filename << " as H bond length database.");
 | 
|---|
| [67c92b] | 417 |   otherstatus = otherstatus && LoadHBondLengthsDatabase(input);
 | 
|---|
| [61745cc] | 418 |   input.close();
 | 
|---|
 | 419 |   input.clear();
 | 
|---|
| [4eb4fe] | 420 | 
 | 
|---|
| [3613a2] | 421 |   // fill color DB per element
 | 
|---|
 | 422 |   strncpy(filename, path, MAXSTRINGSIZE);
 | 
|---|
 | 423 |   strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
 | 
|---|
 | 424 |   strncat(filename, STANDARDCOLORDB, MAXSTRINGSIZE-strlen(filename));
 | 
|---|
 | 425 |   input.open(filename);
 | 
|---|
 | 426 |   if (!input.fail())
 | 
|---|
| [47d041] | 427 |     LOG(0, "Using " << filename << " as color database.");
 | 
|---|
| [3613a2] | 428 |   otherstatus = otherstatus && LoadColorDatabase(input);
 | 
|---|
 | 429 |   input.close();
 | 
|---|
 | 430 |   input.clear();
 | 
|---|
 | 431 | 
 | 
|---|
| [4eb4fe] | 432 |   if (!otherstatus){
 | 
|---|
| [47d041] | 433 |     ELOG(2, "Something went wrong while parsing the other databases!");
 | 
|---|
| [4eb4fe] | 434 |   }
 | 
|---|
 | 435 | 
 | 
|---|
 | 436 |   return status;
 | 
|---|
 | 437 | };
 | 
|---|
 | 438 | 
 | 
|---|
 | 439 | /** load the element info.
 | 
|---|
 | 440 |  * \param *input stream to parse from
 | 
|---|
 | 441 |  * \return true - parsing successful, false - something went wrong
 | 
|---|
 | 442 |  */
 | 
|---|
| [e5c0a1] | 443 | bool periodentafel::LoadElementsDatabase(istream &input)
 | 
|---|
| [4eb4fe] | 444 | {
 | 
|---|
| [ff73a2] | 445 |   bool status = true;
 | 
|---|
| [e5c0a1] | 446 |   string header1tmp,header2tmp;
 | 
|---|
| [47d041] | 447 | //  std::stringstream parsedelements;
 | 
|---|
| [e5c0a1] | 448 |   // first parse into a map, so we can revert to old status in case something goes wront
 | 
|---|
 | 449 |   map<atomicNumber_t,element*> parsedElements;
 | 
|---|
 | 450 |   if (!input.fail()) {
 | 
|---|
 | 451 |     getline(input,header1tmp);
 | 
|---|
 | 452 |     getline(input,header2tmp); // skip first two header lines
 | 
|---|
| [4e6d74] | 453 |     //cout << "First header: " << header1tmp << endl;
 | 
|---|
 | 454 |     //cout << "Second header: " << header2tmp << endl;
 | 
|---|
| [47d041] | 455 | //    parsedelements <<  "Parsed elements:");
 | 
|---|
| [e5c0a1] | 456 |     while (!input.eof()) {
 | 
|---|
| [042f82] | 457 |       element *neues = new element;
 | 
|---|
| [83f176] | 458 |       input >> neues->name;
 | 
|---|
| [67c92b] | 459 |       //input >> ws;
 | 
|---|
| [83f176] | 460 |       input >> neues->symbol;
 | 
|---|
| [67c92b] | 461 |       //input >> ws;
 | 
|---|
| [e5c0a1] | 462 |       input >> neues->period;
 | 
|---|
| [67c92b] | 463 |       //input >> ws;
 | 
|---|
| [e5c0a1] | 464 |       input >> neues->group;
 | 
|---|
| [67c92b] | 465 |       //input >> ws;
 | 
|---|
| [e5c0a1] | 466 |       input >> neues->block;
 | 
|---|
| [67c92b] | 467 |       //input >> ws;
 | 
|---|
| [e5c0a1] | 468 |       input >> neues->Z;
 | 
|---|
| [67c92b] | 469 |       //input >> ws;
 | 
|---|
| [e5c0a1] | 470 |       input >> neues->mass;
 | 
|---|
| [67c92b] | 471 |       //input >> ws;
 | 
|---|
| [e5c0a1] | 472 |       input >> neues->CovalentRadius;
 | 
|---|
| [67c92b] | 473 |       //input >> ws;
 | 
|---|
| [e5c0a1] | 474 |       input >> neues->VanDerWaalsRadius;
 | 
|---|
| [67c92b] | 475 |       //input >> ws;
 | 
|---|
| [e5c0a1] | 476 |       input >> ws;
 | 
|---|
| [042f82] | 477 |       //neues->Output((ofstream *)&cout);
 | 
|---|
| [ed26ae] | 478 |       if ((neues->getAtomicNumber() > 0) && (neues->getAtomicNumber() < MAX_ELEMENTS)) {
 | 
|---|
| [e5c0a1] | 479 |         parsedElements[neues->Z] = neues;
 | 
|---|
| [47d041] | 480 | //        parsedelements << " " << *neues);
 | 
|---|
| [ff73a2] | 481 |       } else {
 | 
|---|
| [47d041] | 482 |         ELOG(2, "Detected empty line or invalid element in elements db, discarding.");
 | 
|---|
 | 483 | //        parsedelements << " <?>");
 | 
|---|
| [db6bf74] | 484 |         delete(neues);
 | 
|---|
| [042f82] | 485 |       }
 | 
|---|
| [e5c0a1] | 486 |       // when the input is in failed state, we most likely just read garbage
 | 
|---|
 | 487 |       if(input.fail()) {
 | 
|---|
| [47d041] | 488 |         ELOG(2, "Error parsing elements db.");
 | 
|---|
| [e5c0a1] | 489 |         status = false;
 | 
|---|
 | 490 |         break;
 | 
|---|
 | 491 |       }
 | 
|---|
| [042f82] | 492 |     }
 | 
|---|
| [61745cc] | 493 |   } else {
 | 
|---|
| [47d041] | 494 |     ELOG(1, "Could not open the database.");
 | 
|---|
| [ff73a2] | 495 |     status = false;
 | 
|---|
| [61745cc] | 496 |   }
 | 
|---|
| [47d041] | 497 |   //LOG(0, parsedElements.str());
 | 
|---|
| [ff73a2] | 498 | 
 | 
|---|
| [e5c0a1] | 499 |   if (!parsedElements.size())
 | 
|---|
| [ff73a2] | 500 |     status = false;
 | 
|---|
 | 501 | 
 | 
|---|
| [e5c0a1] | 502 |   if(status){
 | 
|---|
 | 503 |     for(map<atomicNumber_t,element*>::iterator iter=parsedElements.begin();
 | 
|---|
 | 504 |                                                iter!=parsedElements.end();
 | 
|---|
 | 505 |                                                ++iter){
 | 
|---|
 | 506 |       if (elements.count(iter->first)) {
 | 
|---|
 | 507 |         // if element already present, replace the old one
 | 
|---|
 | 508 |         // pointer to old element might still be in use, so we have to replace into the old element
 | 
|---|
 | 509 |         *(elements[iter->first])=*iter->second;
 | 
|---|
| [9f99b3] | 510 |         delete(iter->second);
 | 
|---|
| [e5c0a1] | 511 |       }
 | 
|---|
 | 512 |       else {
 | 
|---|
 | 513 |         // no such element in periodentafel... we can just insert
 | 
|---|
 | 514 |         elements[iter->first] = iter->second;
 | 
|---|
 | 515 |       }
 | 
|---|
 | 516 |     }
 | 
|---|
 | 517 |     // all went well.. we now copy the header
 | 
|---|
 | 518 |     strncpy(header1,header1tmp.c_str(),MAXSTRINGSIZE);
 | 
|---|
 | 519 |     header1[MAXSTRINGSIZE-1]=0;
 | 
|---|
 | 520 |     strncpy(header2,header2tmp.c_str(),MAXSTRINGSIZE);
 | 
|---|
 | 521 |     header2[MAXSTRINGSIZE-1]=0;
 | 
|---|
 | 522 |   }
 | 
|---|
 | 523 | 
 | 
|---|
| [ff73a2] | 524 |   return status;
 | 
|---|
| [4eb4fe] | 525 | }
 | 
|---|
| [6ac7ee] | 526 | 
 | 
|---|
| [67c92b] | 527 | /** load the electronegativity info.
 | 
|---|
 | 528 |  * \param *input stream to parse from
 | 
|---|
 | 529 |  * \return true - parsing successful, false - something went wrong
 | 
|---|
 | 530 |  */
 | 
|---|
 | 531 | bool periodentafel::LoadElectronegativityDatabase(std::istream &input)
 | 
|---|
 | 532 | {
 | 
|---|
 | 533 |   char dummy[MAXSTRINGSIZE];
 | 
|---|
 | 534 |   if (!input.fail()) {
 | 
|---|
 | 535 |     input.getline(dummy, MAXSTRINGSIZE);
 | 
|---|
 | 536 |     while (!input.eof()) {
 | 
|---|
 | 537 |       atomicNumber_t Z;
 | 
|---|
 | 538 |       input >> Z;
 | 
|---|
 | 539 |       ASSERT(elements.count(Z), "Element not present");
 | 
|---|
 | 540 |       input >> ws;
 | 
|---|
 | 541 |       input >> elements[Z]->Electronegativity;
 | 
|---|
 | 542 |       input >> ws;
 | 
|---|
| [47d041] | 543 |       //LOG(1, "INFO: Element " << Z << " has " << FindElement(Z)->Electronegativity << " valence electrons.");
 | 
|---|
| [67c92b] | 544 |     }
 | 
|---|
 | 545 |     return true;
 | 
|---|
 | 546 |   } else
 | 
|---|
 | 547 |     return false;
 | 
|---|
 | 548 | }
 | 
|---|
 | 549 | 
 | 
|---|
| [4eb4fe] | 550 | /** load the valence info.
 | 
|---|
 | 551 |  * \param *input stream to parse from
 | 
|---|
 | 552 |  * \return true - parsing successful, false - something went wrong
 | 
|---|
 | 553 |  */
 | 
|---|
| [67c92b] | 554 | bool periodentafel::LoadValenceDatabase(istream &input)
 | 
|---|
| [4eb4fe] | 555 | {
 | 
|---|
 | 556 |   char dummy[MAXSTRINGSIZE];
 | 
|---|
| [67c92b] | 557 |   if (!input.fail()) {
 | 
|---|
 | 558 |     input.getline(dummy, MAXSTRINGSIZE);
 | 
|---|
 | 559 |     while (!input.eof()) {
 | 
|---|
| [ead4e6] | 560 |       atomicNumber_t Z;
 | 
|---|
| [67c92b] | 561 |       input >> Z;
 | 
|---|
| [4eb4fe] | 562 |       ASSERT(elements.count(Z), "Element not present");
 | 
|---|
| [67c92b] | 563 |       input >> ws;
 | 
|---|
 | 564 |       input >> elements[Z]->Valence;
 | 
|---|
 | 565 |       input >> ws;
 | 
|---|
| [47d041] | 566 |       //LOG(3, "INFO: Element " << Z << " has " << FindElement(Z)->Valence << " valence electrons.");
 | 
|---|
| [042f82] | 567 |     }
 | 
|---|
| [4eb4fe] | 568 |     return true;
 | 
|---|
| [042f82] | 569 |   } else
 | 
|---|
| [4eb4fe] | 570 |                 return false;
 | 
|---|
 | 571 | }
 | 
|---|
| [6ac7ee] | 572 | 
 | 
|---|
| [4eb4fe] | 573 | /** load the orbitals info.
 | 
|---|
 | 574 |  * \param *input stream to parse from
 | 
|---|
 | 575 |  * \return true - parsing successful, false - something went wrong
 | 
|---|
 | 576 |  */
 | 
|---|
| [67c92b] | 577 | bool periodentafel::LoadOrbitalsDatabase(istream &input)
 | 
|---|
| [4eb4fe] | 578 | {
 | 
|---|
 | 579 |   char dummy[MAXSTRINGSIZE];
 | 
|---|
| [67c92b] | 580 |   if (!input.fail()) {
 | 
|---|
 | 581 |     input.getline(dummy, MAXSTRINGSIZE);
 | 
|---|
 | 582 |     while (!input.eof()) {
 | 
|---|
| [ead4e6] | 583 |       atomicNumber_t Z;
 | 
|---|
| [67c92b] | 584 |       input >> Z;
 | 
|---|
| [4eb4fe] | 585 |       ASSERT(elements.count(Z), "Element not present");
 | 
|---|
| [67c92b] | 586 |       input >> ws;
 | 
|---|
 | 587 |       input >> elements[Z]->NoValenceOrbitals;
 | 
|---|
 | 588 |       input >> ws;
 | 
|---|
| [47d041] | 589 |       //LOG(3, "Element " << Z << " has " << FindElement(Z)->NoValenceOrbitals << " number of singly occupied valence orbitals.");
 | 
|---|
| [042f82] | 590 |     }
 | 
|---|
| [4eb4fe] | 591 |     return true;
 | 
|---|
| [042f82] | 592 |   } else
 | 
|---|
| [4eb4fe] | 593 |     return false;
 | 
|---|
 | 594 | }
 | 
|---|
| [6ac7ee] | 595 | 
 | 
|---|
| [4eb4fe] | 596 | /** load the hbond angles info.
 | 
|---|
 | 597 |  * \param *input stream to parse from
 | 
|---|
 | 598 |  * \return true - parsing successful, false - something went wrong
 | 
|---|
 | 599 |  */
 | 
|---|
| [67c92b] | 600 | bool periodentafel::LoadHBondAngleDatabase(istream &input)
 | 
|---|
| [4eb4fe] | 601 | {
 | 
|---|
 | 602 |   char dummy[MAXSTRINGSIZE];
 | 
|---|
| [67c92b] | 603 |   if (!input.fail()) {
 | 
|---|
 | 604 |     input.getline(dummy, MAXSTRINGSIZE);
 | 
|---|
 | 605 |     while (!input.eof()) {
 | 
|---|
| [ead4e6] | 606 |       atomicNumber_t Z;
 | 
|---|
| [67c92b] | 607 |       input >> Z;
 | 
|---|
| [4eb4fe] | 608 |       ASSERT(elements.count(Z), "Element not present");
 | 
|---|
| [67c92b] | 609 |       input >> ws;
 | 
|---|
 | 610 |       input >> elements[Z]->HBondAngle[0];
 | 
|---|
 | 611 |       input >> elements[Z]->HBondAngle[1];
 | 
|---|
 | 612 |       input >> elements[Z]->HBondAngle[2];
 | 
|---|
 | 613 |       input >> ws;
 | 
|---|
| [47d041] | 614 |       //LOG(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.");
 | 
|---|
| [042f82] | 615 |     }
 | 
|---|
| [4eb4fe] | 616 |     return true;
 | 
|---|
| [042f82] | 617 |   } else
 | 
|---|
| [4eb4fe] | 618 |                 return false;
 | 
|---|
 | 619 | }
 | 
|---|
| [6ac7ee] | 620 | 
 | 
|---|
| [4eb4fe] | 621 | /** load the hbond lengths info.
 | 
|---|
 | 622 |  * \param *input stream to parse from
 | 
|---|
 | 623 |  * \return true - parsing successful, false - something went wrong
 | 
|---|
 | 624 |  */
 | 
|---|
| [67c92b] | 625 | bool periodentafel::LoadHBondLengthsDatabase(istream &input)
 | 
|---|
| [4eb4fe] | 626 | {
 | 
|---|
 | 627 |   char dummy[MAXSTRINGSIZE];
 | 
|---|
| [67c92b] | 628 |   if (!input.fail()) {
 | 
|---|
 | 629 |     input.getline(dummy, MAXSTRINGSIZE);
 | 
|---|
 | 630 |     while (!input.eof()) {
 | 
|---|
| [ead4e6] | 631 |       atomicNumber_t Z;
 | 
|---|
| [67c92b] | 632 |       input >> Z;
 | 
|---|
| [4eb4fe] | 633 |       ASSERT(elements.count(Z), "Element not present");
 | 
|---|
| [67c92b] | 634 |       input >> ws;
 | 
|---|
 | 635 |       input >> elements[Z]->HBondDistance[0];
 | 
|---|
 | 636 |       input >> elements[Z]->HBondDistance[1];
 | 
|---|
 | 637 |       input >> elements[Z]->HBondDistance[2];
 | 
|---|
 | 638 |       input >> ws;
 | 
|---|
| [47d041] | 639 |       //LOG(3, "Element " << (int)tmp << " has " << FindElement((int)tmp)->HBondDistance[0] << " Angstrom typical distance to hydrogen.");
 | 
|---|
| [042f82] | 640 |     }
 | 
|---|
| [4eb4fe] | 641 |     return true;
 | 
|---|
| [042f82] | 642 |   } else
 | 
|---|
| [4eb4fe] | 643 |                 return false;
 | 
|---|
 | 644 | }
 | 
|---|
| [6ac7ee] | 645 | 
 | 
|---|
| [064178] | 646 | /** load the color info.
 | 
|---|
 | 647 |  * \param *input stream to parse from
 | 
|---|
 | 648 |  * \return true - parsing successful, false - something went wrong
 | 
|---|
 | 649 |  */
 | 
|---|
 | 650 | bool periodentafel::LoadColorDatabase(istream &input)
 | 
|---|
 | 651 | {
 | 
|---|
 | 652 |   char dummy[MAXSTRINGSIZE];
 | 
|---|
 | 653 |   if (!input.fail()) {
 | 
|---|
 | 654 |     input.getline(dummy, MAXSTRINGSIZE);
 | 
|---|
 | 655 |     while (!input.eof()) {
 | 
|---|
 | 656 |       atomicNumber_t Z;
 | 
|---|
 | 657 |       input >> Z;
 | 
|---|
 | 658 |       ASSERT(elements.count(Z), "Element not present");
 | 
|---|
 | 659 |       input >> ws;
 | 
|---|
 | 660 |       input >> dummy;
 | 
|---|
 | 661 |       {
 | 
|---|
 | 662 |         int tmpcolor;   // char here will only parse a single char (i.e. only "2" out of "255")
 | 
|---|
 | 663 |         for (int i=0;i<3;++i) {
 | 
|---|
 | 664 |           input >> ws;
 | 
|---|
 | 665 |           input >> tmpcolor;
 | 
|---|
 | 666 |           elements[Z]->color[i] = (unsigned char)tmpcolor;
 | 
|---|
 | 667 |         }
 | 
|---|
 | 668 |       }
 | 
|---|
 | 669 |       input >> ws;
 | 
|---|
| [907636] | 670 | //      {
 | 
|---|
 | 671 | //        const element * tmp = FindElement(Z);
 | 
|---|
 | 672 | //        LOG(0, "Element " << tmp->getName() << " has ("
 | 
|---|
| [064178] | 673 | //            << (int)tmp->color[0] << "," << (int)tmp->color[1] << "," << (int)tmp->color[2]
 | 
|---|
| [907636] | 674 | //            << ") colors.");
 | 
|---|
 | 675 | //      }
 | 
|---|
| [064178] | 676 |     }
 | 
|---|
 | 677 |     return true;
 | 
|---|
 | 678 |   } else
 | 
|---|
 | 679 |     return false;
 | 
|---|
 | 680 | }
 | 
|---|
 | 681 | 
 | 
|---|
| [6ac7ee] | 682 | /** Stores element list to file.
 | 
|---|
 | 683 |  */
 | 
|---|
| [989bf6] | 684 | bool periodentafel::StorePeriodentafel(const char *path) const
 | 
|---|
| [6ac7ee] | 685 | {
 | 
|---|
| [042f82] | 686 |   bool result = true;
 | 
|---|
 | 687 |   ofstream f;
 | 
|---|
 | 688 |   char filename[MAXSTRINGSIZE];
 | 
|---|
| [6ac7ee] | 689 | 
 | 
|---|
| [76096d] | 690 |   if (strlen(path)+1+strlen(STANDARDELEMENTSDB) > MAXSTRINGSIZE-1)
 | 
|---|
 | 691 |     ELOG(2, "Generated path '" << path << "' will be too long.");
 | 
|---|
 | 692 |   filename[0] = '\0';
 | 
|---|
 | 693 |   strncat(filename, path, MAXSTRINGSIZE);
 | 
|---|
| [042f82] | 694 |   strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
 | 
|---|
 | 695 |   strncat(filename, STANDARDELEMENTSDB, MAXSTRINGSIZE-strlen(filename));
 | 
|---|
 | 696 |   f.open(filename);
 | 
|---|
| [0f9eb0] | 697 |   if (f.good()) {
 | 
|---|
| [042f82] | 698 |     f << header1 << endl;
 | 
|---|
 | 699 |     f << header2 << endl;
 | 
|---|
| [ead4e6] | 700 |     for(const_iterator iter=elements.begin();iter!=elements.end();++iter){
 | 
|---|
| [47ed3d] | 701 |       OutputElement(&f, iter->second);
 | 
|---|
| [042f82] | 702 |     }
 | 
|---|
 | 703 |     f.close();
 | 
|---|
| [4eb4fe] | 704 |     return true;
 | 
|---|
| [0f9eb0] | 705 |   }
 | 
|---|
 | 706 |   return result;
 | 
|---|
| [6ac7ee] | 707 | };
 | 
|---|
| [b60804] | 708 | 
 | 
|---|
 | 709 | /** Comparison operator for periodentafel.
 | 
|---|
 | 710 |  *
 | 
|---|
 | 711 |  * @param other other instance to compare to
 | 
|---|
 | 712 |  * @return true when both contain same elements
 | 
|---|
 | 713 |  */
 | 
|---|
 | 714 | bool periodentafel::operator==(const periodentafel &other) const
 | 
|---|
 | 715 | {
 | 
|---|
 | 716 |   // there are only pointers in the elementSet, hence we have to compare ourselves
 | 
|---|
 | 717 |   if (elements.size() != other.elements.size()) return false;
 | 
|---|
 | 718 |   const_iterator iter = elements.begin();
 | 
|---|
 | 719 |   const_iterator otheriter = other.elements.begin();
 | 
|---|
 | 720 |   for (;(iter != elements.end()) && (otheriter != other.elements.end());
 | 
|---|
 | 721 |       ++iter, ++otheriter) {
 | 
|---|
 | 722 |     bool status = true;
 | 
|---|
 | 723 |     status = status && (iter->first == otheriter->first);
 | 
|---|
 | 724 |     status = status && (*(iter->second) == *(otheriter->second));
 | 
|---|
 | 725 |     if (!status) {
 | 
|---|
 | 726 |       std::cout << *(iter->second) << " not equal to " << *(otheriter->second) << "." << std::endl;
 | 
|---|
 | 727 |       return false;
 | 
|---|
 | 728 |     }
 | 
|---|
 | 729 | //    else
 | 
|---|
 | 730 | //      std::cout << (iter->second)->getName() << " are equal to " << (otheriter->second)->getName() << "." << std::endl;
 | 
|---|
 | 731 |   }
 | 
|---|
 | 732 |   if (strncmp(header1, other.header1, MAXSTRINGSIZE) != 0) return false;
 | 
|---|
 | 733 |   if (strncmp(header2, other.header2, MAXSTRINGSIZE) != 0) return false;
 | 
|---|
 | 734 |   return true;
 | 
|---|
 | 735 | }
 | 
|---|