Changeset b6b3b2
- Timestamp:
- Feb 10, 2011, 7:08:22 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:
- 528b3e
- Parents:
- 0bfe73 (diff), 311da7b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src/Parser
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/MpqcParser.cpp
r0bfe73 rb6b3b2 64 64 boost::char_separator<char> sep("[]"); 65 65 boost::char_separator<char> angularsep("<>"); 66 boost::char_separator<char> equalitysep(" =");66 boost::char_separator<char> equalitysep(" ="); 67 67 boost::char_separator<char> whitesep(" \t"); 68 68 ConvertTo<double> toDouble; … … 90 90 // throw MpqcParseException; 91 91 tokenizer::iterator tok_iter = tokens.begin(); 92 ASSERT(tok_iter != tokens.end(), 93 "MpqcParser::load() - missing token for MoleculeSection in line "+linestring+"!"); 92 94 std::stringstream whitespacefilter(*tok_iter++); 93 95 std::string element; 94 whitespacefilter >> element; 96 whitespacefilter >> ws >> element; 97 ASSERT(tok_iter != tokens.end(), 98 "MpqcParser::load() - missing token for MoleculeSection in line "+linestring+"!"); 95 99 std::string vector = *tok_iter; 96 100 tokenizer vectorcomponents(vector, whitesep); … … 111 115 } 112 116 if (MpqcSection) { 113 tokenizer tokens(linestring, equalitysep); 114 tokenizer::iterator tok_iter = tokens.begin(); 115 std::stringstream whitespacefilter(*tok_iter++); 116 std::string key(*tok_iter++); 117 if (params.haveParam(key)) { 118 std::stringstream linestream(linestring); 119 linestream >> params; 120 } else if (linestring.find("mole<") != string::npos) { // get theory 117 if (linestring.find("mole<") != string::npos) { // get theory 121 118 tokenizer tokens(linestring, angularsep); 122 119 tokenizer::iterator tok_iter = tokens.begin(); 123 std::string value(*(++tok_iter)); 120 ++tok_iter; 121 ASSERT(tok_iter != tokens.end(), 122 "MpqcParser::load() - missing token in brackets<> for mole< in line "+linestring+"!"); 123 std::string value(*tok_iter); 124 124 std::stringstream linestream("theory = "+value); 125 125 linestream >> params; … … 127 127 tokenizer tokens(linestring, angularsep); 128 128 tokenizer::iterator tok_iter = tokens.begin(); 129 std::string value(*(++tok_iter)); 129 ++tok_iter; 130 ASSERT(tok_iter != tokens.end(), 131 "MpqcParser::load() - missing token in brackets<> for integrals< in line "+linestring+"!"); 132 std::string value(*tok_iter); 130 133 std::stringstream linestream("integration = "+value); 131 134 linestream >> params; 135 } else if ((linestring.find("molecule") == string::npos) && (linestring.find("basis") == string::npos)){ 136 // molecule and basis must not be parsed in this section 137 tokenizer tokens(linestring, equalitysep); 138 tokenizer::iterator tok_iter = tokens.begin(); 139 ASSERT(tok_iter != tokens.end(), 140 "MpqcParser::load() - missing token before '=' for MpqcSection in line "+linestring+"!"); 141 std::stringstream whitespacefilter(*tok_iter); 142 std::string key; 143 whitespacefilter >> ws >> key; 144 if (params.haveParam(key)) { 145 std::stringstream linestream(linestring); 146 linestream >> params; 147 } else { // unknown keys are simply ignored as long as parser is incomplete 148 DoLog(2) && (Log() << Verbose(2) << "INFO: '"+key+"' is unknown and ignored." << std::endl); 149 } 132 150 } 133 151 } … … 135 153 tokenizer tokens(linestring, equalitysep); 136 154 tokenizer::iterator tok_iter = tokens.begin(); 155 ASSERT(tok_iter != tokens.end(), 156 "MpqcParser::load() - missing token for BasisSection in line "+linestring+"!"); 137 157 std::string key(*tok_iter++); 158 ASSERT(tok_iter != tokens.end(), 159 "MpqcParser::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!"); 138 160 std::string value(*tok_iter); 161 tok_iter++; 139 162 // TODO: use exception instead of ASSERT 140 163 ASSERT(tok_iter == tokens.end(), … … 148 171 tokenizer tokens(linestring, equalitysep); 149 172 tokenizer::iterator tok_iter = tokens.begin(); 173 ASSERT(tok_iter != tokens.end(), 174 "MpqcParser::load() - missing token for AuxBasisSection in line "+linestring+"!"); 150 175 std::string key(*tok_iter++); 176 ASSERT(tok_iter != tokens.end(), 177 "MpqcParser::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!"); 151 178 std::string value(*tok_iter); 179 tok_iter++; 152 180 // TODO: use exception instead of ASSERT 153 181 ASSERT(tok_iter == tokens.end(), -
src/Parser/MpqcParser_Parameters.cpp
r0bfe73 rb6b3b2 152 152 boost::char_separator<char> semicolonsep(";"); 153 153 boost::char_separator<char> equalitysep(" ="); 154 boost::char_separator<char> ticksep("\""); 154 155 std::string line; 155 156 std::getline( ist, line ); … … 157 158 tokenizer tokens(line, semicolonsep); 158 159 ASSERT(tokens.begin() != tokens.end(), 159 "operator<< on MpqcParser_Parameters - empty string, need at least ';' !");160 "operator<< on MpqcParser_Parameters - empty string, need at least ';' in line "+line+"!"); 160 161 for (tokenizer::iterator tok_iter = tokens.begin(); 161 162 tok_iter != tokens.end(); ++tok_iter) { … … 165 166 tokenizer::iterator tok_valueiter = tok_paramiter; 166 167 tokenizer::iterator tok_checkiter = ++tok_valueiter; 168 ++tok_checkiter; 167 169 // TODO: throw exception instead of ASSERT 168 ASSERT(tok_valueiter == params.end(), 169 "operator<< on MpqcParser_Parameters - missing value before ';'!"); 170 ++tok_checkiter; 171 ASSERT(tok_checkiter == params.end(), 172 "operator<< on MpqcParser_Parameters - still tokens before ';'!"); 173 DoLog(0) && (Log() << Verbose(0) 174 << "INFO: Token pair is " << *tok_paramiter << "," << *tok_valueiter << std::endl); 175 std::stringstream value(*tok_valueiter); 170 ASSERT(tok_paramiter != paramtokens.end(), 171 "operator<< on MpqcParser_Parameters - missing value before ' =' in token "+*tok_iter+"!"); 172 ASSERT(tok_valueiter != paramtokens.end(), 173 "operator<< on MpqcParser_Parameters - missing value after ' =' in token "+*tok_iter+"!"); 174 ASSERT(tok_checkiter == paramtokens.end(), 175 "operator<< on MpqcParser_Parameters - still more tokens after ' =' in token "+*tok_iter+":" 176 +*tok_checkiter+"!"); 177 std::stringstream keystream(*tok_paramiter); 178 std::string key; 179 keystream >> ws >> key; 180 tokenizer ticklesstokens(*tok_valueiter, ticksep); 181 ASSERT(ticklesstokens.begin() != ticklesstokens.end(), 182 "operator<< on MpqcParser_Parameters - no tokens present after removing ticks in token "+*tok_valueiter+"!"); 183 std::stringstream valuestream(*(ticklesstokens.begin())); 184 DoLog(2) && (Log() << Verbose(2) 185 << "INFO: Token pair is " << key << "," << valuestream.str() << std::endl); 176 186 177 187 // TODO: throw exception instead of DoeLog() 178 if ((params.haveParam(*tok_paramiter))) { 179 params.setter(params.getParam(*tok_paramiter), value); 180 } else { 181 DoeLog(0) && (eLog() << Verbose(0) 182 << *tok_paramiter << " is not a valid parameter name!" << std::endl); 183 } 188 ASSERT(params.haveParam(key), 189 "operator >> on MpqcParser_Parameters - unknown parameter name '" 190 +key+"' with value "+valuestream.str()+"!"); 191 if (params.haveParam(key)) 192 params.setter(params.getParam(key), valuestream); 184 193 } else { 185 194 ist.setstate(std::ios::eofbit); … … 247 256 { 248 257 // TODO: throw exception instead of eLog() 249 try {258 // try { 250 259 params[theoryParam] = _theory; 251 } catch(const boost::bad_any_cast &) {252 DoeLog(0) && (eLog() << Verbose(0)253 << "MpqcParser_Parameters::setTheory() - could not set boolean!" << std::endl);254 }260 // } catch(const boost::bad_any_cast &) { 261 // DoeLog(0) && (eLog() << Verbose(0) 262 // << "MpqcParser_Parameters::setTheory() - could not set boolean!" << std::endl); 263 // } 255 264 } 256 265 257 266 void MpqcParser_Parameters::setIntegration(enum MpqcParser_Parameters::IntegrationMethod _integration){ 258 267 // TODO: throw exception instead of eLog() 259 try {268 // try { 260 269 params[integrationParam] = _integration; 261 } catch(const boost::bad_any_cast &) {262 DoeLog(0) && (eLog() << Verbose(0)263 << "MpqcParser_Parameters::setIntegration() - could not set boolean!" << std::endl);264 }270 // } catch(const boost::bad_any_cast &) { 271 // DoeLog(0) && (eLog() << Verbose(0) 272 // << "MpqcParser_Parameters::setIntegration() - could not set boolean!" << std::endl); 273 // } 265 274 } 266 275 … … 279 288 enum IntegrationMethod value; 280 289 // TODO: throw exception instead of eLog() 281 try {290 // try { 282 291 value = boost::any_cast<enum IntegrationMethod>(params[integrationParam]); 283 } catch(const boost::bad_any_cast &) {284 DoeLog(0) && (eLog() << Verbose(0)285 << "MpqcParser_Parameters::getIntegration() - could not convert "286 +ParamNames[integrationParam]+" to enum IntegrationMethod!" << std::endl);287 }292 // } catch(const boost::bad_any_cast &) { 293 // DoeLog(0) && (eLog() << Verbose(0) 294 // << "MpqcParser_Parameters::getIntegration() - could not convert " 295 // +ParamNames[integrationParam]+" to enum IntegrationMethod!" << std::endl); 296 // } 288 297 return value; 289 298 } … … 293 302 enum Theory value; 294 303 // TODO: throw exception instead of eLog() 295 try {304 // try { 296 305 value = boost::any_cast<enum Theory>(params[theoryParam]); 297 } catch(const boost::bad_any_cast &) {298 DoeLog(0) && (eLog() << Verbose(0)299 << "MpqcParser_Parameters::getTheory() - could not convert "300 +ParamNames[theoryParam]+" to enum Theory!" << std::endl);301 }306 // } catch(const boost::bad_any_cast &) { 307 // DoeLog(0) && (eLog() << Verbose(0) 308 // << "MpqcParser_Parameters::getTheory() - could not convert " 309 // +ParamNames[theoryParam]+" to enum Theory!" << std::endl); 310 // } 302 311 return value; 303 312 } … … 321 330 case integrationParam: 322 331 // TODO: throw exception instead of eLog() 323 try {332 // try { 324 333 Iindex = boost::any_cast<enum IntegrationMethod>(params[_param]); 325 } catch(const boost::bad_any_cast &) {326 DoeLog(0) && (eLog() << Verbose(0)327 << "MpqcParser_Parameters::getString() - could not convert "328 +ParamNames[_param]+" to string!" << std::endl);329 }334 // } catch(const boost::bad_any_cast &) { 335 // DoeLog(0) && (eLog() << Verbose(0) 336 // << "MpqcParser_Parameters::getString() - could not convert " 337 // +ParamNames[_param]+" to string!" << std::endl); 338 // } 330 339 value = IntegrationNames[Iindex]; 331 340 break; 332 341 case theoryParam: 333 342 // TODO: throw exception instead of eLog() 334 try {343 // try { 335 344 Tindex = boost::any_cast<enum Theory>(params[_param]); 336 } catch(const boost::bad_any_cast &) {337 DoeLog(0) && (eLog() << Verbose(0)338 << "MpqcParser_Parameters::getString() - could not convert "339 +ParamNames[_param]+" to string!" << std::endl);340 }345 // } catch(const boost::bad_any_cast &) { 346 // DoeLog(0) && (eLog() << Verbose(0) 347 // << "MpqcParser_Parameters::getString() - could not convert " 348 // +ParamNames[_param]+" to string!" << std::endl); 349 // } 341 350 value = TheoryNames[(enum Theory)Tindex]; 342 351 break; 343 352 default: 344 353 // TODO: throw exception instead of eLog() 345 try {354 // try { 346 355 value = boost::any_cast<std::string>(params[_param]); 347 } catch(const boost::bad_any_cast &) {348 DoeLog(0) && (eLog() << Verbose(0)349 << "MpqcParser_Parameters::getString() - could not convert "350 +ParamNames[_param]+" to string!" << std::endl);351 }356 // } catch(const boost::bad_any_cast &) { 357 // DoeLog(0) && (eLog() << Verbose(0) 358 // << "MpqcParser_Parameters::getString() - could not convert " 359 // +ParamNames[_param]+" to string!" << std::endl); 360 // } 352 361 break; 353 362 } … … 362 371 default: 363 372 // TODO: throw exception instead of eLog() 364 try {373 // try { 365 374 value = boost::any_cast<int>(params[_param]); 366 } catch(const boost::bad_any_cast &) {367 DoeLog(0) && (eLog() << Verbose(0)368 << "MpqcParser_Parameters::getInt() - could not convert "369 +ParamNames[_param]+" to int!" << std::endl);370 }375 // } catch(const boost::bad_any_cast &) { 376 // DoeLog(0) && (eLog() << Verbose(0) 377 // << "MpqcParser_Parameters::getInt() - could not convert " 378 // +ParamNames[_param]+" to int!" << std::endl); 379 // } 371 380 break; 372 381 } … … 378 387 double value; 379 388 // TODO: throw exception instead of eLog() 380 try {389 // try { 381 390 value = boost::any_cast<double>(params[_param]); 382 } catch(const boost::bad_any_cast &) {383 DoeLog(0) && (eLog() << Verbose(0)384 << "MpqcParser_Parameters::getDouble() - could not convert "385 +ParamNames[_param]+" to double!" << std::endl);386 }391 // } catch(const boost::bad_any_cast &) { 392 // DoeLog(0) && (eLog() << Verbose(0) 393 // << "MpqcParser_Parameters::getDouble() - could not convert " 394 // +ParamNames[_param]+" to double!" << std::endl); 395 // } 387 396 return value; 388 397 } … … 392 401 bool value; 393 402 // TODO: throw exception instead of eLog() 394 try {403 // try { 395 404 value = boost::any_cast<bool>(params[_param]); 396 } catch(const boost::bad_any_cast &) {397 DoeLog(0) && (eLog() << Verbose(0)398 << "MpqcParser_Parameters::getBool() - could not convert "399 +ParamNames[_param]+" to bool!" << std::endl);400 }405 // } catch(const boost::bad_any_cast &) { 406 // DoeLog(0) && (eLog() << Verbose(0) 407 // << "MpqcParser_Parameters::getBool() - could not convert " 408 // +ParamNames[_param]+" to bool!" << std::endl); 409 // } 401 410 return value; 402 411 } -
src/Parser/unittests/ParserMpqcUnitTest.cpp
r0bfe73 rb6b3b2 31 31 #include "periodentafel.hpp" 32 32 #include "Descriptors/AtomTypeDescriptor.hpp" 33 #include "CodePatterns/Assert.hpp" 33 34 34 35 #ifdef HAVE_TESTRUNNER … … 214 215 215 216 // check throw, for the moment aren't, are caught in getInt() 216 //CPPUNIT_ASSERT_THROW(mpqc->params.getInt(MpqcParser_Parameters::integrationParam), boost::bad_any_cast);217 //CPPUNIT_ASSERT_THROW(mpqc->params.getInt(MpqcParser_Parameters::theoryParam), boost::bad_any_cast);217 CPPUNIT_ASSERT_THROW(mpqc->params.getInt(MpqcParser_Parameters::integrationParam), boost::bad_any_cast); 218 CPPUNIT_ASSERT_THROW(mpqc->params.getInt(MpqcParser_Parameters::theoryParam), boost::bad_any_cast); 218 219 219 220 } … … 245 246 } 246 247 // test whether unknown key fails 247 std::cout << "The following CRITICALwarning is desired and does not indicate a failure of the test." << std::endl;248 std::cout << "The following Assertion warning is desired and does not indicate a failure of the test." << std::endl; 248 249 { 249 250 std::stringstream setvalue("hessian = no"); 251 #ifndef NDEBUG 252 ASSERT_DO(Assert::Throw); 253 CPPUNIT_ASSERT_THROW(setvalue >> mpqc->params, Assert::AssertionFailure); 254 #else 250 255 setvalue >> mpqc->params; 256 #endif 251 257 // std::cout << "Hessian is still " 252 258 // << mpqc->params.getString(MpqcParser_Parameters::hessianParam) << std::endl;
Note:
See TracChangeset
for help on using the changeset viewer.