source: src/RandomNumbers/RandomNumberDistribution_Parameters.cpp@ 94d5ac6

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 94d5ac6 was 94d5ac6, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

  • GNU Scientific Library is used at every place in the code, especially the sub-package LinearAlgebra is based on it which in turn is used really everywhere in the remainder of MoleCuilder. Hence, we have to use the GPL license for the whole of MoleCuilder. In effect, GPL's COPYING was present all along and stated the terms of the GPL v2 license.
  • Hence, I added the default GPL v2 disclaimer to every source file and removed the note about a (actually missing) LICENSE file.
  • also, I added a help-redistribute action which again gives the disclaimer of the GPL v2.
  • also, I changed in the disclaimer that is printed at every program start in builder_init.cpp.
  • TEST: Added check on GPL statement present in every module to test CodeChecks project-disclaimer.
  • Property mode set to 100644
File size: 8.8 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * RandomNumberDistribution_Parameters.cpp
25 *
26 * Created on: Jan 6, 2011
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include "CodePatterns/MemDebug.hpp"
36
37#include <iostream>
38#include <boost/tokenizer.hpp>
39#include <string>
40#include <map>
41
42#include "CodePatterns/Assert.hpp"
43#include "CodePatterns/Log.hpp"
44#include "CodePatterns/Verbose.hpp"
45
46#include "RandomNumberDistribution_Parameters.hpp"
47
48#include "RandomNumberDistribution.hpp"
49
50RandomNumberDistribution_Parameters::ParamNames RandomNumberDistribution_Parameters::params;
51const double RandomNumberDistribution_Parameters::noset_value = -1.;
52
53RandomNumberDistribution_Parameters::RandomNumberDistribution_Parameters() :
54 min(noset_value),
55 max(noset_value),
56 p(noset_value),
57 t(noset_value),
58 median(noset_value),
59 sigma(noset_value),
60 alpha(noset_value),
61 mean(noset_value),
62 a(noset_value),
63 b(noset_value),
64 c(noset_value),
65 lambda(noset_value)
66{
67 // if param names map not yet filled, do so
68 if (params.begin() == params.end()) {
69 params["min"] = param_min;
70 params["max"] = param_max;
71 params["p"] = param_p;
72 params["t"] = param_t;
73 params["median"] = param_median;
74 params["sigma"] = param_sigma;
75 params["alpha"] = param_alpha;
76 params["mean"] = param_mean;
77 params["a"] = param_a;
78 params["b"] = param_b;
79 params["c"] = param_c;
80 params["lambda"] = param_lambda;
81 }
82}
83
84RandomNumberDistribution_Parameters::RandomNumberDistribution_Parameters(
85 const RandomNumberDistribution_Parameters &_ref)
86{
87 // check self assignment
88 if (&_ref != this) {
89 min = _ref.min;
90 max = _ref.max;
91 p = _ref.p;
92 p = _ref.t;
93 median = _ref.median;
94 sigma = _ref.sigma;
95 alpha = _ref.alpha;
96 mean = _ref.mean;
97 a = _ref.a;
98 b = _ref.b;
99 c = _ref.c;
100 lambda = _ref.lambda;
101 }
102}
103
104RandomNumberDistribution_Parameters::~RandomNumberDistribution_Parameters()
105{}
106
107void RandomNumberDistribution_Parameters::getParameters(const RandomNumberDistribution* const _distribution)
108{
109 min = _distribution->min();
110 max = _distribution->max();
111 p = _distribution->p();
112 t = _distribution->t();
113 median = _distribution->median();
114 sigma = _distribution->sigma();
115 alpha = _distribution->alpha();
116 mean = _distribution->mean();
117 a = _distribution->a();
118 b = _distribution->b();
119 c = _distribution->c();
120 lambda = _distribution->lambda();
121}
122
123void RandomNumberDistribution_Parameters::update(const RandomNumberDistribution_Parameters &_params)
124{
125 min = _params.min != noset_value ? _params.min : min;
126 max = _params.max != noset_value ? _params.max : max;
127 p = _params.p != noset_value ? _params.p : p;
128 p = _params.t != noset_value ? _params.t : t;
129 median = _params.median != noset_value ? _params.median : median;
130 sigma = _params.sigma != noset_value ? _params.sigma : sigma;
131 alpha = _params.alpha != noset_value ? _params.alpha : alpha;
132 mean = _params.mean != noset_value ? _params.mean : mean;
133 a = _params.a != noset_value ? _params.a : a;
134 b = _params.b != noset_value ? _params.b : b;
135 c = _params.c != noset_value ? _params.c : c;
136 lambda = _params.lambda != noset_value ? _params.lambda : lambda;
137}
138
139bool RandomNumberDistribution_Parameters::isDefault() const
140{
141 bool status = true;
142 status = status && (min == noset_value);
143 status = status && (max == noset_value);
144 status = status && (p == noset_value);
145 status = status && (t == noset_value);
146 status = status && (median == noset_value);
147 status = status && (sigma == noset_value);
148 status = status && (alpha == noset_value);
149 status = status && (mean == noset_value);
150 status = status && (a == noset_value);
151 status = status && (b == noset_value);
152 status = status && (c == noset_value);
153 status = status && (lambda == noset_value);
154 return status;
155}
156
157std::ostream & operator << (std::ostream& ost, const RandomNumberDistribution_Parameters &params)
158{
159 std::ostringstream output;
160 output << "min=" << params.min << ";";
161 output << "max=" << params.max << ";";
162 output << "p=" << params.p << ";";
163 output << "t=" << params.t << ";";
164 output << "median=" << params.median << ";";
165 output << "sigma=" << params.sigma << ";";
166 output << "alpha=" << params.alpha << ";";
167 output << "mean=" << params.mean << ";";
168 output << "a=" << params.a << ";";
169 output << "b=" << params.b << ";";
170 output << "c=" << params.c << ";";
171 output << "lambda=" << params.lambda << ";" << std::endl;
172 ost << output.str();
173 return ost;
174}
175
176// TODO: These should throw exceptions such that invalid user entry can be detected.
177std::istream & operator >> (std::istream& ist, RandomNumberDistribution_Parameters &params)
178{
179 typedef boost::tokenizer<boost::char_separator<char> >
180 tokenizer;
181 boost::char_separator<char> semicolonsep(";");
182 boost::char_separator<char> equalitysep("=");
183 std::string line;
184 double tmp;
185 std::getline( ist, line );
186 //LOG(0, "INFO: full line of parameters is '" << line << "'");
187 tokenizer tokens(line, semicolonsep);
188 ASSERT(tokens.begin() != tokens.end(),
189 "operator<< on RandomNumberDistribution_Parameters - empty string, need at least ';'!");
190 for (tokenizer::iterator tok_iter = tokens.begin();
191 tok_iter != tokens.end(); ++tok_iter) {
192 tokenizer paramtokens(*tok_iter, equalitysep);
193 if (paramtokens.begin() != paramtokens.end()) {
194 tokenizer::iterator tok_paramiter = paramtokens.begin();
195 tokenizer::iterator tok_valueiter = tok_paramiter;
196 tokenizer::iterator tok_checkiter = ++tok_valueiter;
197 ASSERT(tok_paramiter != paramtokens.end(),
198 "operator<< on RandomNumberDistribution_Parameters - missing value before '='!");
199 ASSERT(tok_valueiter != paramtokens.end(),
200 "operator<< on RandomNumberDistribution_Parameters - missing value after '='!");
201 ++tok_checkiter;
202 ASSERT(tok_checkiter == paramtokens.end(),
203 "operator<< on RandomNumberDistribution_Parameters - still tokens before ';'!");
204 LOG(0, "INFO: Token pair is " << *tok_paramiter << "," << *tok_valueiter);
205 std::stringstream value(*tok_valueiter);
206 value >> tmp;
207 if ((RandomNumberDistribution_Parameters::params.count(*tok_paramiter) != 0)
208 && (tmp != RandomNumberDistribution_Parameters::noset_value)) {
209 switch (RandomNumberDistribution_Parameters::params[*tok_paramiter]) {
210 case (RandomNumberDistribution_Parameters::param_min):
211 params.min = tmp;
212 break;
213 case (RandomNumberDistribution_Parameters::param_max):
214 params.max = tmp;
215 break;
216 case (RandomNumberDistribution_Parameters::param_p):
217 params.p = tmp;
218 break;
219 case (RandomNumberDistribution_Parameters::param_t):
220 params.t = tmp;
221 break;
222 case (RandomNumberDistribution_Parameters::param_median):
223 params.median = tmp;
224 break;
225 case (RandomNumberDistribution_Parameters::param_sigma):
226 params.sigma = tmp;
227 break;
228 case (RandomNumberDistribution_Parameters::param_alpha):
229 params.alpha = tmp;
230 break;
231 case (RandomNumberDistribution_Parameters::param_mean):
232 params.mean = tmp;
233 break;
234 case (RandomNumberDistribution_Parameters::param_a):
235 params.a = tmp;
236 break;
237 case (RandomNumberDistribution_Parameters::param_b):
238 params.b = tmp;
239 break;
240 case (RandomNumberDistribution_Parameters::param_c):
241 params.c = tmp;
242 break;
243 case (RandomNumberDistribution_Parameters::param_lambda):
244 params.lambda = tmp;
245 break;
246 default:
247 std::cerr << "This is weird, we cannot get here!" << std::endl;
248 }
249 LOG(1, "ACCEPT: Value for token " << *tok_paramiter << " set.");
250 } else {
251 LOG(1, "REJECT: Value for token " << *tok_paramiter << " not specified.");
252 }
253 } else {
254 ist.setstate(std::ios::eofbit);
255 }
256 }
257 return ist;
258}
Note: See TracBrowser for help on using the repository browser.