source: src/Actions/MapOfActions.cpp@ 986ed3

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 986ed3 was 986ed3, checked in by Tillmann Crueger <crueger@…>, 15 years ago

COMPILE_SPEEDUP: Replaced all implicit inclusions of iostream with forwards

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