source: src/Actions/ValueStorage.cpp@ f844ef

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

Renamed Matrix to RealSpaceMatrix.

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