source: src/Actions/MapOfActions.cpp@ 6e5084

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

created LibMolecuilderHelpers.

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