source: src/Potentials/Specifics/ConstantPotential.cpp@ d29b31

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 d29b31 was 94453f1, checked in by Frederik Heber <heber@…>, 11 years ago

Added getCoordinator() to EmpiricalPotential interface.

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