source: src/Actions/MapOfActions.cpp@ 5b5c4d

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

TESTFIX: Molecules/* all needed replacement of option --molecule-by-id by action --select-molecule-by-id in front of.

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