source: src/Actions/MapOfActions.cpp@ b9c847

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

New SetOutputFormatsAction introduced.

Fixes:

new SetOutputFormatsAction:

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