source: src/periodentafel.cpp@ bcedf7

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since bcedf7 was b60804, checked in by Frederik Heber <heber@…>, 13 years ago

Added serialization to class periodentafel.

  • added unit test on comparison and serialization.
  • FIX: removed inclusion of PeriodentafelUnitTest.hpp in periodentafel.hpp as forward declaration is sufficient.
  • ComparisonTest and fix of operator==() for class periodentafel.
  • Property mode set to 100755
File size: 19.0 KB
RevLine 
[bcf653]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
[6ac7ee]8/** \file periodentafel.cpp
9 *
10 * Function implementations for the class periodentafel.
11 *
12 */
13
[bf3817]14// include config.h
15#ifdef HAVE_CONFIG_H
16#include <config.h>
17#endif
[112b09]18
[ad011c]19#include "CodePatterns/MemDebug.hpp"
[6ac7ee]20
[cd4ccc]21#include <iomanip>
[4eb4fe]22#include <iostream>
[cd4ccc]23#include <fstream>
[49e1ae]24#include <cstring>
[cd4ccc]25
[ad011c]26#include "CodePatterns/Assert.hpp"
[f66195]27#include "element.hpp"
[4eb4fe]28#include "elements_db.hpp"
[ad011c]29#include "CodePatterns/Log.hpp"
[6ac7ee]30#include "periodentafel.hpp"
[ad011c]31#include "CodePatterns/Verbose.hpp"
[6ac7ee]32
[ead4e6]33using namespace std;
34
[6ac7ee]35/************************************* Functions for class periodentafel ***************************/
36
37/** constructor for class periodentafel
38 * Initialises start and end of list and resets periodentafel::checkliste to false.
39 */
[ead4e6]40periodentafel::periodentafel()
[4eb4fe]41{
[f34c23]42 {
43 stringstream input(elementsDB,ios_base::in);
[b2ae3b]44#ifndef NDEBUG
45 bool status =
46#endif
47 LoadElementsDatabase(input);
[f34c23]48 ASSERT(status, "General element initialization failed");
49 }
[67c92b]50 {
51 stringstream input(ElectronegativitiesDB,ios_base::in);
52#ifndef NDEBUG
53 bool status =
54#endif
55 LoadElectronegativityDatabase(input);
56 ASSERT(status, "Electronegativities entry of element initialization failed");
57 }
[f34c23]58 {
59 stringstream input(valenceDB,ios_base::in);
[b2ae3b]60#ifndef NDEBUG
61 bool status =
62#endif
[67c92b]63 LoadValenceDatabase(input);
[f34c23]64 ASSERT(status, "Valence entry of element initialization failed");
65 }
66 {
67 stringstream input(orbitalsDB,ios_base::in);
[b2ae3b]68#ifndef NDEBUG
69 bool status =
70#endif
[67c92b]71 LoadOrbitalsDatabase(input);
[f34c23]72 ASSERT(status, "Orbitals entry of element initialization failed");
73 }
74 {
75 stringstream input(HbondangleDB,ios_base::in);
[b2ae3b]76#ifndef NDEBUG
77 bool status =
78#endif
[67c92b]79 LoadHBondAngleDatabase(input);
[f34c23]80 ASSERT(status, "HBond angle entry of element initialization failed");
81 }
82 {
83 stringstream input(HbonddistanceDB,ios_base::in);
[b2ae3b]84#ifndef NDEBUG
85 bool status =
86#endif
[67c92b]87 LoadHBondLengthsDatabase(input);
[f34c23]88 ASSERT(status, "HBond distance entry of element initialization failed");
89 }
[064178]90 {
91 stringstream input(ColorDB,ios_base::in);
92#ifndef NDEBUG
93 bool status =
94#endif
95 LoadColorDatabase(input);
96 ASSERT(status, "color entry of element initialization failed");
97 }
[4eb4fe]98};
[6ac7ee]99
100/** destructor for class periodentafel
101 * Removes every element and afterwards deletes start and end of list.
[42af9e]102 * TODO: Handle when elements have changed and store databases then
[6ac7ee]103 */
104periodentafel::~periodentafel()
105{
[042f82]106 CleanupPeriodtable();
[6ac7ee]107};
108
109/** Adds element to period table list
110 * \param *pointer element to be added
[4eb4fe]111 * \return iterator to added element
[6ac7ee]112 */
[e5c0a1]113periodentafel::iterator periodentafel::AddElement(element * pointer)
[6ac7ee]114{
[ead4e6]115 atomicNumber_t Z = pointer->getNumber();
[4eb4fe]116 ASSERT(!elements.count(Z), "Element is already present.");
[ead4e6]117 if (pointer->getNumber() < 1 && pointer->getNumber() >= MAX_ELEMENTS)
[5f612ee]118 DoeLog(0) && (eLog() << Verbose(0) << "Invalid Z number!\n");
[ead4e6]119 pair<iterator,bool> res = elements.insert(pair<atomicNumber_t,element*>(Z,pointer));
120 return res.first;
[6ac7ee]121};
122
123/** Removes element from list.
124 * \param *pointer element to be removed
125 */
[e5c0a1]126size_t periodentafel::RemoveElement(const element * pointer)
[6ac7ee]127{
[61745cc]128 return RemoveElement(pointer->getNumber());
[4eb4fe]129};
130
131/** Removes element from list.
132 * \param Z element to be removed
133 */
[61745cc]134size_t periodentafel::RemoveElement(atomicNumber_t Z)
[4eb4fe]135{
[61745cc]136 return elements.erase(Z);
[6ac7ee]137};
138
139/** Removes every element from the period table.
140 */
[ead4e6]141void periodentafel::CleanupPeriodtable()
[6ac7ee]142{
[745a85]143 for(iterator iter=elements.begin();iter!=elements.end();++iter){
144 delete(*iter).second;
145 }
[ead4e6]146 elements.clear();
[6ac7ee]147};
148
149/** Finds an element by its atomic number.
[fb73b8]150 * If element is not yet in list, returns NULL.
[6ac7ee]151 * \param Z atomic number
[fb73b8]152 * \return pointer to element or NULL if not found
[6ac7ee]153 */
[e5c0a1]154const element * periodentafel::FindElement(atomicNumber_t Z) const
[6ac7ee]155{
[ead4e6]156 const_iterator res = elements.find(Z);
157 return res!=elements.end()?((*res).second):0;
[6ac7ee]158};
159
160/** Finds an element by its atomic number.
161 * If element is not yet in list, datas are asked and stored in database.
162 * \param shorthand chemical symbol of the element, e.g. H for hydrogene
163 * \return pointer to element
164 */
[e5c0a1]165const element * periodentafel::FindElement(const string &shorthand) const
[6ac7ee]166{
[ead4e6]167 element *res = 0;
168 for(const_iterator iter=elements.begin();iter!=elements.end();++iter) {
169 if((*iter).second->getSymbol() == shorthand){
170 res = (*iter).second;
171 break;
172 }
[042f82]173 }
[ead4e6]174 return res;
[6ac7ee]175};
176
177/** Asks for element number and returns pointer to element
[4eb4fe]178 * \return desired element or NULL
[6ac7ee]179 */
[e5c0a1]180const element * periodentafel::AskElement() const
[6ac7ee]181{
[e5c0a1]182 const element * walker = NULL;
[042f82]183 int Z;
184 do {
[a67d19]185 DoLog(0) && (Log() << Verbose(0) << "Atomic number Z: ");
[042f82]186 cin >> Z;
187 walker = this->FindElement(Z); // give type
188 } while (walker == NULL);
189 return walker;
[6ac7ee]190};
191
[fb73b8]192/** Asks for element and if not found, presents mask to enter info.
193 * \return pointer to either present or newly created element
194 */
[e5c0a1]195const element * periodentafel::EnterElement()
[fb73b8]196{
[ead4e6]197 atomicNumber_t Z = 0;
[a67d19]198 DoLog(0) && (Log() << Verbose(0) << "Atomic number: " << Z << endl);
[fb73b8]199 cin >> Z;
[e5c0a1]200 const element *res = FindElement(Z);
[ead4e6]201 if (!res) {
202 // TODO: make this using the constructor
[a67d19]203 DoLog(0) && (Log() << Verbose(0) << "Element not found in database, please enter." << endl);
[4eb4fe]204 element *tmp = new element;
[ead4e6]205 tmp->Z = Z;
[a67d19]206 DoLog(0) && (Log() << Verbose(0) << "Mass: " << endl);
[ead4e6]207 cin >> tmp->mass;
[a67d19]208 DoLog(0) && (Log() << Verbose(0) << "Name [max 64 chars]: " << endl);
[bae8b0]209 cin >> tmp->name;
[a67d19]210 DoLog(0) && (Log() << Verbose(0) << "Short form [max 3 chars]: " << endl);
[bae8b0]211 cin >> tmp->symbol;
[ead4e6]212 AddElement(tmp);
[4eb4fe]213 return tmp;
[fb73b8]214 }
[ead4e6]215 return res;
[fb73b8]216};
217
[ead4e6]218
219/******************** Access to iterators ****************************/
[e5c0a1]220periodentafel::const_iterator periodentafel::begin() const{
[ead4e6]221 return elements.begin();
222}
223
[e5c0a1]224periodentafel::const_iterator periodentafel::end() const{
[ead4e6]225 return elements.end();
226}
227
[e5c0a1]228periodentafel::reverse_iterator periodentafel::rbegin() const{
[ead4e6]229 return reverse_iterator(elements.end());
230}
231
[e5c0a1]232periodentafel::reverse_iterator periodentafel::rend() const{
[ead4e6]233 return reverse_iterator(elements.begin());
234}
235
[6ac7ee]236/** Prints period table to given stream.
237 * \param output stream
238 */
[ead4e6]239bool periodentafel::Output(ostream * const output) const
[6ac7ee]240{
[042f82]241 bool result = true;
242 if (output != NULL) {
[ead4e6]243 for(const_iterator iter=elements.begin(); iter !=elements.end();++iter){
244 result = result && (*iter).second->Output(output);
[042f82]245 }
246 return result;
247 } else
248 return false;
[6ac7ee]249};
250
251/** Loads element list from file.
252 * \param *path to to standard file names
253 */
[989bf6]254bool periodentafel::LoadPeriodentafel(const char *path)
[6ac7ee]255{
[4eb4fe]256 ifstream input;
[042f82]257 bool status = true;
258 bool otherstatus = true;
259 char filename[255];
[6ac7ee]260
[042f82]261 // fill elements DB
262 strncpy(filename, path, MAXSTRINGSIZE);
263 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
264 strncat(filename, STANDARDELEMENTSDB, MAXSTRINGSIZE-strlen(filename));
[4eb4fe]265 input.open(filename);
[61745cc]266 if (!input.fail())
267 DoLog(0) && (Log() << Verbose(0) << "Using " << filename << " as elements database." << endl);
[e5c0a1]268 status = status && LoadElementsDatabase(input);
[61745cc]269 input.close();
270 input.clear();
[4eb4fe]271
[67c92b]272 // fill valence DB per element
273 strncpy(filename, path, MAXSTRINGSIZE);
274 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
275 strncat(filename, STANDARDELECTRONEGATIVITYDB, MAXSTRINGSIZE-strlen(filename));
276 input.open(filename);
277 if (!input.fail())
278 DoLog(0) && (Log() << Verbose(0) << "Using " << filename << " as electronegativity database." << endl);
279 otherstatus = otherstatus && LoadElectronegativityDatabase(input);
280 input.close();
281 input.clear();
282
[4eb4fe]283 // fill valence DB per element
284 strncpy(filename, path, MAXSTRINGSIZE);
285 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
286 strncat(filename, STANDARDVALENCEDB, MAXSTRINGSIZE-strlen(filename));
287 input.open(filename);
[61745cc]288 if (!input.fail())
289 DoLog(0) && (Log() << Verbose(0) << "Using " << filename << " as valence database." << endl);
[67c92b]290 otherstatus = otherstatus && LoadValenceDatabase(input);
[61745cc]291 input.close();
292 input.clear();
[4eb4fe]293
294 // fill orbitals DB per element
295 strncpy(filename, path, MAXSTRINGSIZE);
296 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
297 strncat(filename, STANDARDORBITALDB, MAXSTRINGSIZE-strlen(filename));
298 input.open(filename);
[61745cc]299 if (!input.fail())
300 DoLog(0) && (Log() << Verbose(0) << "Using " << filename << " as orbitals database." << endl);
[67c92b]301 otherstatus = otherstatus && LoadOrbitalsDatabase(input);
[61745cc]302 input.close();
303 input.clear();
[4eb4fe]304
305 // fill H-BondAngle DB per element
306 strncpy(filename, path, MAXSTRINGSIZE);
307 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
308 strncat(filename, STANDARDHBONDANGLEDB, MAXSTRINGSIZE-strlen(filename));
309 input.open(filename);
[61745cc]310 if (!input.fail())
311 DoLog(0) && (Log() << Verbose(0) << "Using " << filename << " as H bond angle database." << endl);
[67c92b]312 otherstatus = otherstatus && LoadHBondAngleDatabase(input);
[61745cc]313 input.close();
314 input.clear();
[4eb4fe]315
316 // fill H-BondDistance DB per element
317 strncpy(filename, path, MAXSTRINGSIZE);
318 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
319 strncat(filename, STANDARDHBONDDISTANCEDB, MAXSTRINGSIZE-strlen(filename));
320 input.open(filename);
[61745cc]321 if (!input.fail())
322 DoLog(0) && (Log() << Verbose(0) << "Using " << filename << " as H bond length database." << endl);
[67c92b]323 otherstatus = otherstatus && LoadHBondLengthsDatabase(input);
[61745cc]324 input.close();
325 input.clear();
[4eb4fe]326
327 if (!otherstatus){
328 DoeLog(2) && (eLog()<< Verbose(2) << "Something went wrong while parsing the other databases!" << endl);
329 }
330
331 return status;
332};
333
334/** load the element info.
335 * \param *input stream to parse from
336 * \return true - parsing successful, false - something went wrong
337 */
[e5c0a1]338bool periodentafel::LoadElementsDatabase(istream &input)
[4eb4fe]339{
[ff73a2]340 bool status = true;
[e5c0a1]341 string header1tmp,header2tmp;
342 // first parse into a map, so we can revert to old status in case something goes wront
343 map<atomicNumber_t,element*> parsedElements;
344 if (!input.fail()) {
345 getline(input,header1tmp);
346 getline(input,header2tmp); // skip first two header lines
[4e6d74]347 //cout << "First header: " << header1tmp << endl;
348 //cout << "Second header: " << header2tmp << endl;
[ad7270]349// DoLog(0) && (Log() << Verbose(0) << "Parsed elements:");
[e5c0a1]350 while (!input.eof()) {
[042f82]351 element *neues = new element;
[83f176]352 input >> neues->name;
[67c92b]353 //input >> ws;
[83f176]354 input >> neues->symbol;
[67c92b]355 //input >> ws;
[e5c0a1]356 input >> neues->period;
[67c92b]357 //input >> ws;
[e5c0a1]358 input >> neues->group;
[67c92b]359 //input >> ws;
[e5c0a1]360 input >> neues->block;
[67c92b]361 //input >> ws;
[e5c0a1]362 input >> neues->Z;
[67c92b]363 //input >> ws;
[e5c0a1]364 input >> neues->mass;
[67c92b]365 //input >> ws;
[e5c0a1]366 input >> neues->CovalentRadius;
[67c92b]367 //input >> ws;
[e5c0a1]368 input >> neues->VanDerWaalsRadius;
[67c92b]369 //input >> ws;
[e5c0a1]370 input >> ws;
[042f82]371 //neues->Output((ofstream *)&cout);
[61745cc]372 if ((neues->getNumber() > 0) && (neues->getNumber() < MAX_ELEMENTS)) {
[e5c0a1]373 parsedElements[neues->Z] = neues;
[ad7270]374// DoLog(0) && (Log() << Verbose(0) << " " << *neues);
[ff73a2]375 } else {
376 DoeLog(2) && (eLog() << Verbose(2) << "Detected empty line or invalid element in elements db, discarding." << endl);
377 DoLog(0) && (Log() << Verbose(0) << " <?>");
[db6bf74]378 delete(neues);
[042f82]379 }
[e5c0a1]380 // when the input is in failed state, we most likely just read garbage
381 if(input.fail()) {
382 DoeLog(2) && (eLog() << Verbose(2) << "Error parsing elements db." << endl);
383 status = false;
384 break;
385 }
[042f82]386 }
[ad7270]387// DoLog(0) && (Log() << Verbose(0) << endl);
[61745cc]388 } else {
389 DoeLog(1) && (eLog() << Verbose(1) << "Could not open the database." << endl);
[ff73a2]390 status = false;
[61745cc]391 }
[ff73a2]392
[e5c0a1]393 if (!parsedElements.size())
[ff73a2]394 status = false;
395
[e5c0a1]396 if(status){
397 for(map<atomicNumber_t,element*>::iterator iter=parsedElements.begin();
398 iter!=parsedElements.end();
399 ++iter){
400 if (elements.count(iter->first)) {
401 // if element already present, replace the old one
402 // pointer to old element might still be in use, so we have to replace into the old element
403 *(elements[iter->first])=*iter->second;
[9f99b3]404 delete(iter->second);
[e5c0a1]405 }
406 else {
407 // no such element in periodentafel... we can just insert
408 elements[iter->first] = iter->second;
409 }
410 }
411 // all went well.. we now copy the header
412 strncpy(header1,header1tmp.c_str(),MAXSTRINGSIZE);
413 header1[MAXSTRINGSIZE-1]=0;
414 strncpy(header2,header2tmp.c_str(),MAXSTRINGSIZE);
415 header2[MAXSTRINGSIZE-1]=0;
416 }
417
[ff73a2]418 return status;
[4eb4fe]419}
[6ac7ee]420
[67c92b]421/** load the electronegativity info.
422 * \param *input stream to parse from
423 * \return true - parsing successful, false - something went wrong
424 */
425bool periodentafel::LoadElectronegativityDatabase(std::istream &input)
426{
427 char dummy[MAXSTRINGSIZE];
428 if (!input.fail()) {
429 input.getline(dummy, MAXSTRINGSIZE);
430 while (!input.eof()) {
431 atomicNumber_t Z;
432 input >> Z;
433 ASSERT(elements.count(Z), "Element not present");
434 input >> ws;
435 input >> elements[Z]->Electronegativity;
436 input >> ws;
[febef3]437 //DoLog(1) && (Log() << Verbose(1)
438 // << "Element " << Z << " has " << FindElement(Z)->Electronegativity << " valence electrons." << endl);
[67c92b]439 }
440 return true;
441 } else
442 return false;
443}
444
[4eb4fe]445/** load the valence info.
446 * \param *input stream to parse from
447 * \return true - parsing successful, false - something went wrong
448 */
[67c92b]449bool periodentafel::LoadValenceDatabase(istream &input)
[4eb4fe]450{
451 char dummy[MAXSTRINGSIZE];
[67c92b]452 if (!input.fail()) {
453 input.getline(dummy, MAXSTRINGSIZE);
454 while (!input.eof()) {
[ead4e6]455 atomicNumber_t Z;
[67c92b]456 input >> Z;
[4eb4fe]457 ASSERT(elements.count(Z), "Element not present");
[67c92b]458 input >> ws;
459 input >> elements[Z]->Valence;
460 input >> ws;
[274d45]461 //Log() << Verbose(3) << "Element " << Z << " has " << FindElement(Z)->Valence << " valence electrons." << endl;
[042f82]462 }
[4eb4fe]463 return true;
[042f82]464 } else
[4eb4fe]465 return false;
466}
[6ac7ee]467
[4eb4fe]468/** load the orbitals info.
469 * \param *input stream to parse from
470 * \return true - parsing successful, false - something went wrong
471 */
[67c92b]472bool periodentafel::LoadOrbitalsDatabase(istream &input)
[4eb4fe]473{
474 char dummy[MAXSTRINGSIZE];
[67c92b]475 if (!input.fail()) {
476 input.getline(dummy, MAXSTRINGSIZE);
477 while (!input.eof()) {
[ead4e6]478 atomicNumber_t Z;
[67c92b]479 input >> Z;
[4eb4fe]480 ASSERT(elements.count(Z), "Element not present");
[67c92b]481 input >> ws;
482 input >> elements[Z]->NoValenceOrbitals;
483 input >> ws;
[274d45]484 //Log() << Verbose(3) << "Element " << Z << " has " << FindElement(Z)->NoValenceOrbitals << " number of singly occupied valence orbitals." << endl;
[042f82]485 }
[4eb4fe]486 return true;
[042f82]487 } else
[4eb4fe]488 return false;
489}
[6ac7ee]490
[4eb4fe]491/** load the hbond angles info.
492 * \param *input stream to parse from
493 * \return true - parsing successful, false - something went wrong
494 */
[67c92b]495bool periodentafel::LoadHBondAngleDatabase(istream &input)
[4eb4fe]496{
497 char dummy[MAXSTRINGSIZE];
[67c92b]498 if (!input.fail()) {
499 input.getline(dummy, MAXSTRINGSIZE);
500 while (!input.eof()) {
[ead4e6]501 atomicNumber_t Z;
[67c92b]502 input >> Z;
[4eb4fe]503 ASSERT(elements.count(Z), "Element not present");
[67c92b]504 input >> ws;
505 input >> elements[Z]->HBondAngle[0];
506 input >> elements[Z]->HBondAngle[1];
507 input >> elements[Z]->HBondAngle[2];
508 input >> ws;
[4eb4fe]509 //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]510 }
[4eb4fe]511 return true;
[042f82]512 } else
[4eb4fe]513 return false;
514}
[6ac7ee]515
[4eb4fe]516/** load the hbond lengths info.
517 * \param *input stream to parse from
518 * \return true - parsing successful, false - something went wrong
519 */
[67c92b]520bool periodentafel::LoadHBondLengthsDatabase(istream &input)
[4eb4fe]521{
522 char dummy[MAXSTRINGSIZE];
[67c92b]523 if (!input.fail()) {
524 input.getline(dummy, MAXSTRINGSIZE);
525 while (!input.eof()) {
[ead4e6]526 atomicNumber_t Z;
[67c92b]527 input >> Z;
[4eb4fe]528 ASSERT(elements.count(Z), "Element not present");
[67c92b]529 input >> ws;
530 input >> elements[Z]->HBondDistance[0];
531 input >> elements[Z]->HBondDistance[1];
532 input >> elements[Z]->HBondDistance[2];
533 input >> ws;
[4eb4fe]534 //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->HBondDistance[0] << " Angstrom typical distance to hydrogen." << endl;
[042f82]535 }
[4eb4fe]536 return true;
[042f82]537 } else
[4eb4fe]538 return false;
539}
[6ac7ee]540
[064178]541/** load the color info.
542 * \param *input stream to parse from
543 * \return true - parsing successful, false - something went wrong
544 */
545bool periodentafel::LoadColorDatabase(istream &input)
546{
547 char dummy[MAXSTRINGSIZE];
548 if (!input.fail()) {
549 input.getline(dummy, MAXSTRINGSIZE);
550 while (!input.eof()) {
551 atomicNumber_t Z;
552 input >> Z;
553 ASSERT(elements.count(Z), "Element not present");
554 input >> ws;
555 input >> dummy;
556 {
557 int tmpcolor; // char here will only parse a single char (i.e. only "2" out of "255")
558 for (int i=0;i<3;++i) {
559 input >> ws;
560 input >> tmpcolor;
561 elements[Z]->color[i] = (unsigned char)tmpcolor;
562 }
563 }
564 input >> ws;
[907636]565// {
566// const element * tmp = FindElement(Z);
567// LOG(0, "Element " << tmp->getName() << " has ("
[064178]568// << (int)tmp->color[0] << "," << (int)tmp->color[1] << "," << (int)tmp->color[2]
[907636]569// << ") colors.");
570// }
[064178]571 }
572 return true;
573 } else
574 return false;
575}
576
[6ac7ee]577/** Stores element list to file.
578 */
[989bf6]579bool periodentafel::StorePeriodentafel(const char *path) const
[6ac7ee]580{
[042f82]581 bool result = true;
582 ofstream f;
583 char filename[MAXSTRINGSIZE];
[6ac7ee]584
[042f82]585 strncpy(filename, path, MAXSTRINGSIZE);
586 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
587 strncat(filename, STANDARDELEMENTSDB, MAXSTRINGSIZE-strlen(filename));
588 f.open(filename);
589 if (f != NULL) {
590 f << header1 << endl;
591 f << header2 << endl;
[ead4e6]592 for(const_iterator iter=elements.begin();iter!=elements.end();++iter){
593 result = result && (*iter).second->Output(&f);
[042f82]594 }
595 f.close();
[4eb4fe]596 return true;
[042f82]597 } else
[4eb4fe]598 return result;
[6ac7ee]599};
[b60804]600
601/** Comparison operator for periodentafel.
602 *
603 * @param other other instance to compare to
604 * @return true when both contain same elements
605 */
606bool periodentafel::operator==(const periodentafel &other) const
607{
608 // there are only pointers in the elementSet, hence we have to compare ourselves
609 if (elements.size() != other.elements.size()) return false;
610 const_iterator iter = elements.begin();
611 const_iterator otheriter = other.elements.begin();
612 for (;(iter != elements.end()) && (otheriter != other.elements.end());
613 ++iter, ++otheriter) {
614 bool status = true;
615 status = status && (iter->first == otheriter->first);
616 status = status && (*(iter->second) == *(otheriter->second));
617 if (!status) {
618 std::cout << *(iter->second) << " not equal to " << *(otheriter->second) << "." << std::endl;
619 return false;
620 }
621// else
622// std::cout << (iter->second)->getName() << " are equal to " << (otheriter->second)->getName() << "." << std::endl;
623 }
624 if (strncmp(header1, other.header1, MAXSTRINGSIZE) != 0) return false;
625 if (strncmp(header2, other.header2, MAXSTRINGSIZE) != 0) return false;
626 return true;
627}
Note: See TracBrowser for help on using the repository browser.