source: src/Actions/ValueStorage.cpp@ 9df680

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 9df680 was ad011c, checked in by Frederik Heber <heber@…>, 14 years ago

CodePatterns places all includes now in subfolder CodePatterns/.

  • change all includes accordingly.
  • this was necessary as Helpers and Patterns are not very distinctive names for include folders. Already now, we had a conflict between Helpers from CodePatterns and Helpers from this project.
  • changed compilation test in ax_codepatterns.m4 when changing CodePatterns includes.
  • Property mode set to 100644
File size: 12.3 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * ValueStorage.cpp
10 *
11 * Created on: Jul 22, 2010
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include "CodePatterns/Singleton_impl.hpp"
23
24#include "Actions/OptionTrait.hpp"
25#include "Actions/OptionRegistry.hpp"
26#include "Actions/Values.hpp"
27#include "Actions/ValueStorage.hpp"
28#include "Descriptors/AtomIdDescriptor.hpp"
29#include "Descriptors/MoleculeIdDescriptor.hpp"
30#include "CodePatterns/Assert.hpp"
31#include "CodePatterns/Log.hpp"
32#include "CodePatterns/Verbose.hpp"
33#include "LinearAlgebra/BoxVector.hpp"
34#include "LinearAlgebra/RealSpaceMatrix.hpp"
35#include "LinearAlgebra/Vector.hpp"
36#include "atom.hpp"
37#include "Box.hpp"
38#include "element.hpp"
39#include "molecule.hpp"
40#include "periodentafel.hpp"
41#include "World.hpp"
42
43ValueStorage::ValueStorage() :
44OptionRegistry_instance(OptionRegistry::getInstance())
45{};
46
47ValueStorage::~ValueStorage() {};
48
49
50bool ValueStorage::isCurrentValuePresent(const char *name) const
51{
52 return (CurrentValueMap.find(name) != CurrentValueMap.end());
53}
54
55void ValueStorage::queryCurrentValue(const char * name, const atom * &_T)
56{
57 int atomID = -1;
58 if (typeid( atom *) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
59 if (CurrentValueMap.find(name) == CurrentValueMap.end())
60 throw MissingValueException(__FILE__, __LINE__);
61 atomID = lexical_cast<int>(CurrentValueMap[name].c_str());
62 CurrentValueMap.erase(name);
63 } else if (typeid( const atom *) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
64 if (CurrentValueMap.find(name) == CurrentValueMap.end())
65 throw MissingValueException(__FILE__, __LINE__);
66 atomID = lexical_cast<int>(CurrentValueMap[name].c_str());
67 CurrentValueMap.erase(name);
68 } else
69 throw IllegalTypeException(__FILE__,__LINE__);
70 _T = World::getInstance().getAtom(AtomById(atomID));
71}
72
73void ValueStorage::queryCurrentValue(const char * name, const element * &_T) {
74 int Z = -1;
75 if (typeid(const element *) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
76 if (CurrentValueMap.find(name) == CurrentValueMap.end())
77 throw MissingValueException(__FILE__, __LINE__);
78 Z = lexical_cast<int>(CurrentValueMap[name].c_str());
79 CurrentValueMap.erase(name);
80 } else
81 throw IllegalTypeException(__FILE__,__LINE__);
82 _T = World::getInstance().getPeriode()->FindElement(Z);
83}
84
85void ValueStorage::queryCurrentValue(const char * name, const molecule * &_T) {
86 int molID = -1;
87 if (typeid( const molecule *) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
88 if (CurrentValueMap.find(name) == CurrentValueMap.end())
89 throw MissingValueException(__FILE__, __LINE__);
90 molID = lexical_cast<int>(CurrentValueMap[name].c_str());
91 CurrentValueMap.erase(name);
92 } else
93 throw IllegalTypeException(__FILE__,__LINE__);
94 _T = World::getInstance().getMolecule(MoleculeById(molID));
95}
96
97void ValueStorage::queryCurrentValue(const char * name, class Box &_T) {
98 RealSpaceMatrix M;
99 double tmp;
100 if (typeid( Box ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
101 if (CurrentValueMap.find(name) == CurrentValueMap.end())
102 throw MissingValueException(__FILE__, __LINE__);
103 std::istringstream stream(CurrentValueMap[name]);
104 stream >> tmp;
105 M.set(0,0,tmp);
106 stream >> tmp;
107 M.set(0,1,tmp);
108 M.set(1,0,tmp);
109 stream >> tmp;
110 M.set(0,2,tmp);
111 M.set(2,0,tmp);
112 stream >> tmp;
113 M.set(1,1,tmp);
114 stream >> tmp;
115 M.set(1,2,tmp);
116 M.set(2,1,tmp);
117 stream >> tmp;
118 M.set(2,2,tmp);
119 _T = M;
120 CurrentValueMap.erase(name);
121 } else
122 throw IllegalTypeException(__FILE__,__LINE__);
123}
124
125void ValueStorage::queryCurrentValue(const char * name, class Vector &_T) {
126 if (typeid( Vector ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
127 std::istringstream stream(CurrentValueMap[name]);
128 CurrentValueMap.erase(name);
129 for (size_t i = 0; i < NDIM; ++i) {
130 stream >> _T[i];
131 ASSERT(!stream.fail(),
132 "ValueStorage::queryCurrentValue() - Vector in value map has only "+toString(i)+" components!");
133 }
134 } else
135 throw IllegalTypeException(__FILE__,__LINE__);
136}
137
138void ValueStorage::queryCurrentValue(const char * name, class BoxVector &_T) {
139 if (typeid( BoxVector ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
140 std::istringstream stream(CurrentValueMap[name]);
141 CurrentValueMap.erase(name);
142 for (size_t i = 0; i < NDIM; ++i) {
143 stream >> _T[i];
144 ASSERT(!stream.fail(),
145 "ValueStorage::queryCurrentValue() - BoxVector in value map has only "+toString(i)+" components!");
146 }
147 } else
148 throw IllegalTypeException(__FILE__,__LINE__);
149}
150
151void ValueStorage::queryCurrentValue(const char * name, std::vector<const atom *>&_T)
152{
153 int atomID = -1;
154 size_t count = 0;
155 atom *Walker = NULL;
156 if (typeid( std::vector<const atom *> ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
157 if (CurrentValueMap.find(name) == CurrentValueMap.end())
158 throw MissingValueException(__FILE__, __LINE__);
159 std::istringstream stream(CurrentValueMap[name]);
160 CurrentValueMap.erase(name);
161 while (!stream.fail()) {
162 stream >> atomID >> ws;
163 ASSERT((!stream.fail()) || (count != 0),
164 "ValueStorage::queryCurrentValue() - Atom is missing id!");
165 if (!stream.fail()) {
166 Walker = World::getInstance().getAtom(AtomById(atomID));
167 if (Walker != NULL)
168 _T.push_back(Walker);
169 atomID = -1;
170 Walker = NULL;
171 ++count;
172 }
173 }
174 } else
175 throw IllegalTypeException(__FILE__,__LINE__);
176}
177
178void ValueStorage::queryCurrentValue(const char * name, std::vector<const element *>&_T)
179{
180 int Z = -1;
181 size_t count = 0;
182 const element *elemental = NULL;
183 if (typeid( std::vector<const element *> ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
184 if (CurrentValueMap.find(name) == CurrentValueMap.end())
185 throw MissingValueException(__FILE__, __LINE__);
186 std::istringstream stream(CurrentValueMap[name]);
187 CurrentValueMap.erase(name);
188 while (!stream.fail()) {
189 stream >> Z >> ws;
190 ASSERT((!stream.fail()) || (count != 0),
191 "ValueStorage::queryCurrentValue() - atomic number is missing!");
192 if (!stream.fail()) {
193 elemental = World::getInstance().getPeriode()->FindElement(Z);
194 if (elemental != NULL)
195 _T.push_back(elemental);
196 Z = -1;
197 ++count;
198 }
199 }
200 } else
201 throw IllegalTypeException(__FILE__,__LINE__);
202}
203
204void ValueStorage::queryCurrentValue(const char * name, std::vector<const molecule *>&_T)
205{
206 int molID = -1;
207 size_t count = 0;
208 molecule *mol = NULL;
209 if (typeid( std::vector<const molecule *> ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
210 if (CurrentValueMap.find(name) == CurrentValueMap.end())
211 throw MissingValueException(__FILE__, __LINE__);
212 std::istringstream stream(CurrentValueMap[name]);
213 CurrentValueMap.erase(name);
214 while (!stream.fail()) {
215 stream >> molID >> ws;
216 ASSERT((!stream.fail()) || (count != 0),
217 "ValueStorage::queryCurrentValue() - molecule is missing id!");
218 if (!stream.fail()) {
219 mol = World::getInstance().getMolecule(MoleculeById(molID));
220 if (mol != NULL)
221 _T.push_back(mol);
222 molID = -1;
223 mol = NULL;
224 ++count;
225 }
226 }
227 } else
228 throw IllegalTypeException(__FILE__,__LINE__);
229}
230
231void ValueStorage::queryCurrentValue(const char * name, boost::filesystem::path&_T)
232{
233 std::string tmp;
234 if (typeid( boost::filesystem::path ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
235 if (CurrentValueMap.find(name) == CurrentValueMap.end())
236 throw MissingValueException(__FILE__, __LINE__);
237 std::istringstream stream(CurrentValueMap[name]);
238 CurrentValueMap.erase(name);
239 stream >> tmp >> ws;
240 ASSERT(!stream.fail(),
241 "ValueStorage::queryCurrentValue() - boost::filesystem::path is missing!");
242 _T = tmp;
243 } else
244 throw IllegalTypeException(__FILE__,__LINE__);
245}
246
247void ValueStorage::setCurrentValue(const char * name, const atom * &_T)
248{
249 if (typeid( const atom *) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
250 std::ostringstream stream;
251 stream << _T->getId();
252 CurrentValueMap[name] = stream.str();
253 } else
254 throw IllegalTypeException(__FILE__,__LINE__);
255}
256
257void ValueStorage::setCurrentValue(const char * name, const element * &_T)
258{
259 if (typeid( const element *) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
260 std::ostringstream stream;
261 stream << _T->getAtomicNumber();
262 CurrentValueMap[name] = stream.str();
263 } else
264 throw IllegalTypeException(__FILE__,__LINE__);
265}
266
267void ValueStorage::setCurrentValue(const char * name, const molecule * &_T)
268{
269 if (typeid( const molecule *) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
270 std::ostringstream stream;
271 stream << _T->getId();
272 CurrentValueMap[name] = stream.str();
273 } else
274 throw IllegalTypeException(__FILE__,__LINE__);
275}
276
277void ValueStorage::setCurrentValue(const char * name, class Box &_T)
278{
279 const RealSpaceMatrix &M = _T.getM();
280 if (typeid( Box ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
281 std::ostringstream stream;
282 stream << M.at(0,0) << " ";
283 stream << M.at(0,1) << " ";
284 stream << M.at(0,2) << " ";
285 stream << M.at(1,1) << " ";
286 stream << M.at(1,2) << " ";
287 stream << M.at(2,2) << " ";
288 CurrentValueMap[name] = stream.str();
289 } else
290 throw IllegalTypeException(__FILE__,__LINE__);
291}
292
293void ValueStorage::setCurrentValue(const char * name, class Vector &_T)
294{
295 if (typeid( Vector ) == *(OptionRegistry_instance.getOptionByName(name)->getType())){
296 std::ostringstream stream;
297 stream << _T[0] << " ";
298 stream << _T[1] << " ";
299 stream << _T[2] << " ";
300 CurrentValueMap[name] = stream.str();
301 } else if (typeid( BoxVector ) == *(OptionRegistry_instance.getOptionByName(name)->getType())){
302 std::ostringstream stream;
303 stream << _T[0] << " ";
304 stream << _T[1] << " ";
305 stream << _T[2] << " ";
306 CurrentValueMap[name] = stream.str();
307 } else
308 throw IllegalTypeException(__FILE__,__LINE__);
309}
310
311void ValueStorage::setCurrentValue(const char * name, std::vector<const atom *>&_T)
312{
313 if (typeid( std::vector<const atom *> ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
314 std::ostringstream stream;
315 for (std::vector<const atom *>::const_iterator iter = _T.begin(); iter != _T.end(); ++iter) {
316 stream << (*iter)->getId() << " ";
317 }
318 CurrentValueMap[name] = stream.str();
319 } else
320 throw IllegalTypeException(__FILE__,__LINE__);
321}
322
323void ValueStorage::setCurrentValue(const char * name, std::vector<const element *>&_T)
324{
325 if (typeid( std::vector<const element *> ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
326 std::ostringstream stream;
327 for (std::vector<const element *>::const_iterator iter = _T.begin(); iter != _T.end(); ++iter) {
328 stream << (*iter)->getAtomicNumber() << " ";
329 }
330 CurrentValueMap[name] = stream.str();
331 } else
332 throw IllegalTypeException(__FILE__,__LINE__);
333}
334
335void ValueStorage::setCurrentValue(const char * name, std::vector<const molecule *>&_T)
336{
337 if (typeid( std::vector<const molecule *> ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
338 std::ostringstream stream;
339 for (std::vector<const molecule *>::const_iterator iter = _T.begin(); iter != _T.end(); ++iter) {
340 stream << (*iter)->getId() << " ";
341 }
342 CurrentValueMap[name] = stream.str();
343 } else
344 throw IllegalTypeException(__FILE__,__LINE__);
345}
346
347void ValueStorage::setCurrentValue(const char * name, boost::filesystem::path &_T)
348{
349 if (typeid( boost::filesystem::path ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
350 std::ostringstream stream;
351 stream << _T.string();
352 CurrentValueMap[name] = stream.str();
353 } else
354 throw IllegalTypeException(__FILE__,__LINE__);
355}
356
357const std::string ValueStorage::getCurrentValue(std::string actionname) {
358 return CurrentValueMap[actionname];
359}
360
361CONSTRUCT_SINGLETON(ValueStorage)
Note: See TracBrowser for help on using the repository browser.