source: src/Actions/MapOfActions.cpp@ 6670a97

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

Change to testsuite as verbosity is now defined as (-v 3) not as (-vvv) anymore.

  • MapofActions.cpp: verbose and version shortforms were mixed (-v,-V), corrected.

Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 18.9 KB
Line 
1/*
2 * MapOfActions.cpp
3 *
4 * Created on: 10.05.2010
5 * Author: heber
6 */
7
8using namespace std;
9
10#include "Patterns/Singleton_impl.hpp"
11#include "Actions/MapOfActions.hpp"
12#include "Helpers/Assert.hpp"
13
14#include "CommandLineParser.hpp"
15#include "log.hpp"
16#include "verbose.hpp"
17
18/** Constructor of class MapOfActions.
19 *
20 */
21MapOfActions::MapOfActions()
22{
23 // initialise lookup map
24 CmdParserLookup[&generic] = &(CommandLineParser::getInstance().generic);
25 CmdParserLookup[&config] = &(CommandLineParser::getInstance().config);
26 CmdParserLookup[&hidden] = &(CommandLineParser::getInstance().hidden);
27 CmdParserLookup[&visible] = &(CommandLineParser::getInstance().visible);
28
29 // keys for actions
30 DescriptionMap["add-atom"] = "add atom of specified element";
31 DescriptionMap["bond-table"] = "setting name of the bond length table file";
32 DescriptionMap["bond-file"] = "name of the bond file";
33 DescriptionMap["boundary"] = "change box to add an empty boundary around all atoms";
34 DescriptionMap["bound-in-box"] = "bound all atoms in the domain";
35 DescriptionMap["center-edge"] = "center edge of all atoms on (0,0,0)";
36 DescriptionMap["center-in-box"] = "center all atoms in the domain";
37 DescriptionMap["change-box"] = "change the symmetrc matrix of the simulation domain";
38 DescriptionMap["change-element"] = "change the element of an atom";
39 DescriptionMap["change-molname"] = "change the name of a molecule";
40 DescriptionMap["convex-envelope"] = "create the convex envelope for a molecule";
41 DescriptionMap["default-molname"] = "set the default name of new molecules";
42 DescriptionMap["depth-first-search"] = "Depth-First Search analysis of the molecular system";
43 DescriptionMap["element-db"] = "setting the path where the element databases can be found";
44 DescriptionMap["fastparsing"] = "setting whether trajectories shall be parsed completely (n) or just first step (y)";
45 DescriptionMap["fill-molecule"] = "fill empty space of box with a filler molecule";
46 DescriptionMap["fragment-mol"] = "create for a given molecule into fragments up to given order";
47 DescriptionMap["help"] = "Give this help screen";
48 DescriptionMap["linear-interpolate"] = "linear interpolation in discrete steps between start and end position of a molecule";
49 DescriptionMap["nonconvex-envelope"] = "create the non-convex envelope for a molecule";
50 DescriptionMap["molecular-volume"] = "calculate the volume of a given molecule";
51 DescriptionMap["pair-correlation"] = "pair correlation analysis between two elements";
52 DescriptionMap["pair-correlation-point"] = "pair correlation analysis between atoms of a element to a given point";
53 DescriptionMap["pair-correlation-surface"] = "pair correlation analysis between atoms of a given element and a surface";
54 DescriptionMap["parse-xyz"] = "parse xyz file into World";
55 DescriptionMap["principal-axis-system"] = "calculate the principal axis system of the specified molecule";
56 DescriptionMap["remove-atom"] = "remove a specified atom";
57 DescriptionMap["remove-sphere"] = "remove sphere of atoms of around a specified atom";
58 DescriptionMap["repeat-box"] = "create periodic copies of the simulation box per axis";
59 DescriptionMap["rotate-to-pas"] = "calculate the principal axis system of the specified molecule and rotate specified axis to align with main axis";
60 DescriptionMap["set-basis"] = "set the name of the gaussian basis set for MPQC";
61 DescriptionMap["save-adjacency"] = "name of the adjacency file to write to";
62 DescriptionMap["save-bonds"] = "name of the bonds file to write to";
63 DescriptionMap["save-temperature"] = "name of the temperature file to write to";
64 DescriptionMap["subspace-dissect"] = "dissect the molecular system into molecules representing disconnected subgraphs";
65 DescriptionMap["suspend-in-water"] = "suspend the given molecule in water such that in the domain the mean density is as specified";
66 DescriptionMap["translate-mol"] = "translate molecule by given vector";
67 DescriptionMap["verbose"] = "set verbosity level";
68 DescriptionMap["verlet-integrate"] = "perform verlet integration of a given force file";
69 DescriptionMap["version"] = "show version";
70 // keys for values
71 DescriptionMap["bin-output-file"] = "name of the bin output file";
72 DescriptionMap["bin-end"] = "start of the last bin";
73 DescriptionMap["bin-start"] = "start of the first bin";
74 DescriptionMap["bin-width"] = "width of the bins";
75 DescriptionMap["distance"] = "distance in space";
76 DescriptionMap["distances"] = "list of three of distances in space, one for each axis direction";
77 DescriptionMap["element"] = "set of elements";
78 DescriptionMap["end-mol"] = "last or end step";
79 DescriptionMap["input"] = "name of input file";
80 DescriptionMap["length"] = "length in space";
81 DescriptionMap["lengths"] = "list of three of lengths in space, one for each axis direction";
82 DescriptionMap["MaxDistance"] = "maximum distance in space";
83 DescriptionMap["molecule-by-id"] = "index of a molecule";
84 DescriptionMap["output-file"] = "name of the output file";
85 DescriptionMap["periodic"] = "system is constraint to periodic boundary conditions (y/n)";
86 DescriptionMap["position"] = "position in R^3 space";
87 DescriptionMap["start-mol"] = "first or start step";
88
89 // short forms for the actions
90 ShortFormMap["add-atom"] = "a";
91 ShortFormMap["bond-table"] = "g";
92 ShortFormMap["bond-file"] = "A";
93 ShortFormMap["boundary"] = "c";
94 ShortFormMap["bound-in-box"] = "B";
95 ShortFormMap["center-edge"] = "O";
96 ShortFormMap["center-in-box"] = "b";
97 ShortFormMap["change-element"] = "E";
98 ShortFormMap["convex-envelope"] = "o";
99 ShortFormMap["default-molname"] = "X";
100 ShortFormMap["depth-first-search"] = "D";
101 ShortFormMap["element-db"] = "e";
102 ShortFormMap["fastparsing"] = "n";
103 ShortFormMap["fill-molecule"] = "F";
104 ShortFormMap["fragment-mol"] = "f";
105 ShortFormMap["help"] = "h";
106 ShortFormMap["input"] = "i";
107 ShortFormMap["linear-interpolate"] = "L";
108 ShortFormMap["nonconvex-envelope"] = "N";
109 ShortFormMap["pair-correlation"] = "CE";
110 ShortFormMap["pair-correlation-point"] = "CP";
111 ShortFormMap["pair-correlation-surface"] = "CS";
112 ShortFormMap["parse-xyz"] = "p";
113 ShortFormMap["remove-atom"] = "r";
114 ShortFormMap["remove-sphere"] = "R";
115 ShortFormMap["repeat-box"] = "d";
116 ShortFormMap["rotate-to-pas"] = "m";
117 ShortFormMap["save-adjacency"] = "J";
118 ShortFormMap["save-bonds"] = "j";
119 ShortFormMap["save-temperature"] = "S";
120 ShortFormMap["scale-box"] = "s";
121 ShortFormMap["set-basis"] = "M";
122 ShortFormMap["subspace-dissect"] = "I";
123 ShortFormMap["suspend-in-water"] = "U";
124 ShortFormMap["translate-mol"] = "t";
125 ShortFormMap["verbose"] = "v";
126 ShortFormMap["verlet-integrate"] = "P";
127 ShortFormMap["version"] = "V";
128
129 // value types for the actions
130 TypeMap["add-atom"] = Atom;
131 TypeMap["bond-file"] = String;
132 TypeMap["bond-table"] = String;
133 TypeMap["boundary"] = Vector;
134 TypeMap["change-box"] = Vector;
135 TypeMap["change-element"] = Element;
136 TypeMap["change-molname"] = String;
137 TypeMap["convex-envelope"] = Molecule;
138 TypeMap["default-molname"] = String;
139 TypeMap["depth-first-search"] = Double;
140 TypeMap["element-db"] = String;
141 TypeMap["end-mol"] = Molecule;
142 TypeMap["fastparsing"] = Boolean;
143 TypeMap["fill-molecule"] = String;
144 TypeMap["fragment-mol"] = Molecule;
145 TypeMap["input"] = String;
146 TypeMap["linear-interpolate"] = String;
147 TypeMap["molecular-volume"] = Molecule;
148 TypeMap["nonconvex-envelope"] = Molecule;
149 TypeMap["parse-xyz"] = String;
150 TypeMap["principal-axis-system"] = Axis;
151 TypeMap["remove-atom"] = Atom;
152 TypeMap["remove-sphere"] = Atom;
153 TypeMap["repeat-box"] = ListOfInts;
154 TypeMap["rotate-to-pas"] = Molecule;
155 TypeMap["save-adjacency"] = String;
156 TypeMap["save-bonds"] = String;
157 TypeMap["save-temperature"] = String;
158 TypeMap["scale-box"] = Vector;
159 TypeMap["set-basis"] = String;
160 TypeMap["start-mol"] = Molecule;
161 TypeMap["suspend-in-water"] = Molecule;
162 TypeMap["translate-mol"] = Vector;
163 TypeMap["verlet-integrate"] = String;
164 TypeMap["verbose"] = Integer;
165 // value types for the values
166 TypeMap["bin-output-file"] = String;
167 TypeMap["bin-end"] = Double;
168 TypeMap["bin-start"] = Double;
169 TypeMap["distance"] = Double;
170 TypeMap["distances"] = ListOfDoubles;
171 TypeMap["elements"] = Element;
172 TypeMap["elements"] = ListOfElements;
173 TypeMap["length"] = Double;
174 TypeMap["lengths"] = ListOfDoubles;
175 TypeMap["MaxDistance"] = Double;
176 TypeMap["molecule-by-id"] = Molecule;
177 TypeMap["output-file"] = String;
178 TypeMap["periodic"] = Boolean;
179 TypeMap["position"] = Vector;
180
181 // list of generic actions
182// generic.insert("add-atom");
183// generic.insert("bond-file");
184// generic.insert("bond-table");
185// generic.insert("boundary");
186// generic.insert("bound-in-box");
187// generic.insert("center-edge");
188// generic.insert("center-in-box");
189// generic.insert("change-box");
190// generic.insert("change-molname");
191// generic.insert("change-element");
192// generic.insert("convex-envelope");
193// generic.insert("default-molname");
194// generic.insert("depth-first-search");
195// generic.insert("element-db");
196// generic.insert("fastparsing");
197// generic.insert("fill-molecule");
198// generic.insert("fragment-mol");
199 generic.insert("help");
200// generic.insert("linear-interpolate");
201// generic.insert("molecular-volume");
202// generic.insert("nonconvex-envelope");
203// generic.insert("pair-correlation");
204// generic.insert("pair-correlation-point");
205// generic.insert("pair-correlation-surface");
206// generic.insert("parse-xyz");
207// generic.insert("principal-axis-system");
208// generic.insert("remove-atom");
209// generic.insert("remove-sphere");
210// generic.insert("rotate-to-pas");
211// generic.insert("save-adjacency");
212// generic.insert("save-bonds");
213// generic.insert("save-temperature");
214// generic.insert("scale-box");
215// generic.insert("set-basis");
216// generic.insert("subspace-dissect");
217// generic.insert("suspend-in-water");
218// generic.insert("translate-mol");
219 generic.insert("verbose");
220// generic.insert("verlet-integrate");
221 generic.insert("version");
222// // list of generic values
223// generic.insert("bin-output-file");
224// generic.insert("bin-end");
225// generic.insert("bin-start");
226// generic.insert("distance");
227// generic.insert("distances");
228// generic.insert("element");
229// generic.insert("end-mol");
230 generic.insert("input");
231// generic.insert("length");
232// generic.insert("lengths");
233// generic.insert("MaxDistance");
234// generic.insert("molecule-by-id");
235// generic.insert("output-file");
236// generic.insert("periodic");
237// generic.insert("position");
238// generic.insert("start-mol");
239
240 // positional arguments
241 inputfile.insert("input");
242}
243
244/** Destructor of class MapOfActions.
245 *
246 */
247MapOfActions::~MapOfActions()
248{
249 DescriptionMap.clear();
250}
251
252/** Adds all options to the CommandLineParser.
253 *
254 */
255void MapOfActions::AddOptionsToParser()
256{
257 // add other options
258 for (map< set<string>*, po::options_description* >::iterator ListRunner = CmdParserLookup.begin(); ListRunner != CmdParserLookup.end(); ++ListRunner) {
259 for (set<string>::iterator OptionRunner = ListRunner->first->begin(); OptionRunner != ListRunner->first->end(); ++OptionRunner) {
260 if (hasValue(*OptionRunner)) {
261 DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " with type " << TypeMap[*OptionRunner] << " to CommandLineParser." << endl);
262 switch((enum OptionTypes) TypeMap[*OptionRunner]) {
263 default:
264 case None:
265 ListRunner->second->add_options()
266 (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
267 ;
268 break;
269 case Boolean:
270 ListRunner->second->add_options()
271 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< bool >(), getDescription(*OptionRunner).c_str())
272 ;
273 break;
274 case Integer:
275 ListRunner->second->add_options()
276 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< int >(), getDescription(*OptionRunner).c_str())
277 ;
278 break;
279 case ListOfInts:
280 ListRunner->second->add_options()
281 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< vector<int> >(), getDescription(*OptionRunner).c_str())
282 ;
283 break;
284 case Double:
285 ListRunner->second->add_options()
286 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< double >(), getDescription(*OptionRunner).c_str())
287 ;
288 break;
289 case ListOfDoubles:
290 ListRunner->second->add_options()
291 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< vector<double> >(), getDescription(*OptionRunner).c_str())
292 ;
293 break;
294 case String:
295 ListRunner->second->add_options()
296 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< std::string >(), getDescription(*OptionRunner).c_str())
297 ;
298 break;
299 case Axis:
300 ListRunner->second->add_options()
301 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< int >(), getDescription(*OptionRunner).c_str())
302 ;
303 break;
304 case Vector:
305 ListRunner->second->add_options()
306 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< vector<double> >(), getDescription(*OptionRunner).c_str())
307 ;
308 break;
309 case Box:
310 ListRunner->second->add_options()
311 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< vector<double> >(), getDescription(*OptionRunner).c_str())
312 ;
313 break;
314 case Molecule:
315 ListRunner->second->add_options()
316 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< int >(), getDescription(*OptionRunner).c_str())
317 ;
318 break;
319 case ListOfMolecules:
320 ListRunner->second->add_options()
321 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< vector<int> >(), getDescription(*OptionRunner).c_str())
322 ;
323 break;
324 case Atom:
325 ListRunner->second->add_options()
326 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< int >(), getDescription(*OptionRunner).c_str())
327 ;
328 break;
329 case ListOfAtoms:
330 ListRunner->second->add_options()
331 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< vector<int> >(), getDescription(*OptionRunner).c_str())
332 ;
333 break;
334 case Element:
335 ListRunner->second->add_options()
336 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< int >(), getDescription(*OptionRunner).c_str())
337 ;
338 break;
339 case ListOfElements:
340 ListRunner->second->add_options()
341 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< vector<int> >(), getDescription(*OptionRunner).c_str())
342 ;
343 break;
344 }
345 } else {
346 DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " to CommandLineParser." << endl);
347 ListRunner->second->add_options()
348 (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
349 ;
350 }
351 }
352 }
353 // add positional arguments
354 for (set<string>::iterator OptionRunner = inputfile.begin(); OptionRunner != inputfile.end(); ++OptionRunner) {
355 DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " to positional CommandLineParser." << endl);
356 CommandLineParser::getInstance().inputfile.add((*OptionRunner).c_str(), -1);
357 }
358 cout << "Name for position 1: " << CommandLineParser::getInstance().inputfile.name_for_position(1) << endl;
359}
360
361/** Getter for MapOfActions:DescriptionMap.
362 * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
363 * \param actionname name of the action to lookup
364 * \return Description of the action
365 */
366std::string MapOfActions::getDescription(string actionname)
367{
368 ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescription");
369 return DescriptionMap[actionname];
370}
371
372/** Specific Getter for a MapOfActions:ShortFormMap.
373 * If action has a short for, then combination is as "actionname,ShortForm" (this is
374 * the desired format for boost::program_options). If no short form exists in the map,
375 * just actionname will be returned
376 * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
377 * \param actionname name of the action to lookup
378 * \return actionname,ShortForm or Description of the action
379 */
380std::string MapOfActions::getKeyAndShortForm(string actionname)
381{
382 stringstream output;
383 ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescriptionAndShortForm");
384 output << actionname;
385 if (ShortFormMap.find(actionname) != DescriptionMap.end())
386 output << "," << ShortFormMap[actionname];
387 return output.str();
388}
389
390/** Getter for MapOfActions:ShortFormMap.
391 * Note that we assert when action does not exist CommandLineParser::ShortFormMap.
392 * \param actionname name of the action to lookup
393 * \return ShortForm of the action
394 */
395std::string MapOfActions::getShortForm(string actionname)
396{
397 ASSERT(ShortFormMap.find(actionname) != ShortFormMap.end(), "Unknown action name passed to MapOfActions::getShortForm");
398 return ShortFormMap[actionname];
399}
400
401/** Returns whether the given action needs a value or not.
402 * \param actionname name of the action to look up
403 * \return true - value is needed, false - no value is stored in MapOfActions::TypeMap
404 */
405bool MapOfActions::hasValue(string actionname)
406{
407 return (TypeMap.find(actionname) != TypeMap.end());
408}
409
410/** Getter for MapOfActions::TypeMap.
411 * \param actionname name of the action to look up
412 * \return type of the action
413 */
414enum MapOfActions::OptionTypes MapOfActions::getValueType(string actionname)
415{
416 return TypeMap[actionname];
417}
418
419/** Searches whether action is registered with CommandLineParser.
420 * Note that this method is only meant transitionally for ParseCommandLineOptions' removal.
421 * I.e. All actions that are already handled by the new CommandLineUIFactory can be checked
422 * by this function.
423 * \param shortform command short form to look for
424 * \return true - action has been registered, false - action has not been registered.
425 */
426bool MapOfActions::isShortFormPresent(string shortform)
427{
428 bool result = false;
429 string actionname;
430 for (map<std::string, std::string>::iterator ShortFormRunner = ShortFormMap.begin(); ShortFormRunner != ShortFormMap.end(); ++ShortFormRunner)
431 if (ShortFormRunner->second == shortform) {
432 actionname = ShortFormRunner->first;
433 break;
434 }
435 result = result || (generic.find(actionname) != generic.end());
436 result = result || (config.find(actionname) != config.end());
437 result = result || (hidden.find(actionname) != hidden.end());
438 result = result || (visible.find(actionname) != visible.end());
439 result = result || (inputfile.find(actionname) != inputfile.end());
440 return result;
441}
442
443
444
445CONSTRUCT_SINGLETON(MapOfActions)
Note: See TracBrowser for help on using the repository browser.