Ignore:
Timestamp:
Nov 27, 2012, 8:35:34 AM (12 years ago)
Author:
Frederik Heber <heber@…>
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:
3dd32f
Parents:
995e2f
git-author:
Frederik Heber <heber@…> (08/27/12 11:51:09)
git-committer:
Frederik Heber <heber@…> (11/27/12 08:35:34)
Message:

Combining FragmentResult's id and ...Data in FragmentationAutomationAction's helpers.

  • all ...Data are always placed into map, hence associated to fragment job id.
  • necessitated changes to all ..Summators, ..SumUpPerLevel, and DataConverter.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/FragmentationAction/FragmentationAutomationAction.cpp

    r995e2f rc9f9bb  
    4040
    4141#include <boost/mpl/remove.hpp>
     42#include <boost/lambda/lambda.hpp>
    4243
    4344#include "CodePatterns/Assert.hpp"
     
    173174void ConvertFragmentResultTo(
    174175    const std::vector<FragmentResult::ptr> &results,
    175     std::vector<T> &fragmentData)
     176    std::map<JobId_t, T> &fragmentData)
    176177{
    177178  // extract results
    178179  fragmentData.clear();
    179   fragmentData.reserve(results.size());
    180180
    181181  LOG(2, "DEBUG: Parsing now through " << results.size() << " results.");
     
    189189    ia >> extractedData;
    190190    LOG(1, "INFO: extracted data is " << extractedData << ".");
    191     fragmentData.push_back(extractedData);
     191    fragmentData.insert( std::make_pair( (*iter)->getId(), extractedData) );
    192192  }
    193193
     
    225225/** Place results from FragmentResult into EnergyMatrix and ForceMatrix.
    226226 *
    227  * @param jobids jobids with ids to associate with fragment number
    228227 * @param fragmentData MPQCData resulting from the jobs
    229228 * @param MatrixNrLookup Lookup up-map from job id to fragment number
     
    235234 */
    236235bool putResultsintoMatrices(
    237     const std::vector<JobId_t> &jobids,
    238     const std::vector<MPQCData> &fragmentData,
     236    const std::map<JobId_t, MPQCData> &fragmentData,
    239237    std::map< JobId_t, size_t > &MatrixNrLookup,
    240238    const size_t FragmentCounter,
     
    243241    ForceMatrix &Force)
    244242{
    245   ASSERT( jobids.size() == fragmentData.size(),
    246       "putResultsintoMatrices() - jobids and fragmentData differ in size.");
    247   std::vector<MPQCData>::const_iterator dataiter = fragmentData.begin();
    248   std::vector<JobId_t>::const_iterator iditer = jobids.begin();
    249   for (; dataiter != fragmentData.end(); ++dataiter, ++iditer) {
    250     const MPQCData &extractedData = *dataiter;
     243  for (std::map<JobId_t, MPQCData>::const_iterator dataiter = fragmentData.begin();
     244      dataiter != fragmentData.end(); ++dataiter) {
     245    const MPQCData &extractedData = dataiter->second;
     246    const JobId_t &jobid = dataiter->first;
    251247    // place results into EnergyMatrix ...
    252248    {
     
    255251      matrix[0].resize(1, extractedData.energies.total);
    256252      if (!Energy.AddMatrix(
    257           std::string("MPQCJob ")+toString(*iditer),
     253          std::string("MPQCJob ")+toString(jobid),
    258254          matrix,
    259           MatrixNrLookup[*iditer])) {
     255          MatrixNrLookup[jobid])) {
    260256        ELOG(1, "Adding energy matrix failed.");
    261257        return false;
     
    276272      }
    277273      if (!Force.AddMatrix(
    278           std::string("MPQCJob ")+toString(*iditer),
     274          std::string("MPQCJob ")+toString(jobid),
    279275          matrix,
    280           MatrixNrLookup[*iditer])) {
     276          MatrixNrLookup[jobid])) {
    281277        ELOG(1, "Adding force matrix failed.");
    282278        return false;
     
    301297/** Print MPQCData from received results.
    302298 *
    303  * @param jobids jobids with ids to associate with fragment number
    304  * @param fragmentData MPQCData resulting from the jobs
     299 * @param fragmentData MPQCData resulting from the jobs, each associated to a job
    305300 * @param KeySetFilename filename with keysets to associate forces correctly
    306301 * @param NoAtoms total number of atoms
     
    309304 */
    310305bool sumUpChargeDensity(
    311     const std::vector<JobId_t> &jobids,
    312     const std::vector<MPQCData> &fragmentData,
     306    const std::map<JobId_t,MPQCData> &fragmentData,
    313307    const std::string &KeySetFilename,
    314308    SamplingGrid &full_sample,
    315309    Fragment &full_fragment)
    316310{
     311  // create a vector of all job ids
     312  std::vector<JobId_t> jobids;
     313  std::transform(fragmentData.begin(),fragmentData.end(),
     314      std::back_inserter(jobids),
     315      boost::bind( &std::map<JobId_t,MPQCData>::value_type::first, boost::lambda::_1 )
     316  );
     317
    317318  // create lookup from job nr to fragment number
    318319  std::map< JobId_t, size_t > MatrixNrLookup;
     
    339340  std::vector<MPQCDataGridMap_t> Result_Grid_fused(
    340341    OrthogonalSumUpPerLevel<MPQCDataGridMap_t, MPQCDataGridVector_t>(
    341         fragmentData, jobids, MatrixNrLookup, container, subsetmap));
     342        fragmentData, MatrixNrLookup, container, subsetmap));
    342343  std::vector<MPQCDataFragmentMap_t> Result_Fragment_fused(
    343344    OrthogonalSumUpPerLevel<MPQCDataFragmentMap_t, MPQCDataFragmentVector_t>(
    344         fragmentData, jobids, MatrixNrLookup, container, subsetmap));
     345        fragmentData, MatrixNrLookup, container, subsetmap));
    345346  // obtain full grid
    346347  full_sample = boost::fusion::at_key<MPQCDataFused::sampled_grid>(Result_Grid_fused.back());
     
    352353/** Print MPQCData from received results.
    353354 *
    354  * @param results results with ids to associate with fragment number
    355  * @param fragmentData MPQCData resulting from the jobs
     355 * @param fragmentData MPQCData resulting from the jobs, associated to job id
    356356 * @param KeySetFilename filename with keysets to associate forces correctly
    357357 * @param NoAtoms total number of atoms
     
    359359 */
    360360bool printReceivedMPQCResults(
    361     const std::vector<JobId_t> &jobids,
    362     const std::vector<MPQCData> &fragmentData,
     361    const std::map<JobId_t, MPQCData> &fragmentData,
    363362    const std::string &KeySetFilename,
    364363    size_t NoAtoms,
    365364    SamplingGrid &full_sample)
    366365{
     366  // create a vector of all job ids
     367  std::vector<JobId_t> jobids;
     368  std::transform(fragmentData.begin(),fragmentData.end(),
     369      std::back_inserter(jobids),
     370      boost::bind( &std::map<JobId_t,MPQCData>::value_type::first, boost::lambda::_1 )
     371  );
     372
    367373  // create lookup from job nr to fragment number
    368374  std::map< JobId_t, size_t > MatrixNrLookup;
     
    373379  EnergyMatrix Energy;
    374380  ForceMatrix Force;
    375   if (!putResultsintoMatrices(jobids, fragmentData, MatrixNrLookup, FragmentCounter, NoAtoms, Energy, Force))
     381  if (!putResultsintoMatrices(fragmentData, MatrixNrLookup, FragmentCounter, NoAtoms, Energy, Force))
    376382    return false;
    377383
     
    412418    std::vector<MPQCDataEnergyMap_t> Result_Energy_fused(
    413419        OrthogonalSumUpPerLevel<MPQCDataEnergyMap_t, MPQCDataEnergyVector_t>(
    414             fragmentData, jobids, MatrixNrLookup, container, subsetmap));
     420            fragmentData, MatrixNrLookup, container, subsetmap));
    415421    std::vector<MPQCDataGridMap_t> Result_Grid_fused(
    416422      OrthogonalSumUpPerLevel<MPQCDataGridMap_t, MPQCDataGridVector_t>(
    417           fragmentData, jobids, MatrixNrLookup, container, subsetmap));
     423          fragmentData, MatrixNrLookup, container, subsetmap));
    418424    std::vector<MPQCDataTimeMap_t> Result_Time_fused(
    419425      SumUpPerLevel<MPQCDataTimeMap_t, MPQCDataTimeVector_t>(
    420           fragmentData, jobids, MatrixNrLookup, container, subsetmap));
     426          fragmentData, MatrixNrLookup, container, subsetmap));
    421427
    422428    // force has extra converter
    423     std::vector<MPQCDataForceMap_t> MPQCData_Force_fused;
     429    std::map<JobId_t, MPQCDataForceMap_t> MPQCData_Force_fused;
    424430    convertMPQCDatatoForceMap(fragmentData, ForceKeySet, MPQCData_Force_fused);
    425431    std::vector<MPQCDataForceMap_t> Result_Force_fused(subsetmap->getMaximumSubsetLevel());
     
    427433                subsetmap,
    428434                MPQCData_Force_fused,
    429                 jobids,
    430435                container->getContainer(),
    431436                MatrixNrLookup,
     
    496501/** Print MPQCData from received results.
    497502 *
    498  * @param fragmentresults results with short-range job ids to associate with fragment number
    499  * @param longrangeresults results with long-range job ids to associate with fragment number
    500503 * @param fragmentData MPQCData resulting from the jobs
    501504 * @param longrangeData VMGData resulting from long-range jobs
     
    506509 */
    507510bool printReceivedFullResults(
    508     const std::vector<FragmentResult::ptr> &fragmentresults,
    509     const std::vector<FragmentResult::ptr> &longrangeresults,
    510     const std::vector<MPQCData> &fragmentData,
    511     const std::vector<VMGData> &longrangeData,
     511    const std::map<JobId_t,MPQCData> &fragmentData,
     512    const std::map<JobId_t,VMGData> &longrangeData,
    512513    const VMGData &fullsolutionData,
    513514    const std::string &KeySetFilename,
     
    515516    SamplingGrid &full_sample)
    516517{
    517   // create a vector of all job ids from short-range
    518   std::vector<JobId_t> jobids(fragmentresults.size(), JobId::IllegalJob);
    519   std::transform(fragmentresults.begin(), fragmentresults.end(), jobids.begin(),
    520       boost::bind(&FragmentResult::getId,
    521           boost::bind(&FragmentResult::ptr::operator->, _1)));
     518  // create a vector of all job ids
     519  std::vector<JobId_t> jobids;
     520  std::transform(fragmentData.begin(),fragmentData.end(),
     521      std::back_inserter(jobids),
     522      boost::bind( &std::map<JobId_t,MPQCData>::value_type::first, boost::lambda::_1 )
     523  );
    522524
    523525  // create lookup from job nr to fragment number
     
    555557    std::vector<MPQCDataEnergyMap_t> Result_Energy_fused(
    556558        OrthogonalSumUpPerLevel<MPQCDataEnergyMap_t, MPQCDataEnergyVector_t>(
    557             fragmentData, jobids, MatrixNrLookup, container, subsetmap));
     559            fragmentData, MatrixNrLookup, container, subsetmap));
    558560    std::vector<MPQCDataGridMap_t> Result_Grid_fused(
    559561      OrthogonalSumUpPerLevel<MPQCDataGridMap_t, MPQCDataGridVector_t>(
    560           fragmentData, jobids, MatrixNrLookup, container, subsetmap));
     562          fragmentData, MatrixNrLookup, container, subsetmap));
    561563    std::vector<MPQCDataTimeMap_t> Result_Time_fused(
    562564      SumUpPerLevel<MPQCDataTimeMap_t, MPQCDataTimeVector_t>(
    563           fragmentData, jobids, MatrixNrLookup, container, subsetmap));
     565          fragmentData, MatrixNrLookup, container, subsetmap));
    564566    std::vector<MPQCDataFragmentMap_t> Result_Fragment_fused(
    565567      OrthogonalSumUpPerLevel<MPQCDataFragmentMap_t, MPQCDataFragmentVector_t>(
    566           fragmentData, jobids, MatrixNrLookup, container, subsetmap));
     568          fragmentData, MatrixNrLookup, container, subsetmap));
    567569
    568570    // force has extra converter
    569     std::vector<MPQCDataForceMap_t> MPQCData_Force_fused;
     571    std::map<JobId_t, MPQCDataForceMap_t> MPQCData_Force_fused;
    570572    convertMPQCDatatoForceMap(fragmentData, ForceKeySet, MPQCData_Force_fused);
    571573    std::vector<MPQCDataForceMap_t> Result_Force_fused(subsetmap->getMaximumSubsetLevel());
     
    573575                subsetmap,
    574576                MPQCData_Force_fused,
    575                 jobids,
    576577                container->getContainer(),
    577578                MatrixNrLookup,
     
    580581
    581582    // obtain full grid
    582     std::vector<VMGDataMap_t> VMGData_Potential_fused;
     583    std::map<JobId_t, VMGDataMap_t> VMGData_Potential_fused;
    583584    convertDataTo<VMGData, VMGDataMap_t>(longrangeData, VMGData_Potential_fused);
    584585    OrthogonalFullSummator<VMGDataMap_t, VMGDataFused::sampled_potential> potentialSummer(
    585586                subsetmap,
    586587                VMGData_Potential_fused,
    587                 jobids,
    588588                container->getContainer(),
    589589                MatrixNrLookup);
     
    592592                subsetmap,
    593593                VMGData_Potential_fused,
    594                 jobids,
    595594                container->getContainer(),
    596595                MatrixNrLookup);
     
    605604                subsetmap,
    606605                VMGData_Potential_fused,
    607                 jobids,
    608606                container->getContainer(),
    609607                MatrixNrLookup);
     
    685683    FragmentController &controller,
    686684    const FragmentationFragmentationAutomationAction::FragmentationFragmentationAutomationParameters &params,
    687     const std::vector<MPQCData> &fragmentData,
     685    const std::map<JobId_t, MPQCData> &fragmentData,
    688686    const SamplingGrid &full_sampled_grid,
    689687    const Fragment &full_fragment)
     
    692690  // add one job for each fragment as the short-range correction which we need
    693691  // to subtract from the obtained full potential to get the long-range part only
    694   for (std::vector<MPQCData>::const_iterator iter = fragmentData.begin();
     692  for (std::map<JobId_t, MPQCData>::const_iterator iter = fragmentData.begin();
    695693      iter != fragmentData.end(); ++iter) {
    696694    const JobId_t next_id = controller.getAvailableId();
    697     LOG(1, "INFO: Creating VMGJob with " << iter->sampled_grid.sampled_grid.size()
    698         << " gridpoints and " << iter->charges.size() << " particle charges.");
     695    LOG(1, "INFO: Creating VMGJob with " << iter->second.sampled_grid.sampled_grid.size()
     696        << " gridpoints and " << iter->second.charges.size() << " particle charges.");
    699697    FragmentJob::ptr testJob(
    700         new VMGJob(next_id, iter->sampled_grid, iter->positions, iter->charges) );
     698        new VMGJob(next_id, iter->second.sampled_grid, iter->second.positions, iter->second.charges) );
    701699    jobs.push_back(testJob);
    702700  }
     
    776774  RunService(io_service, "Requesting short-range results");
    777775  std::vector<FragmentResult::ptr> MPQCresults = controller.getReceivedResults();
    778   std::vector<MPQCData> fragmentData;
     776  std::map<JobId_t, MPQCData> fragmentData;
    779777  ConvertFragmentResultTo<MPQCData>(MPQCresults, fragmentData);
    780778
     
    795793  Fragment full_fragment;
    796794  sumUpChargeDensity(
    797       jobids,
    798795      fragmentData,
    799796      params.path.get(),
     
    818815      "FragmentationFragmentationAutomationAction::performCall() - number of MPQCresultd and VMGresults don't match.");
    819816
    820   std::vector<VMGData> longrangeData;
     817  std::map<JobId_t, VMGData> longrangeData;
    821818  ConvertFragmentResultTo<VMGData>(VMGresults, longrangeData);
    822   // remove full solution from vector, has to be treated extra
    823   VMGData fullsolutionData = longrangeData.back();
    824   longrangeData.pop_back();
     819  // remove full solution from map (must be highest id), has to be treated extra
     820  VMGData fullsolutionData = (--longrangeData.end())->second;
     821  longrangeData.erase(--longrangeData.end());
    825822
    826823  // Final phase: print result
     
    828825    LOG(1, "INFO: Parsing fragment files from " << params.path.get() << ".");
    829826    printReceivedFullResults(
    830         MPQCresults,
    831         VMGresults,
    832827        fragmentData,
    833828        longrangeData,
     
    843838    LOG(1, "INFO: Parsing fragment files from " << params.path.get() << ".");
    844839    printReceivedMPQCResults(
    845         jobids,
    846840        fragmentData,
    847841        params.path.get(),
Note: See TracChangeset for help on using the changeset viewer.