source: src/Element/periodentafel.cpp@ 105b72

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 105b72 was 94d5ac6, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

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