Changeset 7e5b94 for src


Ignore:
Timestamp:
Jul 8, 2013, 2:22:02 PM (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:
1e565c
Parents:
cf4905
git-author:
Frederik Heber <heber@…> (05/09/13 13:21:58)
git-committer:
Frederik Heber <heber@…> (07/08/13 14:22:02)
Message:

CompoundPotential now combines ConstantPotential and PairPotential_Morse successfully.

  • we set PairPotential_Morse::energy_offset to 0 as default value, but we need to remove the offsets fully from all potentials.
Location:
src/Potentials
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Potentials/CompoundPotential.cpp

    rcf4905 r7e5b94  
    7676    Extractors::elementcounts_t counts_per_charge =
    7777        Extractors::_detail::getElementCounts(charges);
    78     ASSERT( !counts_per_charge.empty(),
    79         "getFirstGraphwithSpecifiedElements() - charge counts are empty?");
     78//    ASSERT( !counts_per_charge.empty(),
     79//        "getFirstGraphwithSpecifiedElements() - charge counts are empty?");
    8080    LOG(2, "DEBUG: counts_per_charge is " << counts_per_charge << ".");
    8181
     
    120120      if (dim < model_dim) {
    121121        std::copy(iter, iter+dim, std::back_inserter(subparams));
     122        iter += dim;
    122123        dim = 0;
    123124      } else {
    124125        std::copy(iter, iter+model_dim, std::back_inserter(subparams));
     126        iter += model_dim;
    125127        dim -= model_dim;
    126128      }
     
    166168}
    167169
     170std::vector<CompoundPotential::arguments_t> CompoundPotential::splitUpArgumentsByModels(
     171    const arguments_t &arguments) const
     172{
     173  std::vector<arguments_t> partial_args(models.size());
     174  std::vector<arguments_t>::iterator partialiter = partial_args.begin();
     175  arguments_t::const_iterator argiter = arguments.begin();
     176  BOOST_FOREACH( const SerializablePotential::ParticleTypes_t &types, particletypes_per_model) {
     177    // we always expect N(N-1)/2 distances for N particle types
     178    arguments_t::const_iterator enditer = argiter+(types.size()*(types.size()-1)/2);
     179    ASSERT( argiter != arguments.end(),
     180        "CompoundPotential::splitUpArgumentsByModels() - incorrect number of arguments.");
     181    std::copy(argiter, enditer, std::back_inserter(*partialiter++));
     182    argiter = enditer;
     183  }
     184  ASSERT( argiter == arguments.end(),
     185      "CompoundPotential::splitUpArgumentsByModels() - incorrect number of arguments.");
     186  return partial_args;
     187}
     188
    168189CompoundPotential::results_t CompoundPotential::operator()(const arguments_t &arguments) const
    169190{
     191  // first, we have to split up the given arguments
     192  std::vector<arguments_t> partial_args =
     193      splitUpArgumentsByModels(arguments);
     194  // then, with each bunch of arguments, we call the specific model
    170195  results_t results(1,0.);
    171196  std::vector<results_t> partial_results(models.size());
    172   std::transform(models.begin(), models.end(), partial_results.begin(),
    173           boost::bind(&FunctionModel::operator(), _1, boost::cref(arguments))
     197  std::transform(
     198      models.begin(), models.end(),
     199      partial_args.begin(),
     200      partial_results.begin(),
     201      boost::bind(&FunctionModel::operator(), _1, _2)
    174202  );
     203  std::for_each(partial_results.begin(), partial_results.end(),
     204      std::cout << (boost::lambda::_1)[0] << "\t");
    175205  std::for_each(partial_results.begin(), partial_results.end(),
    176206      results[0] += (boost::lambda::_1)[0]);
     
    180210CompoundPotential::results_t CompoundPotential::parameter_derivative(const arguments_t &arguments, const size_t index) const
    181211{
     212  // first, we have to split up the given arguments
     213  std::vector<arguments_t> partial_args =
     214      splitUpArgumentsByModels(arguments);
     215  // then, with each bunch of arguments, we call the specific model
    182216  // get parameter dimensions per model
    183217  std::vector<size_t> dimensions(models.size(), 0);
     
    191225  std::vector<size_t>::const_iterator iter =
    192226      std::lower_bound(dimensions.begin(), dimensions.end(), index);
     227
     228  // step forward to same model
    193229  models_t::const_iterator modeliter = models.begin();
    194 
    195   // step forward to same model
    196230  std::advance(modeliter,
     231      std::distance(const_cast<const std::vector<size_t> &>(dimensions).begin(), iter) );
     232  std::vector<arguments_t>::const_iterator argiter = partial_args.begin();
     233  std::advance(argiter,
    197234      std::distance(const_cast<const std::vector<size_t> &>(dimensions).begin(), iter) );
    198235
     
    200237  const size_t indexbase = (iter == dimensions.begin()) ? 0 : *(--iter);
    201238  CompoundPotential::results_t results =
    202       (*modeliter)->parameter_derivative(arguments, index-indexbase);
     239      (*modeliter)->parameter_derivative(*argiter, index-indexbase);
    203240  return results;
    204241}
     
    268305
    269306    returnfunction =
    270           boost::bind(&Extractors::combineArguments,
     307          boost::bind(&Extractors::concatenateArguments,
    271308              boost::bind(returnfunction, _1, _2),
    272309              boost::bind(&Extractors::gatherAllDistancesFromFragment,
  • src/Potentials/CompoundPotential.hpp

    rcf4905 r7e5b94  
    132132
    133133private:
     134  /** Helper function to split up concatenated arguments for operator() calls.
     135   *
     136   * \param arguments arguments to split up
     137   * \return vector of partial arguments
     138   */
     139  std::vector<arguments_t> splitUpArgumentsByModels(const arguments_t &arguments) const;
     140
     141private:
    134142  //!> typedef for internal vector of simultaneously fitted models.
    135143  typedef std::vector<FunctionModel*> models_t;
  • src/Potentials/Specifics/PairPotential_Morse.cpp

    rcf4905 r7e5b94  
    7575  params[equilibrium_distance] = 1.;
    7676  params[dissociation_energy] = 0.1;
    77   params[energy_offset] = 0.1;
     77  params[energy_offset] = 0.;
    7878}
    7979
  • src/Potentials/unittests/CompoundPotentialUnitTest.cpp

    rcf4905 r7e5b94  
    5050#include "Potentials/PotentialFactory.hpp"
    5151#include "Potentials/PotentialRegistry.hpp"
     52#include "Potentials/Specifics/ConstantPotential.hpp"
    5253#include "Potentials/Specifics/PairPotential_Morse.hpp"
    5354
     
    8081    PotentialRegistry::getInstance().registerInstance(morse);
    8182    morse = NULL;
     83  }
     84  // register ConstantPotential with registry
     85  {
     86    ConstantPotential::ParticleTypes_t types;
     87    EmpiricalPotential *constant =
     88        PotentialFactory::getInstance().createInstance(
     89            std::string("constant"), types);
     90    PotentialRegistry::getInstance().registerInstance(constant);
     91    constant = NULL;
    8292  }
    8393
     
    144154  CompoundPotential compound(*graph);
    145155  CompoundPotential::parameters_t params;
    146   params += a,c,D,d;
     156  params += d,a,c,D;
    147157  compound.setParameters(params);
    148158  for (size_t index = 0; index < input.size(); ++index) {
    149159    argument_t arg(argument_t::indices_t(0,1), argument_t::types_t(0,1), input[index]);
     160    const double result = compound( FunctionModel::arguments_t(1,arg) )[0];
    150161    CPPUNIT_ASSERT(
    151162        Helpers::isEqual(
    152163            output[index],
    153             compound( FunctionModel::arguments_t(1,arg) )[0],
     164            result,
    154165            1.e-4/std::numeric_limits<double>::epsilon() // only compare four digits
    155166        )
     
    164175//  CompoundPotential compound(*graph);
    165176//  CompoundPotential::parameters_t params;
    166 //  params += a,c,D,d;
     177//  params += d,a,c,D;
    167178//  compound.setParameters(params);
    168179//  argument_t arg(argument_t::indices_t(0,1), argument_t::types_t(0,1), c);
     180//  const double result = compound.derivative(FunctionModel::arguments_t(1,arg))[0]
    169181//  CPPUNIT_ASSERT(
    170182//      Helpers::isEqual(
    171183//          0.,
    172 //          compound.derivative(
    173 //              FunctionModel::arguments_t(1,arg)
    174 //          )[0],
     184//          result,
    175185//          1.e+6
    176186//      )
     
    185195  CompoundPotential compound(*graph);
    186196  CompoundPotential::parameters_t params;
    187   params += a,c,D,d;
     197  params += d,a,c,D;
    188198  compound.setParameters(params);
    189199  argument_t arg(argument_t::indices_t(0,1), argument_t::types_t(0,1), c);
    190   CPPUNIT_ASSERT(
    191       Helpers::isEqual(
    192           0.,
    193           compound.parameter_derivative(
    194               FunctionModel::arguments_t(1,arg),
    195               0
    196           )[0],
    197           1.e+6
    198       )
    199   );
    200   CPPUNIT_ASSERT(
    201       Helpers::isEqual(
    202           0.,
    203           compound.parameter_derivative(
    204               FunctionModel::arguments_t(1,arg),
    205               1
    206           )[0],
    207           1.e+6
    208       )
    209   );
    210   CPPUNIT_ASSERT(
    211       Helpers::isEqual(
    212           0.,
    213           compound.parameter_derivative(
    214               FunctionModel::arguments_t(1,arg),
    215               2
    216           )[0],
    217           1.e+6
    218       )
    219   );
    220   CPPUNIT_ASSERT(
    221       Helpers::isEqual(
    222           1.,
    223           compound.parameter_derivative(
    224               FunctionModel::arguments_t(1,arg),
    225               3
    226           )[0],
    227           1.e+6
    228       )
    229   );
    230 }
     200  {
     201    const double result =
     202        compound.parameter_derivative(
     203            FunctionModel::arguments_t(1,arg),
     204            0)[0];
     205    CPPUNIT_ASSERT(
     206        Helpers::isEqual(
     207            1.,
     208            result,
     209            1.e+6
     210        )
     211    );
     212  }
     213  {
     214    const double result =
     215        compound.parameter_derivative(
     216            FunctionModel::arguments_t(1,arg),
     217            1)[0];
     218    CPPUNIT_ASSERT(
     219        Helpers::isEqual(
     220            0.,
     221            result,
     222            1.e+6
     223        )
     224    );
     225  }
     226  {
     227    const double result =
     228        compound.parameter_derivative(
     229            FunctionModel::arguments_t(1,arg),
     230            2)[0];
     231    CPPUNIT_ASSERT(
     232        Helpers::isEqual(
     233            0.,
     234            result,
     235            1.e+6
     236        )
     237    );
     238  }
     239  {
     240    const double result =
     241        compound.parameter_derivative(
     242            FunctionModel::arguments_t(1,arg),
     243            3)[0];
     244    CPPUNIT_ASSERT(
     245        Helpers::isEqual(
     246            0.,
     247            result,
     248            1.e+6
     249        )
     250    );
     251  }
     252}
Note: See TracChangeset for help on using the changeset viewer.