source: src/Actions/MapOfActions.cpp@ 1d9b7d2

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 1d9b7d2 was 1d9b7d2, checked in by Frederik Heber <heber@…>, 15 years ago

TESTFIX: Tesselation/* all needed replacement of option --molecule-by-id by action --select-molecule-by-id in front of, Action changes.

  • Property mode set to 100644
File size: 44.1 KB
Line 
1/*
2 * MapOfActions.cpp
3 *
4 * Created on: 10.05.2010
5 * Author: heber
6 */
7
8#include "Helpers/MemDebug.hpp"
9
10using namespace std;
11
12#include "Actions/MapOfActions.hpp"
13#include "Descriptors/AtomIdDescriptor.hpp"
14#include "Descriptors/MoleculeIdDescriptor.hpp"
15#include "Helpers/Assert.hpp"
16#include "Patterns/Singleton_impl.hpp"
17
18#include <boost/lexical_cast.hpp>
19#include <boost/optional.hpp>
20#include <boost/program_options.hpp>
21
22#include <iostream>
23
24#include "atom.hpp"
25#include "Box.hpp"
26#include "CommandLineParser.hpp"
27#include "element.hpp"
28#include "log.hpp"
29#include "Matrix.hpp"
30#include "molecule.hpp"
31#include "periodentafel.hpp"
32#include "vector.hpp"
33#include "verbose.hpp"
34
35#include "Actions/ActionRegistry.hpp"
36#include "Actions/AnalysisAction/MolecularVolumeAction.hpp"
37#include "Actions/AnalysisAction/PairCorrelationAction.hpp"
38#include "Actions/AnalysisAction/PointCorrelationAction.hpp"
39#include "Actions/AnalysisAction/PrincipalAxisSystemAction.hpp"
40#include "Actions/AnalysisAction/SurfaceCorrelationAction.hpp"
41#include "Actions/AtomAction/AddAction.hpp"
42#include "Actions/AtomAction/ChangeElementAction.hpp"
43#include "Actions/AtomAction/RemoveAction.hpp"
44#include "Actions/CmdAction/BondLengthTableAction.hpp"
45#include "Actions/CmdAction/ElementDbAction.hpp"
46#include "Actions/CmdAction/FastParsingAction.hpp"
47#include "Actions/CmdAction/HelpAction.hpp"
48#include "Actions/CmdAction/VerboseAction.hpp"
49#include "Actions/CmdAction/VersionAction.hpp"
50#include "Actions/FragmentationAction/DepthFirstSearchAction.hpp"
51#include "Actions/FragmentationAction/SubgraphDissectionAction.hpp"
52#include "Actions/FragmentationAction/FragmentationAction.hpp"
53#include "Actions/MoleculeAction/BondFileAction.hpp"
54#include "Actions/MoleculeAction/ChangeNameAction.hpp"
55#include "Actions/MoleculeAction/FillWithMoleculeAction.hpp"
56#include "Actions/MoleculeAction/LinearInterpolationofTrajectoriesAction.hpp"
57#include "Actions/MoleculeAction/RotateToPrincipalAxisSystemAction.hpp"
58#include "Actions/MoleculeAction/SaveAdjacencyAction.hpp"
59#include "Actions/MoleculeAction/SaveBondsAction.hpp"
60#include "Actions/MoleculeAction/SaveTemperatureAction.hpp"
61#include "Actions/MoleculeAction/SuspendInWaterAction.hpp"
62#include "Actions/MoleculeAction/TranslateAction.hpp"
63#include "Actions/MoleculeAction/VerletIntegrationAction.hpp"
64#include "Actions/ParserAction/LoadXyzAction.hpp"
65#include "Actions/ParserAction/SaveXyzAction.hpp"
66#include "Actions/SelectionAction/AtomByIdAction.hpp"
67#include "Actions/SelectionAction/MoleculeByIdAction.hpp"
68#include "Actions/SelectionAction/NotAtomByIdAction.hpp"
69#include "Actions/SelectionAction/NotMoleculeByIdAction.hpp"
70#include "Actions/TesselationAction/ConvexEnvelopeAction.hpp"
71#include "Actions/TesselationAction/NonConvexEnvelopeAction.hpp"
72#include "Actions/WorldAction/AddEmptyBoundaryAction.hpp"
73#include "Actions/WorldAction/BoundInBoxAction.hpp"
74#include "Actions/WorldAction/CenterInBoxAction.hpp"
75#include "Actions/WorldAction/CenterOnEdgeAction.hpp"
76#include "Actions/WorldAction/ChangeBoxAction.hpp"
77#include "Actions/WorldAction/InputAction.hpp"
78#include "Actions/WorldAction/OutputAction.hpp"
79#include "Actions/WorldAction/RemoveSphereOfAtomsAction.hpp"
80#include "Actions/WorldAction/RepeatBoxAction.hpp"
81#include "Actions/WorldAction/ScaleBoxAction.hpp"
82#include "Actions/WorldAction/SetDefaultNameAction.hpp"
83#include "Actions/WorldAction/SetGaussianBasisAction.hpp"
84#include "Actions/WorldAction/SetOutputFormatsAction.hpp"
85#include "Actions/Values.hpp"
86
87void validate(boost::any& v, const std::vector<std::string>& values, VectorValue *, int)
88{
89 VectorValue VV;
90 std::vector<std::string> components;
91
92 // split comma-separated values
93 if (values.size() != 1) {
94 cerr << "Not one vector but " << components.size() << " given " << endl;
95 throw boost::program_options::validation_error("Unequal to one vector given");
96 }
97 std::string argument(values.at(0));
98 std::string::iterator Aiter = argument.begin();
99 std::string::iterator Biter = argument.begin();
100 for (; Aiter != argument.end(); ++Aiter) {
101 if (*Aiter == ',') {
102 components.push_back(string(Biter,Aiter));
103 do {
104 Aiter++;
105 } while (*Aiter == ' ' || *Aiter == '\t');
106 Biter = Aiter;
107 }
108 }
109 components.push_back(string(Biter,argument.end()));
110
111 if (components.size() != 3) {
112 cerr << "Specified vector does not have three components but " << components.size() << endl;
113 throw boost::program_options::validation_error("Specified vector does not have three components");
114 }
115 VV.x = boost::lexical_cast<double>(components.at(0));
116 VV.y = boost::lexical_cast<double>(components.at(1));
117 VV.z = boost::lexical_cast<double>(components.at(2));
118 v = boost::any(VectorValue(VV));
119}
120
121void validate(boost::any& v, const std::vector<std::string>& values, BoxValue *, int)
122{
123 BoxValue BV;
124 std::vector<std::string> components;
125
126 // split comma-separated values
127 if (values.size() != 1) {
128 cerr << "Not one vector but " << components.size() << " given " << endl;
129 throw boost::program_options::validation_error("Unequal to one vector given");
130 }
131 std::string argument(values.at(0));
132 std::string::iterator Aiter = argument.begin();
133 std::string::iterator Biter = argument.begin();
134 for (; Aiter != argument.end(); ++Aiter) {
135 if (*Aiter == ',') {
136 components.push_back(string(Biter,Aiter));
137 do {
138 Aiter++;
139 } while (*Aiter == ' ' || *Aiter == '\t');
140 Biter = Aiter;
141 }
142 }
143 components.push_back(string(Biter,argument.end()));
144
145 if (components.size() != 6) {
146 cerr << "Specified vector does not have three components but " << components.size() << endl;
147 throw boost::program_options::validation_error("Specified symmetric box matrix does not have six components");
148 }
149 BV.xx = boost::lexical_cast<double>(components.at(0));
150 BV.yx = boost::lexical_cast<double>(components.at(1));
151 BV.yy = boost::lexical_cast<double>(components.at(2));
152 BV.zx = boost::lexical_cast<double>(components.at(3));
153 BV.zy = boost::lexical_cast<double>(components.at(4));
154 BV.zz = boost::lexical_cast<double>(components.at(5));
155 v = boost::any(BoxValue(BV));
156}
157
158/** Constructor of class MapOfActions.
159 *
160 */
161MapOfActions::MapOfActions()
162{
163 // initialise lookup map
164 CmdParserLookup[&generic] = &(CommandLineParser::getInstance().generic);
165 CmdParserLookup[&config] = &(CommandLineParser::getInstance().config);
166 CmdParserLookup[&hidden] = &(CommandLineParser::getInstance().hidden);
167 CmdParserLookup[&visible] = &(CommandLineParser::getInstance().visible);
168
169 // keys for actions
170 DescriptionMap["add-atom"] = "add atom of specified element";
171 DescriptionMap["bond-table"] = "setting name of the bond length table file";
172 DescriptionMap["bond-file"] = "name of the bond file";
173 DescriptionMap["boundary"] = "change box to add an empty boundary around all atoms";
174 DescriptionMap["bound-in-box"] = "bound all atoms in the domain";
175 DescriptionMap["center-edge"] = "center edge of all atoms on (0,0,0)";
176 DescriptionMap["center-in-box"] = "center all atoms in the domain";
177 DescriptionMap["change-box"] = "change the symmetrc matrix of the simulation domain";
178 DescriptionMap["change-element"] = "change the element of an atom";
179 DescriptionMap["change-molname"] = "change the name of a molecule";
180 DescriptionMap["convex-envelope"] = "create the convex envelope for a molecule";
181 DescriptionMap["default-molname"] = "set the default name of new molecules";
182 DescriptionMap["depth-first-search"] = "Depth-First Search analysis of the molecular system";
183 DescriptionMap["element-db"] = "setting the path where the element databases can be found";
184 DescriptionMap["fastparsing"] = "setting whether trajectories shall be parsed completely (n) or just first step (y)";
185 DescriptionMap["fill-molecule"] = "fill empty space of box with a filler molecule";
186 DescriptionMap["fragment-mol"] = "create for a given molecule into fragments up to given order";
187 DescriptionMap["help"] = "Give this help screen";
188 DescriptionMap["input"] = "specify input files";
189 DescriptionMap["linear-interpolate"] = "linear interpolation in discrete steps between start and end position of a molecule";
190 DescriptionMap["molecular-volume"] = "calculate the volume of a given molecule";
191 DescriptionMap["nonconvex-envelope"] = "create the non-convex envelope for a molecule";
192 DescriptionMap["output"] = "write output files";
193 DescriptionMap["set-output"] = "specify output formats";
194 DescriptionMap["pair-correlation"] = "pair correlation analysis between two elements, element and point or element and surface";
195 DescriptionMap["parse-xyz"] = "parse xyz file into World";
196 DescriptionMap["principal-axis-system"] = "calculate the principal axis system of the specified molecule";
197 DescriptionMap["remove-atom"] = "remove a specified atom";
198 DescriptionMap["remove-sphere"] = "remove sphere of atoms of around a specified atom";
199 DescriptionMap["repeat-box"] = "create periodic copies of the simulation box per axis";
200 DescriptionMap["rotate-to-pas"] = "calculate the principal axis system of the specified molecule and rotate specified axis to align with main axis";
201 DescriptionMap["save-adjacency"] = "name of the adjacency file to write to";
202 DescriptionMap["save-bonds"] = "name of the bonds file to write to";
203 DescriptionMap["save-temperature"] = "name of the temperature file to write to";
204 DescriptionMap["SaveXyz"] = "save world as xyz file";
205 DescriptionMap["scale-box"] = "scale box and atomic positions inside";
206 DescriptionMap["set-basis"] = "set the name of the gaussian basis set for MPQC";
207 DescriptionMap["set-output"] = "specify output formats";
208 DescriptionMap["subgraph-dissect"] = "dissect the molecular system into molecules representing disconnected subgraphs";
209 DescriptionMap["suspend-in-water"] = "suspend the given molecule in water such that in the domain the mean density is as specified";
210 DescriptionMap["translate-mol"] = "translate molecule by given vector";
211 DescriptionMap["verbose"] = "set verbosity level";
212 DescriptionMap["verlet-integrate"] = "perform verlet integration of a given force file";
213 DescriptionMap["version"] = "show version";
214 // keys for values
215 DescriptionMap["bin-output-file"] = "name of the bin output file";
216 DescriptionMap["bin-end"] = "start of the last bin";
217 DescriptionMap["bin-start"] = "start of the first bin";
218 DescriptionMap["bin-width"] = "width of the bins";
219 DescriptionMap["convex-file"] = "filename of the non-convex envelope";
220 DescriptionMap["distance"] = "distance in space";
221 DescriptionMap["distances"] = "list of three of distances in space, one for each axis direction";
222 DescriptionMap["DoRotate"] = "whether to rotate or just report angles";
223 DescriptionMap["element"] = "single element";
224 DescriptionMap["elements"] = "set of elements";
225 DescriptionMap["end-step"] = "last or end step";
226 DescriptionMap["id-mapping"] = "whether the identity shall be used in mapping atoms onto atoms or some closest distance measure shall be used";
227 DescriptionMap["input"] = "name of input file";
228 DescriptionMap["length"] = "length in space";
229 DescriptionMap["lengths"] = "list of three of lengths in space, one for each axis direction";
230 DescriptionMap["MaxDistance"] = "maximum distance in space";
231 DescriptionMap["molecule-by-id"] = "index of a molecule";
232 DescriptionMap["molecule-by-name"] = "name of a molecule";
233 DescriptionMap["nonconvex-file"] = "filename of the non-convex envelope";
234 DescriptionMap["order"] = "order of a discretization, dissection, ...";
235 DescriptionMap["output-file"] = "name of the output file";
236 DescriptionMap["periodic"] = "system is constraint to periodic boundary conditions (y/n)";
237 DescriptionMap["position"] = "position in R^3 space";
238 DescriptionMap["select-atom-by-id"] = "select an atom by index";
239 DescriptionMap["select-molecule-by-id"] = "select a molecule by index";
240 DescriptionMap["start-step"] = "first or start step";
241 DescriptionMap["unselect-atom-by-id"] = "unselect an atom by index";
242 DescriptionMap["unselect-molecule-by-id"] = "unselect a molecule by index";
243
244 // short forms for the actions
245 ShortFormMap["add-atom"] = "a";
246 ShortFormMap["bond-table"] = "g";
247 ShortFormMap["bond-file"] = "A";
248 ShortFormMap["boundary"] = "c";
249 ShortFormMap["change-box"] = "B";
250 ShortFormMap["center-edge"] = "O";
251 ShortFormMap["center-in-box"] = "b";
252 ShortFormMap["change-element"] = "E";
253// ShortFormMap["convex-envelope"] = "x";
254 ShortFormMap["default-molname"] = "X";
255 ShortFormMap["depth-first-search"] = "D";
256 ShortFormMap["element-db"] = "e";
257 ShortFormMap["fastparsing"] = "n";
258 ShortFormMap["fill-molecule"] = "F";
259 ShortFormMap["fragment-mol"] = "f";
260 ShortFormMap["help"] = "h";
261 ShortFormMap["input"] = "i";
262 ShortFormMap["linear-interpolate"] = "L";
263 ShortFormMap["nonconvex-envelope"] = "N";
264// ShortFormMap["output"] = "o";
265 ShortFormMap["pair-correlation"] = "C";
266 ShortFormMap["parse-xyz"] = "p";
267 ShortFormMap["remove-atom"] = "r";
268 ShortFormMap["remove-sphere"] = "R";
269 ShortFormMap["repeat-box"] = "d";
270 ShortFormMap["rotate-to-pas"] = "m";
271 ShortFormMap["save-adjacency"] = "J";
272 ShortFormMap["save-bonds"] = "j";
273 ShortFormMap["save-temperature"] = "S";
274 ShortFormMap["scale-box"] = "s";
275 ShortFormMap["set-basis"] = "M";
276 ShortFormMap["set-output"] = "o";
277 ShortFormMap["subgraph-dissect"] = "I";
278 ShortFormMap["suspend-in-water"] = "u";
279 ShortFormMap["translate-mol"] = "t";
280 ShortFormMap["verbose"] = "v";
281 ShortFormMap["verlet-integrate"] = "P";
282 ShortFormMap["version"] = "V";
283
284 // value types for the actions
285 TypeMap["add-atom"] = &typeid(element);
286 TypeMap["bond-file"] = &typeid(std::string);
287 TypeMap["bond-table"] = &typeid(std::string);
288 TypeMap["boundary"] = &typeid(VectorValue);
289 TypeMap["center-in-box"] = &typeid(BoxValue);
290 TypeMap["change-box"] = &typeid(BoxValue);
291 TypeMap["change-element"] = &typeid(element);
292 TypeMap["change-molname"] = &typeid(std::string);
293 TypeMap["convex-envelope"] = &typeid(void);
294 TypeMap["default-molname"] = &typeid(std::string);
295 TypeMap["depth-first-search"] = &typeid(double);
296 TypeMap["element-db"] = &typeid(std::string);
297 TypeMap["fastparsing"] = &typeid(bool);
298 TypeMap["fill-molecule"] = &typeid(std::string);
299 TypeMap["fragment-mol"] = &typeid(std::string);
300 TypeMap["input"] = &typeid(std::string);
301 TypeMap["linear-interpolate"] = &typeid(std::string);
302 TypeMap["molecular-volume"] = &typeid(molecule);
303 TypeMap["nonconvex-envelope"] = &typeid(double);
304 TypeMap["output"] = &typeid(void);
305 TypeMap["parse-xyz"] = &typeid(std::string);
306 TypeMap["pair-correlation"] = &typeid(std::string);
307 TypeMap["principal-axis-system"] = &typeid(molecule);
308 TypeMap["remove-atom"] = &typeid(void);
309 TypeMap["remove-sphere"] = &typeid(double);
310 TypeMap["repeat-box"] = &typeid(VectorValue);
311 TypeMap["rotate-to-pas"] = &typeid(molecule);
312 TypeMap["save-adjacency"] = &typeid(std::string);
313 TypeMap["save-bonds"] = &typeid(std::string);
314 TypeMap["save-temperature"] = &typeid(std::string);
315 TypeMap["scale-box"] = &typeid(VectorValue);
316 TypeMap["set-basis"] = &typeid(std::string);
317 TypeMap["set-output"] = &typeid(std::vector<std::string>);
318 TypeMap["subgraph-dissect"] = &typeid(void);
319 TypeMap["suspend-in-water"] = &typeid(double);
320 TypeMap["translate-mol"] = &typeid(VectorValue);
321 TypeMap["verlet-integrate"] = &typeid(std::string);
322 TypeMap["verbose"] = &typeid(int);
323
324 // value types for the values
325 TypeMap["bin-output-file"] = &typeid(std::string);
326 TypeMap["bin-end"] = &typeid(double);
327 TypeMap["bin-start"] = &typeid(double);
328 TypeMap["bin-width"] = &typeid(double);
329 TypeMap["convex-file"] = &typeid(std::string);
330 TypeMap["distance"] = &typeid(double);
331 TypeMap["distances"] = &typeid(VectorValue);
332 TypeMap["DoRotate"] = &typeid(bool);
333 TypeMap["element"] = &typeid(element);
334 TypeMap["elements"] = &typeid(std::vector<element *>);
335 TypeMap["end-step"] = &typeid(int);
336 TypeMap["id-mapping"] = &typeid(bool);
337 TypeMap["length"] = &typeid(double);
338 TypeMap["lengths"] = &typeid(VectorValue);
339 TypeMap["MaxDistance"] = &typeid(double);
340 TypeMap["nonconvex-file"] = &typeid(std::string);
341 TypeMap["order"] = &typeid(int);
342 TypeMap["output-file"] = &typeid(std::string);
343 TypeMap["periodic"] = &typeid(bool);
344 TypeMap["position"] = &typeid(VectorValue);
345 TypeMap["select-atom-by-id"] = &typeid(atom);
346 TypeMap["select-molecule-by-id"] = &typeid(molecule);
347 TypeMap["start-step"] = &typeid(int);
348 TypeMap["unselect-atom-by-id"] = &typeid(atom);
349 TypeMap["unselect-molecule-by-id"] = &typeid(molecule);
350
351 TypeEnumMap[&typeid(void)] = None;
352 TypeEnumMap[&typeid(bool)] = Boolean;
353 TypeEnumMap[&typeid(int)] = Integer;
354 TypeEnumMap[&typeid(std::vector<int>)] = ListOfIntegers;
355 TypeEnumMap[&typeid(double)] = Double;
356 TypeEnumMap[&typeid(std::vector<double>)] = ListOfDoubles;
357 TypeEnumMap[&typeid(std::string)] = String;
358 TypeEnumMap[&typeid(std::vector<std::string>)] = ListOfStrings;
359 TypeEnumMap[&typeid(VectorValue)] = Vector;
360 TypeEnumMap[&typeid(std::vector<VectorValue>)] = ListOfVectors;
361 TypeEnumMap[&typeid(BoxValue)] = Box;
362 TypeEnumMap[&typeid(molecule)] = Molecule;
363 TypeEnumMap[&typeid(std::vector<molecule *>)] = ListOfMolecules;
364 TypeEnumMap[&typeid(atom)] = Atom;
365 TypeEnumMap[&typeid(std::vector<atom *>)] = ListOfAtoms;
366 TypeEnumMap[&typeid(element)] = Element;
367 TypeEnumMap[&typeid(std::vector<element *>)] = ListOfElements;
368
369 // default values for any action that needs one (always string!)
370 CurrentValue["bin-width"] = "0.5";
371 CurrentValue["fastparsing"] = "0";
372 CurrentValue["atom-by-id"] = "-1";
373 CurrentValue["molecule-by-id"] = "-1";
374 CurrentValue["periodic"] = "0";
375
376 // put action into each menu category
377 MenuDescription["analysis"] = pair<std::string,std::string>("Analysis (pair correlation, volume)", "Analysis");
378 MenuDescription["atom"] = pair<std::string,std::string>("Edit atoms", "Atoms");
379 MenuDescription["command"] = pair<std::string,std::string>("Configuration", "configuration options");
380 MenuDescription["fragmentation"] = pair<std::string,std::string>("Fragmentation", "Fragmentation");
381 MenuDescription["molecule"] = pair<std::string,std::string>("Parse files into system", "Molecules");
382 MenuDescription["parser"] = pair<std::string,std::string>("Edit molecules (load, parse, save)", "Input/Output");
383 MenuDescription["selection"] = pair<std::string,std::string>("Select atoms/molecules", "Selection");
384 MenuDescription["tesselation"] = pair<std::string,std::string>("Tesselate molecules", "Tesselation");
385 MenuDescription["world"] = pair<std::string,std::string>("Edit world", "Globals");
386
387 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "molecular-volume") );
388 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "pair-correlation") );
389 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "principal-axis-system") );
390
391 MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "add-atom") );
392 MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "change-element") );
393 MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "remove-atom") );
394
395 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "bond-table") );
396 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "element-db") );
397 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "fastparsing") );
398 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "verbose") );
399 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "version") );
400
401 MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "depth-first-search") );
402 MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "fragment-mol") );
403 MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "subgraph-dissect") );
404
405 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "bond-file") );
406 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "change-molname") );
407 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "fill-molecule") );
408 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "linear-interpolate") );
409 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "rotate-to-pas") );
410 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "save-adjacency") );
411 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "save-bonds") );
412 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "save-temperature") );
413 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "suspend-in-water") );
414 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "translate-mol") );
415 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "verlet-integrate") );
416
417 MenuContainsActionMap.insert( pair<std::string, std::string> ("parser", "parse-xyz") );
418 MenuContainsActionMap.insert( pair<std::string, std::string> ("parser", "SaveXyz") );
419
420 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "select-atom-by-id") );
421 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "select-molecule-by-id") );
422 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "unselect-atom-by-id") );
423 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "unselect-molecule-by-id") );
424
425 MenuContainsActionMap.insert( pair<std::string, std::string> ("tesselation", "convex-envelope") );
426 MenuContainsActionMap.insert( pair<std::string, std::string> ("tesselation", "nonconvex-envelope") );
427
428 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "boundary") );
429 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "bound-in-box") );
430 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "center-in-box") );
431 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "center-edge") );
432 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "change-box") );
433 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "input") );
434 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "output") );
435 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "remove-sphere") );
436 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "repeat-box") );
437 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "scale-box") );
438 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "default-molname") );
439 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "set-basis") );
440 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "set-output") );
441
442 // put actions into command line category
443 generic.insert("add-atom");
444 generic.insert("bond-file");
445 generic.insert("bond-table");
446 generic.insert("boundary");
447// generic.insert("bound-in-box");
448 generic.insert("center-edge");
449 generic.insert("center-in-box");
450 generic.insert("change-box");
451// generic.insert("change-molname");
452 generic.insert("change-element");
453 generic.insert("convex-envelope");
454 generic.insert("default-molname");
455 generic.insert("depth-first-search");
456 generic.insert("element-db");
457 generic.insert("fastparsing");
458 generic.insert("fill-molecule");
459 generic.insert("fragment-mol");
460 generic.insert("help");
461 generic.insert("input");
462 generic.insert("linear-interpolate");
463// generic.insert("molecular-volume");
464 generic.insert("nonconvex-envelope");
465 generic.insert("output");
466 generic.insert("pair-correlation");
467 generic.insert("parse-xyz");
468// generic.insert("principal-axis-system");
469 generic.insert("remove-atom");
470 generic.insert("remove-sphere");
471 generic.insert("repeat-box");
472 generic.insert("rotate-to-pas");
473 generic.insert("save-adjacency");
474 generic.insert("save-bonds");
475 generic.insert("save-temperature");
476 generic.insert("scale-box");
477 generic.insert("set-basis");
478 generic.insert("set-output");
479 generic.insert("subgraph-dissect");
480 generic.insert("suspend-in-water");
481 generic.insert("translate-mol");
482 generic.insert("verbose");
483 generic.insert("verlet-integrate");
484 generic.insert("version");
485
486 // positional arguments
487 generic.insert("input");
488
489 // hidden arguments
490 hidden.insert("bin-end");
491 hidden.insert("bin-output-file");
492 hidden.insert("bin-start");
493 hidden.insert("bin-width");
494 hidden.insert("convex-file");
495 hidden.insert("distance");
496 hidden.insert("DoRotate");
497 hidden.insert("distances");
498 hidden.insert("element");
499 hidden.insert("elements");
500 hidden.insert("end-step");
501 hidden.insert("id-mapping");
502 hidden.insert("lengths");
503 hidden.insert("MaxDistance");
504 hidden.insert("nonconvex-file");
505 hidden.insert("order");
506 hidden.insert("output-file");
507 hidden.insert("periodic");
508 hidden.insert("position");
509 hidden.insert("select-atom-by-id");
510 hidden.insert("select-molecule-by-id");
511 hidden.insert("start-step");
512 hidden.insert("unselect-atom-by-id");
513 hidden.insert("unselect-molecule-by-id");
514}
515
516/** Destructor of class MapOfActions.
517 *
518 */
519MapOfActions::~MapOfActions()
520{
521 DescriptionMap.clear();
522}
523
524void MapOfActions::queryCurrentValue(const char * name, class atom * &_T)
525{
526 int atomID = -1;
527 if (typeid( atom ) == *TypeMap[name]) {
528 if (CurrentValue.find(name) == CurrentValue.end())
529 throw MissingValueException(__FILE__, __LINE__);
530 atomID = lexical_cast<int>(CurrentValue[name].c_str());
531 CurrentValue.erase(name);
532 } else
533 throw IllegalTypeException(__FILE__,__LINE__);
534 _T = World::getInstance().getAtom(AtomById(atomID));
535}
536
537void MapOfActions::queryCurrentValue(const char * name, class element * &_T) {
538 int Z = -1;
539 if (typeid( element ) == *TypeMap[name]) {
540 if (CurrentValue.find(name) == CurrentValue.end())
541 throw MissingValueException(__FILE__, __LINE__);
542 Z = lexical_cast<int>(CurrentValue[name].c_str());
543 CurrentValue.erase(name);
544 } else
545 throw IllegalTypeException(__FILE__,__LINE__);
546 _T = World::getInstance().getPeriode()->FindElement(Z);
547}
548
549void MapOfActions::queryCurrentValue(const char * name, class molecule * &_T) {
550 int molID = -1;
551 if (typeid( molecule ) == *TypeMap[name]) {
552 if (CurrentValue.find(name) == CurrentValue.end())
553 throw MissingValueException(__FILE__, __LINE__);
554 molID = lexical_cast<int>(CurrentValue[name].c_str());
555 CurrentValue.erase(name);
556 } else
557 throw IllegalTypeException(__FILE__,__LINE__);
558 _T = World::getInstance().getMolecule(MoleculeById(molID));
559}
560
561void MapOfActions::queryCurrentValue(const char * name, class Box &_T) {
562 Matrix M;
563 double tmp;
564 if (typeid( BoxValue ) == *TypeMap[name]) {
565 if (CurrentValue.find(name) == CurrentValue.end())
566 throw MissingValueException(__FILE__, __LINE__);
567 std::istringstream stream(CurrentValue[name]);
568 stream >> tmp;
569 M.set(0,0,tmp);
570 stream >> tmp;
571 M.set(0,1,tmp);
572 M.set(1,0,tmp);
573 stream >> tmp;
574 M.set(0,2,tmp);
575 M.set(2,0,tmp);
576 stream >> tmp;
577 M.set(1,1,tmp);
578 stream >> tmp;
579 M.set(1,2,tmp);
580 M.set(2,1,tmp);
581 stream >> tmp;
582 M.set(2,2,tmp);
583 _T = M;
584 CurrentValue.erase(name);
585 } else
586 throw IllegalTypeException(__FILE__,__LINE__);
587}
588
589void MapOfActions::queryCurrentValue(const char * name, class Vector &_T) {
590 if (typeid( VectorValue ) == *TypeMap[name]) {
591 std::istringstream stream(CurrentValue[name]);
592 CurrentValue.erase(name);
593 stream >> _T[0];
594 stream >> _T[1];
595 stream >> _T[2];
596 } else
597 throw IllegalTypeException(__FILE__,__LINE__);
598}
599
600void MapOfActions::queryCurrentValue(const char * name, std::vector<atom *>&_T)
601{
602 int atomID = -1;
603 atom *Walker = NULL;
604 if (typeid( std::vector<atom *> ) == *TypeMap[name]) {
605 if (CurrentValue.find(name) == CurrentValue.end())
606 throw MissingValueException(__FILE__, __LINE__);
607 std::istringstream stream(CurrentValue[name]);
608 CurrentValue.erase(name);
609 while (!stream.fail()) {
610 stream >> atomID;
611 Walker = World::getInstance().getAtom(AtomById(atomID));
612 if (Walker != NULL)
613 _T.push_back(Walker);
614 }
615 } else
616 throw IllegalTypeException(__FILE__,__LINE__);
617}
618
619void MapOfActions::queryCurrentValue(const char * name, std::vector<element *>&_T)
620{
621 int Z = -1;
622 element *elemental = NULL;
623 if (typeid( std::vector<element *> ) == *TypeMap[name]) {
624 if (CurrentValue.find(name) == CurrentValue.end())
625 throw MissingValueException(__FILE__, __LINE__);
626 std::istringstream stream(CurrentValue[name]);
627 CurrentValue.erase(name);
628 while (!stream.fail()) {
629 stream >> Z;
630 elemental = World::getInstance().getPeriode()->FindElement(Z);
631 if (elemental != NULL)
632 _T.push_back(elemental);
633 }
634 } else
635 throw IllegalTypeException(__FILE__,__LINE__);
636}
637
638void MapOfActions::queryCurrentValue(const char * name, std::vector<molecule *>&_T)
639{
640 int molID = -1;
641 molecule *mol = NULL;
642 if (typeid( std::vector<molecule *> ) == *TypeMap[name]) {
643 if (CurrentValue.find(name) == CurrentValue.end())
644 throw MissingValueException(__FILE__, __LINE__);
645 std::istringstream stream(CurrentValue[name]);
646 CurrentValue.erase(name);
647 while (!stream.fail()) {
648 stream >> molID;
649 mol = World::getInstance().getMolecule(MoleculeById(molID));
650 if (mol != NULL)
651 _T.push_back(mol);
652 }
653 } else
654 throw IllegalTypeException(__FILE__,__LINE__);
655}
656
657
658void MapOfActions::setCurrentValue(const char * name, class atom * &_T)
659{
660 if (typeid( atom ) == *TypeMap[name]) {
661 std::ostringstream stream;
662 stream << _T->getId();
663 CurrentValue[name] = stream.str();
664 } else
665 throw IllegalTypeException(__FILE__,__LINE__);
666}
667
668void MapOfActions::setCurrentValue(const char * name, class element * &_T)
669{
670 if (typeid( element ) == *TypeMap[name]) {
671 std::ostringstream stream;
672 stream << _T->Z;
673 CurrentValue[name] = stream.str();
674 } else
675 throw IllegalTypeException(__FILE__,__LINE__);
676}
677
678void MapOfActions::setCurrentValue(const char * name, class molecule * &_T)
679{
680 if (typeid( molecule ) == *TypeMap[name]) {
681 std::ostringstream stream;
682 stream << _T->getId();
683 CurrentValue[name] = stream.str();
684 } else
685 throw IllegalTypeException(__FILE__,__LINE__);
686}
687
688void MapOfActions::setCurrentValue(const char * name, class Box &_T)
689{
690 const Matrix &M = _T.getM();
691 if (typeid( BoxValue ) == *TypeMap[name]) {
692 std::ostringstream stream;
693 stream << M.at(0,0) << " ";
694 stream << M.at(0,1) << " ";
695 stream << M.at(0,2) << " ";
696 stream << M.at(1,1) << " ";
697 stream << M.at(1,2) << " ";
698 stream << M.at(2,2) << " ";
699 CurrentValue[name] = stream.str();
700 } else
701 throw IllegalTypeException(__FILE__,__LINE__);
702}
703
704void MapOfActions::setCurrentValue(const char * name, class Vector &_T)
705{
706 if (typeid( VectorValue ) == *TypeMap[name]){
707 std::ostringstream stream;
708 stream << _T[0] << " ";
709 stream << _T[1] << " ";
710 stream << _T[2] << " ";
711 CurrentValue[name] = stream.str();
712 } else
713 throw IllegalTypeException(__FILE__,__LINE__);
714}
715
716void MapOfActions::setCurrentValue(const char * name, std::vector<atom *>&_T)
717{
718 if (typeid( std::vector<atom *> ) == *TypeMap[name]) {
719 std::ostringstream stream;
720 for (std::vector<atom *>::iterator iter = _T.begin(); iter != _T.end(); ++iter) {
721 stream << (*iter)->getId() << " ";
722 }
723 CurrentValue[name] = stream.str();
724 } else
725 throw IllegalTypeException(__FILE__,__LINE__);
726}
727
728void MapOfActions::setCurrentValue(const char * name, std::vector<element *>&_T)
729{
730 if (typeid( std::vector<element *> ) == *TypeMap[name]) {
731 std::ostringstream stream;
732 for (std::vector<element *>::iterator iter = _T.begin(); iter != _T.end(); ++iter) {
733 stream << (*iter)->Z << " ";
734 }
735 CurrentValue[name] = stream.str();
736 } else
737 throw IllegalTypeException(__FILE__,__LINE__);
738}
739
740void MapOfActions::setCurrentValue(const char * name, std::vector<molecule *>&_T)
741{
742 if (typeid( std::vector<molecule *> ) == *TypeMap[name]) {
743 std::ostringstream stream;
744 for (std::vector<molecule *>::iterator iter = _T.begin(); iter != _T.end(); ++iter) {
745 stream << (*iter)->getId() << " ";
746 }
747 CurrentValue[name] = stream.str();
748 } else
749 throw IllegalTypeException(__FILE__,__LINE__);
750}
751
752
753
754void MapOfActions::populateActions()
755{
756 new AnalysisMolecularVolumeAction();
757 new AnalysisPairCorrelationAction();
758 new AnalysisPointCorrelationAction();
759 new AnalysisPrincipalAxisSystemAction();
760 new AnalysisSurfaceCorrelationAction();
761
762 new AtomAddAction();
763 new AtomChangeElementAction();
764 new AtomRemoveAction();
765
766 new CommandLineBondLengthTableAction();
767 new CommandLineElementDbAction();
768 new CommandLineFastParsingAction();
769 new CommandLineHelpAction();
770 new CommandLineVerboseAction();
771 new CommandLineVersionAction();
772
773 new FragmentationDepthFirstSearchAction();
774 new FragmentationFragmentationAction();
775 new FragmentationSubgraphDissectionAction();
776
777 new MoleculeBondFileAction();
778 new MoleculeChangeNameAction();
779 new MoleculeFillWithMoleculeAction();
780 new MoleculeLinearInterpolationofTrajectoriesAction();
781 new MoleculeRotateToPrincipalAxisSystemAction();
782 new MoleculeSaveAdjacencyAction();
783 new MoleculeSaveBondsAction();
784 new MoleculeSaveTemperatureAction();
785 new MoleculeSuspendInWaterAction();
786 new MoleculeTranslateAction();
787 new MoleculeVerletIntegrationAction();
788
789 new ParserLoadXyzAction();
790 new ParserSaveXyzAction();
791
792 new SelectionAtomByIdAction();
793 new SelectionMoleculeByIdAction();
794 new SelectionNotAtomByIdAction();
795 new SelectionNotMoleculeByIdAction();
796
797 new TesselationConvexEnvelopeAction();
798 new TesselationNonConvexEnvelopeAction();
799
800 new WorldAddEmptyBoundaryAction();
801 new WorldBoundInBoxAction();
802 new WorldCenterInBoxAction();
803 new WorldCenterOnEdgeAction();
804 new WorldChangeBoxAction();
805 new WorldInputAction();
806 new WorldOutputAction();
807 new WorldRemoveSphereOfAtomsAction();
808 new WorldRepeatBoxAction();
809 new WorldScaleBoxAction();
810 new WorldSetDefaultNameAction();
811 new WorldSetGaussianBasisAction();
812 new WorldSetOutputFormatsAction();
813}
814
815/** Adds all options to the CommandLineParser.
816 *
817 */
818void MapOfActions::AddOptionsToParser()
819{
820 // add other options
821 for (map< set<string>*, po::options_description* >::iterator ListRunner = CmdParserLookup.begin(); ListRunner != CmdParserLookup.end(); ++ListRunner) {
822 for (set<string>::iterator OptionRunner = ListRunner->first->begin(); OptionRunner != ListRunner->first->end(); ++OptionRunner) {
823 if (hasValue(*OptionRunner)) {
824 DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " with type " << TypeMap[*OptionRunner]->name() << " to CommandLineParser." << endl);
825 switch(TypeEnumMap[TypeMap[*OptionRunner]]) {
826 default:
827 case None:
828 ListRunner->second->add_options()
829 (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
830 ;
831 break;
832 case Boolean:
833 ListRunner->second->add_options()
834 (getKeyAndShortForm(*OptionRunner).c_str(),
835 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
836 po::value< bool >()->default_value(lexical_cast<int>(CurrentValue[*OptionRunner].c_str())) :
837 po::value< bool >(),
838 getDescription(*OptionRunner).c_str())
839 ;
840 break;
841 case Box:
842 ListRunner->second->add_options()
843 (getKeyAndShortForm(*OptionRunner).c_str(),
844 po::value<BoxValue>(),
845 getDescription(*OptionRunner).c_str())
846 ;
847 break;
848 case Integer:
849 ListRunner->second->add_options()
850 (getKeyAndShortForm(*OptionRunner).c_str(),
851 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
852 po::value< int >()->default_value(lexical_cast<int>(CurrentValue[*OptionRunner].c_str())) :
853 po::value< int >(),
854 getDescription(*OptionRunner).c_str())
855 ;
856 break;
857 case ListOfIntegers:
858 ListRunner->second->add_options()
859 (getKeyAndShortForm(*OptionRunner).c_str(),
860 po::value< vector<int> >()->multitoken(),
861 getDescription(*OptionRunner).c_str())
862 ;
863 break;
864 case Double:
865 ListRunner->second->add_options()
866 (getKeyAndShortForm(*OptionRunner).c_str(),
867 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
868 po::value< double >()->default_value(lexical_cast<double>(CurrentValue[*OptionRunner].c_str())) :
869 po::value< double >(),
870 getDescription(*OptionRunner).c_str())
871 ;
872 break;
873 case ListOfDoubles:
874 ListRunner->second->add_options()
875 (getKeyAndShortForm(*OptionRunner).c_str(),
876 po::value< vector<double> >()->multitoken(),
877 getDescription(*OptionRunner).c_str())
878 ;
879 break;
880 case String:
881 ListRunner->second->add_options()
882 (getKeyAndShortForm(*OptionRunner).c_str(),
883 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
884 po::value< std::string >()->default_value(CurrentValue[*OptionRunner]) :
885 po::value< std::string >(),
886 getDescription(*OptionRunner).c_str())
887 ;
888 break;
889 case ListOfStrings:
890 ListRunner->second->add_options()
891 (getKeyAndShortForm(*OptionRunner).c_str(),
892 po::value< vector<std::string> >()->multitoken(),
893 getDescription(*OptionRunner).c_str())
894 ;
895 break;
896 case Vector:
897 ListRunner->second->add_options()
898 (getKeyAndShortForm(*OptionRunner).c_str(),
899 po::value<VectorValue>(),
900 getDescription(*OptionRunner).c_str())
901 ;
902 break;
903 case ListOfVectors:
904 ListRunner->second->add_options()
905 (getKeyAndShortForm(*OptionRunner).c_str(),
906 po::value< vector<VectorValue> >()->multitoken(),
907 getDescription(*OptionRunner).c_str())
908 ;
909 break;
910 case Molecule:
911 ListRunner->second->add_options()
912 (getKeyAndShortForm(*OptionRunner).c_str(),
913 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
914 po::value< int >()->default_value(lexical_cast<int>(CurrentValue[*OptionRunner].c_str())) :
915 po::value< int >(),
916 getDescription(*OptionRunner).c_str())
917 ;
918 break;
919 case ListOfMolecules:
920 ListRunner->second->add_options()
921 (getKeyAndShortForm(*OptionRunner).c_str(),
922 po::value< vector<int> >()->multitoken(),
923 getDescription(*OptionRunner).c_str())
924 ;
925 break;
926 case Atom:
927 ListRunner->second->add_options()
928 (getKeyAndShortForm(*OptionRunner).c_str(),
929 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
930 po::value< int >()->default_value(lexical_cast<int>(CurrentValue[*OptionRunner].c_str())) :
931 po::value< int >(),
932 getDescription(*OptionRunner).c_str())
933 ;
934 break;
935 case ListOfAtoms:
936 ListRunner->second->add_options()
937 (getKeyAndShortForm(*OptionRunner).c_str(),
938 po::value< vector<int> >()->multitoken(),
939 getDescription(*OptionRunner).c_str())
940 ;
941 break;
942 case Element:
943 ListRunner->second->add_options()
944 (getKeyAndShortForm(*OptionRunner).c_str(),
945 po::value< int >(),
946 getDescription(*OptionRunner).c_str())
947 ;
948 break;
949 case ListOfElements:
950 ListRunner->second->add_options()
951 (getKeyAndShortForm(*OptionRunner).c_str(),
952 po::value< vector<int> >()->multitoken(),
953 getDescription(*OptionRunner).c_str())
954 ;
955 break;
956 }
957 } else {
958 DoLog(3) && (Log() << Verbose(3) << "Adding option " << *OptionRunner << " to CommandLineParser." << endl);
959 ListRunner->second->add_options()
960 (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
961 ;
962 }
963 }
964 }
965}
966
967/** Getter for MapOfActions:DescriptionMap.
968 * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
969 * \param actionname name of the action to lookup
970 * \return Description of the action
971 */
972std::string MapOfActions::getDescription(string actionname)
973{
974 ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescription");
975 return DescriptionMap[actionname];
976}
977
978/** Specific Getter for a MapOfActions:ShortFormMap.
979 * If action has a short for, then combination is as "actionname,ShortForm" (this is
980 * the desired format for boost::program_options). If no short form exists in the map,
981 * just actionname will be returned
982 * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
983 * \param actionname name of the action to lookup
984 * \return actionname,ShortForm or Description of the action
985 */
986std::string MapOfActions::getKeyAndShortForm(string actionname)
987{
988 stringstream output;
989 ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescriptionAndShortForm");
990 output << actionname;
991 if (ShortFormMap.find(actionname) != DescriptionMap.end())
992 output << "," << ShortFormMap[actionname];
993 return output.str();
994}
995
996/** Getter for MapOfActions:ShortFormMap.
997 * Note that we assert when action does not exist CommandLineParser::ShortFormMap.
998 * \param actionname name of the action to lookup
999 * \return ShortForm of the action
1000 */
1001std::string MapOfActions::getShortForm(string actionname)
1002{
1003 ASSERT(ShortFormMap.find(actionname) != ShortFormMap.end(), "Unknown action name passed to MapOfActions::getShortForm");
1004 return ShortFormMap[actionname];
1005}
1006
1007/** Returns whether the given action needs a value or not.
1008 * \param actionname name of the action to look up
1009 * \return true - value is needed, false - no value is stored in MapOfActions::TypeMap
1010 */
1011bool MapOfActions::hasValue(string actionname)
1012{
1013 return (TypeMap.find(actionname) != TypeMap.end());
1014}
1015
1016/** Getter for MapOfActions::TypeMap.
1017 * \param actionname name of the action to look up
1018 * \return type of the action
1019 */
1020std::string MapOfActions::getValueType(string actionname)
1021{
1022 return TypeMap[actionname]->name();
1023}
1024
1025/** Searches whether action is registered with CommandLineParser.
1026 * Note that this method is only meant transitionally for ParseCommandLineOptions' removal.
1027 * I.e. All actions that are already handled by the new CommandLineUIFactory can be checked
1028 * by this function.
1029 * \param shortform command short form to look for
1030 * \return true - action has been registered, false - action has not been registered.
1031 */
1032bool MapOfActions::isShortFormPresent(string shortform)
1033{
1034 bool result = false;
1035 string actionname;
1036 for (map<std::string, std::string>::iterator ShortFormRunner = ShortFormMap.begin(); ShortFormRunner != ShortFormMap.end(); ++ShortFormRunner)
1037 if (ShortFormRunner->second == shortform) {
1038 actionname = ShortFormRunner->first;
1039 break;
1040 }
1041 result = result || (generic.find(actionname) != generic.end());
1042 result = result || (config.find(actionname) != config.end());
1043 result = result || (hidden.find(actionname) != hidden.end());
1044 result = result || (visible.find(actionname) != visible.end());
1045 result = result || (inputfile.find(actionname) != inputfile.end());
1046 return result;
1047}
1048
1049/** Returns the inverse to MapOfActions::ShortFormMap, i.e. lookup actionname for its short form.
1050 * \return map from short form of action to name of action
1051 */
1052map <std::string, std::string> MapOfActions::getShortFormToActionMap()
1053{
1054 map <std::string, std::string> result;
1055
1056 for (map<std::string, std::string>::iterator iter = ShortFormMap.begin(); iter != ShortFormMap.end(); ++iter)
1057 result[iter->second] = iter->first;
1058
1059 return result;
1060}
1061
1062
1063CONSTRUCT_SINGLETON(MapOfActions)
Note: See TracBrowser for help on using the repository browser.