Ignore:
Timestamp:
Feb 25, 2013, 5:28:57 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:
dd8094
Parents:
b17e0f
git-author:
Frederik Heber <heber@…> (11/13/12 13:03:13)
git-committer:
Frederik Heber <heber@…> (02/25/13 17:28:57)
Message:

FIX: SaturationPotential's parameter derivatives seem to be working now.

  • the problem seems to be the fitting itself is no good, maybe fitting Morse and Angle to CH4 at the same time just does not work ...
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Potentials/Specifics/SaturationPotential.cpp

    rb17e0f r2ba2ed  
    4545
    4646SaturationPotential::SaturationPotential(
     47    const double _saturation_cutoff,
    4748    boost::function< std::vector<arguments_t>(const argument_t &, const double)> &_triplefunction) :
    4849  energy_offset(0.),
    4950  triplefunction(_triplefunction),
    50   saturation_cutoff(2.5)
     51  saturation_cutoff(_saturation_cutoff)
    5152{}
    5253
     
    5859    const double _angle_equilibrium_distance,
    5960    const double _all_energy_offset,
     61    const double _saturation_cutoff,
    6062    boost::function< std::vector<arguments_t>(const argument_t &, const double)> &_triplefunction) :
    6163  energy_offset(_all_energy_offset),
    6264  triplefunction(_triplefunction),
    63   saturation_cutoff(2.5)
     65  saturation_cutoff(_saturation_cutoff)
    6466{
    6567  parameters_t morse_params(morse.getParameterDimension());
     
    148150      ++argiter) {
    149151    const argument_t &r_ij = *argiter;
    150     arguments_t args(1, r_ij);
    151     if ((r_ij.indices.first == 0)) { // || (r_ij.indices.second == 0)) {
     152    if ((r_ij.indices.first == 0)) { // first item must be the non-hydrogen
     153      arguments_t args(1, r_ij);
     154
     155      // Morse contribution
    152156      result += morse(args)[0];
    153157      if (result != result)
    154158        ELOG(1, "result is NAN.");
     159
     160      // Angle contribution
    155161      std::vector<arguments_t> triples = triplefunction(r_ij, saturation_cutoff);
     162      args.resize(3, r_ij);
    156163      for (std::vector<arguments_t>::const_iterator iter = triples.begin();
    157164          iter != triples.end(); ++iter) {
    158165        ASSERT( iter->size() == 2,
    159             "ManyBodyPotential_Tersoff::function_derivative_c() - the triples result must contain exactly two distances.");
     166            "SaturationPotential::function_derivative_c() - the triples result must contain exactly two distances.");
    160167        const argument_t &r_ik = (*iter)[0];
    161168        const argument_t &r_jk = (*iter)[1];
    162         arguments_t args;
    163         args.push_back(r_ij);
    164         args.push_back(r_ik);
    165         args.push_back(r_jk);
    166         result += .5 * angle(args)[0];
     169        args[1] = r_ik;
     170        args[2] = r_jk;
     171        result += .5*angle(args)[0];  // as we have all distances we get both jk and kj
    167172        if (result != result)
    168173          ELOG(1, "result is NAN.");
     
    191196{
    192197  double result = 0.;
    193   for(arguments_t::const_iterator argiter = arguments.begin();
    194       argiter != arguments.end();
    195       ++argiter) {
    196     const argument_t &r_ij = *argiter;
    197     arguments_t args(1, r_ij);
    198     if ((r_ij.indices.first == 0)) { // || (r_ij.indices.second == 0)) {
    199       switch (index) {
    200         case morse_spring_constant:
    201         {
    202           result += morse.parameter_derivative(args, PairPotential_Morse::spring_constant)[0];
    203           break;
    204         }
    205         case morse_equilibrium_distance:
    206         {
    207           result += morse.parameter_derivative(args, PairPotential_Morse::equilibrium_distance)[0];
    208           break;
    209         }
    210         case morse_dissociation_energy:
    211         {
    212           result += morse.parameter_derivative(args, PairPotential_Morse::dissociation_energy)[0];
    213           break;
    214         }
    215         default:
    216         {
    217           std::vector<arguments_t> triples = triplefunction(r_ij, saturation_cutoff);
    218           for (std::vector<arguments_t>::const_iterator iter = triples.begin();
    219               iter != triples.end(); ++iter) {
    220             ASSERT( iter->size() == 2,
    221                 "ManyBodyPotential_Tersoff::function_derivative_c() - the triples result must contain exactly two distances.");
    222             const argument_t &r_ik = (*iter)[0];
    223             const argument_t &r_jk = (*iter)[1];
    224             arguments_t args;
    225             args.push_back(r_ij);
    226             args.push_back(r_ik);
    227             args.push_back(r_jk);
    228             switch (index) {
    229               case angle_spring_constant:
    230               {
    231                 result += .5*angle.parameter_derivative(args, PairPotential_Angle::spring_constant)[0];
    232                 break;
     198  if (index == all_energy_offset) {
     199    result = 1.;
     200  } else {
     201    for(arguments_t::const_iterator argiter = arguments.begin();
     202        argiter != arguments.end();
     203        ++argiter) {
     204      const argument_t &r_ij = *argiter;
     205      if ((r_ij.indices.first == 0)) { // first item must be the non-hydrogen
     206        arguments_t args(1, r_ij);
     207        switch (index) {
     208          case morse_spring_constant:
     209          {
     210            result += morse.parameter_derivative(args, PairPotential_Morse::spring_constant)[0];
     211            break;
     212          }
     213          case morse_equilibrium_distance:
     214          {
     215            result += morse.parameter_derivative(args, PairPotential_Morse::equilibrium_distance)[0];
     216            break;
     217          }
     218          case morse_dissociation_energy:
     219          {
     220            result += morse.parameter_derivative(args, PairPotential_Morse::dissociation_energy)[0];
     221            break;
     222          }
     223          default:
     224          {
     225            args.resize(3, r_ij);
     226            std::vector<arguments_t> triples = triplefunction(r_ij, saturation_cutoff);
     227            for (std::vector<arguments_t>::const_iterator iter = triples.begin();
     228                iter != triples.end(); ++iter) {
     229              ASSERT( iter->size() == 2,
     230                  "SaturationPotential::parameter_derivative() - the triples result must contain exactly two distances.");
     231              const argument_t &r_ik = (*iter)[0];
     232              ASSERT( r_ik.indices.first == r_ij.indices.first,
     233                  "SaturationPotential::parameter_derivative() - i not same in ij, ik.");
     234              const argument_t &r_jk = (*iter)[1];
     235              ASSERT( r_jk.indices.first == r_ij.indices.second,
     236                  "SaturationPotential::parameter_derivative() - j not same in ij, jk.");
     237              ASSERT( r_ik.indices.second == r_jk.indices.second,
     238                  "SaturationPotential::parameter_derivative() - k not same in ik, jk.");
     239              args[1] = r_ik;
     240              args[2] = r_jk;
     241              switch (index) {   // .5 due to we have all distances we get both jk and kj
     242                case angle_spring_constant:
     243                {
     244                  result += .5*angle.parameter_derivative(args, PairPotential_Angle::spring_constant)[0];
     245                  break;
     246                }
     247                case angle_equilibrium_distance:
     248                {
     249                  result += .5*angle.parameter_derivative(args, PairPotential_Angle::equilibrium_distance)[0];
     250                  break;
     251                }
     252                default:
     253                  break;
    233254              }
    234               case angle_equilibrium_distance:
    235               {
    236                 result += .5*angle.parameter_derivative(args, PairPotential_Angle::equilibrium_distance)[0];
    237                 break;
    238               }
    239               default:
    240                 break;
    241255            }
     256            break;
    242257          }
    243258        }
     
    245260    }
    246261  }
    247   if (index == all_energy_offset)
    248     result = 1.;
    249262  return SaturationPotential::results_t(1, result);
    250263}
Note: See TracChangeset for help on using the changeset viewer.