Changeset c4ee08


Ignore:
Timestamp:
Nov 21, 2012, 9:57:01 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:
635645
Parents:
a22e05
git-author:
Frederik Heber <heber@…> (08/08/12 11:33:59)
git-committer:
Frederik Heber <heber@…> (11/21/12 09:57:01)
Message:

Extracted several functions out of printReceivedMPQCResults().

File:
1 edited

Legend:

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

    ra22e05 rc4ee08  
    186186}
    187187
    188 
    189 /** Print MPQCData from received results.
    190  *
    191  * @param results results with ids to associate with fragment number
    192  * @param fragmentData MPQCData resulting from the jobs
    193  * @param KeySetFilename filename with keysets to associate forces correctly
    194  * @param NoAtoms total number of atoms
     188/** Creates a lookup from FragmentJob::id to the true fragment  number.
     189 *
     190 * @param results result with job ids
     191 * @param MatrixNrLookup Lookup up-map, filled on return
     192 * @param FragmentCounter total number of fragments on return
    195193 */
    196 bool printReceivedMPQCResults(
     194void createMatrixNrLookup(
    197195    const std::vector<FragmentResult::ptr> &results,
    198     const std::vector<MPQCData> &fragmentData,
    199     const std::string &KeySetFilename,
    200     size_t NoAtoms)
    201 {
    202   EnergyMatrix Energy;
    203   EnergyMatrix EnergyFragments;
    204   ForceMatrix Force;
    205   ForceMatrix ForceFragments;
    206 
     196    std::map< JobId_t, size_t > &MatrixNrLookup,
     197    size_t &FragmentCounter)
     198{
    207199  // align fragments
    208   std::map< JobId_t, size_t > MatrixNrLookup;
    209   size_t FragmentCounter = 0;
     200  MatrixNrLookup.clear();
     201  FragmentCounter = 0;
    210202  {
    211203    // bring ids in order ...
     
    228220  }
    229221  LOG(1, "INFO: There are " << FragmentCounter << " fragments.");
    230 
     222}
     223
     224/** Place results from FragmentResult into EnergyMatrix and ForceMatrix.
     225 *
     226 * @param results results with ids to associate with fragment number
     227 * @param fragmentData MPQCData resulting from the jobs
     228 * @param MatrixNrLookup Lookup up-map from job id to fragment number
     229 * @param FragmentCounter total number of fragments
     230 * @param NoAtoms total number of atoms
     231 * @param Energy energy matrix to be filled on return
     232 * @param Force force matrix to be filled on return
     233 * @return true - everything ok, false - else
     234 */
     235bool putResultsintoMatrices(
     236    const std::vector<FragmentResult::ptr> &results,
     237    const std::vector<MPQCData> &fragmentData,
     238    std::map< JobId_t, size_t > &MatrixNrLookup,
     239    const size_t FragmentCounter,
     240    const size_t NoAtoms,
     241    EnergyMatrix &Energy,
     242    ForceMatrix &Force)
     243{
     244  ASSERT( results.size() == fragmentData.size(),
     245      "printReceivedMPQCResults() - results and fragmentData differ in size.");
    231246  std::vector<MPQCData>::const_iterator dataiter = fragmentData.begin();
    232247  std::vector<FragmentResult::ptr>::const_iterator resultiter = results.begin();
     
    281296    return false;
    282297
    283   // initialise indices
     298  return true;
     299}
     300
     301void convertMPQCDatatoEnergyMap(
     302    const std::vector<MPQCData> &fragmentData,
     303    std::vector<MPQCDataEnergyMap_t> &MPQCData_Energy_fused)
     304{
     305  // energy_t
     306  MPQCData_Energy_fused.clear();
     307  MPQCData_Energy_fused.reserve(fragmentData.size());
     308  for(std::vector<MPQCData>::const_iterator dataiter = fragmentData.begin();
     309      dataiter != fragmentData.end(); ++dataiter) {
     310    const MPQCData &extractedData = *dataiter;
     311    LOG(2, "DEBUG: Current extracted Data is " << extractedData << ".");
     312    MPQCDataEnergyMap_t instance;
     313    boost::fusion::at_key<MPQCDataFused::energy_total>(instance) = extractedData.energies.total;
     314    boost::fusion::at_key<MPQCDataFused::energy_nuclear_repulsion>(instance) = extractedData.energies.nuclear_repulsion;
     315    boost::fusion::at_key<MPQCDataFused::energy_electron_coulomb>(instance) = extractedData.energies.electron_coulomb;
     316    boost::fusion::at_key<MPQCDataFused::energy_electron_exchange>(instance) = extractedData.energies.electron_exchange;
     317    boost::fusion::at_key<MPQCDataFused::energy_correlation>(instance) = extractedData.energies.correlation;
     318    boost::fusion::at_key<MPQCDataFused::energy_overlap>(instance) = extractedData.energies.overlap;
     319    boost::fusion::at_key<MPQCDataFused::energy_kinetic>(instance) = extractedData.energies.kinetic;
     320    boost::fusion::at_key<MPQCDataFused::energy_hcore>(instance) = extractedData.energies.hcore;
     321    boost::fusion::at_key<MPQCDataFused::energy_eigenvalues>(instance) = extractedData.energies.eigenvalues;
     322    MPQCData_Energy_fused.push_back(instance);
     323  }
     324}
     325
     326void convertMPQCDatatoForceMap(
     327    const std::vector<MPQCData> &fragmentData,
     328    const KeySetsContainer &ForceKeySet,
     329    std::vector<MPQCDataForceMap_t> &MPQCData_Force_fused)
     330{
     331  // forces
     332  ASSERT( ForceKeySet.KeySets.size() == fragmentData.size(),
     333      "FragmentationAutomationAction::performCall() - indices and fragmentData differ in size.");
     334  MPQCData_Force_fused.clear();
     335  MPQCData_Force_fused.reserve(fragmentData.size());
     336  std::vector<MPQCData>::const_iterator dataiter = fragmentData.begin();
     337  KeySetsContainer::ArrayOfIntVectors::const_iterator arrayiter = ForceKeySet.KeySets.begin();
     338  for(;dataiter != fragmentData.end(); ++dataiter, ++arrayiter) {
     339    const MPQCData &extractedData = *dataiter;
     340    LOG(2, "DEBUG: Current extracted Data is " << extractedData << ".");
     341    MPQCDataForceMap_t instance;
     342    // must convert int to index_t
     343    IndexedVectors::indices_t indices(arrayiter->begin(), arrayiter->end());
     344    boost::fusion::at_key<MPQCDataFused::forces>(instance) =
     345        IndexedVectors(indices, extractedData.forces);
     346    MPQCData_Force_fused.push_back(instance);
     347  }
     348}
     349
     350void convertMPQCDatatoGridMap(
     351    const std::vector<MPQCData> &fragmentData,
     352    std::vector<MPQCDataGridMap_t> &MPQCData_Grid_fused)
     353{
     354  // sampled_grid
     355  MPQCData_Grid_fused.clear();
     356  MPQCData_Grid_fused.reserve(fragmentData.size());
     357  for(std::vector<MPQCData>::const_iterator dataiter = fragmentData.begin();
     358      dataiter != fragmentData.end(); ++dataiter) {
     359    const MPQCData &extractedData = *dataiter;
     360    LOG(2, "DEBUG: Current extracted Data is " << extractedData << ".");
     361    MPQCDataGridMap_t instance;
     362    boost::fusion::at_key<MPQCDataFused::sampled_grid>(instance) = extractedData.sampled_grid;
     363    MPQCData_Grid_fused.push_back(instance);
     364  }
     365}
     366
     367void convertMPQCDatatoTimeMap(
     368    const std::vector<MPQCData> &fragmentData,
     369    std::vector<MPQCDataTimeMap_t> &MPQCData_Time_fused)
     370{
     371  // times
     372  MPQCData_Time_fused.clear();
     373  MPQCData_Time_fused.reserve(fragmentData.size());
     374  for(std::vector<MPQCData>::const_iterator dataiter = fragmentData.begin();
     375      dataiter != fragmentData.end(); ++dataiter) {
     376    const MPQCData &extractedData = *dataiter;
     377    LOG(2, "DEBUG: Current extracted Data is " << extractedData << ".");
     378    MPQCDataTimeMap_t instance;
     379    boost::fusion::at_key<MPQCDataFused::times_walltime>(instance) = extractedData.times.walltime;
     380    boost::fusion::at_key<MPQCDataFused::times_cputime>(instance) = extractedData.times.cputime;
     381    boost::fusion::at_key<MPQCDataFused::times_flops>(instance) = extractedData.times.flops;
     382    MPQCData_Time_fused.push_back(instance);
     383  }
     384}
     385
     386/** Print MPQCData from received results.
     387 *
     388 * @param results results with ids to associate with fragment number
     389 * @param fragmentData MPQCData resulting from the jobs
     390 * @param KeySetFilename filename with keysets to associate forces correctly
     391 * @param NoAtoms total number of atoms
     392 */
     393bool printReceivedMPQCResults(
     394    const std::vector<FragmentResult::ptr> &results,
     395    const std::vector<MPQCData> &fragmentData,
     396    const std::string &KeySetFilename,
     397    size_t NoAtoms)
     398{
     399  // create lookup from job nr to fragment number
     400  std::map< JobId_t, size_t > MatrixNrLookup;
     401  size_t FragmentCounter = 0;
     402  createMatrixNrLookup(results, MatrixNrLookup, FragmentCounter);
     403
     404  // place results into maps
     405  EnergyMatrix Energy;
     406  ForceMatrix Force;
     407  if (!putResultsintoMatrices(results, fragmentData, MatrixNrLookup, FragmentCounter, NoAtoms, Energy, Force))
     408    return false;
     409
     410  // initialise keysets
    284411  KeySetsContainer KeySet;
    285412  KeySetsContainer ForceKeySet;
     
    289416
    290417  {
     418    // else needs keysets without hydrogens
    291419    std::stringstream filename;
    292420    filename << FRAGMENTPREFIX << KEYSETFILE;
     
    295423
    296424  {
     425    // forces need keysets including hydrogens
    297426    std::stringstream filename;
    298427    filename << FRAGMENTPREFIX << FORCESFILE;
     
    307436  SubsetMap::ptr subsetmap(new SubsetMap(*container));
    308437
    309 // we probably don't need this, it suffices if IndexedVectors has some extra indices
    310 //  // forces need different keysets: they must include hydrogen
    311 //  // (though without ones added by saturation)
    312 //  IndexSetContainer::ptr forceindices(new IndexSetContainer(ForceKeySet));
    313 //  // create the map of all keysets
    314 //  SubsetMap::ptr subsetmapforces(new SubsetMap(*forceindices));
    315 
    316438  /// convert all MPQCData to MPQCDataMap_t
    317439  {
    318     // energy_t
    319     std::vector<MPQCDataEnergyMap_t> MPQCData_Energy_fused;
    320     MPQCData_Energy_fused.reserve(fragmentData.size());
    321     for(std::vector<MPQCData>::const_iterator dataiter = fragmentData.begin();
    322         dataiter != fragmentData.end(); ++dataiter) {
    323       const MPQCData &extractedData = *dataiter;
    324       LOG(2, "DEBUG: Current extracted Data is " << extractedData << ".");
    325       MPQCDataEnergyMap_t instance;
    326       boost::fusion::at_key<MPQCDataFused::energy_total>(instance) = extractedData.energies.total;
    327       boost::fusion::at_key<MPQCDataFused::energy_nuclear_repulsion>(instance) = extractedData.energies.nuclear_repulsion;
    328       boost::fusion::at_key<MPQCDataFused::energy_electron_coulomb>(instance) = extractedData.energies.electron_coulomb;
    329       boost::fusion::at_key<MPQCDataFused::energy_electron_exchange>(instance) = extractedData.energies.electron_exchange;
    330       boost::fusion::at_key<MPQCDataFused::energy_correlation>(instance) = extractedData.energies.correlation;
    331       boost::fusion::at_key<MPQCDataFused::energy_overlap>(instance) = extractedData.energies.overlap;
    332       boost::fusion::at_key<MPQCDataFused::energy_kinetic>(instance) = extractedData.energies.kinetic;
    333       boost::fusion::at_key<MPQCDataFused::energy_hcore>(instance) = extractedData.energies.hcore;
    334       boost::fusion::at_key<MPQCDataFused::energy_eigenvalues>(instance) = extractedData.energies.eigenvalues;
    335       MPQCData_Energy_fused.push_back(instance);
    336     }
    337 
    338     // forces
    339440    ASSERT( ForceKeySet.KeySets.size() == fragmentData.size(),
    340441        "FragmentationAutomationAction::performCall() - ForceKeySet's KeySets and fragmentData differ in size.");
     442
     443    std::vector<MPQCDataEnergyMap_t> MPQCData_Energy_fused;
     444    convertMPQCDatatoEnergyMap(fragmentData, MPQCData_Energy_fused);
    341445    std::vector<MPQCDataForceMap_t> MPQCData_Force_fused;
    342     MPQCData_Force_fused.reserve(fragmentData.size());
    343     std::vector<MPQCData>::const_iterator dataiter = fragmentData.begin();
    344     KeySetsContainer::ArrayOfIntVectors::const_iterator arrayiter = ForceKeySet.KeySets.begin();
    345     for(;dataiter != fragmentData.end(); ++dataiter, ++arrayiter) {
    346       const MPQCData &extractedData = *dataiter;
    347       LOG(2, "DEBUG: Current extracted Data is " << extractedData << ".");
    348       MPQCDataForceMap_t instance;
    349       // must convert int to index_t
    350       IndexedVectors::indices_t indices(arrayiter->begin(), arrayiter->end());
    351       boost::fusion::at_key<MPQCDataFused::forces>(instance) =
    352           IndexedVectors(indices, extractedData.forces);
    353       MPQCData_Force_fused.push_back(instance);
    354     }
    355 
    356     // sampled_grid
     446    convertMPQCDatatoForceMap(fragmentData, ForceKeySet, MPQCData_Force_fused);
    357447    std::vector<MPQCDataGridMap_t> MPQCData_Grid_fused;
    358     MPQCData_Grid_fused.reserve(fragmentData.size());
    359     for(std::vector<MPQCData>::const_iterator dataiter = fragmentData.begin();
    360         dataiter != fragmentData.end(); ++dataiter) {
    361       const MPQCData &extractedData = *dataiter;
    362       LOG(2, "DEBUG: Current extracted Data is " << extractedData << ".");
    363       MPQCDataGridMap_t instance;
    364       boost::fusion::at_key<MPQCDataFused::sampled_grid>(instance) = extractedData.sampled_grid;
    365       MPQCData_Grid_fused.push_back(instance);
    366     }
    367 
    368     // times
     448    convertMPQCDatatoGridMap(fragmentData, MPQCData_Grid_fused);
    369449    std::vector<MPQCDataTimeMap_t> MPQCData_Time_fused;
    370     MPQCData_Time_fused.reserve(fragmentData.size());
    371     for(std::vector<MPQCData>::const_iterator dataiter = fragmentData.begin();
    372         dataiter != fragmentData.end(); ++dataiter) {
    373       const MPQCData &extractedData = *dataiter;
    374       LOG(2, "DEBUG: Current extracted Data is " << extractedData << ".");
    375       MPQCDataTimeMap_t instance;
    376       boost::fusion::at_key<MPQCDataFused::times_walltime>(instance) = extractedData.times.walltime;
    377       boost::fusion::at_key<MPQCDataFused::times_cputime>(instance) = extractedData.times.cputime;
    378       boost::fusion::at_key<MPQCDataFused::times_flops>(instance) = extractedData.times.flops;
    379       MPQCData_Time_fused.push_back(instance);
    380     }
     450    convertMPQCDatatoTimeMap(fragmentData, MPQCData_Time_fused);
    381451
    382452    // create a vector of all job ids
     
    452522  if (!KeySet.ParseManyBodyTerms()) return false;
    453523
     524  EnergyMatrix EnergyFragments;
     525  ForceMatrix ForceFragments;
    454526  if (!EnergyFragments.AllocateMatrix(Energy.Header, Energy.MatrixCounter, Energy.RowCounter, Energy.ColumnCounter)) return false;
    455527  if (!ForceFragments.AllocateMatrix(Force.Header, Force.MatrixCounter, Force.RowCounter, Force.ColumnCounter)) return false;
Note: See TracChangeset for help on using the changeset viewer.