source: src/periodentafel.cpp@ d4fa23

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

definitions for class element and verbose moved to their own header files and reducing contents of helpers.hpp

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