source: src/Actions/MapOfActions.cpp@ 381c5f

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

New selection: unselect-molecules-atoms.

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