source: src/Potentials/SerializablePotential.hpp@ 3400bb

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator 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_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 3400bb was 96c7d2, checked in by Frederik Heber <heber@…>, 10 years ago

MEMFIX: PotentialRegistry's dstor forgot cleanup().

  • also we purge static potential factory and registry instances in cleanup.
  • dstor of SerializablePotential was not virtual.
  • Property mode set to 100644
File size: 5.4 KB
RevLine 
[6efcae]1/*
2 * SerializablePotential.hpp
3 *
4 * Created on: 23.11.2012
5 * Author: heber
6 */
7
8#ifndef SERIALIZABLEPOTENTIAL_HPP_
9#define SERIALIZABLEPOTENTIAL_HPP_
10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16#include <iosfwd>
17#include <vector>
18
19/** SerializablePotential is a potential that can be parsed from and stored to
20 * a .potentials file.
21 *
22 * All required functionality for printing and parsing the set of parameters
23 * is set as virtual functions and have to be implemented specifically, e.g.
24 * -# ParameterNames: Should be static instance as are the same over each
25 * potential type despite although there may be more than one instance.
26 * \note If the parameter name is left empty, the value is neither printed
27 * nor parsed. This may be issued to skip internal parameters (e.g. offset).
28 * -# ParticleTypes: has been implemented here, as is different per instance.
29 *
30 * Specifically, what you need to do when inheriting is:
31 * -# implement getParameters() and setParameters()
32 * -# have some static const ParameterNames_t in your class and implement
33 * getParameterNames() as a getter for it (or any other way you prefer).
34 * The static instance can be easily initialized via boost::assign::list_of.
35 *
36 */
37class SerializablePotential
38{
39public:
40 //!> typedef for particle designation
41 typedef int ParticleType_t;
42 //!> typedef for a vector of particle designations
43 typedef std::vector<ParticleType_t> ParticleTypes_t;
44 //!> typedef for a vector of parameter names
45 typedef std::vector<std::string> ParameterNames_t;
46 //!> typedef for a single parameter degree of freedom of the function
47 typedef double parameter_t;
48 //!> typedef for the whole set of parameters of the function
49 typedef std::vector<parameter_t> parameters_t;
50
51public:
52 SerializablePotential(const ParticleTypes_t &_ParticleTypes) :
53 ParticleTypes(_ParticleTypes)
54 {}
[96c7d2]55 virtual ~SerializablePotential() {}
[6efcae]56
57 /** Return the token name of this specific potential.
58 *
59 * \return token name of the potential
60 */
61 virtual const std::string& getToken() const=0;
62
63 /** Return the name of this specific potential.
64 *
65 * This is required for storage in a Registry. The name is the token name
66 * followed by "_" and the particle types to make it unique.
67 *
68 * \return name of the potential
69 */
70 const std::string getName() const;
71
72
73 /** Getter for the parameters of this model function.
74 *
75 * \return current set of parameters of the model function
76 */
77 virtual parameters_t getParameters() const=0;
78
79 /** Getter for the number of parameters of this model function.
80 *
81 * \return number of parameters
82 */
83 virtual size_t getParameterDimension() const=0;
84
85 /** Returns a vector of particle designations.
86 *
87 * These designations denote the particle types for which this potential
88 * has been parametrized.
89 *
90 * \return vector of particle type
91 */
92 const ParticleTypes_t& getParticleTypes() const
93 { return ParticleTypes; }
94
95 /** Returns a vector of parameter names.
96 *
97 * This is required from the specific implementation
98 *
99 * \return vector of strings containing parameter names
100 */
101 virtual const ParameterNames_t& getParameterNames() const=0;
102
103 /** Returns the index associated to a specific parameter \a _name.
104 *
105 * \param _name parameter name to look up index for
106 * \return index to the given \a _name or (size_t)-1 if none found
107 */
108 const size_t getParameterIndex(const std::string &_name) const;
109
[3d2559]110 /** Print parameters to given stream \a ost.
111 *
112 * These are virtual functions to allow for overriding and hence
113 * changing the default behavior.
114 *
115 * @param ost stream to print to
116 */
117 virtual void stream_to(std::ostream &ost) const;
118
119 /** Parse parameters from given stream \a ist.
120 *
121 * These are virtual functions to allow for overriding and hence
122 * changing the default behavior.
123 *
124 * @param ist stream to parse from
125 */
126 virtual void stream_from(std::istream &ist);
127
[6efcae]128protected:
129
130 /** Setter for the parameters of the model function.
131 *
132 * \param params set of parameters to set
133 */
134 virtual void setParameters(const parameters_t &params)=0;
135
136 /** Setter for a given particle type.
137 *
138 * \param index index of type to set
139 * \param _designation type to set to
140 */
141 void setParticleType(const size_t index, const ParticleType_t& _designation)
142 {
[5f0c60]143 if (ParticleTypes.size() <= index)
144 const_cast<ParticleTypes_t &>(ParticleTypes).resize(index+1);
[6efcae]145 const_cast<ParticleTypes_t &>(ParticleTypes)[index] = _designation;
146 }
147
[713888]148protected:
149 /** Default constructor for class EmpiricalPotential.
150 *
151 * Callable only by derived functions.
152 *
153 */
154 SerializablePotential();
155
[6efcae]156private:
157
158 //!> static definition of the particle types for this potential
159 const ParticleTypes_t ParticleTypes;
160};
161
162/** Output operations stores .potentials line containing these parameters
163 * coefficients and designations.
164 *
165 * \param ost output stream to print to
166 * \param potential potential whose coefficients to print
167 * \return output stream for concatenation
168 */
169std::ostream& operator<<(std::ostream &ost, const SerializablePotential &potential);
170
171/** Input operation parses coefficients from a given line of a .potentials
172 * file.
173 *
174 * \param ist input stream to parse from
175 * \param potential potential to set
176 * \return input stream for concatenation
177 */
178std::istream& operator>>(std::istream &ist, SerializablePotential &potential);
179
180
181#endif /* SERIALIZABLEPOTENTIAL_HPP_ */
Note: See TracBrowser for help on using the repository browser.