source: src/periodentafel.cpp@ 390248

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 390248 was 82cd9f, checked in by Frederik Heber <heber@…>, 16 years ago

BUGFIX: elements.db is now using path instead of file

elements database was not correctly stored, as a filename was still given in Load/StorePeriodentafel instead of the path. This is corrected.

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