Changeset ead4e6 for src/periodentafel.cpp
- Timestamp:
- Mar 12, 2010, 1:16:01 PM (15 years ago)
- Branches:
- 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
- Children:
- 745a85
- Parents:
- c3dbe0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/periodentafel.cpp
rc3dbe0 read4e6 10 10 #include <fstream> 11 11 #include <cstring> 12 #include <cassert> 12 13 13 14 #include "element.hpp" … … 18 19 #include "verbose.hpp" 19 20 21 using namespace std; 22 20 23 /************************************* Functions for class periodentafel ***************************/ 21 24 … … 23 26 * Initialises start and end of list and resets periodentafel::checkliste to false. 24 27 */ 25 periodentafel::periodentafel() : start(new element), end(new element) 26 { 27 start->previous = NULL; 28 start->next = end; 29 end->previous = start; 30 end->next = NULL; 31 }; 28 periodentafel::periodentafel() 29 {}; 32 30 33 31 /** destructor for class periodentafel … … 37 35 { 38 36 CleanupPeriodtable(); 39 delete(end);40 delete(start);41 37 }; 42 38 … … 45 41 * \return true - succeeded, false - does not occur 46 42 */ 47 bool periodentafel::AddElement(element * const pointer) 48 { 43 periodentafel::iterator periodentafel::AddElement(element * const pointer) 44 { 45 atomicNumber_t Z = pointer->getNumber(); 46 assert(!elements.count(Z)); 49 47 pointer->sort = &pointer->Z; 50 if (pointer-> Z < 1 && pointer->Z>= MAX_ELEMENTS)48 if (pointer->getNumber() < 1 && pointer->getNumber() >= MAX_ELEMENTS) 51 49 Log() << Verbose(0) << "Invalid Z number!\n"; 52 return add(pointer, end); 50 pair<iterator,bool> res = elements.insert(pair<atomicNumber_t,element*>(Z,pointer)); 51 return res.first; 53 52 }; 54 53 … … 57 56 * \return true - succeeded, false - element not found 58 57 */ 59 bool periodentafel::RemoveElement(element * const pointer) 60 { 61 return remove(pointer, start, end); 58 void periodentafel::RemoveElement(element * const pointer) 59 { 60 atomicNumber_t Z = pointer->getNumber(); 61 elements.erase(Z); 62 62 }; 63 63 … … 65 65 * \return true - succeeded, false - does not occur 66 66 */ 67 boolperiodentafel::CleanupPeriodtable()68 { 69 return cleanup(start,end);67 void periodentafel::CleanupPeriodtable() 68 { 69 elements.clear(); 70 70 }; 71 71 … … 75 75 * \return pointer to element or NULL if not found 76 76 */ 77 element * const periodentafel::FindElement(const int Z) const78 { 79 element *walker = find(&Z, start,end);80 return (walker);77 const element * periodentafel::FindElement(atomicNumber_t Z) const 78 { 79 const_iterator res = elements.find(Z); 80 return res!=elements.end()?((*res).second):0; 81 81 }; 82 82 … … 86 86 * \return pointer to element 87 87 */ 88 element * const periodentafel::FindElement(const char * const shorthand) const 89 { 90 element *walker = periodentafel::start; 91 while (walker->next != periodentafel::end) { 92 walker = walker->next; 93 if (strncmp(walker->symbol, shorthand, 3) == 0) 94 return(walker); 88 const element * periodentafel::FindElement(const char * const shorthand) const 89 { 90 element *res = 0; 91 for(const_iterator iter=elements.begin();iter!=elements.end();++iter) { 92 if((*iter).second->getSymbol() == shorthand){ 93 res = (*iter).second; 94 break; 95 } 95 96 } 96 return (NULL);97 return res; 97 98 }; 98 99 99 100 /** Asks for element number and returns pointer to element 100 101 */ 101 element * constperiodentafel::AskElement() const102 { 103 element *walker = NULL;102 const element * periodentafel::AskElement() const 103 { 104 const element *walker = NULL; 104 105 int Z; 105 106 do { … … 114 115 * \return pointer to either present or newly created element 115 116 */ 116 element * constperiodentafel::EnterElement()117 { 118 element *walker= NULL;119 int Z = -1;117 const element * periodentafel::EnterElement() 118 { 119 const element *res = NULL; 120 atomicNumber_t Z = 0; 120 121 Log() << Verbose(0) << "Atomic number: " << Z << endl; 121 122 cin >> Z; 122 walker = FindElement(Z); 123 if (walker == NULL) { 123 res = FindElement(Z); 124 if (!res) { 125 // TODO: make this using the constructor 126 element *tmp; 124 127 Log() << Verbose(0) << "Element not found in database, please enter." << endl; 125 walker= new element;126 walker->Z = Z;128 tmp = new element; 129 tmp->Z = Z; 127 130 Log() << Verbose(0) << "Mass: " << endl; 128 cin >> walker->mass;131 cin >> tmp->mass; 129 132 Log() << Verbose(0) << "Name [max 64 chars]: " << endl; 130 cin >> walker->name;133 cin >> tmp->name; 131 134 Log() << Verbose(0) << "Short form [max 3 chars]: " << endl; 132 cin >> walker->symbol; 133 periodentafel::AddElement(walker); 135 cin >> tmp->symbol; 136 AddElement(tmp); 137 res = tmp; 134 138 } 135 return(walker); 136 }; 139 return res; 140 }; 141 142 143 /******************** Access to iterators ****************************/ 144 periodentafel::const_iterator periodentafel::begin(){ 145 return elements.begin(); 146 } 147 148 periodentafel::const_iterator periodentafel::end(){ 149 return elements.end(); 150 } 151 152 periodentafel::reverse_iterator periodentafel::rbegin(){ 153 return reverse_iterator(elements.end()); 154 } 155 156 periodentafel::reverse_iterator periodentafel::rend(){ 157 return reverse_iterator(elements.begin()); 158 } 137 159 138 160 /** Prints period table to given stream. 139 161 * \param output stream 140 162 */ 141 bool periodentafel::Output(o fstream * const output) const163 bool periodentafel::Output(ostream * const output) const 142 164 { 143 165 bool result = true; 144 element *walker = start;145 166 if (output != NULL) { 146 while (walker->next != end) { 147 walker = walker->next; 148 result = result && walker->Output(output); 167 for(const_iterator iter=elements.begin(); iter !=elements.end();++iter){ 168 result = result && (*iter).second->Output(output); 149 169 } 150 170 return result; … … 157 177 * \param *checkliste elements table for this molecule 158 178 */ 159 bool periodentafel::Checkout(ofstream * const output, const int * const checkliste) const 160 { 161 element *walker = start; 179 bool periodentafel::Checkout(ostream * const output, const int * const checkliste) const 180 { 162 181 bool result = true; 163 182 int No = 1; … … 166 185 *output << "# Ion type data (PP = PseudoPotential, Z = atomic number)" << endl; 167 186 *output << "#Ion_TypeNr.\tAmount\tZ\tRGauss\tL_Max(PP)L_Loc(PP)IonMass\t# chemical name, symbol" << endl; 168 while (walker->next != end) { 169 walker = walker->next; 170 if ((walker != NULL) && (walker->Z > 0) && (walker->Z < MAX_ELEMENTS) && (checkliste[walker->Z])) { 171 walker->No = No; 172 result = result && walker->Checkout(output, No++, checkliste[walker->Z]); 187 for(const_iterator iter=elements.begin(); iter!=elements.end();++iter){ 188 if (((*iter).first < MAX_ELEMENTS) && (checkliste[(*iter).first])) { 189 (*iter).second->No = No; 190 result = result && (*iter).second->Checkout(output, No++, checkliste[(*iter).first]); 173 191 } 174 192 } … … 184 202 { 185 203 ifstream infile; 186 double tmp;187 204 element *ptr; 205 map<atomicNumber_t,element*> parsedElems; 188 206 bool status = true; 189 207 bool otherstatus = true; … … 223 241 //neues->Output((ofstream *)&cout); 224 242 if ((neues->Z > 0) && (neues->Z < MAX_ELEMENTS)) 225 p eriodentafel::AddElement(neues);243 parsedElems[neues->getNumber()] = neues; 226 244 else { 227 245 Log() << Verbose(0) << "Could not parse element: "; … … 243 261 if (infile != NULL) { 244 262 while (!infile.eof()) { 245 infile >> tmp; 246 infile >> ws; 247 infile >> FindElement((int)tmp)->Valence; 263 atomicNumber_t Z; 264 infile >> Z; 265 infile >> ws; 266 infile >> parsedElems[Z]->Valence; 248 267 infile >> ws; 249 268 //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->Valence << " valence electrons." << endl; … … 261 280 if (infile != NULL) { 262 281 while (!infile.eof()) { 263 infile >> tmp; 264 infile >> ws; 265 infile >> FindElement((int)tmp)->NoValenceOrbitals; 282 atomicNumber_t Z; 283 infile >> Z; 284 infile >> ws; 285 infile >> parsedElems[Z]->NoValenceOrbitals; 266 286 infile >> ws; 267 287 //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->NoValenceOrbitals << " number of singly occupied valence orbitals." << endl; … … 279 299 if (infile != NULL) { 280 300 while (!infile.eof()) { 281 infile >> tmp; 282 ptr = FindElement((int)tmp); 301 atomicNumber_t Z; 302 infile >> Z; 303 ptr = parsedElems[Z]; 283 304 infile >> ws; 284 305 infile >> ptr->HBondDistance[0]; … … 300 321 if (infile != NULL) { 301 322 while (!infile.eof()) { 302 infile >> tmp; 303 ptr = FindElement((int)tmp); 323 atomicNumber_t Z; 324 infile >> Z; 325 ptr = parsedElems[Z]; 304 326 infile >> ws; 305 327 infile >> ptr->HBondAngle[0]; … … 313 335 otherstatus = false; 314 336 315 if (!otherstatus) 337 if (otherstatus){ 338 map<atomicNumber_t,element*>::iterator iter; 339 for(iter=parsedElems.begin();iter!=parsedElems.end();++iter){ 340 AddElement((*iter).second); 341 } 342 } 343 else{ 316 344 eLog() << Verbose(2) << "Something went wrong while parsing the other databases!" << endl; 345 } 317 346 318 347 return status; … … 334 363 f << header1 << endl; 335 364 f << header2 << endl; 336 element *walker = periodentafel::start; 337 while (walker->next != periodentafel::end) { 338 walker = walker->next; 339 result = result && walker->Output(&f); 365 for(const_iterator iter=elements.begin();iter!=elements.end();++iter){ 366 result = result && (*iter).second->Output(&f); 340 367 } 341 368 f.close();
Note:
See TracChangeset
for help on using the changeset viewer.