source: src/Actions/MapOfActions.cpp@ e472eab

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

Added new all/none selection actions for atoms and molecules.

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