source: src/Actions/MapOfActions.cpp@ ab9a27

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

MapOfActions::TypeMap now contains type_info.

We are going to use the information contained in MapOfActions to split Dialog (information gathering) from the performCall (execution) of the Action.
Therefore, Dialogs will store information as string in MapOfActions' maps and the Actions will retrieve the needed information therefrom.

  • TypeMap now contains pointers to type_info
  • new TypeEnumMap mapping *type_info to enum Options
  • renamed map DefaultValue -> CurrentValue
  • new functions MapOfActions::getCurrentValue(), ...::setCurrentValue() as getter and setter of current value
  • new exception IllegalTypeException derived from CustomException, thrown when getCurrentValue is asked for value from an action/option-name with different type than stored in TypeMap.
  • Property mode set to 100644
File size: 35.8 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 "Patterns/Singleton_impl.hpp"
13#include "Actions/MapOfActions.hpp"
14#include "Helpers/Assert.hpp"
15
16#include <boost/lexical_cast.hpp>
17#include <boost/optional.hpp>
18#include <boost/program_options.hpp>
19
20#include <iostream>
21
22#include "atom.hpp"
23#include "CommandLineParser.hpp"
24#include "element.hpp"
25#include "log.hpp"
26#include "molecule.hpp"
27#include "verbose.hpp"
28
29#include "Actions/ActionRegistry.hpp"
30#include "Actions/AnalysisAction/MolecularVolumeAction.hpp"
31#include "Actions/AnalysisAction/PairCorrelationAction.hpp"
32#include "Actions/AnalysisAction/PrincipalAxisSystemAction.hpp"
33#include "Actions/AtomAction/AddAction.hpp"
34#include "Actions/AtomAction/ChangeElementAction.hpp"
35#include "Actions/AtomAction/RemoveAction.hpp"
36#include "Actions/CmdAction/BondLengthTableAction.hpp"
37#include "Actions/CmdAction/ElementDbAction.hpp"
38#include "Actions/CmdAction/FastParsingAction.hpp"
39#include "Actions/CmdAction/HelpAction.hpp"
40#include "Actions/CmdAction/VerboseAction.hpp"
41#include "Actions/CmdAction/VersionAction.hpp"
42#include "Actions/FragmentationAction/DepthFirstSearchAction.hpp"
43#include "Actions/FragmentationAction/SubgraphDissectionAction.hpp"
44#include "Actions/FragmentationAction/FragmentationAction.hpp"
45#include "Actions/MoleculeAction/BondFileAction.hpp"
46#include "Actions/MoleculeAction/ChangeNameAction.hpp"
47#include "Actions/MoleculeAction/FillWithMoleculeAction.hpp"
48#include "Actions/MoleculeAction/LinearInterpolationofTrajectoriesAction.hpp"
49#include "Actions/MoleculeAction/RotateToPrincipalAxisSystemAction.hpp"
50#include "Actions/MoleculeAction/SaveAdjacencyAction.hpp"
51#include "Actions/MoleculeAction/SaveBondsAction.hpp"
52#include "Actions/MoleculeAction/SaveTemperatureAction.hpp"
53#include "Actions/MoleculeAction/SuspendInWaterAction.hpp"
54#include "Actions/MoleculeAction/TranslateAction.hpp"
55#include "Actions/MoleculeAction/VerletIntegrationAction.hpp"
56#include "Actions/ParserAction/LoadXyzAction.hpp"
57#include "Actions/ParserAction/SaveXyzAction.hpp"
58#include "Actions/TesselationAction/ConvexEnvelopeAction.hpp"
59#include "Actions/TesselationAction/NonConvexEnvelopeAction.hpp"
60#include "Actions/WorldAction/AddEmptyBoundaryAction.hpp"
61#include "Actions/WorldAction/BoundInBoxAction.hpp"
62#include "Actions/WorldAction/CenterInBoxAction.hpp"
63#include "Actions/WorldAction/CenterOnEdgeAction.hpp"
64#include "Actions/WorldAction/ChangeBoxAction.hpp"
65#include "Actions/WorldAction/InputAction.hpp"
66#include "Actions/WorldAction/OutputAction.hpp"
67#include "Actions/WorldAction/RemoveSphereOfAtomsAction.hpp"
68#include "Actions/WorldAction/RepeatBoxAction.hpp"
69#include "Actions/WorldAction/ScaleBoxAction.hpp"
70#include "Actions/WorldAction/SetDefaultNameAction.hpp"
71#include "Actions/WorldAction/SetGaussianBasisAction.hpp"
72#include "Actions/WorldAction/SetOutputFormatsAction.hpp"
73#include "Actions/Values.hpp"
74
75void validate(boost::any& v, const std::vector<std::string>& values, VectorValue *, int)
76{
77 VectorValue VV;
78 std::vector<std::string> components;
79
80 // split comma-separated values
81 if (values.size() != 1) {
82 cerr << "Not one vector but " << components.size() << " given " << endl;
83 throw boost::program_options::validation_error("Unequal to one vector given");
84 }
85 std::string argument(values.at(0));
86 std::string::iterator Aiter = argument.begin();
87 std::string::iterator Biter = argument.begin();
88 for (; Aiter != argument.end(); ++Aiter) {
89 if (*Aiter == ',') {
90 components.push_back(string(Biter,Aiter));
91 do {
92 Aiter++;
93 } while (*Aiter == ' ' || *Aiter == '\t');
94 Biter = Aiter;
95 }
96 }
97 components.push_back(string(Biter,argument.end()));
98
99 if (components.size() != 3) {
100 cerr << "Specified vector does not have three components but " << components.size() << endl;
101 throw boost::program_options::validation_error("Specified vector does not have three components");
102 }
103 VV.x = boost::lexical_cast<double>(components.at(0));
104 VV.y = boost::lexical_cast<double>(components.at(1));
105 VV.z = boost::lexical_cast<double>(components.at(2));
106 v = boost::any(VectorValue(VV));
107}
108
109void validate(boost::any& v, const std::vector<std::string>& values, BoxValue *, int)
110{
111 BoxValue BV;
112 std::vector<std::string> components;
113
114 // split comma-separated values
115 if (values.size() != 1) {
116 cerr << "Not one vector but " << components.size() << " given " << endl;
117 throw boost::program_options::validation_error("Unequal to one vector given");
118 }
119 std::string argument(values.at(0));
120 std::string::iterator Aiter = argument.begin();
121 std::string::iterator Biter = argument.begin();
122 for (; Aiter != argument.end(); ++Aiter) {
123 if (*Aiter == ',') {
124 components.push_back(string(Biter,Aiter));
125 do {
126 Aiter++;
127 } while (*Aiter == ' ' || *Aiter == '\t');
128 Biter = Aiter;
129 }
130 }
131 components.push_back(string(Biter,argument.end()));
132
133 if (components.size() != 6) {
134 cerr << "Specified vector does not have three components but " << components.size() << endl;
135 throw boost::program_options::validation_error("Specified symmetric box matrix does not have six components");
136 }
137 BV.xx = boost::lexical_cast<double>(components.at(0));
138 BV.xy = boost::lexical_cast<double>(components.at(1));
139 BV.xz = boost::lexical_cast<double>(components.at(2));
140 BV.yy = boost::lexical_cast<double>(components.at(3));
141 BV.yz = boost::lexical_cast<double>(components.at(4));
142 BV.zz = boost::lexical_cast<double>(components.at(5));
143 v = boost::any(BoxValue(BV));
144}
145
146/** Constructor of class MapOfActions.
147 *
148 */
149MapOfActions::MapOfActions()
150{
151 // initialise lookup map
152 CmdParserLookup[&generic] = &(CommandLineParser::getInstance().generic);
153 CmdParserLookup[&config] = &(CommandLineParser::getInstance().config);
154 CmdParserLookup[&hidden] = &(CommandLineParser::getInstance().hidden);
155 CmdParserLookup[&visible] = &(CommandLineParser::getInstance().visible);
156
157 // keys for actions
158 DescriptionMap["add-atom"] = "add atom of specified element";
159 DescriptionMap["bond-table"] = "setting name of the bond length table file";
160 DescriptionMap["bond-file"] = "name of the bond file";
161 DescriptionMap["boundary"] = "change box to add an empty boundary around all atoms";
162 DescriptionMap["bound-in-box"] = "bound all atoms in the domain";
163 DescriptionMap["center-edge"] = "center edge of all atoms on (0,0,0)";
164 DescriptionMap["center-in-box"] = "center all atoms in the domain";
165 DescriptionMap["change-box"] = "change the symmetrc matrix of the simulation domain";
166 DescriptionMap["change-element"] = "change the element of an atom";
167 DescriptionMap["change-molname"] = "change the name of a molecule";
168 DescriptionMap["convex-envelope"] = "create the convex envelope for a molecule";
169 DescriptionMap["default-molname"] = "set the default name of new molecules";
170 DescriptionMap["depth-first-search"] = "Depth-First Search analysis of the molecular system";
171 DescriptionMap["element-db"] = "setting the path where the element databases can be found";
172 DescriptionMap["fastparsing"] = "setting whether trajectories shall be parsed completely (n) or just first step (y)";
173 DescriptionMap["fill-molecule"] = "fill empty space of box with a filler molecule";
174 DescriptionMap["fragment-mol"] = "create for a given molecule into fragments up to given order";
175 DescriptionMap["help"] = "Give this help screen";
176 DescriptionMap["input"] = "specify input files";
177 DescriptionMap["linear-interpolate"] = "linear interpolation in discrete steps between start and end position of a molecule";
178 DescriptionMap["molecular-volume"] = "calculate the volume of a given molecule";
179 DescriptionMap["nonconvex-envelope"] = "create the non-convex envelope for a molecule";
180 DescriptionMap["output"] = "write output files";
181 DescriptionMap["set-output"] = "specify output formats";
182 DescriptionMap["pair-correlation"] = "pair correlation analysis between two elements, element and point or element and surface";
183 DescriptionMap["parse-xyz"] = "parse xyz file into World";
184 DescriptionMap["principal-axis-system"] = "calculate the principal axis system of the specified molecule";
185 DescriptionMap["remove-atom"] = "remove a specified atom";
186 DescriptionMap["remove-sphere"] = "remove sphere of atoms of around a specified atom";
187 DescriptionMap["repeat-box"] = "create periodic copies of the simulation box per axis";
188 DescriptionMap["rotate-to-pas"] = "calculate the principal axis system of the specified molecule and rotate specified axis to align with main axis";
189 DescriptionMap["save-adjacency"] = "name of the adjacency file to write to";
190 DescriptionMap["save-bonds"] = "name of the bonds file to write to";
191 DescriptionMap["save-temperature"] = "name of the temperature file to write to";
192 DescriptionMap["SaveXyz"] = "save world as xyz file";
193 DescriptionMap["scale-box"] = "scale box and atomic positions inside";
194 DescriptionMap["set-basis"] = "set the name of the gaussian basis set for MPQC";
195 DescriptionMap["set-output"] = "specify output formats";
196 DescriptionMap["subgraph-dissect"] = "dissect the molecular system into molecules representing disconnected subgraphs";
197 DescriptionMap["suspend-in-water"] = "suspend the given molecule in water such that in the domain the mean density is as specified";
198 DescriptionMap["translate-mol"] = "translate molecule by given vector";
199 DescriptionMap["verbose"] = "set verbosity level";
200 DescriptionMap["verlet-integrate"] = "perform verlet integration of a given force file";
201 DescriptionMap["version"] = "show version";
202 // keys for values
203 DescriptionMap["atom-by-id"] = "index of an atom";
204 DescriptionMap["bin-output-file"] = "name of the bin output file";
205 DescriptionMap["bin-end"] = "start of the last bin";
206 DescriptionMap["bin-start"] = "start of the first bin";
207 DescriptionMap["bin-width"] = "width of the bins";
208 DescriptionMap["convex-file"] = "filename of the non-convex envelope";
209 DescriptionMap["distance"] = "distance in space";
210 DescriptionMap["distances"] = "list of three of distances in space, one for each axis direction";
211 DescriptionMap["DoRotate"] = "whether to rotate or just report angles";
212 DescriptionMap["element"] = "single element";
213 DescriptionMap["elements"] = "set of elements";
214 DescriptionMap["end-step"] = "last or end step";
215 DescriptionMap["id-mapping"] = "whether the identity shall be used in mapping atoms onto atoms or some closest distance measure shall be used";
216 DescriptionMap["input"] = "name of input file";
217 DescriptionMap["length"] = "length in space";
218 DescriptionMap["lengths"] = "list of three of lengths in space, one for each axis direction";
219 DescriptionMap["MaxDistance"] = "maximum distance in space";
220 DescriptionMap["molecule-by-id"] = "index of a molecule";
221 DescriptionMap["molecule-by-name"] = "name of a molecule";
222 DescriptionMap["nonconvex-file"] = "filename of the non-convex envelope";
223 DescriptionMap["order"] = "order of a discretization, dissection, ...";
224 DescriptionMap["output-file"] = "name of the output file";
225 DescriptionMap["periodic"] = "system is constraint to periodic boundary conditions (y/n)";
226 DescriptionMap["position"] = "position in R^3 space";
227 DescriptionMap["sphere-radius"] = "radius of tesselation sphere";
228 DescriptionMap["start-step"] = "first or start step";
229
230 // short forms for the actions
231 ShortFormMap["add-atom"] = "a";
232 ShortFormMap["bond-table"] = "g";
233 ShortFormMap["bond-file"] = "A";
234 ShortFormMap["boundary"] = "c";
235 ShortFormMap["change-box"] = "B";
236 ShortFormMap["center-edge"] = "O";
237 ShortFormMap["center-in-box"] = "b";
238 ShortFormMap["change-element"] = "E";
239// ShortFormMap["convex-envelope"] = "x";
240 ShortFormMap["default-molname"] = "X";
241 ShortFormMap["depth-first-search"] = "D";
242 ShortFormMap["element-db"] = "e";
243 ShortFormMap["fastparsing"] = "n";
244 ShortFormMap["fill-molecule"] = "F";
245 ShortFormMap["fragment-mol"] = "f";
246 ShortFormMap["help"] = "h";
247 ShortFormMap["input"] = "i";
248 ShortFormMap["linear-interpolate"] = "L";
249 ShortFormMap["nonconvex-envelope"] = "N";
250// ShortFormMap["output"] = "o";
251 ShortFormMap["pair-correlation"] = "C";
252 ShortFormMap["parse-xyz"] = "p";
253 ShortFormMap["remove-atom"] = "r";
254 ShortFormMap["remove-sphere"] = "R";
255 ShortFormMap["repeat-box"] = "d";
256 ShortFormMap["rotate-to-pas"] = "m";
257 ShortFormMap["save-adjacency"] = "J";
258 ShortFormMap["save-bonds"] = "j";
259 ShortFormMap["save-temperature"] = "S";
260 ShortFormMap["scale-box"] = "s";
261 ShortFormMap["set-basis"] = "M";
262 ShortFormMap["set-output"] = "o";
263 ShortFormMap["subgraph-dissect"] = "I";
264 ShortFormMap["suspend-in-water"] = "u";
265 ShortFormMap["translate-mol"] = "t";
266 ShortFormMap["verbose"] = "v";
267 ShortFormMap["verlet-integrate"] = "P";
268 ShortFormMap["version"] = "V";
269
270 // value types for the actions
271 TypeMap["add-atom"] = &typeid(element);
272 TypeMap["bond-file"] = &typeid(std::string);
273 TypeMap["bond-table"] = &typeid(std::string);
274 TypeMap["boundary"] = &typeid(VectorValue);
275 TypeMap["center-in-box"] = &typeid(BoxValue);
276 TypeMap["change-box"] = &typeid(BoxValue);
277 TypeMap["change-element"] = &typeid(element);
278 TypeMap["change-molname"] = &typeid(std::string);
279 TypeMap["convex-envelope"] = &typeid(molecule);
280 TypeMap["default-molname"] = &typeid(std::string);
281 TypeMap["depth-first-search"] = &typeid(double);
282 TypeMap["element-db"] = &typeid(std::string);
283 TypeMap["fastparsing"] = &typeid(bool);
284 TypeMap["fill-molecule"] = &typeid(std::string);
285 TypeMap["fragment-mol"] = &typeid(std::string);
286 TypeMap["input"] = &typeid(std::string);
287 TypeMap["linear-interpolate"] = &typeid(std::string);
288 TypeMap["molecular-volume"] = &typeid(molecule);
289 TypeMap["nonconvex-envelope"] = &typeid(molecule);
290 TypeMap["output"] = &typeid(void);
291 TypeMap["parse-xyz"] = &typeid(std::string);
292 TypeMap["pair-correlation"] = &typeid(std::string);
293 TypeMap["principal-axis-system"] = &typeid(molecule);
294 TypeMap["remove-atom"] = &typeid(atom);
295 TypeMap["remove-sphere"] = &typeid(double);
296 TypeMap["repeat-box"] = &typeid(VectorValue);
297 TypeMap["rotate-to-pas"] = &typeid(molecule);
298 TypeMap["save-adjacency"] = &typeid(std::string);
299 TypeMap["save-bonds"] = &typeid(std::string);
300 TypeMap["save-temperature"] = &typeid(std::string);
301 TypeMap["scale-box"] = &typeid(VectorValue);
302 TypeMap["set-basis"] = &typeid(std::string);
303 TypeMap["set-output"] = &typeid(std::vector<std::string>);
304 TypeMap["subgraph-dissect"] = &typeid(void);
305 TypeMap["suspend-in-water"] = &typeid(double);
306 TypeMap["translate-mol"] = &typeid(VectorValue);
307 TypeMap["verlet-integrate"] = &typeid(std::string);
308 TypeMap["verbose"] = &typeid(int);
309
310 // value types for the values
311 TypeMap["atom-by-id"] = &typeid(atom);
312 TypeMap["bin-output-file"] = &typeid(std::string);
313 TypeMap["bin-end"] = &typeid(double);
314 TypeMap["bin-start"] = &typeid(double);
315 TypeMap["bin-width"] = &typeid(double);
316 TypeMap["convex-file"] = &typeid(std::string);
317 TypeMap["distance"] = &typeid(double);
318 TypeMap["distances"] = &typeid(VectorValue);
319 TypeMap["DoRotate"] = &typeid(bool);
320 TypeMap["element"] = &typeid(element);
321 TypeMap["elements"] = &typeid(std::vector<element *>);
322 TypeMap["end-step"] = &typeid(int);
323 TypeMap["id-mapping"] = &typeid(bool);
324 TypeMap["length"] = &typeid(double);
325 TypeMap["lengths"] = &typeid(VectorValue);
326 TypeMap["MaxDistance"] = &typeid(double);
327 TypeMap["molecule-by-id"] = &typeid(molecule);
328 TypeMap["molecule-by-name"] = &typeid(std::string);
329 TypeMap["nonconvex-file"] = &typeid(std::string);
330 TypeMap["order"] = &typeid(int);
331 TypeMap["output-file"] = &typeid(std::string);
332 TypeMap["periodic"] = &typeid(bool);
333 TypeMap["position"] = &typeid(VectorValue);
334 TypeMap["sphere-radius"] = &typeid(double);
335 TypeMap["start-step"] = &typeid(int);
336
337 TypeEnumMap[&typeid(int)] = Integer;
338 TypeEnumMap[&typeid(double)] = Double;
339 TypeEnumMap[&typeid(bool)] = Boolean;
340 TypeEnumMap[&typeid(std::string)] = String;
341 TypeEnumMap[&typeid(atom)] = Atom;
342 TypeEnumMap[&typeid(element)] = Element;
343 TypeEnumMap[&typeid(std::vector<element *>)] = ListOfElements;
344 TypeEnumMap[&typeid(molecule)] = Molecule;
345 TypeEnumMap[&typeid(VectorValue)] = Vector;
346 TypeEnumMap[&typeid(BoxValue)] = Box;
347
348
349 // default values for any action that needs one (always string!)
350 CurrentValue["bin-width"] = "0.5";
351 CurrentValue["fastparsing"] = "0";
352 CurrentValue["atom-by-id"] = "-1";
353 CurrentValue["molecule-by-id"] = "-1";
354 CurrentValue["periodic"] = "0";
355
356 // put action into each menu category
357 MenuDescription["analysis"] = pair<std::string,std::string>("Analysis (pair correlation, volume)", "Analysis");
358 MenuDescription["atom"] = pair<std::string,std::string>("Edit atoms", "Edit atoms");
359 MenuDescription["command"] = pair<std::string,std::string>("Configuration", "Configuration");
360 MenuDescription["fragmentation"] = pair<std::string,std::string>("Fragmentation", "Fragmentation");
361 MenuDescription["molecule"] = pair<std::string,std::string>("Parse files into system", "Parse files");
362 MenuDescription["parser"] = pair<std::string,std::string>("Edit molecules (load, parse, save)", "Edit molecules");
363 MenuDescription["tesselation"] = pair<std::string,std::string>("Tesselate molecules", "Tesselate molecules");
364 MenuDescription["world"] = pair<std::string,std::string>("Edit world", "Edit world");
365
366 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "molecular-volume") );
367 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "pair-correlation") );
368 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "principal-axis-system") );
369
370 MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "add-atom") );
371 MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "change-element") );
372 MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "remove-atom") );
373
374 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "bond-table") );
375 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "element-db") );
376 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "fastparsing") );
377 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "verbose") );
378 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "version") );
379
380 MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "depth-first-search") );
381 MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "fragment-mol") );
382 MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "subgraph-dissect") );
383
384 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "bond-file") );
385 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "change-molname") );
386 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "fill-molecule") );
387 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "linear-interpolate") );
388 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "rotate-to-pas") );
389 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "save-adjacency") );
390 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "save-bonds") );
391 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "save-temperature") );
392 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "suspend-in-water") );
393 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "translate-mol") );
394 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "verlet-integrate") );
395
396 MenuContainsActionMap.insert( pair<std::string, std::string> ("parser", "parse-xyz") );
397 MenuContainsActionMap.insert( pair<std::string, std::string> ("parser", "SaveXyz") );
398
399 MenuContainsActionMap.insert( pair<std::string, std::string> ("tesselation", "convex-envelope") );
400 MenuContainsActionMap.insert( pair<std::string, std::string> ("tesselation", "nonconvex-envelope") );
401
402 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "boundary") );
403 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "bound-in-box") );
404 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "center-in-box") );
405 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "center-edge") );
406 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "change-box") );
407 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "input") );
408 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "output") );
409 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "remove-sphere") );
410 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "repeat-box") );
411 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "scale-box") );
412 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "default-molname") );
413 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "set-basis") );
414 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "set-output") );
415
416 // put actions into command line category
417 generic.insert("add-atom");
418 generic.insert("bond-file");
419 generic.insert("bond-table");
420 generic.insert("boundary");
421// generic.insert("bound-in-box");
422 generic.insert("center-edge");
423 generic.insert("center-in-box");
424 generic.insert("change-box");
425// generic.insert("change-molname");
426 generic.insert("change-element");
427 generic.insert("convex-envelope");
428 generic.insert("default-molname");
429 generic.insert("depth-first-search");
430 generic.insert("element-db");
431 generic.insert("fastparsing");
432 generic.insert("fill-molecule");
433 generic.insert("fragment-mol");
434 generic.insert("help");
435 generic.insert("input");
436 generic.insert("linear-interpolate");
437// generic.insert("molecular-volume");
438 generic.insert("nonconvex-envelope");
439 generic.insert("output");
440 generic.insert("pair-correlation");
441 generic.insert("parse-xyz");
442// generic.insert("principal-axis-system");
443 generic.insert("remove-atom");
444 generic.insert("remove-sphere");
445 generic.insert("repeat-box");
446 generic.insert("rotate-to-pas");
447 generic.insert("save-adjacency");
448 generic.insert("save-bonds");
449 generic.insert("save-temperature");
450 generic.insert("scale-box");
451 generic.insert("set-basis");
452 generic.insert("set-output");
453 generic.insert("subgraph-dissect");
454 generic.insert("suspend-in-water");
455 generic.insert("translate-mol");
456 generic.insert("verbose");
457 generic.insert("verlet-integrate");
458 generic.insert("version");
459
460 // positional arguments
461 generic.insert("input");
462 inputfile.insert("input");
463
464 // hidden arguments
465 generic.insert("atom-by-id");
466 generic.insert("bin-end");
467 generic.insert("bin-output-file");
468 generic.insert("bin-start");
469 generic.insert("bin-width");
470 generic.insert("convex-file");
471 generic.insert("distance");
472 generic.insert("DoRotate");
473 generic.insert("distances");
474 generic.insert("element");
475 generic.insert("elements");
476 generic.insert("end-step");
477 generic.insert("id-mapping");
478 generic.insert("lengths");
479 generic.insert("MaxDistance");
480 generic.insert("molecule-by-id");
481 generic.insert("molecule-by-name");
482 generic.insert("nonconvex-file");
483 generic.insert("order");
484 generic.insert("output-file");
485 generic.insert("periodic");
486 generic.insert("position");
487 generic.insert("sphere-radius");
488 generic.insert("start-step");
489}
490
491/** Destructor of class MapOfActions.
492 *
493 */
494MapOfActions::~MapOfActions()
495{
496 DescriptionMap.clear();
497}
498
499
500void MapOfActions::populateActions()
501{
502 new AnalysisMolecularVolumeAction();
503 new AnalysisPairCorrelationAction();
504 new AnalysisPrincipalAxisSystemAction();
505
506 new AtomAddAction();
507 new AtomChangeElementAction();
508 new AtomRemoveAction();
509
510 new CommandLineBondLengthTableAction();
511 new CommandLineElementDbAction();
512 new CommandLineFastParsingAction();
513 new CommandLineHelpAction();
514 new CommandLineVerboseAction();
515 new CommandLineVersionAction();
516
517 new FragmentationDepthFirstSearchAction();
518 new FragmentationFragmentationAction();
519 new FragmentationSubgraphDissectionAction();
520
521 new MoleculeBondFileAction();
522 new MoleculeChangeNameAction();
523 new MoleculeFillWithMoleculeAction();
524 new MoleculeLinearInterpolationofTrajectoriesAction();
525 new MoleculeRotateToPrincipalAxisSystemAction();
526 new MoleculeSaveAdjacencyAction();
527 new MoleculeSaveBondsAction();
528 new MoleculeSaveTemperatureAction();
529 new MoleculeSuspendInWaterAction();
530 new MoleculeTranslateAction();
531 new MoleculeVerletIntegrationAction();
532
533 new ParserLoadXyzAction();
534 new ParserSaveXyzAction();
535
536 new TesselationConvexEnvelopeAction();
537 new TesselationNonConvexEnvelopeAction();
538
539 new WorldAddEmptyBoundaryAction();
540 new WorldBoundInBoxAction();
541 new WorldCenterInBoxAction();
542 new WorldCenterOnEdgeAction();
543 new WorldChangeBoxAction();
544 new WorldInputAction();
545 new WorldOutputAction();
546 new WorldRemoveSphereOfAtomsAction();
547 new WorldRepeatBoxAction();
548 new WorldScaleBoxAction();
549 new WorldSetDefaultNameAction();
550 new WorldSetGaussianBasisAction();
551 new WorldSetOutputFormatsAction();
552}
553
554/** Adds all options to the CommandLineParser.
555 *
556 */
557void MapOfActions::AddOptionsToParser()
558{
559 // add other options
560 for (map< set<string>*, po::options_description* >::iterator ListRunner = CmdParserLookup.begin(); ListRunner != CmdParserLookup.end(); ++ListRunner) {
561 for (set<string>::iterator OptionRunner = ListRunner->first->begin(); OptionRunner != ListRunner->first->end(); ++OptionRunner) {
562 if (hasValue(*OptionRunner)) {
563 DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " with type " << TypeMap[*OptionRunner] << " to CommandLineParser." << endl);
564 switch(TypeEnumMap[TypeMap[*OptionRunner]]) {
565 default:
566 case None:
567 ListRunner->second->add_options()
568 (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
569 ;
570 break;
571 case Boolean:
572 ListRunner->second->add_options()
573 (getKeyAndShortForm(*OptionRunner).c_str(),
574 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
575 po::value< bool >()->default_value(atoi(CurrentValue[*OptionRunner].c_str())) :
576 po::value< bool >(),
577 getDescription(*OptionRunner).c_str())
578 ;
579 break;
580 case Box:
581 ListRunner->second->add_options()
582 (getKeyAndShortForm(*OptionRunner).c_str(),
583 po::value<BoxValue>()->multitoken(),
584 getDescription(*OptionRunner).c_str())
585 ;
586 break;
587 case Integer:
588 ListRunner->second->add_options()
589 (getKeyAndShortForm(*OptionRunner).c_str(),
590 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
591 po::value< int >()->default_value(atoi(CurrentValue[*OptionRunner].c_str())) :
592 po::value< int >(),
593 getDescription(*OptionRunner).c_str())
594 ;
595 break;
596 case ListOfInts:
597 ListRunner->second->add_options()
598 (getKeyAndShortForm(*OptionRunner).c_str(),
599 po::value< vector<int> >()->multitoken(),
600 getDescription(*OptionRunner).c_str())
601 ;
602 break;
603 case Double:
604 ListRunner->second->add_options()
605 (getKeyAndShortForm(*OptionRunner).c_str(),
606 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
607 po::value< double >()->default_value(atof(CurrentValue[*OptionRunner].c_str())) :
608 po::value< double >(),
609 getDescription(*OptionRunner).c_str())
610 ;
611 break;
612 case ListOfDoubles:
613 ListRunner->second->add_options()
614 (getKeyAndShortForm(*OptionRunner).c_str(),
615 po::value< vector<double> >()->multitoken(),
616 getDescription(*OptionRunner).c_str())
617 ;
618 break;
619 case String:
620 ListRunner->second->add_options()
621 (getKeyAndShortForm(*OptionRunner).c_str(),
622 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
623 po::value< std::string >()->default_value(CurrentValue[*OptionRunner]) :
624 po::value< std::string >(),
625 getDescription(*OptionRunner).c_str())
626 ;
627 break;
628 case ListOfString:
629 ListRunner->second->add_options()
630 (getKeyAndShortForm(*OptionRunner).c_str(),
631 po::value< vector<std::string> >()->multitoken(),
632 getDescription(*OptionRunner).c_str())
633 ;
634 break;
635 case Axis:
636 ListRunner->second->add_options()
637 (getKeyAndShortForm(*OptionRunner).c_str(),
638 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
639 po::value< int >()->default_value(atoi(CurrentValue[*OptionRunner].c_str())) :
640 po::value< int >(),
641 getDescription(*OptionRunner).c_str())
642 ;
643 break;
644 case Vector:
645 ListRunner->second->add_options()
646 (getKeyAndShortForm(*OptionRunner).c_str(),
647 po::value<VectorValue>(),
648 getDescription(*OptionRunner).c_str())
649 ;
650 break;
651 case Molecule:
652 ListRunner->second->add_options()
653 (getKeyAndShortForm(*OptionRunner).c_str(),
654 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
655 po::value< int >()->default_value(atoi(CurrentValue[*OptionRunner].c_str())) :
656 po::value< int >(),
657 getDescription(*OptionRunner).c_str())
658 ;
659 break;
660 case ListOfMolecules:
661 ListRunner->second->add_options()
662 (getKeyAndShortForm(*OptionRunner).c_str(),
663 po::value< vector<int> >()->multitoken(),
664 getDescription(*OptionRunner).c_str())
665 ;
666 break;
667 case Atom:
668 ListRunner->second->add_options()
669 (getKeyAndShortForm(*OptionRunner).c_str(),
670 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
671 po::value< int >()->default_value(atoi(CurrentValue[*OptionRunner].c_str())) :
672 po::value< int >(),
673 getDescription(*OptionRunner).c_str())
674 ;
675 break;
676 case ListOfAtoms:
677 ListRunner->second->add_options()
678 (getKeyAndShortForm(*OptionRunner).c_str(),
679 po::value< vector<int> >()->multitoken(),
680 getDescription(*OptionRunner).c_str())
681 ;
682 break;
683 case Element:
684 ListRunner->second->add_options()
685 (getKeyAndShortForm(*OptionRunner).c_str(),
686 po::value< vector<int> >(),
687 getDescription(*OptionRunner).c_str())
688 ;
689 break;
690 case ListOfElements:
691 ListRunner->second->add_options()
692 (getKeyAndShortForm(*OptionRunner).c_str(),
693 po::value< vector<int> >()->multitoken(),
694 getDescription(*OptionRunner).c_str())
695 ;
696 break;
697 }
698 } else {
699 DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " to CommandLineParser." << endl);
700 ListRunner->second->add_options()
701 (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
702 ;
703 }
704 }
705 }
706 // add positional arguments
707 for (set<string>::iterator OptionRunner = inputfile.begin(); OptionRunner != inputfile.end(); ++OptionRunner) {
708 DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " to positional CommandLineParser." << endl);
709 CommandLineParser::getInstance().inputfile.add((*OptionRunner).c_str(), -1);
710 }
711 cout << "Name for position 1: " << CommandLineParser::getInstance().inputfile.name_for_position(1) << endl;
712}
713
714/** Getter for MapOfActions:DescriptionMap.
715 * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
716 * \param actionname name of the action to lookup
717 * \return Description of the action
718 */
719std::string MapOfActions::getDescription(string actionname)
720{
721 ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescription");
722 return DescriptionMap[actionname];
723}
724
725/** Specific Getter for a MapOfActions:ShortFormMap.
726 * If action has a short for, then combination is as "actionname,ShortForm" (this is
727 * the desired format for boost::program_options). If no short form exists in the map,
728 * just actionname will be returned
729 * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
730 * \param actionname name of the action to lookup
731 * \return actionname,ShortForm or Description of the action
732 */
733std::string MapOfActions::getKeyAndShortForm(string actionname)
734{
735 stringstream output;
736 ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescriptionAndShortForm");
737 output << actionname;
738 if (ShortFormMap.find(actionname) != DescriptionMap.end())
739 output << "," << ShortFormMap[actionname];
740 return output.str();
741}
742
743/** Getter for MapOfActions:ShortFormMap.
744 * Note that we assert when action does not exist CommandLineParser::ShortFormMap.
745 * \param actionname name of the action to lookup
746 * \return ShortForm of the action
747 */
748std::string MapOfActions::getShortForm(string actionname)
749{
750 ASSERT(ShortFormMap.find(actionname) != ShortFormMap.end(), "Unknown action name passed to MapOfActions::getShortForm");
751 return ShortFormMap[actionname];
752}
753
754/** Returns whether the given action needs a value or not.
755 * \param actionname name of the action to look up
756 * \return true - value is needed, false - no value is stored in MapOfActions::TypeMap
757 */
758bool MapOfActions::hasValue(string actionname)
759{
760 return (TypeMap.find(actionname) != TypeMap.end());
761}
762
763/** Getter for MapOfActions::TypeMap.
764 * \param actionname name of the action to look up
765 * \return type of the action
766 */
767std::string MapOfActions::getValueType(string actionname)
768{
769 return TypeMap[actionname]->name();
770}
771
772/** Searches whether action is registered with CommandLineParser.
773 * Note that this method is only meant transitionally for ParseCommandLineOptions' removal.
774 * I.e. All actions that are already handled by the new CommandLineUIFactory can be checked
775 * by this function.
776 * \param shortform command short form to look for
777 * \return true - action has been registered, false - action has not been registered.
778 */
779bool MapOfActions::isShortFormPresent(string shortform)
780{
781 bool result = false;
782 string actionname;
783 for (map<std::string, std::string>::iterator ShortFormRunner = ShortFormMap.begin(); ShortFormRunner != ShortFormMap.end(); ++ShortFormRunner)
784 if (ShortFormRunner->second == shortform) {
785 actionname = ShortFormRunner->first;
786 break;
787 }
788 result = result || (generic.find(actionname) != generic.end());
789 result = result || (config.find(actionname) != config.end());
790 result = result || (hidden.find(actionname) != hidden.end());
791 result = result || (visible.find(actionname) != visible.end());
792 result = result || (inputfile.find(actionname) != inputfile.end());
793 return result;
794}
795
796/** Returns the inverse to MapOfActions::ShortFormMap, i.e. lookup actionname for its short form.
797 * \return map from short form of action to name of action
798 */
799map <std::string, std::string> MapOfActions::getShortFormToActionMap()
800{
801 map <std::string, std::string> result;
802
803 for (map<std::string, std::string>::iterator iter = ShortFormMap.begin(); iter != ShortFormMap.end(); ++iter)
804 result[iter->second] = iter->first;
805
806 return result;
807}
808
809
810CONSTRUCT_SINGLETON(MapOfActions)
Note: See TracBrowser for help on using the repository browser.