source: src/Actions/ValueStorage.cpp@ 300220

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 300220 was 0275ad, checked in by Frederik Heber <heber@…>, 14 years ago

Final step in Random numbers is done ...

  • Property mode set to 100644
File size: 13.5 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 "RandomNumbers/RandomNumberDistribution_Parameters.hpp"
37#include "atom.hpp"
38#include "Box.hpp"
39#include "element.hpp"
40#include "molecule.hpp"
41#include "periodentafel.hpp"
42#include "World.hpp"
43
44ValueStorage::ValueStorage() :
45OptionRegistry_instance(OptionRegistry::getInstance())
46{};
47
48ValueStorage::~ValueStorage() {};
49
50
51bool ValueStorage::isCurrentValuePresent(const char *name) const
52{
53 return (CurrentValueMap.find(name) != CurrentValueMap.end());
54}
55
56void ValueStorage::queryCurrentValue(const char * name, const atom * &_T)
57{
58 int atomID = -1;
59 if (typeid( atom *) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
60 if (CurrentValueMap.find(name) == CurrentValueMap.end())
61 throw MissingValueException(__FILE__, __LINE__);
62 atomID = lexical_cast<int>(CurrentValueMap[name].c_str());
63 CurrentValueMap.erase(name);
64 } else if (typeid( const atom *) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
65 if (CurrentValueMap.find(name) == CurrentValueMap.end())
66 throw MissingValueException(__FILE__, __LINE__);
67 atomID = lexical_cast<int>(CurrentValueMap[name].c_str());
68 CurrentValueMap.erase(name);
69 } else
70 throw IllegalTypeException(__FILE__,__LINE__);
71 _T = World::getInstance().getAtom(AtomById(atomID));
72}
73
74void ValueStorage::queryCurrentValue(const char * name, const element * &_T) {
75 int Z = -1;
76 if (typeid(const element *) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
77 if (CurrentValueMap.find(name) == CurrentValueMap.end())
78 throw MissingValueException(__FILE__, __LINE__);
79 Z = lexical_cast<int>(CurrentValueMap[name].c_str());
80 CurrentValueMap.erase(name);
81 } else
82 throw IllegalTypeException(__FILE__,__LINE__);
83 _T = World::getInstance().getPeriode()->FindElement(Z);
84}
85
86void ValueStorage::queryCurrentValue(const char * name, const molecule * &_T) {
87 int molID = -1;
88 if (typeid( const molecule *) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
89 if (CurrentValueMap.find(name) == CurrentValueMap.end())
90 throw MissingValueException(__FILE__, __LINE__);
91 molID = lexical_cast<int>(CurrentValueMap[name].c_str());
92 CurrentValueMap.erase(name);
93 } else
94 throw IllegalTypeException(__FILE__,__LINE__);
95 _T = World::getInstance().getMolecule(MoleculeById(molID));
96}
97
98void ValueStorage::queryCurrentValue(const char * name, class Box &_T) {
99 RealSpaceMatrix M;
100 double tmp;
101 if (typeid( Box ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
102 if (CurrentValueMap.find(name) == CurrentValueMap.end())
103 throw MissingValueException(__FILE__, __LINE__);
104 std::istringstream stream(CurrentValueMap[name]);
105 stream >> tmp;
106 M.set(0,0,tmp);
107 stream >> tmp;
108 M.set(0,1,tmp);
109 M.set(1,0,tmp);
110 stream >> tmp;
111 M.set(0,2,tmp);
112 M.set(2,0,tmp);
113 stream >> tmp;
114 M.set(1,1,tmp);
115 stream >> tmp;
116 M.set(1,2,tmp);
117 M.set(2,1,tmp);
118 stream >> tmp;
119 M.set(2,2,tmp);
120 _T = M;
121 CurrentValueMap.erase(name);
122 } else
123 throw IllegalTypeException(__FILE__,__LINE__);
124}
125
126void ValueStorage::queryCurrentValue(const char * name, class Vector &_T) {
127 if (typeid( Vector ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
128 std::istringstream stream(CurrentValueMap[name]);
129 CurrentValueMap.erase(name);
130 for (size_t i = 0; i < NDIM; ++i) {
131 stream >> _T[i];
132 ASSERT(!stream.fail(),
133 "ValueStorage::queryCurrentValue() - Vector in value map has only "+toString(i)+" components!");
134 }
135 } else
136 throw IllegalTypeException(__FILE__,__LINE__);
137}
138
139void ValueStorage::queryCurrentValue(const char * name, class BoxVector &_T) {
140 if (typeid( BoxVector ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
141 std::istringstream stream(CurrentValueMap[name]);
142 CurrentValueMap.erase(name);
143 for (size_t i = 0; i < NDIM; ++i) {
144 stream >> _T[i];
145 ASSERT(!stream.fail(),
146 "ValueStorage::queryCurrentValue() - BoxVector in value map has only "+toString(i)+" components!");
147 }
148 } else
149 throw IllegalTypeException(__FILE__,__LINE__);
150}
151
152void ValueStorage::queryCurrentValue(const char * name, class RandomNumberDistribution_Parameters &_T) {
153 if (typeid( RandomNumberDistribution_Parameters ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
154 std::istringstream stream(CurrentValueMap[name]);
155 DoLog(0) && (Log() << Verbose(0) << "ValueStorage::queryCurrentValue() for "+toString(name)+" is "+CurrentValueMap[name]+"." << std::endl);
156 CurrentValueMap.erase(name);
157 stream >> _T;
158 ASSERT(!stream.fail(),
159 "ValueStorage::queryCurrentValue() - RandomNumberDistribution_Parameters in value map has only no components!");
160 } else
161 throw IllegalTypeException(__FILE__,__LINE__);
162}
163
164void ValueStorage::queryCurrentValue(const char * name, std::vector<const atom *>&_T)
165{
166 int atomID = -1;
167 size_t count = 0;
168 atom *Walker = NULL;
169 if (typeid( std::vector<const atom *> ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
170 if (CurrentValueMap.find(name) == CurrentValueMap.end())
171 throw MissingValueException(__FILE__, __LINE__);
172 std::istringstream stream(CurrentValueMap[name]);
173 CurrentValueMap.erase(name);
174 while (!stream.fail()) {
175 stream >> atomID >> ws;
176 ASSERT((!stream.fail()) || (count != 0),
177 "ValueStorage::queryCurrentValue() - Atom is missing id!");
178 if (!stream.fail()) {
179 Walker = World::getInstance().getAtom(AtomById(atomID));
180 if (Walker != NULL)
181 _T.push_back(Walker);
182 atomID = -1;
183 Walker = NULL;
184 ++count;
185 }
186 }
187 } else
188 throw IllegalTypeException(__FILE__,__LINE__);
189}
190
191void ValueStorage::queryCurrentValue(const char * name, std::vector<const element *>&_T)
192{
193 int Z = -1;
194 size_t count = 0;
195 const element *elemental = NULL;
196 if (typeid( std::vector<const element *> ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
197 if (CurrentValueMap.find(name) == CurrentValueMap.end())
198 throw MissingValueException(__FILE__, __LINE__);
199 std::istringstream stream(CurrentValueMap[name]);
200 CurrentValueMap.erase(name);
201 while (!stream.fail()) {
202 stream >> Z >> ws;
203 ASSERT((!stream.fail()) || (count != 0),
204 "ValueStorage::queryCurrentValue() - atomic number is missing!");
205 if (!stream.fail()) {
206 elemental = World::getInstance().getPeriode()->FindElement(Z);
207 if (elemental != NULL)
208 _T.push_back(elemental);
209 Z = -1;
210 ++count;
211 }
212 }
213 } else
214 throw IllegalTypeException(__FILE__,__LINE__);
215}
216
217void ValueStorage::queryCurrentValue(const char * name, std::vector<const molecule *>&_T)
218{
219 int molID = -1;
220 size_t count = 0;
221 molecule *mol = NULL;
222 if (typeid( std::vector<const molecule *> ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
223 if (CurrentValueMap.find(name) == CurrentValueMap.end())
224 throw MissingValueException(__FILE__, __LINE__);
225 std::istringstream stream(CurrentValueMap[name]);
226 CurrentValueMap.erase(name);
227 while (!stream.fail()) {
228 stream >> molID >> ws;
229 ASSERT((!stream.fail()) || (count != 0),
230 "ValueStorage::queryCurrentValue() - molecule is missing id!");
231 if (!stream.fail()) {
232 mol = World::getInstance().getMolecule(MoleculeById(molID));
233 if (mol != NULL)
234 _T.push_back(mol);
235 molID = -1;
236 mol = NULL;
237 ++count;
238 }
239 }
240 } else
241 throw IllegalTypeException(__FILE__,__LINE__);
242}
243
244void ValueStorage::queryCurrentValue(const char * name, boost::filesystem::path&_T)
245{
246 std::string tmp;
247 if (typeid( boost::filesystem::path ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
248 if (CurrentValueMap.find(name) == CurrentValueMap.end())
249 throw MissingValueException(__FILE__, __LINE__);
250 std::istringstream stream(CurrentValueMap[name]);
251 CurrentValueMap.erase(name);
252 stream >> tmp >> ws;
253 ASSERT(!stream.fail(),
254 "ValueStorage::queryCurrentValue() - boost::filesystem::path is missing!");
255 _T = tmp;
256 } else
257 throw IllegalTypeException(__FILE__,__LINE__);
258}
259
260void ValueStorage::setCurrentValue(const char * name, const atom * &_T)
261{
262 if (typeid( const atom *) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
263 std::ostringstream stream;
264 stream << _T->getId();
265 CurrentValueMap[name] = stream.str();
266 } else
267 throw IllegalTypeException(__FILE__,__LINE__);
268}
269
270void ValueStorage::setCurrentValue(const char * name, const element * &_T)
271{
272 if (typeid( const element *) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
273 std::ostringstream stream;
274 stream << _T->getAtomicNumber();
275 CurrentValueMap[name] = stream.str();
276 } else
277 throw IllegalTypeException(__FILE__,__LINE__);
278}
279
280void ValueStorage::setCurrentValue(const char * name, const molecule * &_T)
281{
282 if (typeid( const molecule *) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
283 std::ostringstream stream;
284 stream << _T->getId();
285 CurrentValueMap[name] = stream.str();
286 } else
287 throw IllegalTypeException(__FILE__,__LINE__);
288}
289
290void ValueStorage::setCurrentValue(const char * name, class Box &_T)
291{
292 const RealSpaceMatrix &M = _T.getM();
293 if (typeid( Box ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
294 std::ostringstream stream;
295 stream << M.at(0,0) << " ";
296 stream << M.at(0,1) << " ";
297 stream << M.at(0,2) << " ";
298 stream << M.at(1,1) << " ";
299 stream << M.at(1,2) << " ";
300 stream << M.at(2,2) << " ";
301 CurrentValueMap[name] = stream.str();
302 } else
303 throw IllegalTypeException(__FILE__,__LINE__);
304}
305
306void ValueStorage::setCurrentValue(const char * name, class Vector &_T)
307{
308 if (typeid( Vector ) == *(OptionRegistry_instance.getOptionByName(name)->getType())){
309 std::ostringstream stream;
310 stream << _T[0] << " ";
311 stream << _T[1] << " ";
312 stream << _T[2] << " ";
313 CurrentValueMap[name] = stream.str();
314 } else if (typeid( BoxVector ) == *(OptionRegistry_instance.getOptionByName(name)->getType())){
315 std::ostringstream stream;
316 stream << _T[0] << " ";
317 stream << _T[1] << " ";
318 stream << _T[2] << " ";
319 CurrentValueMap[name] = stream.str();
320 } else
321 throw IllegalTypeException(__FILE__,__LINE__);
322}
323
324void ValueStorage::setCurrentValue(const char * name, class RandomNumberDistribution_Parameters &_T)
325{
326 if (typeid( RandomNumberDistribution_Parameters ) == *(OptionRegistry_instance.getOptionByName(name)->getType())){
327 std::ostringstream stream;
328 stream << _T;
329 CurrentValueMap[name] = stream.str();
330 DoLog(0) && (Log() << Verbose(0) << "ValueStorage::setCurrentValue() for "+toString(name)+" to "+stream.str()+"." << std::endl);
331 } else
332 throw IllegalTypeException(__FILE__,__LINE__);
333}
334
335void ValueStorage::setCurrentValue(const char * name, std::vector<const atom *>&_T)
336{
337 if (typeid( std::vector<const atom *> ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
338 std::ostringstream stream;
339 for (std::vector<const atom *>::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, std::vector<const element *>&_T)
348{
349 if (typeid( std::vector<const element *> ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
350 std::ostringstream stream;
351 for (std::vector<const element *>::const_iterator iter = _T.begin(); iter != _T.end(); ++iter) {
352 stream << (*iter)->getAtomicNumber() << " ";
353 }
354 CurrentValueMap[name] = stream.str();
355 } else
356 throw IllegalTypeException(__FILE__,__LINE__);
357}
358
359void ValueStorage::setCurrentValue(const char * name, std::vector<const molecule *>&_T)
360{
361 if (typeid( std::vector<const molecule *> ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
362 std::ostringstream stream;
363 for (std::vector<const molecule *>::const_iterator iter = _T.begin(); iter != _T.end(); ++iter) {
364 stream << (*iter)->getId() << " ";
365 }
366 CurrentValueMap[name] = stream.str();
367 } else
368 throw IllegalTypeException(__FILE__,__LINE__);
369}
370
371void ValueStorage::setCurrentValue(const char * name, boost::filesystem::path &_T)
372{
373 if (typeid( boost::filesystem::path ) == *(OptionRegistry_instance.getOptionByName(name)->getType())) {
374 std::ostringstream stream;
375 stream << _T.string();
376 CurrentValueMap[name] = stream.str();
377 } else
378 throw IllegalTypeException(__FILE__,__LINE__);
379}
380
381const std::string ValueStorage::getCurrentValue(std::string actionname) {
382 return CurrentValueMap[actionname];
383}
384
385CONSTRUCT_SINGLETON(ValueStorage)
Note: See TracBrowser for help on using the repository browser.