source: src/periodentafel.cpp@ 93d120

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 93d120 was f66195, checked in by Frederik Heber <heber@…>, 16 years ago

forward declarations used to untangle interdependet classes.

  • basically, everywhere in header files we removed '#include' lines were only pointer to the respective classes were used and the include line was moved to the implementation file.
  • as a sidenote, lots of funny errors happened because headers were included via a nesting over three other includes. Now, all should be declared directly as needed, as only very little include lines remain in header files.
  • Property mode set to 100755
File size: 9.5 KB
Line 
1/** \file periodentafel.cpp
2 *
3 * Function implementations for the class periodentafel.
4 *
5 */
6
7using namespace std;
8
9#include <iomanip>
10#include <fstream>
11
12#include "element.hpp"
13#include "helpers.hpp"
14#include "lists.hpp"
15#include "periodentafel.hpp"
16#include "verbose.hpp"
17
18/************************************* Functions for class periodentafel ***************************/
19
20/** constructor for class periodentafel
21 * Initialises start and end of list and resets periodentafel::checkliste to false.
22 */
23periodentafel::periodentafel()
24{
25 start = new element;
26 end = new element;
27 start->previous = NULL;
28 start->next = end;
29 end->previous = start;
30 end->next = NULL;
31};
32
33/** destructor for class periodentafel
34 * Removes every element and afterwards deletes start and end of list.
35 */
36periodentafel::~periodentafel()
37{
38 CleanupPeriodtable();
39 delete(end);
40 delete(start);
41};
42
43/** Adds element to period table list
44 * \param *pointer element to be added
45 * \return true - succeeded, false - does not occur
46 */
47bool periodentafel::AddElement(element *pointer)
48{
49 pointer->sort = &pointer->Z;
50 if (pointer->Z < 1 && pointer->Z >= MAX_ELEMENTS)
51 cout << Verbose(0) << "Invalid Z number!\n";
52 return add(pointer, end);
53};
54
55/** Removes element from list.
56 * \param *pointer element to be removed
57 * \return true - succeeded, false - element not found
58 */
59bool periodentafel::RemoveElement(element *pointer)
60{
61 return remove(pointer, start, end);
62};
63
64/** Removes every element from the period table.
65 * \return true - succeeded, false - does not occur
66 */
67bool periodentafel::CleanupPeriodtable()
68{
69 return cleanup(start,end);
70};
71
72/** Finds an element by its atomic number.
73 * If element is not yet in list, datas are asked and stored in database.
74 * \param Z atomic number
75 * \return pointer to element
76 */
77element * periodentafel::FindElement(int Z)
78{
79 element *walker = find(&Z, start,end);
80 if (walker == NULL) { // not found: enter and put into db
81 cout << Verbose(0) << "Element not found in database, please enter." << endl;
82 walker = new element;
83 cout << Verbose(0) << "Mass: " << endl;
84 cin >> walker->mass;
85 walker->Z = Z;
86 cout << Verbose(0) << "Atomic number: " << walker->Z << endl;
87 cout << Verbose(0) << "Name [max 64 chars]: " << endl;
88 cin >> walker->name;
89 cout << Verbose(0) << "Short form [max 3 chars]: " << endl;
90 cin >> walker->symbol;
91 periodentafel::AddElement(walker);
92 }
93 return(walker);
94};
95
96/** Finds an element by its atomic number.
97 * If element is not yet in list, datas are asked and stored in database.
98 * \param shorthand chemical symbol of the element, e.g. H for hydrogene
99 * \return pointer to element
100 */
101element * periodentafel::FindElement(const char *shorthand) const
102{
103 element *walker = periodentafel::start;
104 while (walker->next != periodentafel::end) {
105 walker = walker->next;
106 if (strncmp(walker->symbol, shorthand, 3) == 0)
107 return(walker);
108 }
109 return (NULL);
110};
111
112/** Asks for element number and returns pointer to element
113 */
114element * periodentafel::AskElement()
115{
116 element *walker = NULL;
117 int Z;
118 do {
119 cout << Verbose(0) << "Atomic number Z: ";
120 cin >> Z;
121 walker = this->FindElement(Z); // give type
122 } while (walker == NULL);
123 return walker;
124};
125
126/** Prints period table to given stream.
127 * \param output stream
128 */
129bool periodentafel::Output(ofstream *output) const
130{
131 bool result = true;
132 element *walker = start;
133 if (output != NULL) {
134 while (walker->next != end) {
135 walker = walker->next;
136 result = result && walker->Output(output);
137 }
138 return result;
139 } else
140 return false;
141};
142
143/** Prints period table to given stream.
144 * \param *output output stream
145 * \param *checkliste elements table for this molecule
146 */
147bool periodentafel::Checkout(ofstream *output, const int *checkliste) const
148{
149 element *walker = start;
150 bool result = true;
151 int No = 1;
152
153 if (output != NULL) {
154 *output << "# Ion type data (PP = PseudoPotential, Z = atomic number)" << endl;
155 *output << "#Ion_TypeNr.\tAmount\tZ\tRGauss\tL_Max(PP)L_Loc(PP)IonMass\t# chemical name, symbol" << endl;
156 while (walker->next != end) {
157 walker = walker->next;
158 if ((walker != NULL) && (walker->Z > 0) && (walker->Z < MAX_ELEMENTS) && (checkliste[walker->Z])) {
159 walker->No = No;
160 result = result && walker->Checkout(output, No++, checkliste[walker->Z]);
161 }
162 }
163 return result;
164 } else
165 return false;
166};
167
168/** Loads element list from file.
169 * \param *path to to standard file names
170 */
171bool periodentafel::LoadPeriodentafel(const char *path)
172{
173 ifstream infile;
174 double tmp;
175 element *ptr;
176 bool status = true;
177 bool otherstatus = true;
178 char filename[255];
179
180 // fill elements DB
181 strncpy(filename, path, MAXSTRINGSIZE);
182 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
183 strncat(filename, STANDARDELEMENTSDB, MAXSTRINGSIZE-strlen(filename));
184 infile.open(filename);
185 if (infile != NULL) {
186 infile.getline(header1, MAXSTRINGSIZE);
187 infile.getline(header2, MAXSTRINGSIZE); // skip first two header lines
188 cout << "Parsed elements:";
189 while (!infile.eof()) {
190 element *neues = new element;
191 infile >> neues->name;
192 //infile >> ws;
193 infile >> neues->symbol;
194 //infile >> ws;
195 infile >> neues->period;
196 //infile >> ws;
197 infile >> neues->group;
198 //infile >> ws;
199 infile >> neues->block;
200 //infile >> ws;
201 infile >> neues->Z;
202 //infile >> ws;
203 infile >> neues->mass;
204 //infile >> ws;
205 infile >> neues->CovalentRadius;
206 //infile >> ws;
207 infile >> neues->VanDerWaalsRadius;
208 //infile >> ws;
209 infile >> ws;
210 cout << " " << neues->symbol;
211 //neues->Output((ofstream *)&cout);
212 if ((neues->Z > 0) && (neues->Z < MAX_ELEMENTS))
213 periodentafel::AddElement(neues);
214 else {
215 cout << "Could not parse element: ";
216 neues->Output((ofstream *)&cout);
217 }
218 }
219 cout << endl;
220 infile.close();
221 infile.clear();
222 } else
223 status = false;
224
225 // fill valence DB per element
226 strncpy(filename, path, MAXSTRINGSIZE);
227 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
228 strncat(filename, STANDARDVALENCEDB, MAXSTRINGSIZE-strlen(filename));
229 infile.open(filename);
230 if (infile != NULL) {
231 while (!infile.eof()) {
232 infile >> tmp;
233 infile >> ws;
234 infile >> FindElement((int)tmp)->Valence;
235 infile >> ws;
236 //cout << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->Valence << " valence electrons." << endl;
237 }
238 infile.close();
239 infile.clear();
240 } else
241 otherstatus = false;
242
243 // fill valence DB per element
244 strncpy(filename, path, MAXSTRINGSIZE);
245 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
246 strncat(filename, STANDARDORBITALDB, MAXSTRINGSIZE-strlen(filename));
247 infile.open(filename);
248 if (infile != NULL) {
249 while (!infile.eof()) {
250 infile >> tmp;
251 infile >> ws;
252 infile >> FindElement((int)tmp)->NoValenceOrbitals;
253 infile >> ws;
254 //cout << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->NoValenceOrbitals << " number of singly occupied valence orbitals." << endl;
255 }
256 infile.close();
257 infile.clear();
258 } else
259 otherstatus = false;
260
261 // fill H-BondDistance DB per element
262 strncpy(filename, path, MAXSTRINGSIZE);
263 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
264 strncat(filename, STANDARDHBONDDISTANCEDB, MAXSTRINGSIZE-strlen(filename));
265 infile.open(filename);
266 if (infile != NULL) {
267 while (!infile.eof()) {
268 infile >> tmp;
269 ptr = FindElement((int)tmp);
270 infile >> ws;
271 infile >> ptr->HBondDistance[0];
272 infile >> ptr->HBondDistance[1];
273 infile >> ptr->HBondDistance[2];
274 infile >> ws;
275 //cout << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->HBondDistance[0] << " Angstrom typical distance to hydrogen." << endl;
276 }
277 infile.close();
278 infile.clear();
279 } else
280 otherstatus = false;
281
282 // fill H-BondAngle DB per element
283 strncpy(filename, path, MAXSTRINGSIZE);
284 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
285 strncat(filename, STANDARDHBONDANGLEDB, MAXSTRINGSIZE-strlen(filename));
286 infile.open(filename);
287 if (infile != NULL) {
288 while (!infile.eof()) {
289 infile >> tmp;
290 ptr = FindElement((int)tmp);
291 infile >> ws;
292 infile >> ptr->HBondAngle[0];
293 infile >> ptr->HBondAngle[1];
294 infile >> ptr->HBondAngle[2];
295 infile >> ws;
296 //cout << 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;
297 }
298 infile.close();
299 } else
300 otherstatus = false;
301
302 if (!otherstatus)
303 cerr << "WARNING: Something went wrong while parsing the other databases!" << endl;
304
305 return status;
306};
307
308/** Stores element list to file.
309 */
310bool periodentafel::StorePeriodentafel(const char *path) const
311{
312 bool result = true;
313 ofstream f;
314 char filename[MAXSTRINGSIZE];
315
316 strncpy(filename, path, MAXSTRINGSIZE);
317 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename));
318 strncat(filename, STANDARDELEMENTSDB, MAXSTRINGSIZE-strlen(filename));
319 f.open(filename);
320 if (f != NULL) {
321 f << header1 << endl;
322 f << header2 << endl;
323 element *walker = periodentafel::start;
324 while (walker->next != periodentafel::end) {
325 walker = walker->next;
326 result = result && walker->Output(&f);
327 }
328 f.close();
329 } else
330 result = false;
331 return result;
332};
Note: See TracBrowser for help on using the repository browser.