source: src/Potentials/Specifics/ConstantPotential.cpp@ 1e565c

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
Last change on this file since 1e565c was 8203ce8, checked in by Frederik Heber <heber@…>, 12 years ago

Added ConstantPotential to fit a non-zero offset in potential energy.

  • Property mode set to 100644
File size: 5.2 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2012 University of Bonn. All rights reserved.
5 * Please see the COPYING file or "Copyright notice" in builder.cpp for details.
6 *
7 *
8 * This file is part of MoleCuilder.
9 *
10 * MoleCuilder is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * MoleCuilder is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24/*
25 * ConstantPotential.cpp
26 *
27 * Created on: May 09, 2013
28 * Author: heber
29 */
30
31
32// include config.h
33#ifdef HAVE_CONFIG_H
34#include <config.h>
35#endif
36
37#include "CodePatterns/MemDebug.hpp"
38
39#include "ConstantPotential.hpp"
40
41#include <boost/assign/list_of.hpp> // for 'map_list_of()'
42#include <boost/bind.hpp>
43#include <boost/lambda/lambda.hpp>
44#include <cmath>
45#include <string>
46
47#include "CodePatterns/Assert.hpp"
48
49#include "FunctionApproximation/Extractors.hpp"
50#include "FunctionApproximation/TrainingData.hpp"
51#include "Potentials/helpers.hpp"
52#include "Potentials/ParticleTypeCheckers.hpp"
53
54class Fragment;
55
56// static definitions
57const ConstantPotential::ParameterNames_t
58ConstantPotential::ParameterNames =
59 boost::assign::list_of<std::string>
60 ("energy_offset") //
61 ;
62const std::string ConstantPotential::potential_token("constant");
63
64ConstantPotential::ConstantPotential(
65 const ParticleTypes_t &_ParticleTypes
66 ) :
67 EmpiricalPotential(_ParticleTypes),
68 params(parameters_t(MAXPARAMS, 0.))
69{
70 // have some decent defaults for parameter_derivative checking
71 params[energy_offset] = 0.1;
72}
73
74ConstantPotential::ConstantPotential(
75 const ParticleTypes_t &_ParticleTypes,
76 const double _energy_offset) :
77 EmpiricalPotential(_ParticleTypes),
78 params(parameters_t(MAXPARAMS, 0.))
79{
80 params[energy_offset] = _energy_offset;
81}
82
83void ConstantPotential::setParameters(const parameters_t &_params)
84{
85 const size_t paramsDim = _params.size();
86 ASSERT( paramsDim <= getParameterDimension(),
87 "ConstantPotential::setParameters() - we need not more than "
88 +toString(getParameterDimension())+" parameters.");
89 for(size_t i=0;i<paramsDim;++i)
90 params[i] = _params[i];
91
92#ifndef NDEBUG
93 parameters_t check_params(getParameters());
94 check_params.resize(paramsDim); // truncate to same size
95 ASSERT( check_params == _params,
96 "ConstantPotential::setParameters() - failed, mismatch in to be set "
97 +toString(_params)+" and set "+toString(check_params)+" params.");
98#endif
99}
100
101ConstantPotential::results_t
102ConstantPotential::operator()(
103 const arguments_t &arguments
104 ) const
105{
106 ASSERT( arguments.size() == 0,
107 "ConstantPotential::operator() - requires no argument.");
108 ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypes(
109 arguments, getParticleTypes()),
110 "ConstantPotential::operator() - types don't match with ones in arguments.");
111 const result_t result = params[energy_offset];
112 return std::vector<result_t>(1, result);
113}
114
115ConstantPotential::derivative_components_t
116ConstantPotential::derivative(
117 const arguments_t &arguments
118 ) const
119{
120 ASSERT( arguments.size() == 0,
121 "ConstantPotential::operator() - requires no argument.");
122 ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypes(
123 arguments, getParticleTypes()),
124 "ConstantPotential::operator() - types don't match with ones in arguments.");
125 derivative_components_t result(1, 0.);
126 return result;
127}
128
129ConstantPotential::results_t
130ConstantPotential::parameter_derivative(
131 const arguments_t &arguments,
132 const size_t index
133 ) const
134{
135 ASSERT( arguments.size() == 0,
136 "ConstantPotential::parameter_derivative() - requires no argument.");
137 ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypes(
138 arguments, getParticleTypes()),
139 "ConstantPotential::operator() - types don't match with ones in arguments.");
140 switch (index) {
141 case energy_offset:
142 {
143 // Maple result: 1
144 const result_t result = +1.;
145 return std::vector<result_t>(1, result);
146 break;
147 }
148 default:
149 break;
150 }
151 return std::vector<result_t>(1, 0.);
152}
153
154FunctionModel::extractor_t
155ConstantPotential::getFragmentSpecificExtractor() const
156{
157 Fragment::charges_t charges;
158 charges.resize(getParticleTypes().size());
159 std::transform(getParticleTypes().begin(), getParticleTypes().end(),
160 charges.begin(), boost::lambda::_1);
161 FunctionModel::extractor_t returnfunction =
162 boost::bind(&Extractors::gatherDistancesFromFragment,
163 boost::bind(&Fragment::getPositions, _1),
164 boost::bind(&Fragment::getCharges, _1),
165 charges,
166 _2);
167 return returnfunction;
168}
169
170void
171ConstantPotential::setParametersToRandomInitialValues(
172 const TrainingData &data)
173{
174 params[ConstantPotential::energy_offset] =
175 data.getTrainingOutputAverage()[0];// -1.;
176}
177
Note: See TracBrowser for help on using the repository browser.