Changeset 4eb4fe for src/periodentafel.cpp
- Timestamp:
- May 18, 2010, 3:20:52 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:
- 673c7f, b0e9c9
- Parents:
- 5079a0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/periodentafel.cpp
r5079a0 r4eb4fe 8 8 9 9 #include <iomanip> 10 #include <iostream> 10 11 #include <fstream> 11 12 #include <cstring> 12 #include <cassert> 13 13 14 #include "Helpers/Assert.hpp" 14 15 #include "element.hpp" 16 #include "elements_db.hpp" 15 17 #include "helpers.hpp" 16 18 #include "lists.hpp" … … 27 29 */ 28 30 periodentafel::periodentafel() 29 {}; 31 { 32 ASSERT(LoadElementsDatabase(new stringstream(elementsDB,ios_base::in)), "General element initialization failed"); 33 ASSERT(LoadValenceDatabase(new stringstream(valenceDB,ios_base::in)), "Valence entry of element initialization failed"); 34 ASSERT(LoadOrbitalsDatabase(new stringstream(orbitalsDB,ios_base::in)), "Orbitals entry of element initialization failed"); 35 ASSERT(LoadHBondAngleDatabase(new stringstream(HbondangleDB,ios_base::in)), "HBond angle entry of element initialization failed"); 36 ASSERT(LoadHBondLengthsDatabase(new stringstream(HbonddistanceDB,ios_base::in)), "HBond distance entry of element initialization failed"); 37 }; 30 38 31 39 /** destructor for class periodentafel … … 39 47 /** Adds element to period table list 40 48 * \param *pointer element to be added 41 * \return true - succeeded, false - does not occur49 * \return iterator to added element 42 50 */ 43 51 periodentafel::iterator periodentafel::AddElement(element * const pointer) 44 52 { 45 53 atomicNumber_t Z = pointer->getNumber(); 46 assert(!elements.count(Z));54 ASSERT(!elements.count(Z), "Element is already present."); 47 55 pointer->sort = &pointer->Z; 48 56 if (pointer->getNumber() < 1 && pointer->getNumber() >= MAX_ELEMENTS) … … 54 62 /** Removes element from list. 55 63 * \param *pointer element to be removed 56 * \return true - succeeded, false - element not found57 64 */ 58 65 void periodentafel::RemoveElement(element * const pointer) 59 66 { 60 atomicNumber_t Z = pointer->getNumber(); 67 RemoveElement(pointer->getNumber()); 68 }; 69 70 /** Removes element from list. 71 * \param Z element to be removed 72 */ 73 void periodentafel::RemoveElement(atomicNumber_t Z) 74 { 61 75 elements.erase(Z); 62 76 }; 63 77 64 78 /** Removes every element from the period table. 65 * \return true - succeeded, false - does not occur66 79 */ 67 80 void periodentafel::CleanupPeriodtable() … … 78 91 * \return pointer to element or NULL if not found 79 92 */ 80 const element *periodentafel::FindElement(atomicNumber_t Z) const93 element * const periodentafel::FindElement(atomicNumber_t Z) const 81 94 { 82 95 const_iterator res = elements.find(Z); … … 89 102 * \return pointer to element 90 103 */ 91 const element *periodentafel::FindElement(const char * const shorthand) const104 element * const periodentafel::FindElement(const char * const shorthand) const 92 105 { 93 106 element *res = 0; … … 102 115 103 116 /** Asks for element number and returns pointer to element 104 */ 105 const element * periodentafel::AskElement() const 106 { 107 const element *walker = NULL; 117 * \return desired element or NULL 118 */ 119 element * const periodentafel::AskElement() const 120 { 121 element * walker = NULL; 108 122 int Z; 109 123 do { … … 118 132 * \return pointer to either present or newly created element 119 133 */ 120 const element * periodentafel::EnterElement() 121 { 122 const element *res = NULL; 134 element * const periodentafel::EnterElement() 135 { 123 136 atomicNumber_t Z = 0; 124 137 DoLog(0) && (Log() << Verbose(0) << "Atomic number: " << Z << endl); 125 138 cin >> Z; 126 res = FindElement(Z);139 element * const res = FindElement(Z); 127 140 if (!res) { 128 141 // TODO: make this using the constructor 129 element *tmp;130 142 DoLog(0) && (Log() << Verbose(0) << "Element not found in database, please enter." << endl); 131 tmp = new element;143 element *tmp = new element; 132 144 tmp->Z = Z; 133 145 DoLog(0) && (Log() << Verbose(0) << "Mass: " << endl); … … 138 150 cin >> tmp->symbol; 139 151 AddElement(tmp); 140 re s =tmp;152 return tmp; 141 153 } 142 154 return res; … … 204 216 bool periodentafel::LoadPeriodentafel(const char *path) 205 217 { 206 ifstream infile; 207 element *ptr; 208 map<atomicNumber_t,element*> parsedElems; 218 ifstream input; 209 219 bool status = true; 210 220 bool otherstatus = true; … … 215 225 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); 216 226 strncat(filename, STANDARDELEMENTSDB, MAXSTRINGSIZE-strlen(filename)); 217 infile.open(filename); 218 if (infile != NULL) { 219 infile.getline(header1, MAXSTRINGSIZE); 220 infile.getline(header2, MAXSTRINGSIZE); // skip first two header lines 227 input.open(filename); 228 status = status && LoadElementsDatabase(&input); 229 230 // fill valence DB per element 231 strncpy(filename, path, MAXSTRINGSIZE); 232 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); 233 strncat(filename, STANDARDVALENCEDB, MAXSTRINGSIZE-strlen(filename)); 234 input.open(filename); 235 otherstatus = otherstatus && LoadValenceDatabase(&input); 236 237 // fill orbitals DB per element 238 strncpy(filename, path, MAXSTRINGSIZE); 239 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); 240 strncat(filename, STANDARDORBITALDB, MAXSTRINGSIZE-strlen(filename)); 241 input.open(filename); 242 otherstatus = otherstatus && LoadOrbitalsDatabase(&input); 243 244 // fill H-BondAngle DB per element 245 strncpy(filename, path, MAXSTRINGSIZE); 246 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); 247 strncat(filename, STANDARDHBONDANGLEDB, MAXSTRINGSIZE-strlen(filename)); 248 input.open(filename); 249 otherstatus = otherstatus && LoadHBondAngleDatabase(&input); 250 251 // fill H-BondDistance DB per element 252 strncpy(filename, path, MAXSTRINGSIZE); 253 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); 254 strncat(filename, STANDARDHBONDDISTANCEDB, MAXSTRINGSIZE-strlen(filename)); 255 input.open(filename); 256 otherstatus = otherstatus && LoadHBondLengthsDatabase(&input); 257 258 if (!otherstatus){ 259 DoeLog(2) && (eLog()<< Verbose(2) << "Something went wrong while parsing the other databases!" << endl); 260 } 261 262 return status; 263 }; 264 265 /** load the element info. 266 * \param *input stream to parse from 267 * \return true - parsing successful, false - something went wrong 268 */ 269 bool periodentafel::LoadElementsDatabase(istream *input) 270 { 271 if ((*input) != NULL) { 272 (*input).getline(header1, MAXSTRINGSIZE); 273 (*input).getline(header2, MAXSTRINGSIZE); // skip first two header lines 221 274 DoLog(0) && (Log() << Verbose(0) << "Parsed elements:"); 222 while (! infile.eof()) {275 while (!(*input).eof()) { 223 276 element *neues = new element; 224 infile>> neues->name;225 // infile>> ws;226 infile>> neues->symbol;227 // infile>> ws;228 infile>> neues->period;229 // infile>> ws;230 infile>> neues->group;231 // infile>> ws;232 infile>> neues->block;233 // infile>> ws;234 infile>> neues->Z;235 // infile>> ws;236 infile>> neues->mass;237 // infile>> ws;238 infile>> neues->CovalentRadius;239 // infile>> ws;240 infile>> neues->VanDerWaalsRadius;241 // infile>> ws;242 infile>> ws;277 (*input) >> neues->name; 278 //(*input) >> ws; 279 (*input) >> neues->symbol; 280 //(*input) >> ws; 281 (*input) >> neues->period; 282 //(*input) >> ws; 283 (*input) >> neues->group; 284 //(*input) >> ws; 285 (*input) >> neues->block; 286 //(*input) >> ws; 287 (*input) >> neues->Z; 288 //(*input) >> ws; 289 (*input) >> neues->mass; 290 //(*input) >> ws; 291 (*input) >> neues->CovalentRadius; 292 //(*input) >> ws; 293 (*input) >> neues->VanDerWaalsRadius; 294 //(*input) >> ws; 295 (*input) >> ws; 243 296 DoLog(0) && (Log() << Verbose(0) << " " << neues->symbol); 297 if (elements.count(neues->Z)) {// if element already present, remove and delete it 298 element * const Elemental = FindElement(neues->Z); 299 ASSERT(Elemental != NULL, "element should be present but is not??"); 300 RemoveElement(Elemental); 301 delete(Elemental); 302 } 244 303 //neues->Output((ofstream *)&cout); 245 304 if ((neues->Z > 0) && (neues->Z < MAX_ELEMENTS)) 246 parsedElems[neues->getNumber()] = neues;305 elements[neues->getNumber()] = neues; 247 306 else { 248 307 DoLog(0) && (Log() << Verbose(0) << "Could not parse element: "); … … 252 311 } 253 312 DoLog(0) && (Log() << Verbose(0) << endl); 254 infile.close(); 255 infile.clear(); 256 } else 257 status = false; 258 259 // fill valence DB per element 260 strncpy(filename, path, MAXSTRINGSIZE); 261 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); 262 strncat(filename, STANDARDVALENCEDB, MAXSTRINGSIZE-strlen(filename)); 263 infile.open(filename); 264 if (infile != NULL) { 265 while (!infile.eof()) { 313 return true; 314 } else 315 return false; 316 } 317 318 /** load the valence info. 319 * \param *input stream to parse from 320 * \return true - parsing successful, false - something went wrong 321 */ 322 bool periodentafel::LoadValenceDatabase(istream *input) 323 { 324 char dummy[MAXSTRINGSIZE]; 325 if ((*input) != NULL) { 326 (*input).getline(dummy, MAXSTRINGSIZE); 327 while (!(*input).eof()) { 266 328 atomicNumber_t Z; 267 infile >> Z; 268 infile >> ws; 269 infile >> parsedElems[Z]->Valence; 270 infile >> ws; 329 (*input) >> Z; 330 ASSERT(elements.count(Z), "Element not present"); 331 (*input) >> ws; 332 (*input) >> elements[Z]->Valence; 333 (*input) >> ws; 271 334 //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->Valence << " valence electrons." << endl; 272 335 } 273 infile.close(); 274 infile.clear(); 275 } else 276 otherstatus = false; 277 278 // fill valence DB per element 279 strncpy(filename, path, MAXSTRINGSIZE); 280 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); 281 strncat(filename, STANDARDORBITALDB, MAXSTRINGSIZE-strlen(filename)); 282 infile.open(filename); 283 if (infile != NULL) { 284 while (!infile.eof()) { 336 return true; 337 } else 338 return false; 339 } 340 341 /** load the orbitals info. 342 * \param *input stream to parse from 343 * \return true - parsing successful, false - something went wrong 344 */ 345 bool periodentafel::LoadOrbitalsDatabase(istream *input) 346 { 347 char dummy[MAXSTRINGSIZE]; 348 if ((*input) != NULL) { 349 (*input).getline(dummy, MAXSTRINGSIZE); 350 while (!(*input).eof()) { 285 351 atomicNumber_t Z; 286 infile >> Z; 287 infile >> ws; 288 infile >> parsedElems[Z]->NoValenceOrbitals; 289 infile >> ws; 352 (*input) >> Z; 353 ASSERT(elements.count(Z), "Element not present"); 354 (*input) >> ws; 355 (*input) >> elements[Z]->NoValenceOrbitals; 356 (*input) >> ws; 290 357 //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->NoValenceOrbitals << " number of singly occupied valence orbitals." << endl; 291 358 } 292 infile.close(); 293 infile.clear(); 294 } else 295 otherstatus = false; 296 297 // fill H-BondDistance DB per element 298 strncpy(filename, path, MAXSTRINGSIZE); 299 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); 300 strncat(filename, STANDARDHBONDDISTANCEDB, MAXSTRINGSIZE-strlen(filename)); 301 infile.open(filename); 302 if (infile != NULL) { 303 while (!infile.eof()) { 359 return true; 360 } else 361 return false; 362 } 363 364 /** load the hbond angles info. 365 * \param *input stream to parse from 366 * \return true - parsing successful, false - something went wrong 367 */ 368 bool periodentafel::LoadHBondAngleDatabase(istream *input) 369 { 370 char dummy[MAXSTRINGSIZE]; 371 if ((*input) != NULL) { 372 (*input).getline(dummy, MAXSTRINGSIZE); 373 while (!(*input).eof()) { 304 374 atomicNumber_t Z; 305 infile >> Z; 306 ptr = parsedElems[Z]; 307 infile >> ws; 308 infile >> ptr->HBondDistance[0]; 309 infile >> ptr->HBondDistance[1]; 310 infile >> ptr->HBondDistance[2]; 311 infile >> ws; 375 (*input) >> Z; 376 ASSERT(elements.count(Z), "Element not present"); 377 (*input) >> ws; 378 (*input) >> elements[Z]->HBondAngle[0]; 379 (*input) >> elements[Z]->HBondAngle[1]; 380 (*input) >> elements[Z]->HBondAngle[2]; 381 (*input) >> ws; 382 //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; 383 } 384 return true; 385 } else 386 return false; 387 } 388 389 /** load the hbond lengths info. 390 * \param *input stream to parse from 391 * \return true - parsing successful, false - something went wrong 392 */ 393 bool periodentafel::LoadHBondLengthsDatabase(istream *input) 394 { 395 char dummy[MAXSTRINGSIZE]; 396 if ((*input) != NULL) { 397 (*input).getline(dummy, MAXSTRINGSIZE); 398 while (!(*input).eof()) { 399 atomicNumber_t Z; 400 (*input) >> Z; 401 ASSERT(elements.count(Z), "Element not present"); 402 (*input) >> ws; 403 (*input) >> elements[Z]->HBondDistance[0]; 404 (*input) >> elements[Z]->HBondDistance[1]; 405 (*input) >> elements[Z]->HBondDistance[2]; 406 (*input) >> ws; 312 407 //Log() << Verbose(3) << "Element " << (int)tmp << " has " << FindElement((int)tmp)->HBondDistance[0] << " Angstrom typical distance to hydrogen." << endl; 313 408 } 314 infile.close(); 315 infile.clear(); 316 } else 317 otherstatus = false; 318 319 // fill H-BondAngle DB per element 320 strncpy(filename, path, MAXSTRINGSIZE); 321 strncat(filename, "/", MAXSTRINGSIZE-strlen(filename)); 322 strncat(filename, STANDARDHBONDANGLEDB, MAXSTRINGSIZE-strlen(filename)); 323 infile.open(filename); 324 if (infile != NULL) { 325 while (!infile.eof()) { 326 atomicNumber_t Z; 327 infile >> Z; 328 ptr = parsedElems[Z]; 329 infile >> ws; 330 infile >> ptr->HBondAngle[0]; 331 infile >> ptr->HBondAngle[1]; 332 infile >> ptr->HBondAngle[2]; 333 infile >> ws; 334 //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; 335 } 336 infile.close(); 337 } else 338 otherstatus = false; 339 340 if (otherstatus){ 341 map<atomicNumber_t,element*>::iterator iter; 342 for(iter=parsedElems.begin();iter!=parsedElems.end();++iter){ 343 AddElement((*iter).second); 344 } 345 } 346 else{ 347 DoeLog(2) && (eLog()<< Verbose(2) << "Something went wrong while parsing the other databases!" << endl); 348 map<atomicNumber_t,element*>::iterator iter; 349 for(iter=parsedElems.begin();iter!=parsedElems.end();++iter){ 350 AddElement((*iter).second); 351 } 352 } 353 354 return status; 355 }; 409 return true; 410 } else 411 return false; 412 } 356 413 357 414 /** Stores element list to file. … … 374 431 } 375 432 f.close(); 376 } else377 result = false;378 return result;379 }; 433 return true; 434 } else 435 return result; 436 };
Note:
See TracChangeset
for help on using the changeset viewer.