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:
2ba2ed
Parents:
e920d3d
git-author:
Frederik Heber <heber@…> (11/13/12 13:01:48)
git-committer:
Frederik Heber <heber@…> (02/25/13 17:28:57)
Message:

Using getFirstGraphwithTimesSpecificElement() in main() of LevMartester.

  • Angle, Morse, and Saturation fitting now use this function to obtain the representative graph.
  • added check whether returned graph is empty, then fitting part is skipped.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/LevMartester.cpp

    re920d3d rb17e0f  
    7575
    7676using namespace boost::assign;
    77 
    78 HomologyGraph getFirstGraphWithThreeCarbons(const HomologyContainer &homologies)
    79 {
    80   FragmentNode SaturatedCarbon(6,4); // carbon has atomic number 6 and should have 4 bonds for C3H8
    81   FragmentNode DanglingCarbon(6,3); // carbon has atomic number 6 and should have 3 pure bonds for C3H8
    82   for (HomologyContainer::container_t::const_iterator iter =
    83       homologies.begin(); iter != homologies.end(); ++iter) {
    84     if ((iter->first.hasNode(SaturatedCarbon,2)) && (iter->first.hasNode(DanglingCarbon,1)))
    85       return iter->first;
    86   }
    87   return HomologyGraph();
    88 }
    89 
    90 HomologyGraph getFirstGraphWithTwoCarbons(const HomologyContainer &homologies)
    91 {
    92   FragmentNode SaturatedCarbon(6,3); // carbon has atomic number 6 and should have 4 bonds for C2H6
    93   for (HomologyContainer::container_t::const_iterator iter =
    94       homologies.begin(); iter != homologies.end(); ++iter) {
    95     if (iter->first.hasNode(SaturatedCarbon,2))
    96       return iter->first;
    97   }
    98   return HomologyGraph();
    99 }
    100 
    101 HomologyGraph getFirstGraphWithOneCarbon(const HomologyContainer &homologies)
    102 {
    103   FragmentNode SaturatedCarbon(6,2); // carbon has atomic number 6 and has 3 bonds (to other Hs)
    104   for (HomologyContainer::container_t::const_iterator iter =
    105       homologies.begin(); iter != homologies.end(); ++iter) {
    106     if (iter->first.hasNode(SaturatedCarbon,1))
    107       return iter->first;
    108   }
    109   return HomologyGraph();
    110 }
    11177
    11278HomologyGraph getFirstGraphwithTimesSpecificElement(
     
    247213  {
    248214    // then we ought to pick the right HomologyGraph ...
    249     const HomologyGraph graph = getFirstGraphWithThreeCarbons(homologies);
    250     LOG(1, "First representative graph containing three saturated carbons is " << graph << ".");
    251 
    252     // Afterwards we go through all of this type and gather the distance and the energy value
    253     TrainingData AngleData(
    254         boost::bind(&Extractors::reorderArgumentsByIncreasingDistance,
    255             boost::bind(&Extractors::gatherAllSymmetricDistanceArguments,
    256                 boost::bind(&Extractors::gatherPositionOfTuples,
    257                     _1, Fragment::charges_t(3,6.)
    258                 ), _2 // gather carbon triples
     215    const HomologyGraph graph = getFirstGraphwithTimesSpecificElement(homologies,6,3);
     216    if (graph != HomologyGraph()) {
     217      LOG(1, "First representative graph containing three saturated carbons is " << graph << ".");
     218
     219      // Afterwards we go through all of this type and gather the distance and the energy value
     220      TrainingData AngleData(
     221          boost::bind(&Extractors::reorderArgumentsByIncreasingDistance,
     222              boost::bind(&Extractors::gatherAllSymmetricDistanceArguments,
     223                  boost::bind(&Extractors::gatherPositionOfTuples,
     224                      _1, Fragment::charges_t(3,6.)
     225                  ), _2 // gather carbon triples
     226              )
    259227            )
    260           )
    261         );
    262     AngleData(homologies.getHomologousGraphs(graph));
    263     LOG(1, "INFO: I gathered the following training data:\n" <<
    264         _detail::writeDistanceEnergyTable(AngleData.getDistanceEnergyTable()));
    265     // NOTICE that distance are in bohrradi as they come from MPQC!
    266 
    267     // now perform the function approximation by optimizing the model function
    268     FunctionModel::parameters_t params(PairPotential_Angle::MAXPARAMS, 0.);
    269     params[PairPotential_Angle::energy_offset] =  -1.;
    270     params[PairPotential_Angle::spring_constant] =  1.;
    271     params[PairPotential_Angle::equilibrium_distance] =  0.2;
    272     PairPotential_Angle angle;
    273     LOG(0, "INFO: Initial parameters are " << params << ".");
    274     angle.setParameters(params);
    275     FunctionModel &model = angle;
    276     FunctionApproximation approximator(AngleData, model);
    277     if (model.isBoxConstraint() && approximator.checkParameterDerivatives())
    278       approximator(FunctionApproximation::ParameterDerivative);
    279     else
    280       ELOG(0, "We require parameter derivatives for a box constraint minimization.");
    281     params = model.getParameters();
    282 
    283     LOG(0, "RESULT: Best parameters are " << params << ".");
     228          );
     229      AngleData(homologies.getHomologousGraphs(graph));
     230      LOG(1, "INFO: I gathered the following training data: " << AngleData);
     231      // NOTICE that distance are in bohrradi as they come from MPQC!
     232
     233      // now perform the function approximation by optimizing the model function
     234      FunctionModel::parameters_t params(PairPotential_Angle::MAXPARAMS, 0.);
     235      params[PairPotential_Angle::energy_offset] =  -1.;
     236      params[PairPotential_Angle::spring_constant] =  1.;
     237      params[PairPotential_Angle::equilibrium_distance] =  0.2;
     238      PairPotential_Angle angle;
     239      LOG(0, "INFO: Initial parameters are " << params << ".");
     240      angle.setParameters(params);
     241      FunctionModel &model = angle;
     242      FunctionApproximation approximator(AngleData, model);
     243      if (model.isBoxConstraint() && approximator.checkParameterDerivatives())
     244        approximator(FunctionApproximation::ParameterDerivative);
     245      else {
     246        ELOG(0, "We require parameter derivatives for a box constraint minimization.");
     247        return 1;
     248      }
     249      params = model.getParameters();
     250
     251      LOG(0, "RESULT: Best parameters are " << params << ".");
     252    }
    284253  }
    285254
     
    287256  {
    288257    // then we ought to pick the right HomologyGraph ...
    289     const HomologyGraph graph = getFirstGraphWithTwoCarbons(homologies);
    290     LOG(1, "First representative graph containing two saturated carbons is " << graph << ".");
    291 
    292     // Afterwards we go through all of this type and gather the distance and the energy value
    293     TrainingData MorseData(
    294         boost::bind(&Extractors::gatherAllSymmetricDistanceArguments,
    295             boost::bind(&Extractors::gatherPositionOfTuples,
    296                 _1, Fragment::charges_t(2,6.)
    297             ), _2 // gather first carbon pair
    298           )
    299         );
    300     MorseData(homologies.getHomologousGraphs(graph));
    301     LOG(1, "INFO: I gathered the following training data:\n" <<
    302         _detail::writeDistanceEnergyTable(MorseData.getDistanceEnergyTable()));
    303     // NOTICE that distance are in bohrradi as they come from MPQC!
    304 
    305     // now perform the function approximation by optimizing the model function
    306     FunctionModel::parameters_t params(PairPotential_Morse::MAXPARAMS, 0.);
    307     params[PairPotential_Morse::dissociation_energy] =  0.5;
    308     params[PairPotential_Morse::energy_offset] =  -1.;
    309     params[PairPotential_Morse::spring_constant] =  1.;
    310     params[PairPotential_Morse::equilibrium_distance] =  2.9;
    311     PairPotential_Morse morse;
    312     morse.setParameters(params);
    313     FunctionModel &model = morse;
    314     FunctionApproximation approximator(MorseData, model); // we only give CC distance, hence 1 input dim
    315     if (model.isBoxConstraint() && approximator.checkParameterDerivatives())
    316       approximator(FunctionApproximation::ParameterDerivative);
    317     else
    318       ELOG(0, "We require parameter derivatives for a box constraint minimization.");
    319     params = model.getParameters();
    320 
    321     LOG(0, "RESULT: Best parameters are " << params << ".");
     258    const HomologyGraph graph = getFirstGraphwithTimesSpecificElement(homologies,6,2);
     259    if (graph != HomologyGraph()) {
     260      LOG(1, "First representative graph containing two saturated carbons is " << graph << ".");
     261
     262      // Afterwards we go through all of this type and gather the distance and the energy value
     263      TrainingData MorseData(
     264          boost::bind(&Extractors::gatherAllSymmetricDistanceArguments,
     265              boost::bind(&Extractors::gatherPositionOfTuples,
     266                  _1, Fragment::charges_t(2,6.)
     267              ), _2 // gather first carbon pair
     268            )
     269          );
     270      MorseData(homologies.getHomologousGraphs(graph));
     271      LOG(1, "INFO: I gathered the following training data: " << MorseData);
     272      // NOTICE that distance are in bohrradi as they come from MPQC!
     273
     274      // now perform the function approximation by optimizing the model function
     275      FunctionModel::parameters_t params(PairPotential_Morse::MAXPARAMS, 0.);
     276      params[PairPotential_Morse::dissociation_energy] =  0.5;
     277      params[PairPotential_Morse::energy_offset] =  -1.;
     278      params[PairPotential_Morse::spring_constant] =  1.;
     279      params[PairPotential_Morse::equilibrium_distance] =  2.9;
     280      PairPotential_Morse morse;
     281      LOG(0, "INFO: Initial parameters are " << params << ".");
     282      morse.setParameters(params);
     283      FunctionModel &model = morse;
     284      FunctionApproximation approximator(MorseData, model); // we only give CC distance, hence 1 input dim
     285      if (model.isBoxConstraint() && approximator.checkParameterDerivatives())
     286        approximator(FunctionApproximation::ParameterDerivative);
     287      else {
     288        ELOG(0, "We require parameter derivatives for a box constraint minimization.");
     289        return 1;
     290      }
     291      params = model.getParameters();
     292
     293      LOG(0, "RESULT: Best parameters are " << params << ".");
     294    }
    322295  }
    323296
     
    326299  {
    327300    // then we ought to pick the right HomologyGraph ...
    328     const HomologyGraph graph = getFirstGraphWithOneCarbon(homologies);
    329     LOG(1, "First representative graph containing one saturated carbon is " << graph << ".");
    330 
    331     // Afterwards we go through all of this type and gather the distance and the energy value
    332     TrainingData TersoffData(
    333         TrainingData::extractor_t(&Extractors::gatherAllDistances) // gather first carbon pair
    334         );
    335     TersoffData( homologies.getHomologousGraphs(graph) );
    336     LOG(1, "INFO: I gathered the following training data:\n" <<
    337         _detail::writeDistanceEnergyTable(TersoffData.getDistanceEnergyTable()));
    338     // NOTICE that distance are in bohrradi as they come from MPQC!
    339 
    340     // now perform the function approximation by optimizing the model function
    341     boost::function< std::vector<FunctionModel::arguments_t>(const argument_t &, const double)> triplefunction =
    342         boost::bind(&getTripleFromArgument, boost::cref(TersoffData.getTrainingInputs()), _1, _2);
    343     srand((unsigned)time(0)); // seed with current time
    344     LOG(0, "INFO: Initial parameters are " << params << ".");
    345 
    346     SaturationPotential saturation(triplefunction);
    347     saturation.setParameters(params);
    348     FunctionModel &model = saturation;
    349     FunctionApproximation approximator(TersoffData, model); // CH4 has 5 atoms, hence 5*4/2 distances
    350     if (model.isBoxConstraint() && approximator.checkParameterDerivatives())
    351       approximator(FunctionApproximation::ParameterDerivative);
    352     else
    353       ELOG(0, "We require parameter derivatives for a box constraint minimization.");
    354 
    355     params = model.getParameters();
    356 
    357     LOG(0, "RESULT: Best parameters are " << params << ".");
    358 
    359 //    std::cout << "\tsaturationparticle:";
    360 //    std::cout << "\tparticle_type=C,";
    361 //    std::cout << "\tA=" << params[SaturationPotential::A] << ",";
    362 //    std::cout << "\tB=" << params[SaturationPotential::B] << ",";
    363 //    std::cout << "\tlambda=" << params[SaturationPotential::lambda] << ",";
    364 //    std::cout << "\tmu=" << params[SaturationPotential::mu] << ",";
    365 //    std::cout << "\tbeta=" << params[SaturationPotential::beta] << ",";
    366 //    std::cout << "\tn=" << params[SaturationPotential::n] << ",";
    367 //    std::cout << "\tc=" << params[SaturationPotential::c] << ",";
    368 //    std::cout << "\td=" << params[SaturationPotential::d] << ",";
    369 //    std::cout << "\th=" << params[SaturationPotential::h] << ",";
    370 ////    std::cout << "\toffset=" << params[SaturationPotential::offset] << ",";
    371 //    std::cout << "\tR=" << saturation.R << ",";
    372 //    std::cout << "\tS=" << saturation.S << ";";
    373 //    std::cout << std::endl;
    374 
    375     // check L2 and Lmax error against training set
    376     LOG(1, "INFO: L2sum = " << TersoffData.getL2Error(model)
    377         << ", LMax = " << TersoffData.getLMaxError(model) << ".");
     301    const HomologyGraph graph = getFirstGraphwithTimesSpecificElement(homologies,6,1);
     302    if (graph != HomologyGraph()) {
     303      LOG(1, "First representative graph containing one saturated carbon is " << graph << ".");
     304
     305      // Afterwards we go through all of this type and gather the distance and the energy value
     306      Fragment::charges_t SaturatedCarbon;
     307      SaturatedCarbon += 6.,1.;
     308      TrainingData TersoffData(
     309//          boost::bind(&Extractors::gatherAllSymmetricDistanceArguments,
     310//              boost::bind(&Extractors::gatherPositionOfTuples,
     311//                  _1, boost::cref(SaturatedCarbon)
     312//              ), _2
     313//            )
     314//          );
     315          TrainingData::extractor_t(&Extractors::gatherAllDistances) // gather first carbon pair
     316          );
     317      TersoffData( homologies.getHomologousGraphs(graph) );
     318      LOG(1, "INFO: I gathered the following training data: " << TersoffData);
     319      // NOTICE that distance are in bohrradi as they come from MPQC!
     320
     321      // now perform the function approximation by optimizing the model function
     322      boost::function< std::vector<FunctionModel::arguments_t>(const argument_t &, const double)> triplefunction =
     323          boost::bind(&getTripleFromArgument, boost::cref(TersoffData.getTrainingInputs()), _1, _2);
     324      srand((unsigned)time(0)); // seed with current time
     325      params[SaturationPotential::all_energy_offset] = 1e+1*rand()/(double)RAND_MAX;//3.487900e+00;
     326      params[SaturationPotential::morse_spring_constant] = 1e+1*rand()/(double)RAND_MAX;//1.393600e+03;
     327      params[SaturationPotential::morse_equilibrium_distance] = 1e+1*rand()/(double)RAND_MAX;//3.467000e+02;
     328      params[SaturationPotential::morse_dissociation_energy] = 1e+1*rand()/(double)RAND_MAX;//3.487900e+00;
     329//      params[SaturationPotential::angle_spring_constant] = 1e+1*rand()/(double)RAND_MAX;//3.487900e+00;
     330//      params[SaturationPotential::angle_equilibrium_distance] = 2e+0*rand()/(double)RAND_MAX - 1.;//3.487900e+00;
     331      LOG(0, "INFO: Initial parameters are " << params << ".");
     332
     333      SaturationPotential saturation(triplefunction);
     334      saturation.setParameters(params);
     335      FunctionModel &model = saturation;
     336      FunctionApproximation approximator(TersoffData, model); // CH4 has 5 atoms, hence 5*4/2 distances
     337      if (model.isBoxConstraint() && approximator.checkParameterDerivatives())
     338        approximator(FunctionApproximation::ParameterDerivative);
     339      else {
     340        ELOG(0, "We require parameter derivatives for a box constraint minimization.");
     341        return 1;
     342      }
     343
     344      params = model.getParameters();
     345      LOG(0, "RESULT: Best parameters are " << params << ".");
     346
     347  //    std::cout << "\tsaturationparticle:";
     348  //    std::cout << "\tparticle_type=C,";
     349  //    std::cout << "\tA=" << params[SaturationPotential::A] << ",";
     350  //    std::cout << "\tB=" << params[SaturationPotential::B] << ",";
     351  //    std::cout << "\tlambda=" << params[SaturationPotential::lambda] << ",";
     352  //    std::cout << "\tmu=" << params[SaturationPotential::mu] << ",";
     353  //    std::cout << "\tbeta=" << params[SaturationPotential::beta] << ",";
     354  //    std::cout << "\tn=" << params[SaturationPotential::n] << ",";
     355  //    std::cout << "\tc=" << params[SaturationPotential::c] << ",";
     356  //    std::cout << "\td=" << params[SaturationPotential::d] << ",";
     357  //    std::cout << "\th=" << params[SaturationPotential::h] << ",";
     358  ////    std::cout << "\toffset=" << params[SaturationPotential::offset] << ",";
     359  //    std::cout << "\tR=" << saturation.R << ",";
     360  //    std::cout << "\tS=" << saturation.S << ";";
     361  //    std::cout << std::endl;
     362
     363      // check L2 and Lmax error against training set
     364      LOG(1, "INFO: L2sum = " << TersoffData.getL2Error(model)
     365          << ", LMax = " << TersoffData.getLMaxError(model) << ".");
     366    }
     367
    378368  }
    379369
Note: See TracChangeset for help on using the changeset viewer.