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