source: src/Potentials/SerializablePotential.hpp@ 6efcae

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 6efcae was 6efcae, checked in by Frederik Heber <heber@…>, 12 years ago

SerializablePotential is new type to be stored in PotentialRegistry.

  • added new class SerializablePotential with operator<<() and ..>>() and a a set of virtual functions to be implemented in deriving classes.
  • added unit test SerializablePotentialUnitTest and mock implementation of such a SerializablePotential.
  • added exceptions, thrown when parsing of potential containing line fails.
  • NOTE: empty name/key of a parameter are not printed on output.
  • Property mode set to 100644
File size: 5.0 KB
Line 
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{
39 //!> grant operator access to private functions
40 friend std::ostream& operator<<(std::ostream &ost, const SerializablePotential &potential);
41 //!> grant operator access to private functions
42 friend std::istream& operator>>(std::istream &ost, SerializablePotential &potential);
43
44public:
45 //!> typedef for particle designation
46 typedef int ParticleType_t;
47 //!> typedef for a vector of particle designations
48 typedef std::vector<ParticleType_t> ParticleTypes_t;
49 //!> typedef for a vector of parameter names
50 typedef std::vector<std::string> ParameterNames_t;
51 //!> typedef for a single parameter degree of freedom of the function
52 typedef double parameter_t;
53 //!> typedef for the whole set of parameters of the function
54 typedef std::vector<parameter_t> parameters_t;
55
56public:
57 SerializablePotential(const ParticleTypes_t &_ParticleTypes) :
58 ParticleTypes(_ParticleTypes)
59 {}
60 ~SerializablePotential() {}
61
62 /** Return the token name of this specific potential.
63 *
64 * \return token name of the potential
65 */
66 virtual const std::string& getToken() const=0;
67
68 /** Return the name of this specific potential.
69 *
70 * This is required for storage in a Registry. The name is the token name
71 * followed by "_" and the particle types to make it unique.
72 *
73 * \return name of the potential
74 */
75 const std::string getName() const;
76
77
78 /** Getter for the parameters of this model function.
79 *
80 * \return current set of parameters of the model function
81 */
82 virtual parameters_t getParameters() const=0;
83
84 /** Getter for the number of parameters of this model function.
85 *
86 * \return number of parameters
87 */
88 virtual size_t getParameterDimension() const=0;
89
90 /** Returns a vector of particle designations.
91 *
92 * These designations denote the particle types for which this potential
93 * has been parametrized.
94 *
95 * \return vector of particle type
96 */
97 const ParticleTypes_t& getParticleTypes() const
98 { return ParticleTypes; }
99
100 /** Returns a vector of parameter names.
101 *
102 * This is required from the specific implementation
103 *
104 * \return vector of strings containing parameter names
105 */
106 virtual const ParameterNames_t& getParameterNames() const=0;
107
108 /** Returns the index associated to a specific parameter \a _name.
109 *
110 * \param _name parameter name to look up index for
111 * \return index to the given \a _name or (size_t)-1 if none found
112 */
113 const size_t getParameterIndex(const std::string &_name) const;
114
115protected:
116
117 /** Setter for the parameters of the model function.
118 *
119 * \param params set of parameters to set
120 */
121 virtual void setParameters(const parameters_t &params)=0;
122
123 /** Setter for a given particle type.
124 *
125 * \param index index of type to set
126 * \param _designation type to set to
127 */
128 void setParticleType(const size_t index, const ParticleType_t& _designation)
129 {
130 const_cast<ParticleTypes_t &>(ParticleTypes).resize(index);
131 const_cast<ParticleTypes_t &>(ParticleTypes)[index] = _designation;
132 }
133
134private:
135
136 //!> static definition of the particle types for this potential
137 const ParticleTypes_t ParticleTypes;
138};
139
140/** Output operations stores .potentials line containing these parameters
141 * coefficients and designations.
142 *
143 * \param ost output stream to print to
144 * \param potential potential whose coefficients to print
145 * \return output stream for concatenation
146 */
147std::ostream& operator<<(std::ostream &ost, const SerializablePotential &potential);
148
149/** Input operation parses coefficients from a given line of a .potentials
150 * file.
151 *
152 * \param ist input stream to parse from
153 * \param potential potential to set
154 * \return input stream for concatenation
155 */
156std::istream& operator>>(std::istream &ist, SerializablePotential &potential);
157
158
159#endif /* SERIALIZABLEPOTENTIAL_HPP_ */
Note: See TracBrowser for help on using the repository browser.