source: src/Actions/MapOfActions.cpp@ e212ff

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

New selection: clear-atom-selection.

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