source: src/RandomNumbers/RandomNumberDistribution_Parameters.cpp@ 0275ad

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 0275ad 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: 8.2 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 * RandomNumberDistribution_Parameters.cpp
10 *
11 * Created on: Jan 6, 2011
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 <iostream>
23#include <boost/tokenizer.hpp>
24#include <string>
25#include <map>
26
27#include "CodePatterns/Assert.hpp"
28#include "CodePatterns/Log.hpp"
29#include "CodePatterns/Verbose.hpp"
30
31#include "RandomNumberDistribution_Parameters.hpp"
32
33#include "RandomNumberDistribution.hpp"
34
35RandomNumberDistribution_Parameters::ParamNames RandomNumberDistribution_Parameters::params;
36const double RandomNumberDistribution_Parameters::noset_value = -1.;
37
38RandomNumberDistribution_Parameters::RandomNumberDistribution_Parameters() :
39 min(noset_value),
40 max(noset_value),
41 p(noset_value),
42 t(noset_value),
43 median(noset_value),
44 sigma(noset_value),
45 alpha(noset_value),
46 mean(noset_value),
47 a(noset_value),
48 b(noset_value),
49 c(noset_value),
50 lambda(noset_value)
51{
52 // if param names map not yet filled, do so
53 if (params.begin() == params.end()) {
54 params["min"] = param_min;
55 params["max"] = param_max;
56 params["p"] = param_p;
57 params["t"] = param_t;
58 params["median"] = param_median;
59 params["sigma"] = param_sigma;
60 params["alpha"] = param_alpha;
61 params["mean"] = param_mean;
62 params["a"] = param_a;
63 params["b"] = param_b;
64 params["c"] = param_c;
65 params["lambda"] = param_lambda;
66 }
67}
68
69RandomNumberDistribution_Parameters::RandomNumberDistribution_Parameters(
70 const RandomNumberDistribution_Parameters &_ref)
71{
72 // check self assignment
73 if (&_ref != this) {
74 min = _ref.min;
75 max = _ref.max;
76 p = _ref.p;
77 p = _ref.t;
78 median = _ref.median;
79 sigma = _ref.sigma;
80 alpha = _ref.alpha;
81 mean = _ref.mean;
82 a = _ref.a;
83 b = _ref.b;
84 c = _ref.c;
85 lambda = _ref.lambda;
86 }
87}
88
89RandomNumberDistribution_Parameters::~RandomNumberDistribution_Parameters()
90{}
91
92void RandomNumberDistribution_Parameters::getParameters(const RandomNumberDistribution* const _distribution)
93{
94 min = _distribution->min();
95 max = _distribution->max();
96 p = _distribution->p();
97 t = _distribution->t();
98 median = _distribution->median();
99 sigma = _distribution->sigma();
100 alpha = _distribution->alpha();
101 mean = _distribution->mean();
102 a = _distribution->a();
103 b = _distribution->b();
104 c = _distribution->c();
105 lambda = _distribution->lambda();
106}
107
108void RandomNumberDistribution_Parameters::update(const RandomNumberDistribution_Parameters &_params)
109{
110 min = _params.min != noset_value ? _params.min : min;
111 max = _params.max != noset_value ? _params.max : max;
112 p = _params.p != noset_value ? _params.p : p;
113 p = _params.t != noset_value ? _params.t : t;
114 median = _params.median != noset_value ? _params.median : median;
115 sigma = _params.sigma != noset_value ? _params.sigma : sigma;
116 alpha = _params.alpha != noset_value ? _params.alpha : alpha;
117 mean = _params.mean != noset_value ? _params.mean : mean;
118 a = _params.a != noset_value ? _params.a : a;
119 b = _params.b != noset_value ? _params.b : b;
120 c = _params.c != noset_value ? _params.c : c;
121 lambda = _params.lambda != noset_value ? _params.lambda : lambda;
122}
123
124bool RandomNumberDistribution_Parameters::isDefault() const
125{
126 bool status = true;
127 status = status && (min == noset_value);
128 status = status && (max == noset_value);
129 status = status && (p == noset_value);
130 status = status && (t == noset_value);
131 status = status && (median == noset_value);
132 status = status && (sigma == noset_value);
133 status = status && (alpha == noset_value);
134 status = status && (mean == noset_value);
135 status = status && (a == noset_value);
136 status = status && (b == noset_value);
137 status = status && (c == noset_value);
138 status = status && (lambda == noset_value);
139 return status;
140}
141
142std::ostream & operator << (std::ostream& ost, const RandomNumberDistribution_Parameters &params)
143{
144 std::ostringstream output;
145 output << "min=" << params.min << ";";
146 output << "max=" << params.max << ";";
147 output << "p=" << params.p << ";";
148 output << "t=" << params.t << ";";
149 output << "median=" << params.median << ";";
150 output << "sigma=" << params.sigma << ";";
151 output << "alpha=" << params.alpha << ";";
152 output << "mean=" << params.mean << ";";
153 output << "a=" << params.a << ";";
154 output << "b=" << params.b << ";";
155 output << "c=" << params.c << ";";
156 output << "lambda=" << params.lambda << ";" << std::endl;
157 ost << output.str();
158 return ost;
159}
160
161// TODO: These should throw exceptions such that invalid user entry can be detected.
162std::istream & operator >> (std::istream& ist, RandomNumberDistribution_Parameters &params)
163{
164 typedef boost::tokenizer<boost::char_separator<char> >
165 tokenizer;
166 boost::char_separator<char> semicolonsep(";");
167 boost::char_separator<char> equalitysep("=");
168 std::string line;
169 double tmp;
170 std::getline( ist, line );
171 //DoLog(0) && (Log() << Verbose(0) << "INFO: full line of parameters is '" << line << "'" << std::endl);
172 tokenizer tokens(line, semicolonsep);
173 ASSERT(tokens.begin() != tokens.end(),
174 "operator<< on RandomNumberDistribution_Parameters - empty string, need at least ';'!");
175 for (tokenizer::iterator tok_iter = tokens.begin();
176 tok_iter != tokens.end(); ++tok_iter) {
177 tokenizer paramtokens(*tok_iter, equalitysep);
178 if (paramtokens.begin() != paramtokens.end()) {
179 tokenizer::iterator tok_paramiter = paramtokens.begin();
180 tokenizer::iterator tok_valueiter = tok_paramiter;
181 tokenizer::iterator tok_checkiter = ++tok_valueiter;
182 ASSERT(tok_valueiter == params.end(),
183 "operator<< on RandomNumberDistribution_Parameters - missing value before ';'!");
184 ++tok_checkiter;
185 ASSERT(tok_checkiter == params.end(),
186 "operator<< on RandomNumberDistribution_Parameters - still tokens before ';'!");
187 DoLog(0) && (Log() << Verbose(0) << "INFO: Token pair is " << *tok_paramiter << "," << *tok_valueiter << std::endl);
188 std::stringstream value(*tok_valueiter);
189 value >> tmp;
190 if ((RandomNumberDistribution_Parameters::params.count(*tok_paramiter) != 0)
191 && (tmp != RandomNumberDistribution_Parameters::noset_value)) {
192 switch (RandomNumberDistribution_Parameters::params[*tok_paramiter]) {
193 case (RandomNumberDistribution_Parameters::param_min):
194 params.min = tmp;
195 break;
196 case (RandomNumberDistribution_Parameters::param_max):
197 params.max = tmp;
198 break;
199 case (RandomNumberDistribution_Parameters::param_p):
200 params.p = tmp;
201 break;
202 case (RandomNumberDistribution_Parameters::param_t):
203 params.t = tmp;
204 break;
205 case (RandomNumberDistribution_Parameters::param_median):
206 params.median = tmp;
207 break;
208 case (RandomNumberDistribution_Parameters::param_sigma):
209 params.sigma = tmp;
210 break;
211 case (RandomNumberDistribution_Parameters::param_alpha):
212 params.alpha = tmp;
213 break;
214 case (RandomNumberDistribution_Parameters::param_mean):
215 params.mean = tmp;
216 break;
217 case (RandomNumberDistribution_Parameters::param_a):
218 params.a = tmp;
219 break;
220 case (RandomNumberDistribution_Parameters::param_b):
221 params.b = tmp;
222 break;
223 case (RandomNumberDistribution_Parameters::param_c):
224 params.c = tmp;
225 break;
226 case (RandomNumberDistribution_Parameters::param_lambda):
227 params.lambda = tmp;
228 break;
229 default:
230 std::cerr << "This is weird, we cannot get here!" << std::endl;
231 }
232 DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Value for token " << *tok_paramiter << " set." << std::endl);
233 } else {
234 DoLog(1) && (Log() << Verbose(1) << "REJECT: Value for token " << *tok_paramiter << " not specified." << std::endl);
235 }
236 } else {
237 ist.setstate(std::ios::eofbit);
238 }
239 }
240 return ist;
241}
Note: See TracBrowser for help on using the repository browser.