source: src/Actions/MapOfActions.cpp@ 0c5eeb

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

Legacy/oldmenu is no more.

  • TextWindow::TextWindow() now properly uses the actions that have been created during the Refactoring of CommandLineUI.
  • removed TextWindow::populateEditMolecules() as there is a more general function now
  • new Textwindow::populateMenu() - populates the menu by looking at MapOfActions::MenuContainsActionMap.
  • new TextWindow::getSuitableShortForm() - educatedly guesses good key for action in menu.
  • Hence, Legacy/oldmenu.* is dropped from molecuilder/src/Makefile.am
  • new map MapOfActions::MenuContainsActionMap with menu names and all desired actions therein
  • new MapOfActions::populateActions() which instantiate all possible actions (moved over from CommandLineWindow)
  • DOCU: MapOfActions has full documentation explaining how to add new actions
  • main(): CommandLineUI is taken if at least argument it present, otherwise text menu.

Still missing:

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