source: src/periodentafel.cpp@ e5ad5c

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

Huge change from ofstream * (const) out --> Log().

  • first shift was done via regular expressions
  • then via error messages from the code
  • note that class atom, class element and class molecule kept in parts their output stream, was they print to file.
  • make check runs fine
  • MISSING: Verbosity is not fixed for everything (i.e. if no endl; is present and next has Verbose(0) ...)

Signed-off-by: Frederik Heber <heber@…>

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