Changeset 4d4d33 for src/Parser/TremoloParser.cpp
- Timestamp:
- Feb 9, 2011, 5:25:13 PM (14 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:
- acd638
- Parents:
- 1a6bda
- git-author:
- Frederik Heber <heber@…> (02/09/11 16:18:50)
- git-committer:
- Frederik Heber <heber@…> (02/09/11 17:25:13)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/TremoloParser.cpp
r1a6bda r4d4d33 22 22 #include "CodePatterns/Assert.hpp" 23 23 #include "CodePatterns/Log.hpp" 24 #include "CodePatterns/toString.hpp" 24 25 #include "CodePatterns/Verbose.hpp" 25 26 #include "TremoloParser.hpp" … … 66 67 knownKeys["torsion"] = TremoloKey::torsion; 67 68 69 createKnownTypesByIdentity(); 70 68 71 // default behavior: use all possible keys on output 69 72 for (std::map<std::string, TremoloKey::atomDataKey>::iterator iter = knownKeys.begin(); iter != knownKeys.end(); ++iter) … … 72 75 // and noKey afterwards(!) such that it is not used in usedFields 73 76 knownKeys[" "] = TremoloKey::noKey; // with this we can detect invalid keys 77 78 // invert knownKeys for debug output 79 for (std::map<std::string, TremoloKey::atomDataKey>::iterator iter = knownKeys.begin(); iter != knownKeys.end(); ++iter) 80 knownKeyNames.insert( make_pair( iter->second, iter->first) ); 81 82 additionalAtomData.clear(); 74 83 } 75 84 … … 163 172 TremoloKey::atomDataKey currentField; 164 173 174 DoLog(3) && (Log() << Verbose(3) << "additionalAtomData contains: " << additionalAtomData << std::endl); 175 165 176 for (it = usedFields.begin(); it != usedFields.end(); it++) { 166 177 currentField = knownKeys[it->substr(0, it->find("="))]; … … 168 179 case TremoloKey::x : 169 180 // for the moment, assume there are always three dimensions 181 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << ": " << currentAtom->getPosition() << std::endl); 170 182 *file << currentAtom->at(0) << "\t"; 171 183 *file << currentAtom->at(1) << "\t"; … … 174 186 case TremoloKey::u : 175 187 // for the moment, assume there are always three dimensions 188 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << ": " << currentAtom->AtomicVelocity << std::endl); 176 189 *file << currentAtom->AtomicVelocity[0] << "\t"; 177 190 *file << currentAtom->AtomicVelocity[1] << "\t"; … … 179 192 break; 180 193 case TremoloKey::Type : 181 *file << currentAtom->getType()->getSymbol() << "\t"; 194 if ((!additionalAtomData.count(currentAtom->getId())) || (additionalAtomData[currentAtom->getId()].get(currentField) == "-")) { 195 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << " default value: " << currentAtom->getType()->getSymbol() << std::endl); 196 *file << currentAtom->getType()->getSymbol() << "\t"; 197 } else { 198 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << ": " << additionalAtomData[currentAtom->getId()].get(currentField) << std::endl); 199 *file << additionalAtomData[currentAtom->getId()].get(currentField) << "\t"; 200 } 182 201 break; 183 202 case TremoloKey::Id : 203 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << ": " << currentAtom->getId()+1 << std::endl); 184 204 *file << currentAtom->getId()+1 << "\t"; 185 205 break; 186 206 case TremoloKey::neighbors : 207 DoLog(3) && (Log() << Verbose(3) << "Writing type " << knownKeyNames[currentField] << std::endl); 187 208 writeNeighbors(file, atoi(it->substr(it->find("=") + 1, 1).c_str()), currentAtom); 188 209 break; 189 210 case TremoloKey::resSeq : 190 if (additionalAtomData.find(currentAtom->getId()) != additionalAtomData.end()) { 211 if (additionalAtomData.count(currentAtom->getId())) { 212 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << ": " << additionalAtomData[currentAtom->getId()].get(currentField) << std::endl); 191 213 *file << additionalAtomData[currentAtom->getId()].get(currentField); 192 214 } else if (currentAtom->getMolecule() != NULL) { 215 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << " its own id: " << currentAtom->getMolecule()->getId()+1 << std::endl); 193 216 *file << setw(4) << currentAtom->getMolecule()->getId()+1; 194 217 } else { 218 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << " default value: " << defaultAdditionalData.get(currentField) << std::endl); 195 219 *file << defaultAdditionalData.get(currentField); 196 220 } 197 221 *file << "\t"; 198 break;222 break; 199 223 default : 200 if (additionalAtomData.find(currentAtom->getId()) != additionalAtomData.end()) { 224 if (additionalAtomData.count(currentAtom->getId())) { 225 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << ": " << additionalAtomData[currentAtom->getId()].get(currentField) << std::endl); 201 226 *file << additionalAtomData[currentAtom->getId()].get(currentField); 202 } else if (additionalAtomData.find(currentAtom->GetTrueFather()->getId()) != additionalAtomData.end()) { 227 } else if (additionalAtomData.count(currentAtom->GetTrueFather()->getId())) { 228 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << " stuff from father: " << additionalAtomData[currentAtom->GetTrueFather()->getId()].get(currentField) << std::endl); 203 229 *file << additionalAtomData[currentAtom->GetTrueFather()->getId()].get(currentField); 204 230 } else { 231 DoLog(3) && (Log() << Verbose(3) << "Writing for type " << knownKeyNames[currentField] << " the default: " << defaultAdditionalData.get(currentField) << std::endl); 205 232 *file << defaultAdditionalData.get(currentField); 206 233 } … … 306 333 break; 307 334 case TremoloKey::Type : 308 char type[3];335 { 309 336 ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for "+keyName+"!"); 310 //DoLog(1) && (Log() << Verbose(1) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl); 311 strncpy(type, (*tok_iter).c_str(), 3); 337 DoLog(1) && (Log() << Verbose(1) << "INFO: Parsing key " << keyName << " with next token " << *tok_iter << std::endl); 338 std::string element(knownTypes[(*tok_iter)]); 339 // put type name into container for later use 340 atomInfo->set(currentField, *tok_iter); 341 DoLog(1) && (Log() << Verbose(1) << "INFO: Parsing element " << (*tok_iter) << " as " << element << " according to KnownTypes." << std::endl); 312 342 tok_iter++; 313 //type[1]='\0'; // cutoff after first char, correct for ATOM entries 314 newAtom->setType(World::getInstance().getPeriode()->FindElement(type)); 343 newAtom->setType(World::getInstance().getPeriode()->FindElement(element)); 315 344 ASSERT(newAtom->getType(), "Type was not set for this atom"); 316 345 break; 346 } 317 347 case TremoloKey::Id : 318 348 ASSERT(tok_iter != tokens.end(), "TremoloParser::readAtomDataLine() - no value for "+keyName+"!"); … … 476 506 } 477 507 508 /** Creates knownTypes as the identity, e.g. H -> H, He -> He, ... . 509 * 510 */ 511 void TremoloParser::createKnownTypesByIdentity() 512 { 513 // remove old mapping 514 knownTypes.clear(); 515 // make knownTypes the identity mapping 516 const periodentafel *periode = World::getInstance().getPeriode(); 517 for (periodentafel::const_iterator iter = periode->begin(); 518 iter != periode->end(); 519 ++iter) { 520 knownTypes.insert( make_pair(iter->second->getSymbol(), iter->second->getSymbol()) ); 521 } 522 } 523 524 /** Parses a .potentials file and creates from it the knownTypes file. 525 * 526 * @param file input stream of .potentials file 527 */ 528 void TremoloParser::parseKnownTypes(std::istream &file) 529 { 530 const periodentafel *periode = World::getInstance().getPeriode(); 531 // remove old mapping 532 knownTypes.clear(); 533 534 DoLog(3) && (Log() << Verbose(3) << "additionalAtomData contains: " << additionalAtomData << std::endl); 535 536 // parse in file 537 typedef boost::tokenizer<boost::char_separator<char> > 538 tokenizer; 539 boost::char_separator<char> tokensep(":\t ,;"); 540 boost::char_separator<char> equalitysep("\t ="); 541 std::string line; 542 while (file.good()) { 543 std::getline( file, line ); 544 DoLog(4) && (Log() << Verbose(4) << "INFO: full line of parameters is '" << line << "'" << std::endl); 545 if (line.find("particle:") != string::npos) { 546 DoLog(3) && (Log() << Verbose(3) << "INFO: found line '" << line << "' containing keyword 'particle:'." << std::endl); 547 tokenizer tokens(line, tokensep); 548 ASSERT(tokens.begin() != tokens.end(), 549 "TremoloParser::parseKnownTypes() - line with 'particle:' but no particles separated by comma."); 550 // look for particle_type 551 std::string particle_type("NULL"); 552 std::string element_type("NULL"); 553 for (tokenizer::iterator tok_iter = tokens.begin(); 554 tok_iter != tokens.end(); 555 ++tok_iter) { 556 if ((*tok_iter).find("particle_type") != string::npos) { 557 DoLog(3) && (Log() << Verbose(3) << "INFO: found line '" << line << "' containing keyword 'particle_type'." << std::endl); 558 tokenizer token((*tok_iter), equalitysep); 559 ASSERT(token.begin() != token.end(), 560 "TremoloParser::parseKnownTypes() - could not split particle_type by equality sign"); 561 tokenizer::iterator particle_iter = token.begin(); 562 particle_iter++; 563 particle_type = *particle_iter; 564 } 565 if ((*tok_iter).find("element_name") != string::npos) { 566 DoLog(3) && (Log() << Verbose(3) << "INFO: found line '" << line << "' containing keyword 'element_name'." << std::endl); 567 tokenizer token((*tok_iter), equalitysep); 568 ASSERT(token.begin() != token.end(), 569 "TremoloParser::parseKnownTypes() - could not split particle_type by equality sign"); 570 tokenizer::iterator element_iter = token.begin(); 571 element_iter++; 572 element_type = *element_iter; 573 } 574 } 575 if ((particle_type != "NULL") && (element_type != "NULL")) { 576 if (periode->FindElement(element_type) != NULL) { 577 DoLog(1) && (Log() << Verbose(1) << "INFO: Added Type " << particle_type << " as reference to element " << element_type << "." << std::endl); 578 knownTypes.insert( make_pair (particle_type, element_type) ); 579 } else { 580 DoeLog(1) && (Log() << Verbose(1) << "INFO: Either Type " << particle_type << " or " << element_type << " could not be recognized." << std::endl); 581 } 582 } else { 583 DoeLog(1) && (Log() << Verbose(1) << "INFO: Desired element " << element_type << " is not known." << std::endl); 584 } 585 } 586 } 587 588 }
Note:
See TracChangeset
for help on using the changeset viewer.