source: src/periodentafel.cpp@ 5b9bba

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 5b9bba was 717e0c, checked in by Frederik Heber <heber@…>, 15 years ago

Verbosity corrected for ERROR and WARNING

  • present ERROR and WARNING prefixes removed and placed by eLog() and respective Verbosity().
  • -v... is scanned for number of 'v's and verbosity is set accordingly
  • standard verbosity is now 0.

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

  • Property mode set to 100755
File size: 9.9 KB
RevLine 
[6ac7ee]1/** \file periodentafel.cpp
2 *
3 * Function implementations for the class periodentafel.
4 *
5 */
6
7using namespace std;
8
[cd4ccc]9#include <iomanip>
10#include <fstream>
11
[f66195]12#include "element.hpp"
[cd4ccc]13#include "helpers.hpp"
[f66195]14#include "lists.hpp"
[e138de]15#include "log.hpp"
[6ac7ee]16#include "periodentafel.hpp"
[cd4ccc]17#include "verbose.hpp"
[6ac7ee]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 */
[fb73b8]24periodentafel::periodentafel() : start(new element), end(new element)
[6ac7ee]25{
[042f82]26 start->previous = NULL;
27 start->next = end;
28 end->previous = start;
29 end->next = NULL;
[6ac7ee]30};
31
32/** destructor for class periodentafel
33 * Removes every element and afterwards deletes start and end of list.
34 */
35periodentafel::~periodentafel()
36{
[042f82]37 CleanupPeriodtable();
38 delete(end);
39 delete(start);
[6ac7ee]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 */
[fb73b8]46bool periodentafel::AddElement(element * const pointer)
[6ac7ee]47{
[042f82]48 pointer->sort = &pointer->Z;
49 if (pointer->Z < 1 && pointer->Z >= MAX_ELEMENTS)
[e138de]50 Log() << Verbose(0) << "Invalid Z number!\n";
[042f82]51 return add(pointer, end);
[6ac7ee]52};
53
54/** Removes element from list.
55 * \param *pointer element to be removed
56 * \return true - succeeded, false - element not found
57 */
[fb73b8]58bool periodentafel::RemoveElement(element * const pointer)
[6ac7ee]59{
[042f82]60 return remove(pointer, start, end);
[6ac7ee]61};
62
63/** Removes every element from the period table.
64 * \return true - succeeded, false - does not occur
65 */
66bool periodentafel::CleanupPeriodtable()
67{
[042f82]68 return cleanup(start,end);
[6ac7ee]69};
70
71/** Finds an element by its atomic number.
[fb73b8]72 * If element is not yet in list, returns NULL.
[6ac7ee]73 * \param Z atomic number
[fb73b8]74 * \return pointer to element or NULL if not found
[6ac7ee]75 */
[fb73b8]76element * const periodentafel::FindElement(const int Z) const
[6ac7ee]77{
[042f82]78 element *walker = find(&Z, start,end);
79 return(walker);
[6ac7ee]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 */
[fb73b8]87element * const periodentafel::FindElement(const char * const shorthand) const
[6ac7ee]88{
[042f82]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);
[6ac7ee]96};
97
98/** Asks for element number and returns pointer to element
99 */
[fb73b8]100element * const periodentafel::AskElement() const
[6ac7ee]101{
[042f82]102 element *walker = NULL;
103 int Z;
104 do {
[e138de]105 Log() << Verbose(0) << "Atomic number Z: ";
[042f82]106 cin >> Z;
107 walker = this->FindElement(Z); // give type
108 } while (walker == NULL);
109 return walker;
[6ac7ee]110};
111
[fb73b8]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;
[e138de]119 Log() << Verbose(0) << "Atomic number: " << Z << endl;
[fb73b8]120 cin >> Z;
121 walker = FindElement(Z);
122 if (walker == NULL) {
[e138de]123 Log() << Verbose(0) << "Element not found in database, please enter." << endl;
[fb73b8]124 walker = new element;
125 walker->Z = Z;
[e138de]126 Log() << Verbose(0) << "Mass: " << endl;
[fb73b8]127 cin >> walker->mass;
[e138de]128 Log() << Verbose(0) << "Name [max 64 chars]: " << endl;
[fb73b8]129 cin >> walker->name;
[e138de]130 Log() << Verbose(0) << "Short form [max 3 chars]: " << endl;
[fb73b8]131 cin >> walker->symbol;
132 periodentafel::AddElement(walker);
133 }
134 return(walker);
135};
136
[6ac7ee]137/** Prints period table to given stream.
138 * \param output stream
139 */
[fb73b8]140bool periodentafel::Output(ofstream * const output) const
[6ac7ee]141{
[042f82]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;
[6ac7ee]152};
153
154/** Prints period table to given stream.
155 * \param *output output stream
156 * \param *checkliste elements table for this molecule
157 */
[fb73b8]158bool periodentafel::Checkout(ofstream * const output, const int * const checkliste) const
[6ac7ee]159{
[042f82]160 element *walker = start;
161 bool result = true;
162 int No = 1;
[6ac7ee]163
[042f82]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;
[6ac7ee]177};
178
179/** Loads element list from file.
180 * \param *path to to standard file names
181 */
[989bf6]182bool periodentafel::LoadPeriodentafel(const char *path)
[6ac7ee]183{
[042f82]184 ifstream infile;
185 double tmp;
186 element *ptr;
187 bool status = true;
188 bool otherstatus = true;
189 char filename[255];
[6ac7ee]190
[042f82]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
[e138de]199 Log() << Verbose(0) << "Parsed elements:";
[042f82]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;
[e138de]221 Log() << Verbose(0) << " " << neues->symbol;
[042f82]222 //neues->Output((ofstream *)&cout);
223 if ((neues->Z > 0) && (neues->Z < MAX_ELEMENTS))
224 periodentafel::AddElement(neues);
225 else {
[e138de]226 Log() << Verbose(0) << "Could not parse element: ";
[042f82]227 neues->Output((ofstream *)&cout);
[db6bf74]228 delete(neues);
[042f82]229 }
230 }
[e138de]231 Log() << Verbose(0) << endl;
[042f82]232 infile.close();
233 infile.clear();
234 } else
235 status = false;
[6ac7ee]236
[042f82]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;
[e138de]248 //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->Valence << " valence electrons." << endl;
[042f82]249 }
250 infile.close();
251 infile.clear();
252 } else
253 otherstatus = false;
[6ac7ee]254
[042f82]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;
[e138de]266 //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->NoValenceOrbitals << " number of singly occupied valence orbitals." << endl;
[042f82]267 }
268 infile.close();
269 infile.clear();
270 } else
271 otherstatus = false;
[6ac7ee]272
[042f82]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;
[e138de]287 //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->HBondDistance[0] << " Angstrom typical distance to hydrogen." << endl;
[042f82]288 }
289 infile.close();
290 infile.clear();
291 } else
292 otherstatus = false;
[6ac7ee]293
[042f82]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;
[e138de]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;
[042f82]309 }
310 infile.close();
311 } else
312 otherstatus = false;
[6ac7ee]313
[042f82]314 if (!otherstatus)
[717e0c]315 eLog() << Verbose(2) << "Something went wrong while parsing the other databases!" << endl;
[6ac7ee]316
[042f82]317 return status;
[6ac7ee]318};
319
320/** Stores element list to file.
321 */
[989bf6]322bool periodentafel::StorePeriodentafel(const char *path) const
[6ac7ee]323{
[042f82]324 bool result = true;
325 ofstream f;
326 char filename[MAXSTRINGSIZE];
[6ac7ee]327
[042f82]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;
[6ac7ee]344};
Note: See TracBrowser for help on using the repository browser.