source: src/periodentafel.cpp@ c6efc1

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 c6efc1 was 5f612ee, checked in by Frederik Heber <heber@…>, 15 years ago

Merge branch 'Analysis_PairCorrelation' into StructureRefactoring

Conflicts:

molecuilder/src/Makefile.am
molecuilder/src/World.cpp
molecuilder/src/World.hpp
molecuilder/src/boundary.cpp
molecuilder/src/builder.cpp
molecuilder/src/log.cpp
molecuilder/src/moleculelist.cpp
molecuilder/src/periodentafel.cpp
molecuilder/src/tesselation.cpp
molecuilder/src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
molecuilder/src/unittests/Makefile.am
molecuilder/src/unittests/bondgraphunittest.cpp
molecuilder/src/unittests/gslvectorunittest.cpp
molecuilder/src/unittests/logunittest.cpp
molecuilder/src/unittests/tesselation_boundarytriangleunittest.hpp
molecuilder/src/vector.cpp
molecuilder/tests/Tesselations/defs.in

Conflicts have been many and too numerous to listen here, just the few general cases

  • new molecule() replaced by World::getInstance().createMolecule()
  • new atom() replaced by World::getInstance().createAtom() where appropriate.
  • Some DoLog()s added interfered with changes to the message produced by Log() << Verbose(.) << ...
  • DoLog() has been erroneously added to TestRunner.cpp as well, there cout is appropriate
  • ...

Additionally, there was a bug in atom::clone(), sort was set to atom::nr of the atom to clone not of the clone itself. This caused a failure of the fragmentation.

This merge has been fully checked from a clean build directory with subsequent configure,make all install and make check.
It configures, compiles and runs all test cases and the test suite without errors.

Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100755
File size: 11.1 KB
RevLine 
[6ac7ee]1/** \file periodentafel.cpp
2 *
3 * Function implementations for the class periodentafel.
4 *
5 */
6
7using namespace std;
8
[cd4ccc]9#include <iomanip>
10#include <fstream>
[49e1ae]11#include <cstring>
[ead4e6]12#include <cassert>
[cd4ccc]13
[f66195]14#include "element.hpp"
[cd4ccc]15#include "helpers.hpp"
[f66195]16#include "lists.hpp"
[e138de]17#include "log.hpp"
[6ac7ee]18#include "periodentafel.hpp"
[cd4ccc]19#include "verbose.hpp"
[6ac7ee]20
[ead4e6]21using namespace std;
22
[6ac7ee]23/************************************* Functions for class periodentafel ***************************/
24
25/** constructor for class periodentafel
26 * Initialises start and end of list and resets periodentafel::checkliste to false.
27 */
[ead4e6]28periodentafel::periodentafel()
29{};
[6ac7ee]30
31/** destructor for class periodentafel
32 * Removes every element and afterwards deletes start and end of list.
33 */
34periodentafel::~periodentafel()
35{
[042f82]36 CleanupPeriodtable();
[6ac7ee]37};
38
39/** Adds element to period table list
40 * \param *pointer element to be added
41 * \return true - succeeded, false - does not occur
42 */
[ead4e6]43periodentafel::iterator periodentafel::AddElement(element * const pointer)
[6ac7ee]44{
[ead4e6]45 atomicNumber_t Z = pointer->getNumber();
46 assert(!elements.count(Z));
[042f82]47 pointer->sort = &pointer->Z;
[ead4e6]48 if (pointer->getNumber() < 1 && pointer->getNumber() >= MAX_ELEMENTS)
[5f612ee]49 DoeLog(0) && (eLog() << Verbose(0) << "Invalid Z number!\n");
[ead4e6]50 pair<iterator,bool> res = elements.insert(pair<atomicNumber_t,element*>(Z,pointer));
51 return res.first;
[6ac7ee]52};
53
54/** Removes element from list.
55 * \param *pointer element to be removed
56 * \return true - succeeded, false - element not found
57 */
[ead4e6]58void periodentafel::RemoveElement(element * const pointer)
[6ac7ee]59{
[ead4e6]60 atomicNumber_t Z = pointer->getNumber();
61 elements.erase(Z);
[6ac7ee]62};
63
64/** Removes every element from the period table.
65 * \return true - succeeded, false - does not occur
66 */
[ead4e6]67void periodentafel::CleanupPeriodtable()
[6ac7ee]68{
[745a85]69 for(iterator iter=elements.begin();iter!=elements.end();++iter){
70 delete(*iter).second;
71 }
[ead4e6]72 elements.clear();
[6ac7ee]73};
74
75/** Finds an element by its atomic number.
[fb73b8]76 * If element is not yet in list, returns NULL.
[6ac7ee]77 * \param Z atomic number
[fb73b8]78 * \return pointer to element or NULL if not found
[6ac7ee]79 */
[ead4e6]80const element * periodentafel::FindElement(atomicNumber_t Z) const
[6ac7ee]81{
[ead4e6]82 const_iterator res = elements.find(Z);
83 return res!=elements.end()?((*res).second):0;
[6ac7ee]84};
85
86/** Finds an element by its atomic number.
87 * If element is not yet in list, datas are asked and stored in database.
88 * \param shorthand chemical symbol of the element, e.g. H for hydrogene
89 * \return pointer to element
90 */
[ead4e6]91const element * periodentafel::FindElement(const char * const shorthand) const
[6ac7ee]92{
[ead4e6]93 element *res = 0;
94 for(const_iterator iter=elements.begin();iter!=elements.end();++iter) {
95 if((*iter).second->getSymbol() == shorthand){
96 res = (*iter).second;
97 break;
98 }
[042f82]99 }
[ead4e6]100 return res;
[6ac7ee]101};
102
103/** Asks for element number and returns pointer to element
104 */
[ead4e6]105const element * periodentafel::AskElement() const
[6ac7ee]106{
[ead4e6]107 const element *walker = NULL;
[042f82]108 int Z;
109 do {
[a67d19]110 DoLog(0) && (Log() << Verbose(0) << "Atomic number Z: ");
[042f82]111 cin >> Z;
112 walker = this->FindElement(Z); // give type
113 } while (walker == NULL);
114 return walker;
[6ac7ee]115};
116
[fb73b8]117/** Asks for element and if not found, presents mask to enter info.
118 * \return pointer to either present or newly created element
119 */
[ead4e6]120const element * periodentafel::EnterElement()
[fb73b8]121{
[ead4e6]122 const element *res = NULL;
123 atomicNumber_t Z = 0;
[a67d19]124 DoLog(0) && (Log() << Verbose(0) << "Atomic number: " << Z << endl);
[fb73b8]125 cin >> Z;
[ead4e6]126 res = FindElement(Z);
127 if (!res) {
128 // TODO: make this using the constructor
129 element *tmp;
[a67d19]130 DoLog(0) && (Log() << Verbose(0) << "Element not found in database, please enter." << endl);
[ead4e6]131 tmp = new element;
132 tmp->Z = Z;
[a67d19]133 DoLog(0) && (Log() << Verbose(0) << "Mass: " << endl);
[ead4e6]134 cin >> tmp->mass;
[a67d19]135 DoLog(0) && (Log() << Verbose(0) << "Name [max 64 chars]: " << endl);
[ead4e6]136 cin >> tmp->name;
[a67d19]137 DoLog(0) && (Log() << Verbose(0) << "Short form [max 3 chars]: " << endl);
[ead4e6]138 cin >> tmp->symbol;
139 AddElement(tmp);
140 res = tmp;
[fb73b8]141 }
[ead4e6]142 return res;
[fb73b8]143};
144
[ead4e6]145
146/******************** Access to iterators ****************************/
147periodentafel::const_iterator periodentafel::begin(){
148 return elements.begin();
149}
150
151periodentafel::const_iterator periodentafel::end(){
152 return elements.end();
153}
154
155periodentafel::reverse_iterator periodentafel::rbegin(){
156 return reverse_iterator(elements.end());
157}
158
159periodentafel::reverse_iterator periodentafel::rend(){
160 return reverse_iterator(elements.begin());
161}
162
[6ac7ee]163/** Prints period table to given stream.
164 * \param output stream
165 */
[ead4e6]166bool periodentafel::Output(ostream * const output) const
[6ac7ee]167{
[042f82]168 bool result = true;
169 if (output != NULL) {
[ead4e6]170 for(const_iterator iter=elements.begin(); iter !=elements.end();++iter){
171 result = result && (*iter).second->Output(output);
[042f82]172 }
173 return result;
174 } else
175 return false;
[6ac7ee]176};
177
178/** Prints period table to given stream.
179 * \param *output output stream
180 * \param *checkliste elements table for this molecule
181 */
[ead4e6]182bool periodentafel::Checkout(ostream * const output, const int * const checkliste) const
[6ac7ee]183{
[042f82]184 bool result = true;
185 int No = 1;
[6ac7ee]186
[042f82]187 if (output != NULL) {
188 *output << "# Ion type data (PP = PseudoPotential, Z = atomic number)" << endl;
189 *output << "#Ion_TypeNr.\tAmount\tZ\tRGauss\tL_Max(PP)L_Loc(PP)IonMass\t# chemical name, symbol" << endl;
[ead4e6]190 for(const_iterator iter=elements.begin(); iter!=elements.end();++iter){
191 if (((*iter).first < MAX_ELEMENTS) && (checkliste[(*iter).first])) {
192 (*iter).second->No = No;
193 result = result && (*iter).second->Checkout(output, No++, checkliste[(*iter).first]);
[042f82]194 }
195 }
196 return result;
197 } else
198 return false;
[6ac7ee]199};
200
201/** Loads element list from file.
202 * \param *path to to standard file names
203 */
[989bf6]204bool periodentafel::LoadPeriodentafel(const char *path)
[6ac7ee]205{
[042f82]206 ifstream infile;
207 element *ptr;
[ead4e6]208 map<atomicNumber_t,element*> parsedElems;
[042f82]209 bool status = true;
210 bool otherstatus = true;
211 char filename[255];
[6ac7ee]212
[042f82]213 // fill elements DB
214 strncpy(filename, path, MAXSTRINGSIZE);
215 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
216 strncat(filename, STANDARDELEMENTSDB, MAXSTRINGSIZE-strlen(filename));
217 infile.open(filename);
218 if (infile != NULL) {
219 infile.getline(header1, MAXSTRINGSIZE);
220 infile.getline(header2, MAXSTRINGSIZE); // skip first two header lines
[a67d19]221 DoLog(0) && (Log() << Verbose(0) << "Parsed elements:");
[042f82]222 while (!infile.eof()) {
223 element *neues = new element;
224 infile >> neues->name;
225 //infile >> ws;
226 infile >> neues->symbol;
227 //infile >> ws;
228 infile >> neues->period;
229 //infile >> ws;
230 infile >> neues->group;
231 //infile >> ws;
232 infile >> neues->block;
233 //infile >> ws;
234 infile >> neues->Z;
235 //infile >> ws;
236 infile >> neues->mass;
237 //infile >> ws;
238 infile >> neues->CovalentRadius;
239 //infile >> ws;
240 infile >> neues->VanDerWaalsRadius;
241 //infile >> ws;
242 infile >> ws;
[a67d19]243 DoLog(0) && (Log() << Verbose(0) << " " << neues->symbol);
[042f82]244 //neues->Output((ofstream *)&cout);
245 if ((neues->Z > 0) && (neues->Z < MAX_ELEMENTS))
[ead4e6]246 parsedElems[neues->getNumber()] = neues;
[042f82]247 else {
[a67d19]248 DoLog(0) && (Log() << Verbose(0) << "Could not parse element: ");
[042f82]249 neues->Output((ofstream *)&cout);
[db6bf74]250 delete(neues);
[042f82]251 }
252 }
[a67d19]253 DoLog(0) && (Log() << Verbose(0) << endl);
[042f82]254 infile.close();
255 infile.clear();
256 } else
257 status = false;
[6ac7ee]258
[042f82]259 // fill valence DB per element
260 strncpy(filename, path, MAXSTRINGSIZE);
261 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
262 strncat(filename, STANDARDVALENCEDB, MAXSTRINGSIZE-strlen(filename));
263 infile.open(filename);
264 if (infile != NULL) {
265 while (!infile.eof()) {
[ead4e6]266 atomicNumber_t Z;
267 infile >> Z;
[042f82]268 infile >> ws;
[ead4e6]269 infile >> parsedElems[Z]->Valence;
[042f82]270 infile >> ws;
[e138de]271 //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->Valence << " valence electrons." << endl;
[042f82]272 }
273 infile.close();
274 infile.clear();
275 } else
276 otherstatus = false;
[6ac7ee]277
[042f82]278 // fill valence DB per element
279 strncpy(filename, path, MAXSTRINGSIZE);
280 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
281 strncat(filename, STANDARDORBITALDB, MAXSTRINGSIZE-strlen(filename));
282 infile.open(filename);
283 if (infile != NULL) {
284 while (!infile.eof()) {
[ead4e6]285 atomicNumber_t Z;
286 infile >> Z;
[042f82]287 infile >> ws;
[ead4e6]288 infile >> parsedElems[Z]->NoValenceOrbitals;
[042f82]289 infile >> ws;
[e138de]290 //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->NoValenceOrbitals << " number of singly occupied valence orbitals." << endl;
[042f82]291 }
292 infile.close();
293 infile.clear();
294 } else
295 otherstatus = false;
[6ac7ee]296
[042f82]297 // fill H-BondDistance DB per element
298 strncpy(filename, path, MAXSTRINGSIZE);
299 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
300 strncat(filename, STANDARDHBONDDISTANCEDB, MAXSTRINGSIZE-strlen(filename));
301 infile.open(filename);
302 if (infile != NULL) {
303 while (!infile.eof()) {
[ead4e6]304 atomicNumber_t Z;
305 infile >> Z;
306 ptr = parsedElems[Z];
[042f82]307 infile >> ws;
308 infile >> ptr->HBondDistance[0];
309 infile >> ptr->HBondDistance[1];
310 infile >> ptr->HBondDistance[2];
311 infile >> ws;
[e138de]312 //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->HBondDistance[0] << " Angstrom typical distance to hydrogen." << endl;
[042f82]313 }
314 infile.close();
315 infile.clear();
316 } else
317 otherstatus = false;
[6ac7ee]318
[042f82]319 // fill H-BondAngle DB per element
320 strncpy(filename, path, MAXSTRINGSIZE);
321 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
322 strncat(filename, STANDARDHBONDANGLEDB, MAXSTRINGSIZE-strlen(filename));
323 infile.open(filename);
324 if (infile != NULL) {
325 while (!infile.eof()) {
[ead4e6]326 atomicNumber_t Z;
327 infile >> Z;
328 ptr = parsedElems[Z];
[042f82]329 infile >> ws;
330 infile >> ptr->HBondAngle[0];
331 infile >> ptr->HBondAngle[1];
332 infile >> ptr->HBondAngle[2];
333 infile >> ws;
[e138de]334 //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]335 }
336 infile.close();
337 } else
338 otherstatus = false;
[6ac7ee]339
[ead4e6]340 if (otherstatus){
341 map<atomicNumber_t,element*>::iterator iter;
342 for(iter=parsedElems.begin();iter!=parsedElems.end();++iter){
343 AddElement((*iter).second);
344 }
345 }
346 else{
[58ed4a]347 DoeLog(2) && (eLog()<< Verbose(2) << "Something went wrong while parsing the other databases!" << endl);
[745a85]348 map<atomicNumber_t,element*>::iterator iter;
349 for(iter=parsedElems.begin();iter!=parsedElems.end();++iter){
350 AddElement((*iter).second);
351 }
[ead4e6]352 }
[6ac7ee]353
[042f82]354 return status;
[6ac7ee]355};
356
357/** Stores element list to file.
358 */
[989bf6]359bool periodentafel::StorePeriodentafel(const char *path) const
[6ac7ee]360{
[042f82]361 bool result = true;
362 ofstream f;
363 char filename[MAXSTRINGSIZE];
[6ac7ee]364
[042f82]365 strncpy(filename, path, MAXSTRINGSIZE);
366 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
367 strncat(filename, STANDARDELEMENTSDB, MAXSTRINGSIZE-strlen(filename));
368 f.open(filename);
369 if (f != NULL) {
370 f << header1 << endl;
371 f << header2 << endl;
[ead4e6]372 for(const_iterator iter=elements.begin();iter!=elements.end();++iter){
373 result = result && (*iter).second->Output(&f);
[042f82]374 }
375 f.close();
376 } else
377 result = false;
378 return result;
[6ac7ee]379};
Note: See TracBrowser for help on using the repository browser.