source: src/Parameters/StreamOperators.hpp@ 52575c

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 52575c was 16876c, checked in by Frederik Heber <heber@…>, 13 years ago

Implemented all stream operator >> functions in StreamOperators.hpp.

  • also added operators for const atom* and vector<const atom *>.
  • Property mode set to 100644
File size: 7.2 KB
Line 
1/*
2 * StreamOperators.hpp
3 *
4 * Created on: Apr 16, 2012
5 * Author: ankele, heber
6 */
7
8#ifndef STREAMOPERATORS_HPP_
9#define STREAMOPERATORS_HPP_
10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16#include <boost/tokenizer.hpp>
17#include <string>
18#include <sstream>
19#include <iosfwd>
20
21#include "LinearAlgebra/Vector.hpp"
22#include "LinearAlgebra/RealSpaceMatrix.hpp"
23#include "Box.hpp"
24#include "Descriptors/AtomIdDescriptor.hpp"
25#include "Descriptors/MoleculeIdDescriptor.hpp"
26#include "Element/periodentafel.hpp"
27#include "World.hpp"
28
29#include "CodePatterns/Assert.hpp"
30
31class atom;
32class element;
33class molecule;
34
35/** Returns a single line from \a ist without leading and ending brackets.
36 *
37 * @param ist stream to get line from
38 * @return line as string without ()
39 */
40inline std::string getLine(std::istream& ist)
41{
42 std::string line;
43 getline(ist,line);
44
45 if (!line.empty() && line[0] == '(')
46 line.erase(0, 1);
47 if (!line.empty() && line[line.size() - 1] == ')')
48 line.erase(line.size() - 1, 1);
49
50 return line;
51}
52
53inline std::istream& operator>>(std::istream& ist, Vector& m)
54{
55 std::string line = getLine(ist);
56
57 // dissect by " " or ","
58 ConvertTo<double> converter;
59 std::vector<double> temp_vector;
60 boost::char_separator<char> sep(", ");
61 boost::tokenizer<boost::char_separator<char> > tok(line, sep);
62 for(boost::tokenizer<boost::char_separator<char> >::const_iterator iter = tok.begin();
63 iter != tok.end(); ++iter)
64 temp_vector.push_back(converter(*iter));
65 ASSERT (temp_vector.size() == (size_t)NDIM,
66 "operator>>(std::istream& ist, Vector& m) - not "+toString((size_t)NDIM)+" but "
67 +toString(temp_vector.size())+" components given.");
68 for (size_t i=0;i<NDIM;++i)
69 m[i] = temp_vector[i];
70 return ist;
71};
72
73inline std::istream& operator>>(std::istream& ist, RealSpaceMatrix& m)
74{
75 std::string line = getLine(ist);
76
77 // dissect by " " or ","
78 ConvertTo<double> converter;
79 std::vector<double> temp_vector;
80 boost::char_separator<char> sep(", ");
81 boost::tokenizer<boost::char_separator<char> > tok(line, sep);
82 for(boost::tokenizer<boost::char_separator<char> >::const_iterator iter = tok.begin();
83 iter != tok.end(); ++iter)
84 temp_vector.push_back(converter(*iter));
85 ASSERT (temp_vector.size() == (size_t)NDIM*(NDIM+1)/2,
86 "operator>>(std::istream& ist, RealSpaceMatrix& m) - not "+toString((size_t)NDIM*((size_t)NDIM+1)/2)+" but "
87 +toString(temp_vector.size())+" components given.");
88 m.set(0,0, temp_vector[0]);
89 m.set(0,1, temp_vector[1]);
90 m.set(0,2, temp_vector[2]);
91 m.set(1,0, temp_vector[1]);
92 m.set(1,1, temp_vector[3]);
93 m.set(1,2, temp_vector[4]);
94 m.set(2,0, temp_vector[2]);
95 m.set(2,1, temp_vector[4]);
96 m.set(2,2, temp_vector[5]);
97 return ist;
98};
99
100inline std::istream& operator>>(std::istream& ist, Box& m)
101{
102 RealSpaceMatrix M;
103 ist >> M;
104 m.setM(M);
105 return ist;
106};
107
108
109inline std::istream& operator>>(std::istream& ist, const atom* & m)
110{
111 std::string line = getLine(ist);
112
113 ConvertTo<unsigned int> converter;
114 const atomId_t temp_value = converter(line);
115 const atom *a = World::getInstance().getAtom(AtomById(temp_value));
116 ASSERT( a != NULL,
117 "operator>>(std::istream& ist, const atom* & m) - atom molecule id "
118 +toString(temp_value)+".");
119 m = a;
120 return ist;
121}
122
123inline std::istream& operator>>(std::istream& ist, const molecule* & m)
124{
125 std::string line = getLine(ist);
126
127 ConvertTo<unsigned int> converter;
128 const moleculeId_t temp_value = converter(line);
129 const molecule *mol = World::getInstance().getMolecule(MoleculeById(temp_value));
130 ASSERT( mol != NULL,
131 "operator>>(std::istream& ist, const molecule* & m) - invalid molecule id "
132 +toString(temp_value)+".");
133 m = mol;
134 return ist;
135}
136
137
138inline std::istream& operator>>(std::istream& ist, const element* & m)
139{
140 std::string line = getLine(ist);
141
142 ConvertTo<unsigned int> converter;
143 const atomicNumber_t temp_value = converter(line);
144 const element *elem = World::getInstance().getPeriode()->FindElement(temp_value);
145 ASSERT( elem != NULL,
146 "operator>>(std::istream& ist, const element* & m) - invalid atomic number "
147 +toString(temp_value)+".");
148 m = elem;
149 return ist;
150}
151
152
153inline std::istream& operator>>(std::istream& ist, std::vector<const molecule*> & m)
154{
155 std::string line = getLine(ist);
156
157 // dissect by " " or ","
158 boost::char_separator<char> sep(", ");
159 boost::tokenizer<boost::char_separator<char> > tok(line, sep);
160 ConvertTo<unsigned int> converter;
161 for(boost::tokenizer<boost::char_separator<char> >::const_iterator iter = tok.begin();
162 iter != tok.end(); ++iter) {
163 const moleculeId_t temp_value = converter(*iter);
164 const molecule *mol = World::getInstance().getMolecule(MoleculeById(temp_value));
165 ASSERT( mol != NULL,
166 "operator>>(std::istream& ist, std::vector<const molecule*> & m) - invalid molecule id "
167 +toString(temp_value)+".");
168 m.push_back(mol);
169 }
170 return ist;
171}
172
173
174inline std::istream& operator>>(std::istream& ist, std::vector<const atom*> & m)
175{
176 std::string line = getLine(ist);
177
178 // dissect by " " or ","
179 boost::char_separator<char> sep(", ");
180 boost::tokenizer<boost::char_separator<char> > tok(line, sep);
181 ConvertTo<unsigned int> converter;
182 for(boost::tokenizer<boost::char_separator<char> >::const_iterator iter = tok.begin();
183 iter != tok.end(); ++iter) {
184 const atomId_t temp_value = converter(line);
185 const atom *a = World::getInstance().getAtom(AtomById(temp_value));
186 ASSERT( a != NULL,
187 "operator>>(std::istream& ist, std::vector<const atom*> & m) - invalid atom id "
188 +toString(temp_value)+".");
189 m.push_back(a);
190 }
191 return ist;
192}
193
194inline std::istream& operator>>(std::istream& ist, std::vector<const element*> & m)
195{
196 std::string line = getLine(ist);
197
198 // dissect by " " or ","
199 boost::char_separator<char> sep(", ");
200 boost::tokenizer<boost::char_separator<char> > tok(line, sep);
201 ConvertTo<unsigned int> converter;
202 for(boost::tokenizer<boost::char_separator<char> >::const_iterator iter = tok.begin();
203 iter != tok.end(); ++iter) {
204 const atomicNumber_t temp_value = converter(*iter);
205 const element *elem = World::getInstance().getPeriode()->FindElement(temp_value);
206 ASSERT( elem != NULL,
207 "operator>>(std::istream& ist, std::vector<const element*> & m) - invalid atomic number "
208 +toString(temp_value)+".");
209 m.push_back(elem);
210 }
211 return ist;
212}
213
214
215inline std::istream& operator>>(std::istream& ist, std::vector<std::string> & m)
216{
217 std::string line = getLine(ist);
218
219 // dissect by " " or ","
220 boost::char_separator<char> sep(", ");
221 boost::tokenizer<boost::char_separator<char> > tok(line, sep);
222 for(boost::tokenizer<boost::char_separator<char> >::const_iterator iter = tok.begin();
223 iter != tok.end(); ++iter)
224 m.push_back(*iter);
225 return ist;
226}
227
228inline std::istream& operator>>(std::istream& ist, std::vector<unsigned int> & m)
229{
230 std::string line = getLine(ist);
231
232 // dissect by " " or ","
233 boost::char_separator<char> sep(", ");
234 boost::tokenizer<boost::char_separator<char> > tok(line, sep);
235 ConvertTo<unsigned int> converter;
236 for(boost::tokenizer<boost::char_separator<char> >::const_iterator iter = tok.begin();
237 iter != tok.end(); ++iter)
238 m.push_back(converter(*iter));
239 return ist;
240}
241
242
243#endif /* STREAMOPERATORS_HPP_ */
Note: See TracBrowser for help on using the repository browser.