Changeset 0588e9 for src/Actions
- Timestamp:
- Oct 17, 2013, 7:24:06 AM (11 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:
- f58e56
- Parents:
- 675cd6
- git-author:
- Frederik Heber <heber@…> (09/26/13 16:19:05)
- git-committer:
- Frederik Heber <heber@…> (10/17/13 07:24:06)
- Location:
- src/Actions/FragmentationAction
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/FragmentationAction/AnalyseFragmentationResultsAction.cpp
r675cd6 r0588e9 42 42 43 43 #include <boost/foreach.hpp> 44 #include <boost/lambda/lambda.hpp> 44 45 #include <boost/mpl/remove.hpp> 45 46 47 #include <algorithm> 46 48 #include <fstream> 47 49 #include <iostream> … … 100 102 } 101 103 104 /** Print cycle correction from received results. 105 * 106 * @param results summed up results container 107 */ 108 void printReceivedCycleResults( 109 const FragmentationShortRangeResults &results) 110 { 111 typedef boost::mpl::remove< 112 boost::mpl::remove<MPQCDataEnergyVector_t, MPQCDataFused::energy_eigenvalues>::type, 113 MPQCDataFused::energy_eigenhistogram>::type 114 MPQCDataEnergyVector_noeigenvalues_t; 115 const std::string energyresult = 116 writeTable<MPQCDataEnergyMap_t, MPQCDataEnergyVector_noeigenvalues_t >()( 117 results.Result_Energy_fused, results.getMaxLevel()); 118 LOG(2, "DEBUG: Energy table is \n" << energyresult); 119 std::string filename; 120 filename += FRAGMENTPREFIX + std::string("_CycleEnergy.dat"); 121 writeToFile(filename, energyresult); 122 } 123 102 124 /** Print (short range) energy, forces, and timings from received results. 103 125 * … … 324 346 } 325 347 348 // this it taken from 349 // http://stackoverflow.com/questions/2291802/is-there-a-c-iterator-that-can-iterate-over-a-file-line-by-line 350 namespace detail 351 { 352 /** Extend the string class by a friend function. 353 * 354 */ 355 class Line : public std::string 356 { 357 friend std::istream & operator>>(std::istream & is, Line & line) 358 { 359 return std::getline(is, line); 360 } 361 }; 362 } 363 364 /** Parse the given stream line-by-line, passing each to \a dest. 365 * 366 * \param is stream to parse line-wise 367 * \param dest output iterator 368 */ 369 template<class OutIt> 370 void read_lines(std::istream& is, OutIt dest) 371 { 372 typedef std::istream_iterator<detail::Line> InIt; 373 std::copy(InIt(is), InIt(), dest); 374 } 375 376 326 377 ActionState::ptr FragmentationAnalyseFragmentationResultsAction::performCall() { 327 378 328 // if file is given, parse from file into resultscontainer379 /// if file is given, parse from file into ResultsContainer 329 380 FragmentationResultContainer& container = FragmentationResultContainer::getInstance(); 330 381 if (!params.resultsfile.get().empty()) { … … 342 393 } 343 394 344 // get data and keysets from ResultsContainer395 /// get data and keysets from ResultsContainer 345 396 const std::map<JobId_t, MPQCData> &shortrangedata = container.getShortRangeResults(); 346 397 const KeySetsContainer &keysets = container.getKeySets(); … … 354 405 } 355 406 407 /// calculate normal contributions with (if present) cycles coming at their 408 /// respective bond order. 356 409 std::vector<bool> ValueMask(shortrangedata.size(), true); 357 410 FragmentationShortRangeResults shortrangeresults(shortrangedata, keysets, forcekeysets, ValueMask); 358 411 shortrangeresults(shortrangedata); 359 412 printReceivedShortResults(shortrangeresults); 413 414 /// now do we need to calculate the cycle contribution 415 // check whether there are cycles in container or else in file 416 KeySetsContainer cycles = container.getCycles(); 417 if (cycles.KeySets.empty()) { 418 // parse from file if cycles is empty 419 boost::filesystem::path filename( 420 params.prefix.get() + std::string(CYCLEKEYSETFILE)); 421 if (boost::filesystem::exists(filename)) { 422 LOG(1, "INFO: Parsing cycles file " << filename.string() << "."); 423 // parse file line by line 424 std::ifstream File; 425 File.open(filename.string().c_str()); 426 typedef std::istream_iterator<detail::Line> InIt; 427 for (InIt iter = InIt(File); iter != InIt(); ++iter) { 428 KeySetsContainer::IntVector cycle; 429 std::stringstream line(*iter); 430 while (line.good()) { 431 int id; 432 line >> id >> ws; 433 cycle.push_back(id); 434 } 435 if (!cycle.empty()) { 436 LOG(2, "DEBUG: Adding cycle " << cycle << "."); 437 cycles.insert( cycle, cycle.size()); 438 } 439 } 440 File.close(); 441 } else { 442 LOG(1, "INFO: Cycles file not found at " << filename.string() << "."); 443 } 444 } 445 446 // copy the shortrangeresults such that private MaxLevel is set in 447 // FragmentationShortRangeResults 448 FragmentationShortRangeResults cycleresults(shortrangeresults); 449 // calculate energy if cycles are calculated fully at each level already 450 if (!cycles.KeySets.empty()) { 451 // gather cycle sizes 452 std::vector<size_t> cyclesizes(cycles.KeySets.size()); 453 std::transform( 454 cycles.KeySets.begin(), cycles.KeySets.end(), 455 cyclesizes.begin(), 456 boost::bind(&KeySetsContainer::IntVector::size, boost::lambda::_1) 457 ); 458 // get maximum 459 std::vector<size_t>::const_iterator maximum_size = 460 std::max_element(cyclesizes.begin(), cyclesizes.end()); 461 462 // loop from level 1 to max ring size and gather corrections 463 for (size_t level = 1; level <= *maximum_size; ++level) { 464 // create ValueMask for this level by stepping through each keyset and checking size 465 std::vector<bool> localValueMask(shortrangedata.size(), false); 466 size_t index=0; 467 KeySetsContainer::ArrayOfIntVectors::const_iterator keysetsiter = keysets.KeySets.begin(); 468 KeySetsContainer::ArrayOfIntVectors::const_iterator cyclesiter = cycles.KeySets.begin(); 469 for (; (keysetsiter != keysets.KeySets.end()) && (cyclesiter != cycles.KeySets.end());) { 470 if (cyclesiter->size() > keysetsiter->size()) { 471 // add if not greater than level in size 472 if ((*keysetsiter).size() <= level) 473 localValueMask[index] = true; 474 ++keysetsiter; 475 ++index; 476 } else if (cyclesiter->size() < keysetsiter->size()) { 477 ++cyclesiter; 478 } else { // both sets have same size 479 if (*cyclesiter > *keysetsiter) { 480 // add if not greater than level in size 481 if ((*keysetsiter).size() <= level) 482 localValueMask[index] = true; 483 ++keysetsiter; 484 ++index; 485 } else if (*cyclesiter < *keysetsiter) { 486 ++cyclesiter; 487 } else { 488 // also always add all cycles 489 localValueMask[index] = true; 490 ++cyclesiter; 491 ++keysetsiter; 492 ++index; 493 } 494 } 495 } 496 // activate rest if desired by level 497 for (; keysetsiter != keysets.KeySets.end(); ++keysetsiter) { 498 if ((*keysetsiter).size() <= level) 499 localValueMask[index] = true; 500 ++index; 501 } 502 LOG(2, "DEBUG: ValueMask for cycle correction at level " << level << " is " 503 << localValueMask << "."); 504 // create FragmentationShortRangeResults 505 FragmentationShortRangeResults localresults(shortrangedata, keysets, forcekeysets, localValueMask); 506 // and perform summation 507 localresults(shortrangedata); 508 // finally, extract the corrections 509 cycleresults.Result_Energy_fused[level-1] = 510 localresults.Result_Energy_fused.back(); 511 cycleresults.Result_Time_fused[level-1] = 512 localresults.Result_Time_fused.back(); 513 cycleresults.Result_Force_fused[level-1] = 514 localresults.Result_Force_fused.back(); 515 } 516 printReceivedCycleResults(cycleresults); 517 } 360 518 361 519 // adding obtained forces -
src/Actions/FragmentationAction/AnalyseFragmentationResultsAction.def
r675cd6 r0588e9 8 8 // all includes and forward declarations necessary for non-integral types below 9 9 #include <boost/filesystem/path.hpp> 10 #include <string> 10 11 11 12 #include "Parameters/Validators/DummyValidator.hpp" … … 14 15 // ValueStorage by the token "Z" -> first column: int, Z, "Z" 15 16 // "undefine" if no parameters are required, use (NOPARAM_DEFAULT) for each (undefined) default value 16 #define paramtypes (boost::filesystem::path)(bool) 17 #define paramtokens ("fragment-resultfile")("store-grids") 18 #define paramdescriptions ("parse fragment results from the given file")("whether to store sampled grids in homology files") 19 #define paramdefaults (PARAM_DEFAULT(""))(PARAM_DEFAULT("0")) 20 #define paramreferences (resultsfile)(DoStoreGrids) 17 #define paramtypes (boost::filesystem::path)(bool)(std::string) 18 #define paramtokens ("fragment-resultfile")("store-grids")("fragment-prefix") 19 #define paramdescriptions ("parse fragment results from the given file")("whether to store sampled grids in homology files")("prefix of each fragment file") 20 #define paramdefaults (PARAM_DEFAULT(""))(PARAM_DEFAULT("0"))(NOPARAM_DEFAULT) 21 #define paramreferences (resultsfile)(DoStoreGrids)(prefix) 21 22 #define paramvalids \ 22 23 (DummyValidator< boost::filesystem::path >()) \ 23 (DummyValidator< bool >()) 24 (DummyValidator< bool >()) \ 25 (DummyValidator< std::string >()) 24 26 25 27 #undef statetypes
Note:
See TracChangeset
for help on using the changeset viewer.