source: src/periodentafel.cpp@ d2a294

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 d2a294 was c750cc, checked in by Frederik Heber <heber@…>, 17 years ago

char lengths of 255 and MAXDUMMYSTRING replaced with define MAXSTRINGSIZE in molecuilder and pcp

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