Changeset d3d6c6


Ignore:
Timestamp:
Oct 14, 2011, 3:15:32 PM (13 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:
e09d67
Parents:
765f16
git-author:
Frederik Heber <heber@…> (09/28/11 12:58:10)
git-committer:
Frederik Heber <heber@…> (10/14/11 15:15:32)
Message:

Added templated InvertMap function to ease MpqcParser_Parameters::Init().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/MpqcParser_Parameters.cpp

    r765f16 rd3d6c6  
    2121#include <boost/tokenizer.hpp>
    2222#include <string>
     23#include <typeinfo>
    2324
    2425#include "CodePatterns/MemDebug.hpp"
    2526
    2627#include "CodePatterns/Log.hpp"
    27 #include "CodePatterns/Verbose.hpp"
    2828
    2929#include "MpqcParser.hpp"
     
    3737{
    3838  Init();
     39}
     40
     41/** Inverter for the (key, value) pairs in a map.
     42 *
     43 * Basically, we just clear \a invertmap and fill with (value, key).
     44 * \note critial error is thrown when values are not unique in \a realmap.
     45 *
     46 * \param realmap the map to invert
     47 * \param invertmap the map that is cleared and filled with (value, key)
     48 */
     49template <typename MapType, typename InvertMapType>
     50void InvertMap(const MapType &realmap, InvertMapType &invertmap)
     51{
     52  invertmap.clear();
     53  // TODO: throw exception instead of eLog()
     54  std::pair<typename InvertMapType::iterator, bool> inserter;
     55  for (typename MapType::const_iterator iter = realmap.begin();
     56      iter != realmap.end();
     57      ++iter) {
     58    // check uniqueness
     59    const std::pair<typename InvertMapType::iterator, bool> inserter =
     60        invertmap.insert( std::make_pair(iter->second, iter->first) );
     61    if (!inserter.second)
     62      ELOG(0, "InvertMap<"
     63//+std::typeid(realmap).name()+", "+std::typeid(invertmap).name()
     64          << ">() - cannot invert (" << iter->first
     65          << "," << iter->second << "). Key is already present as (" << inserter.first->first
     66          << "," << inserter.first->second << ") in InvertMap.");
     67  }
    3968}
    4069
     
    4978  TheoryNames[MBPT2]="MBPT2";
    5079  TheoryNames[MBPT2_R12]="MBPT2_R12";
    51 
    52   {
    53     // TODO: throw exception instead of eLog()
    54     std::pair<TheoryLookupType::iterator, bool> inserter;
    55     for (TheoryNamesType::iterator iter = TheoryNames.begin();
    56         iter != TheoryNames.end();
    57         ++iter) {
    58       inserter = TheoryLookup.insert( make_pair(iter->second, iter->first) );
    59       if (!inserter.second)
    60         DoeLog(0) && (eLog() << Verbose(0)
    61             << "MpqcParser_Parameters::MpqcParser_Parameters() - Theory name already present: "
    62             << (inserter.first)->second << " and " << iter->first << "!"
    63             << std::endl);
    64     }
    65   }
     80  InvertMap<TheoryNamesType,TheoryLookupType>(TheoryNames,TheoryLookup);
    6681
    6782  // add all integration names
    6883  IntegrationNames[IntegralCints] = "IntegralCints";
    69   {
    70     // TODO: throw exception instead of eLog()
    71     std::pair<IntegrationLookupType::iterator, bool> inserter;
    72     for (IntegrationNamesType::iterator iter = IntegrationNames.begin();
    73         iter != IntegrationNames.end();
    74         ++iter) {
    75       inserter = IntegrationLookup.insert( make_pair(iter->second, iter->first) );
    76       if (!inserter.second)
    77         DoeLog(0) && (eLog() << Verbose(0)
    78             << "MpqcParser_Parameters::MpqcParser_Parameters() - Integration name already present: "
    79             << (inserter.first)->second << " and " << iter->first << "!"
    80             << std::endl);
    81     }
    82   }
     84  InvertMap<IntegrationNamesType,IntegrationLookupType>(IntegrationNames, IntegrationLookup);
    8385
    8486  // have names for all parmaters
     
    9496  ParamNames[integrationParam] = "integration";
    9597  ParamNames[theoryParam] = "theory";
    96 
    97   {
    98     // TODO: throw exception instead of eLog()
    99     std::pair<ParamLookupType::iterator, bool> inserter;
    100     for (ParamNamesType::iterator iter = ParamNames.begin();
    101         iter != ParamNames.end();
    102         ++iter) {
    103       inserter = ParamLookup.insert( make_pair(iter->second, iter->first) );
    104       if (!inserter.second)
    105         DoeLog(0) && (eLog() << Verbose(0)
    106             << "MpqcParser_Parameters::MpqcParser_Parameters() - parameter name already present: "
    107             << (inserter.first)->second << " and " << iter->first << "!"
    108             << std::endl);
    109     }
    110   }
     98  InvertMap<ParamNamesType,ParamLookupType>(ParamNames, ParamLookup);
    11199
    112100  initParameters();
Note: See TracChangeset for help on using the changeset viewer.