source: src/Actions/MapOfActions.cpp@ 120088

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

TESTFIX: Simple_configuration/5 needs select-atom-by-id in front of and remove-atom now has MapOfActions::TypeMap entry of void.

  • Property mode set to 100644
File size: 43.9 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.xy = boost::lexical_cast<double>(components.at(1));
151 BV.xz = boost::lexical_cast<double>(components.at(2));
152 BV.yy = boost::lexical_cast<double>(components.at(3));
153 BV.yz = 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["sphere-radius"] = "radius of tesselation sphere";
241 DescriptionMap["start-step"] = "first or start step";
242 DescriptionMap["unselect-atom-by-id"] = "unselect an atom by index";
243 DescriptionMap["unselect-molecule-by-id"] = "unselect a molecule by index";
244
245 // short forms for the actions
246 ShortFormMap["add-atom"] = "a";
247 ShortFormMap["bond-table"] = "g";
248 ShortFormMap["bond-file"] = "A";
249 ShortFormMap["boundary"] = "c";
250 ShortFormMap["change-box"] = "B";
251 ShortFormMap["center-edge"] = "O";
252 ShortFormMap["center-in-box"] = "b";
253 ShortFormMap["change-element"] = "E";
254// ShortFormMap["convex-envelope"] = "x";
255 ShortFormMap["default-molname"] = "X";
256 ShortFormMap["depth-first-search"] = "D";
257 ShortFormMap["element-db"] = "e";
258 ShortFormMap["fastparsing"] = "n";
259 ShortFormMap["fill-molecule"] = "F";
260 ShortFormMap["fragment-mol"] = "f";
261 ShortFormMap["help"] = "h";
262 ShortFormMap["input"] = "i";
263 ShortFormMap["linear-interpolate"] = "L";
264 ShortFormMap["nonconvex-envelope"] = "N";
265// ShortFormMap["output"] = "o";
266 ShortFormMap["pair-correlation"] = "C";
267 ShortFormMap["parse-xyz"] = "p";
268 ShortFormMap["remove-atom"] = "r";
269 ShortFormMap["remove-sphere"] = "R";
270 ShortFormMap["repeat-box"] = "d";
271 ShortFormMap["rotate-to-pas"] = "m";
272 ShortFormMap["save-adjacency"] = "J";
273 ShortFormMap["save-bonds"] = "j";
274 ShortFormMap["save-temperature"] = "S";
275 ShortFormMap["scale-box"] = "s";
276 ShortFormMap["set-basis"] = "M";
277 ShortFormMap["set-output"] = "o";
278 ShortFormMap["subgraph-dissect"] = "I";
279 ShortFormMap["suspend-in-water"] = "u";
280 ShortFormMap["translate-mol"] = "t";
281 ShortFormMap["verbose"] = "v";
282 ShortFormMap["verlet-integrate"] = "P";
283 ShortFormMap["version"] = "V";
284
285 // value types for the actions
286 TypeMap["add-atom"] = &typeid(element);
287 TypeMap["bond-file"] = &typeid(std::string);
288 TypeMap["bond-table"] = &typeid(std::string);
289 TypeMap["boundary"] = &typeid(VectorValue);
290 TypeMap["center-in-box"] = &typeid(BoxValue);
291 TypeMap["change-box"] = &typeid(BoxValue);
292 TypeMap["change-element"] = &typeid(element);
293 TypeMap["change-molname"] = &typeid(std::string);
294 TypeMap["convex-envelope"] = &typeid(molecule);
295 TypeMap["default-molname"] = &typeid(std::string);
296 TypeMap["depth-first-search"] = &typeid(double);
297 TypeMap["element-db"] = &typeid(std::string);
298 TypeMap["fastparsing"] = &typeid(bool);
299 TypeMap["fill-molecule"] = &typeid(std::string);
300 TypeMap["fragment-mol"] = &typeid(std::string);
301 TypeMap["input"] = &typeid(std::string);
302 TypeMap["linear-interpolate"] = &typeid(std::string);
303 TypeMap["molecular-volume"] = &typeid(molecule);
304 TypeMap["nonconvex-envelope"] = &typeid(molecule);
305 TypeMap["output"] = &typeid(void);
306 TypeMap["parse-xyz"] = &typeid(std::string);
307 TypeMap["pair-correlation"] = &typeid(std::string);
308 TypeMap["principal-axis-system"] = &typeid(molecule);
309 TypeMap["remove-atom"] = &typeid(void);
310 TypeMap["remove-sphere"] = &typeid(double);
311 TypeMap["repeat-box"] = &typeid(VectorValue);
312 TypeMap["rotate-to-pas"] = &typeid(molecule);
313 TypeMap["save-adjacency"] = &typeid(std::string);
314 TypeMap["save-bonds"] = &typeid(std::string);
315 TypeMap["save-temperature"] = &typeid(std::string);
316 TypeMap["scale-box"] = &typeid(VectorValue);
317 TypeMap["set-basis"] = &typeid(std::string);
318 TypeMap["set-output"] = &typeid(std::vector<std::string>);
319 TypeMap["subgraph-dissect"] = &typeid(void);
320 TypeMap["suspend-in-water"] = &typeid(double);
321 TypeMap["translate-mol"] = &typeid(VectorValue);
322 TypeMap["verlet-integrate"] = &typeid(std::string);
323 TypeMap["verbose"] = &typeid(int);
324
325 // value types for the values
326 TypeMap["bin-output-file"] = &typeid(std::string);
327 TypeMap["bin-end"] = &typeid(double);
328 TypeMap["bin-start"] = &typeid(double);
329 TypeMap["bin-width"] = &typeid(double);
330 TypeMap["convex-file"] = &typeid(std::string);
331 TypeMap["distance"] = &typeid(double);
332 TypeMap["distances"] = &typeid(VectorValue);
333 TypeMap["DoRotate"] = &typeid(bool);
334 TypeMap["element"] = &typeid(element);
335 TypeMap["elements"] = &typeid(std::vector<element *>);
336 TypeMap["end-step"] = &typeid(int);
337 TypeMap["id-mapping"] = &typeid(bool);
338 TypeMap["length"] = &typeid(double);
339 TypeMap["lengths"] = &typeid(VectorValue);
340 TypeMap["MaxDistance"] = &typeid(double);
341 TypeMap["molecule-by-id"] = &typeid(molecule);
342 TypeMap["molecule-by-name"] = &typeid(std::string);
343 TypeMap["nonconvex-file"] = &typeid(std::string);
344 TypeMap["order"] = &typeid(int);
345 TypeMap["output-file"] = &typeid(std::string);
346 TypeMap["periodic"] = &typeid(bool);
347 TypeMap["position"] = &typeid(VectorValue);
348 TypeMap["select-atom-by-id"] = &typeid(atom);
349 TypeMap["select-molecule-by-id"] = &typeid(molecule);
350 TypeMap["sphere-radius"] = &typeid(double);
351 TypeMap["start-step"] = &typeid(int);
352 TypeMap["unselect-atom-by-id"] = &typeid(atom);
353 TypeMap["unselect-molecule-by-id"] = &typeid(molecule);
354
355 TypeEnumMap[&typeid(void)] = None;
356 TypeEnumMap[&typeid(bool)] = Boolean;
357 TypeEnumMap[&typeid(int)] = Integer;
358 TypeEnumMap[&typeid(std::vector<int>)] = ListOfIntegers;
359 TypeEnumMap[&typeid(double)] = Double;
360 TypeEnumMap[&typeid(std::vector<double>)] = ListOfDoubles;
361 TypeEnumMap[&typeid(std::string)] = String;
362 TypeEnumMap[&typeid(std::vector<std::string>)] = ListOfStrings;
363 TypeEnumMap[&typeid(VectorValue)] = Vector;
364 TypeEnumMap[&typeid(std::vector<VectorValue>)] = ListOfVectors;
365 TypeEnumMap[&typeid(BoxValue)] = Box;
366 TypeEnumMap[&typeid(molecule)] = Molecule;
367 TypeEnumMap[&typeid(std::vector<molecule *>)] = ListOfMolecules;
368 TypeEnumMap[&typeid(atom)] = Atom;
369 TypeEnumMap[&typeid(std::vector<atom *>)] = ListOfAtoms;
370 TypeEnumMap[&typeid(element)] = Element;
371 TypeEnumMap[&typeid(std::vector<element *>)] = ListOfElements;
372
373 // default values for any action that needs one (always string!)
374 CurrentValue["bin-width"] = "0.5";
375 CurrentValue["fastparsing"] = "0";
376 CurrentValue["atom-by-id"] = "-1";
377 CurrentValue["molecule-by-id"] = "-1";
378 CurrentValue["periodic"] = "0";
379
380 // put action into each menu category
381 MenuDescription["analysis"] = pair<std::string,std::string>("Analysis (pair correlation, volume)", "Analysis");
382 MenuDescription["atom"] = pair<std::string,std::string>("Edit atoms", "Edit atoms");
383 MenuDescription["command"] = pair<std::string,std::string>("Configuration", "Configuration");
384 MenuDescription["fragmentation"] = pair<std::string,std::string>("Fragmentation", "Fragmentation");
385 MenuDescription["molecule"] = pair<std::string,std::string>("Parse files into system", "Parse files");
386 MenuDescription["parser"] = pair<std::string,std::string>("Edit molecules (load, parse, save)", "Edit molecules");
387 MenuDescription["tesselation"] = pair<std::string,std::string>("Tesselate molecules", "Tesselate molecules");
388 MenuDescription["world"] = pair<std::string,std::string>("Edit world", "Edit world");
389
390 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "molecular-volume") );
391 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "pair-correlation") );
392 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "principal-axis-system") );
393
394 MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "add-atom") );
395 MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "change-element") );
396 MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "remove-atom") );
397
398 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "bond-table") );
399 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "element-db") );
400 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "fastparsing") );
401 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "verbose") );
402 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "version") );
403
404 MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "depth-first-search") );
405 MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "fragment-mol") );
406 MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "subgraph-dissect") );
407
408 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "bond-file") );
409 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "change-molname") );
410 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "fill-molecule") );
411 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "linear-interpolate") );
412 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "rotate-to-pas") );
413 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "save-adjacency") );
414 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "save-bonds") );
415 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "save-temperature") );
416 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "suspend-in-water") );
417 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "translate-mol") );
418 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "verlet-integrate") );
419
420 MenuContainsActionMap.insert( pair<std::string, std::string> ("parser", "parse-xyz") );
421 MenuContainsActionMap.insert( pair<std::string, std::string> ("parser", "SaveXyz") );
422
423 MenuContainsActionMap.insert( pair<std::string, std::string> ("tesselation", "convex-envelope") );
424 MenuContainsActionMap.insert( pair<std::string, std::string> ("tesselation", "nonconvex-envelope") );
425
426 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "boundary") );
427 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "bound-in-box") );
428 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "center-in-box") );
429 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "center-edge") );
430 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "change-box") );
431 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "input") );
432 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "output") );
433 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "remove-sphere") );
434 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "repeat-box") );
435 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "scale-box") );
436 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "default-molname") );
437 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "set-basis") );
438 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "set-output") );
439
440 // put actions into command line category
441 generic.insert("add-atom");
442 generic.insert("bond-file");
443 generic.insert("bond-table");
444 generic.insert("boundary");
445// generic.insert("bound-in-box");
446 generic.insert("center-edge");
447 generic.insert("center-in-box");
448 generic.insert("change-box");
449// generic.insert("change-molname");
450 generic.insert("change-element");
451 generic.insert("convex-envelope");
452 generic.insert("default-molname");
453 generic.insert("depth-first-search");
454 generic.insert("element-db");
455 generic.insert("fastparsing");
456 generic.insert("fill-molecule");
457 generic.insert("fragment-mol");
458 generic.insert("help");
459 generic.insert("input");
460 generic.insert("linear-interpolate");
461// generic.insert("molecular-volume");
462 generic.insert("nonconvex-envelope");
463 generic.insert("output");
464 generic.insert("pair-correlation");
465 generic.insert("parse-xyz");
466// generic.insert("principal-axis-system");
467 generic.insert("remove-atom");
468 generic.insert("remove-sphere");
469 generic.insert("repeat-box");
470 generic.insert("rotate-to-pas");
471 generic.insert("save-adjacency");
472 generic.insert("save-bonds");
473 generic.insert("save-temperature");
474 generic.insert("scale-box");
475 generic.insert("set-basis");
476 generic.insert("set-output");
477 generic.insert("subgraph-dissect");
478 generic.insert("suspend-in-water");
479 generic.insert("translate-mol");
480 generic.insert("verbose");
481 generic.insert("verlet-integrate");
482 generic.insert("version");
483
484 // positional arguments
485 generic.insert("input");
486
487 // hidden arguments
488 hidden.insert("bin-end");
489 hidden.insert("bin-output-file");
490 hidden.insert("bin-start");
491 hidden.insert("bin-width");
492 hidden.insert("convex-file");
493 hidden.insert("distance");
494 hidden.insert("DoRotate");
495 hidden.insert("distances");
496 hidden.insert("element");
497 hidden.insert("elements");
498 hidden.insert("end-step");
499 hidden.insert("id-mapping");
500 hidden.insert("lengths");
501 hidden.insert("MaxDistance");
502 hidden.insert("molecule-by-id");
503 hidden.insert("molecule-by-name");
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("sphere-radius");
512 hidden.insert("start-step");
513 hidden.insert("unselect-atom-by-id");
514 hidden.insert("unselect-molecule-by-id");
515}
516
517/** Destructor of class MapOfActions.
518 *
519 */
520MapOfActions::~MapOfActions()
521{
522 DescriptionMap.clear();
523}
524
525void MapOfActions::queryCurrentValue(const char * name, class atom * &_T)
526{
527 int atomID = -1;
528 if (typeid( atom ) == *TypeMap[name]) {
529 if (CurrentValue.find(name) == CurrentValue.end())
530 throw MissingValueException(__FILE__, __LINE__);
531 atomID = lexical_cast<int>(CurrentValue[name].c_str());
532 CurrentValue.erase(name);
533 } else
534 throw IllegalTypeException(__FILE__,__LINE__);
535 _T = World::getInstance().getAtom(AtomById(atomID));
536}
537
538void MapOfActions::queryCurrentValue(const char * name, class element * &_T) {
539 int Z = -1;
540 if (typeid( element ) == *TypeMap[name]) {
541 if (CurrentValue.find(name) == CurrentValue.end())
542 throw MissingValueException(__FILE__, __LINE__);
543 Z = lexical_cast<int>(CurrentValue[name].c_str());
544 CurrentValue.erase(name);
545 } else
546 throw IllegalTypeException(__FILE__,__LINE__);
547 _T = World::getInstance().getPeriode()->FindElement(Z);
548}
549
550void MapOfActions::queryCurrentValue(const char * name, class molecule * &_T) {
551 int molID = -1;
552 if (typeid( molecule ) == *TypeMap[name]) {
553 if (CurrentValue.find(name) == CurrentValue.end())
554 throw MissingValueException(__FILE__, __LINE__);
555 molID = lexical_cast<int>(CurrentValue[name].c_str());
556 CurrentValue.erase(name);
557 } else
558 throw IllegalTypeException(__FILE__,__LINE__);
559 _T = World::getInstance().getMolecule(MoleculeById(molID));
560}
561
562void MapOfActions::queryCurrentValue(const char * name, class Box &_T) {
563 Matrix M;
564 double tmp;
565 if (typeid( BoxValue ) == *TypeMap[name]) {
566 if (CurrentValue.find(name) == CurrentValue.end())
567 throw MissingValueException(__FILE__, __LINE__);
568 std::istringstream stream(CurrentValue[name]);
569 stream >> tmp;
570 M.set(0,0,tmp);
571 stream >> tmp;
572 M.set(0,1,tmp);
573 M.set(1,0,tmp);
574 stream >> tmp;
575 M.set(0,2,tmp);
576 M.set(2,0,tmp);
577 stream >> tmp;
578 M.set(1,1,tmp);
579 stream >> tmp;
580 M.set(1,2,tmp);
581 M.set(2,1,tmp);
582 stream >> tmp;
583 M.set(2,2,tmp);
584 _T = M;
585 CurrentValue.erase(name);
586 } else
587 throw IllegalTypeException(__FILE__,__LINE__);
588}
589
590void MapOfActions::queryCurrentValue(const char * name, class Vector &_T) {
591 if (typeid( VectorValue ) == *TypeMap[name]) {
592 std::istringstream stream(CurrentValue[name]);
593 CurrentValue.erase(name);
594 stream >> _T[0];
595 stream >> _T[1];
596 stream >> _T[2];
597 } else
598 throw IllegalTypeException(__FILE__,__LINE__);
599}
600
601void MapOfActions::queryCurrentValue(const char * name, std::vector<atom *>&_T)
602{
603 int atomID = -1;
604 atom *Walker = NULL;
605 if (typeid( std::vector<atom *> ) == *TypeMap[name]) {
606 if (CurrentValue.find(name) == CurrentValue.end())
607 throw MissingValueException(__FILE__, __LINE__);
608 std::istringstream stream(CurrentValue[name]);
609 CurrentValue.erase(name);
610 while (!stream.fail()) {
611 stream >> atomID;
612 Walker = World::getInstance().getAtom(AtomById(atomID));
613 if (Walker != NULL)
614 _T.push_back(Walker);
615 }
616 } else
617 throw IllegalTypeException(__FILE__,__LINE__);
618}
619
620void MapOfActions::queryCurrentValue(const char * name, std::vector<element *>&_T)
621{
622 int Z = -1;
623 element *elemental = NULL;
624 if (typeid( std::vector<element *> ) == *TypeMap[name]) {
625 if (CurrentValue.find(name) == CurrentValue.end())
626 throw MissingValueException(__FILE__, __LINE__);
627 std::istringstream stream(CurrentValue[name]);
628 CurrentValue.erase(name);
629 while (!stream.fail()) {
630 stream >> Z;
631 elemental = World::getInstance().getPeriode()->FindElement(Z);
632 if (elemental != NULL)
633 _T.push_back(elemental);
634 }
635 } else
636 throw IllegalTypeException(__FILE__,__LINE__);
637}
638
639void MapOfActions::queryCurrentValue(const char * name, std::vector<molecule *>&_T)
640{
641 int molID = -1;
642 molecule *mol = NULL;
643 if (typeid( std::vector<molecule *> ) == *TypeMap[name]) {
644 if (CurrentValue.find(name) == CurrentValue.end())
645 throw MissingValueException(__FILE__, __LINE__);
646 std::istringstream stream(CurrentValue[name]);
647 CurrentValue.erase(name);
648 while (!stream.fail()) {
649 stream >> molID;
650 mol = World::getInstance().getMolecule(MoleculeById(molID));
651 if (mol != NULL)
652 _T.push_back(mol);
653 }
654 } else
655 throw IllegalTypeException(__FILE__,__LINE__);
656}
657
658
659void MapOfActions::setCurrentValue(const char * name, class atom * &_T)
660{
661 if (typeid( atom ) == *TypeMap[name]) {
662 std::ostringstream stream;
663 stream << _T->getId();
664 CurrentValue[name] = stream.str();
665 } else
666 throw IllegalTypeException(__FILE__,__LINE__);
667}
668
669void MapOfActions::setCurrentValue(const char * name, class element * &_T)
670{
671 if (typeid( element ) == *TypeMap[name]) {
672 std::ostringstream stream;
673 stream << _T->Z;
674 CurrentValue[name] = stream.str();
675 } else
676 throw IllegalTypeException(__FILE__,__LINE__);
677}
678
679void MapOfActions::setCurrentValue(const char * name, class molecule * &_T)
680{
681 if (typeid( molecule ) == *TypeMap[name]) {
682 std::ostringstream stream;
683 stream << _T->getId();
684 CurrentValue[name] = stream.str();
685 } else
686 throw IllegalTypeException(__FILE__,__LINE__);
687}
688
689void MapOfActions::setCurrentValue(const char * name, class Box &_T)
690{
691 const Matrix &M = _T.getM();
692 if (typeid( BoxValue ) == *TypeMap[name]) {
693 std::ostringstream stream;
694 stream << M.at(0,0) << " ";
695 stream << M.at(0,1) << " ";
696 stream << M.at(0,2) << " ";
697 stream << M.at(1,1) << " ";
698 stream << M.at(1,2) << " ";
699 stream << M.at(2,2) << " ";
700 CurrentValue[name] = stream.str();
701 } else
702 throw IllegalTypeException(__FILE__,__LINE__);
703}
704
705void MapOfActions::setCurrentValue(const char * name, class Vector &_T)
706{
707 if (typeid( VectorValue ) == *TypeMap[name]){
708 std::ostringstream stream;
709 stream << _T[0] << " ";
710 stream << _T[1] << " ";
711 stream << _T[2] << " ";
712 CurrentValue[name] = stream.str();
713 } else
714 throw IllegalTypeException(__FILE__,__LINE__);
715}
716
717void MapOfActions::setCurrentValue(const char * name, std::vector<atom *>&_T)
718{
719 if (typeid( std::vector<atom *> ) == *TypeMap[name]) {
720 std::ostringstream stream;
721 for (std::vector<atom *>::iterator iter = _T.begin(); iter != _T.end(); ++iter) {
722 stream << (*iter)->getId() << " ";
723 }
724 CurrentValue[name] = stream.str();
725 } else
726 throw IllegalTypeException(__FILE__,__LINE__);
727}
728
729void MapOfActions::setCurrentValue(const char * name, std::vector<element *>&_T)
730{
731 if (typeid( std::vector<element *> ) == *TypeMap[name]) {
732 std::ostringstream stream;
733 for (std::vector<element *>::iterator iter = _T.begin(); iter != _T.end(); ++iter) {
734 stream << (*iter)->Z << " ";
735 }
736 CurrentValue[name] = stream.str();
737 } else
738 throw IllegalTypeException(__FILE__,__LINE__);
739}
740
741void MapOfActions::setCurrentValue(const char * name, std::vector<molecule *>&_T)
742{
743 if (typeid( std::vector<molecule *> ) == *TypeMap[name]) {
744 std::ostringstream stream;
745 for (std::vector<molecule *>::iterator iter = _T.begin(); iter != _T.end(); ++iter) {
746 stream << (*iter)->getId() << " ";
747 }
748 CurrentValue[name] = stream.str();
749 } else
750 throw IllegalTypeException(__FILE__,__LINE__);
751}
752
753
754
755void MapOfActions::populateActions()
756{
757 new AnalysisMolecularVolumeAction();
758 new AnalysisPairCorrelationAction();
759 new AnalysisPointCorrelationAction();
760 new AnalysisPrincipalAxisSystemAction();
761 new AnalysisSurfaceCorrelationAction();
762
763 new AtomAddAction();
764 new AtomChangeElementAction();
765 new AtomRemoveAction();
766
767 new CommandLineBondLengthTableAction();
768 new CommandLineElementDbAction();
769 new CommandLineFastParsingAction();
770 new CommandLineHelpAction();
771 new CommandLineVerboseAction();
772 new CommandLineVersionAction();
773
774 new FragmentationDepthFirstSearchAction();
775 new FragmentationFragmentationAction();
776 new FragmentationSubgraphDissectionAction();
777
778 new MoleculeBondFileAction();
779 new MoleculeChangeNameAction();
780 new MoleculeFillWithMoleculeAction();
781 new MoleculeLinearInterpolationofTrajectoriesAction();
782 new MoleculeRotateToPrincipalAxisSystemAction();
783 new MoleculeSaveAdjacencyAction();
784 new MoleculeSaveBondsAction();
785 new MoleculeSaveTemperatureAction();
786 new MoleculeSuspendInWaterAction();
787 new MoleculeTranslateAction();
788 new MoleculeVerletIntegrationAction();
789
790 new ParserLoadXyzAction();
791 new ParserSaveXyzAction();
792
793 new SelectionAtomByIdAction();
794 new SelectionMoleculeByIdAction();
795 new SelectionNotAtomByIdAction();
796 new SelectionNotMoleculeByIdAction();
797
798 new TesselationConvexEnvelopeAction();
799 new TesselationNonConvexEnvelopeAction();
800
801 new WorldAddEmptyBoundaryAction();
802 new WorldBoundInBoxAction();
803 new WorldCenterInBoxAction();
804 new WorldCenterOnEdgeAction();
805 new WorldChangeBoxAction();
806 new WorldInputAction();
807 new WorldOutputAction();
808 new WorldRemoveSphereOfAtomsAction();
809 new WorldRepeatBoxAction();
810 new WorldScaleBoxAction();
811 new WorldSetDefaultNameAction();
812 new WorldSetGaussianBasisAction();
813 new WorldSetOutputFormatsAction();
814}
815
816/** Adds all options to the CommandLineParser.
817 *
818 */
819void MapOfActions::AddOptionsToParser()
820{
821 // add other options
822 for (map< set<string>*, po::options_description* >::iterator ListRunner = CmdParserLookup.begin(); ListRunner != CmdParserLookup.end(); ++ListRunner) {
823 for (set<string>::iterator OptionRunner = ListRunner->first->begin(); OptionRunner != ListRunner->first->end(); ++OptionRunner) {
824 if (hasValue(*OptionRunner)) {
825 DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " with type " << TypeMap[*OptionRunner]->name() << " to CommandLineParser." << endl);
826 switch(TypeEnumMap[TypeMap[*OptionRunner]]) {
827 default:
828 case None:
829 ListRunner->second->add_options()
830 (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
831 ;
832 break;
833 case Boolean:
834 ListRunner->second->add_options()
835 (getKeyAndShortForm(*OptionRunner).c_str(),
836 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
837 po::value< bool >()->default_value(lexical_cast<int>(CurrentValue[*OptionRunner].c_str())) :
838 po::value< bool >(),
839 getDescription(*OptionRunner).c_str())
840 ;
841 break;
842 case Box:
843 ListRunner->second->add_options()
844 (getKeyAndShortForm(*OptionRunner).c_str(),
845 po::value<BoxValue>(),
846 getDescription(*OptionRunner).c_str())
847 ;
848 break;
849 case Integer:
850 ListRunner->second->add_options()
851 (getKeyAndShortForm(*OptionRunner).c_str(),
852 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
853 po::value< int >()->default_value(lexical_cast<int>(CurrentValue[*OptionRunner].c_str())) :
854 po::value< int >(),
855 getDescription(*OptionRunner).c_str())
856 ;
857 break;
858 case ListOfIntegers:
859 ListRunner->second->add_options()
860 (getKeyAndShortForm(*OptionRunner).c_str(),
861 po::value< vector<int> >()->multitoken(),
862 getDescription(*OptionRunner).c_str())
863 ;
864 break;
865 case Double:
866 ListRunner->second->add_options()
867 (getKeyAndShortForm(*OptionRunner).c_str(),
868 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
869 po::value< double >()->default_value(lexical_cast<double>(CurrentValue[*OptionRunner].c_str())) :
870 po::value< double >(),
871 getDescription(*OptionRunner).c_str())
872 ;
873 break;
874 case ListOfDoubles:
875 ListRunner->second->add_options()
876 (getKeyAndShortForm(*OptionRunner).c_str(),
877 po::value< vector<double> >()->multitoken(),
878 getDescription(*OptionRunner).c_str())
879 ;
880 break;
881 case String:
882 ListRunner->second->add_options()
883 (getKeyAndShortForm(*OptionRunner).c_str(),
884 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
885 po::value< std::string >()->default_value(CurrentValue[*OptionRunner]) :
886 po::value< std::string >(),
887 getDescription(*OptionRunner).c_str())
888 ;
889 break;
890 case ListOfStrings:
891 ListRunner->second->add_options()
892 (getKeyAndShortForm(*OptionRunner).c_str(),
893 po::value< vector<std::string> >()->multitoken(),
894 getDescription(*OptionRunner).c_str())
895 ;
896 break;
897 case Vector:
898 ListRunner->second->add_options()
899 (getKeyAndShortForm(*OptionRunner).c_str(),
900 po::value<VectorValue>(),
901 getDescription(*OptionRunner).c_str())
902 ;
903 break;
904 case ListOfVectors:
905 ListRunner->second->add_options()
906 (getKeyAndShortForm(*OptionRunner).c_str(),
907 po::value< vector<VectorValue> >()->multitoken(),
908 getDescription(*OptionRunner).c_str())
909 ;
910 break;
911 case Molecule:
912 ListRunner->second->add_options()
913 (getKeyAndShortForm(*OptionRunner).c_str(),
914 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
915 po::value< int >()->default_value(lexical_cast<int>(CurrentValue[*OptionRunner].c_str())) :
916 po::value< int >(),
917 getDescription(*OptionRunner).c_str())
918 ;
919 break;
920 case ListOfMolecules:
921 ListRunner->second->add_options()
922 (getKeyAndShortForm(*OptionRunner).c_str(),
923 po::value< vector<int> >()->multitoken(),
924 getDescription(*OptionRunner).c_str())
925 ;
926 break;
927 case Atom:
928 ListRunner->second->add_options()
929 (getKeyAndShortForm(*OptionRunner).c_str(),
930 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
931 po::value< int >()->default_value(lexical_cast<int>(CurrentValue[*OptionRunner].c_str())) :
932 po::value< int >(),
933 getDescription(*OptionRunner).c_str())
934 ;
935 break;
936 case ListOfAtoms:
937 ListRunner->second->add_options()
938 (getKeyAndShortForm(*OptionRunner).c_str(),
939 po::value< vector<int> >()->multitoken(),
940 getDescription(*OptionRunner).c_str())
941 ;
942 break;
943 case Element:
944 ListRunner->second->add_options()
945 (getKeyAndShortForm(*OptionRunner).c_str(),
946 po::value< int >(),
947 getDescription(*OptionRunner).c_str())
948 ;
949 break;
950 case ListOfElements:
951 ListRunner->second->add_options()
952 (getKeyAndShortForm(*OptionRunner).c_str(),
953 po::value< vector<int> >()->multitoken(),
954 getDescription(*OptionRunner).c_str())
955 ;
956 break;
957 }
958 } else {
959 DoLog(3) && (Log() << Verbose(3) << "Adding option " << *OptionRunner << " to CommandLineParser." << endl);
960 ListRunner->second->add_options()
961 (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
962 ;
963 }
964 }
965 }
966}
967
968/** Getter for MapOfActions:DescriptionMap.
969 * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
970 * \param actionname name of the action to lookup
971 * \return Description of the action
972 */
973std::string MapOfActions::getDescription(string actionname)
974{
975 ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescription");
976 return DescriptionMap[actionname];
977}
978
979/** Specific Getter for a MapOfActions:ShortFormMap.
980 * If action has a short for, then combination is as "actionname,ShortForm" (this is
981 * the desired format for boost::program_options). If no short form exists in the map,
982 * just actionname will be returned
983 * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
984 * \param actionname name of the action to lookup
985 * \return actionname,ShortForm or Description of the action
986 */
987std::string MapOfActions::getKeyAndShortForm(string actionname)
988{
989 stringstream output;
990 ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescriptionAndShortForm");
991 output << actionname;
992 if (ShortFormMap.find(actionname) != DescriptionMap.end())
993 output << "," << ShortFormMap[actionname];
994 return output.str();
995}
996
997/** Getter for MapOfActions:ShortFormMap.
998 * Note that we assert when action does not exist CommandLineParser::ShortFormMap.
999 * \param actionname name of the action to lookup
1000 * \return ShortForm of the action
1001 */
1002std::string MapOfActions::getShortForm(string actionname)
1003{
1004 ASSERT(ShortFormMap.find(actionname) != ShortFormMap.end(), "Unknown action name passed to MapOfActions::getShortForm");
1005 return ShortFormMap[actionname];
1006}
1007
1008/** Returns whether the given action needs a value or not.
1009 * \param actionname name of the action to look up
1010 * \return true - value is needed, false - no value is stored in MapOfActions::TypeMap
1011 */
1012bool MapOfActions::hasValue(string actionname)
1013{
1014 return (TypeMap.find(actionname) != TypeMap.end());
1015}
1016
1017/** Getter for MapOfActions::TypeMap.
1018 * \param actionname name of the action to look up
1019 * \return type of the action
1020 */
1021std::string MapOfActions::getValueType(string actionname)
1022{
1023 return TypeMap[actionname]->name();
1024}
1025
1026/** Searches whether action is registered with CommandLineParser.
1027 * Note that this method is only meant transitionally for ParseCommandLineOptions' removal.
1028 * I.e. All actions that are already handled by the new CommandLineUIFactory can be checked
1029 * by this function.
1030 * \param shortform command short form to look for
1031 * \return true - action has been registered, false - action has not been registered.
1032 */
1033bool MapOfActions::isShortFormPresent(string shortform)
1034{
1035 bool result = false;
1036 string actionname;
1037 for (map<std::string, std::string>::iterator ShortFormRunner = ShortFormMap.begin(); ShortFormRunner != ShortFormMap.end(); ++ShortFormRunner)
1038 if (ShortFormRunner->second == shortform) {
1039 actionname = ShortFormRunner->first;
1040 break;
1041 }
1042 result = result || (generic.find(actionname) != generic.end());
1043 result = result || (config.find(actionname) != config.end());
1044 result = result || (hidden.find(actionname) != hidden.end());
1045 result = result || (visible.find(actionname) != visible.end());
1046 result = result || (inputfile.find(actionname) != inputfile.end());
1047 return result;
1048}
1049
1050/** Returns the inverse to MapOfActions::ShortFormMap, i.e. lookup actionname for its short form.
1051 * \return map from short form of action to name of action
1052 */
1053map <std::string, std::string> MapOfActions::getShortFormToActionMap()
1054{
1055 map <std::string, std::string> result;
1056
1057 for (map<std::string, std::string>::iterator iter = ShortFormMap.begin(); iter != ShortFormMap.end(); ++iter)
1058 result[iter->second] = iter->first;
1059
1060 return result;
1061}
1062
1063
1064CONSTRUCT_SINGLETON(MapOfActions)
Note: See TracBrowser for help on using the repository browser.