source: src/Parameters/StreamOperators.hpp@ 9ec4b8

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

Replaced World::getAtom() wherever possible by const version.

  • some AtomSet member functions now have const atom ptr instead of atom ptr.
  • molecule can return const and non-const AtomSet.
  • added FromIdToConstAtom to allow iterate through atoms in molecule (which are stored by id, not by ptr) in const fashion.
  • in molecule::isInMolecule() is now const, ::CopyMolecule..() is non-const (because copying involves father atom who is stored non-const).
  • Property mode set to 100644
File size: 7.4 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 * const a = const_cast<const World &>(World::getInstance()).
116 getAtom(AtomById(temp_value));
117 ASSERT( a != NULL,
118 "operator>>(std::istream& ist, const atom* & m) - atom molecule id "
119 +toString(temp_value)+".");
120 m = a;
121 return ist;
122}
123
124inline std::istream& operator>>(std::istream& ist, const molecule* & m)
125{
126 std::string line = getLine(ist);
127
128 ConvertTo<unsigned int> converter;
129 const moleculeId_t temp_value = converter(line);
130 const molecule * const mol = const_cast<const World &>(World::getInstance()).
131 getMolecule(MoleculeById(temp_value));
132 ASSERT( mol != NULL,
133 "operator>>(std::istream& ist, const molecule* & m) - invalid molecule id "
134 +toString(temp_value)+".");
135 m = mol;
136 return ist;
137}
138
139
140inline std::istream& operator>>(std::istream& ist, const element* & m)
141{
142 std::string line = getLine(ist);
143
144 ConvertTo<unsigned int> converter;
145 const atomicNumber_t temp_value = converter(line);
146 const element *elem = World::getInstance().getPeriode()->FindElement(temp_value);
147 ASSERT( elem != NULL,
148 "operator>>(std::istream& ist, const element* & m) - invalid atomic number "
149 +toString(temp_value)+".");
150 m = elem;
151 return ist;
152}
153
154
155inline std::istream& operator>>(std::istream& ist, std::vector<const molecule*> & m)
156{
157 std::string line = getLine(ist);
158
159 // dissect by " " or ","
160 boost::char_separator<char> sep(", ");
161 boost::tokenizer<boost::char_separator<char> > tok(line, sep);
162 ConvertTo<unsigned int> converter;
163 for(boost::tokenizer<boost::char_separator<char> >::const_iterator iter = tok.begin();
164 iter != tok.end(); ++iter) {
165 const moleculeId_t temp_value = converter(*iter);
166 const molecule *mol = const_cast<const World &>(World::getInstance()).
167 getMolecule(MoleculeById(temp_value));
168 ASSERT( mol != NULL,
169 "operator>>(std::istream& ist, std::vector<const molecule*> & m) - invalid molecule id "
170 +toString(temp_value)+".");
171 m.push_back(mol);
172 }
173 return ist;
174}
175
176
177inline std::istream& operator>>(std::istream& ist, std::vector<const atom*> & m)
178{
179 std::string line = getLine(ist);
180
181 // dissect by " " or ","
182 boost::char_separator<char> sep(", ");
183 boost::tokenizer<boost::char_separator<char> > tok(line, sep);
184 ConvertTo<unsigned int> converter;
185 for(boost::tokenizer<boost::char_separator<char> >::const_iterator iter = tok.begin();
186 iter != tok.end(); ++iter) {
187 const atomId_t temp_value = converter(line);
188 const atom * const a = const_cast<const World &>(World::getInstance()).
189 getAtom(AtomById(temp_value));
190 ASSERT( a != NULL,
191 "operator>>(std::istream& ist, std::vector<const atom*> & m) - invalid atom id "
192 +toString(temp_value)+".");
193 m.push_back(a);
194 }
195 return ist;
196}
197
198inline std::istream& operator>>(std::istream& ist, std::vector<const element*> & m)
199{
200 std::string line = getLine(ist);
201
202 // dissect by " " or ","
203 boost::char_separator<char> sep(", ");
204 boost::tokenizer<boost::char_separator<char> > tok(line, sep);
205 ConvertTo<unsigned int> converter;
206 for(boost::tokenizer<boost::char_separator<char> >::const_iterator iter = tok.begin();
207 iter != tok.end(); ++iter) {
208 const atomicNumber_t temp_value = converter(*iter);
209 const element * const elem = World::getInstance().getPeriode()->FindElement(temp_value);
210 ASSERT( elem != NULL,
211 "operator>>(std::istream& ist, std::vector<const element*> & m) - invalid atomic number "
212 +toString(temp_value)+".");
213 m.push_back(elem);
214 }
215 return ist;
216}
217
218
219inline std::istream& operator>>(std::istream& ist, std::vector<std::string> & m)
220{
221 std::string line = getLine(ist);
222
223 // dissect by " " or ","
224 boost::char_separator<char> sep(", ");
225 boost::tokenizer<boost::char_separator<char> > tok(line, sep);
226 for(boost::tokenizer<boost::char_separator<char> >::const_iterator iter = tok.begin();
227 iter != tok.end(); ++iter)
228 m.push_back(*iter);
229 return ist;
230}
231
232inline std::istream& operator>>(std::istream& ist, std::vector<unsigned int> & m)
233{
234 std::string line = getLine(ist);
235
236 // dissect by " " or ","
237 boost::char_separator<char> sep(", ");
238 boost::tokenizer<boost::char_separator<char> > tok(line, sep);
239 ConvertTo<unsigned int> converter;
240 for(boost::tokenizer<boost::char_separator<char> >::const_iterator iter = tok.begin();
241 iter != tok.end(); ++iter)
242 m.push_back(converter(*iter));
243 return ist;
244}
245
246
247#endif /* STREAMOPERATORS_HPP_ */
Note: See TracBrowser for help on using the repository browser.