source: src/periodentafel.cpp@ ead4e6

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 Candidate_v1.7.0 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 ead4e6 was ead4e6, checked in by Tillmann Crueger <crueger@…>, 16 years ago

Made the periodentafel use STL-containers instead of custom llists

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