source: src/Actions/MapOfActions.cpp@ 6ca1f7

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

case '-B' now handled by CommandLineUI.

  • Property mode set to 100644
File size: 19.1 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["change-box"] = "B";
96 ShortFormMap["center-edge"] = "O";
97 ShortFormMap["center-in-box"] = "b";
98 ShortFormMap["change-element"] = "E";
99 ShortFormMap["convex-envelope"] = "o";
100 ShortFormMap["default-molname"] = "X";
101 ShortFormMap["depth-first-search"] = "D";
102 ShortFormMap["element-db"] = "e";
103 ShortFormMap["fastparsing"] = "n";
104 ShortFormMap["fill-molecule"] = "F";
105 ShortFormMap["fragment-mol"] = "f";
106 ShortFormMap["help"] = "h";
107 ShortFormMap["input"] = "i";
108 ShortFormMap["linear-interpolate"] = "L";
109 ShortFormMap["nonconvex-envelope"] = "N";
110 ShortFormMap["pair-correlation"] = "CE";
111 ShortFormMap["pair-correlation-point"] = "CP";
112 ShortFormMap["pair-correlation-surface"] = "CS";
113 ShortFormMap["parse-xyz"] = "p";
114 ShortFormMap["remove-atom"] = "r";
115 ShortFormMap["remove-sphere"] = "R";
116 ShortFormMap["repeat-box"] = "d";
117 ShortFormMap["rotate-to-pas"] = "m";
118 ShortFormMap["save-adjacency"] = "J";
119 ShortFormMap["save-bonds"] = "j";
120 ShortFormMap["save-temperature"] = "S";
121 ShortFormMap["scale-box"] = "s";
122 ShortFormMap["set-basis"] = "M";
123 ShortFormMap["subspace-dissect"] = "I";
124 ShortFormMap["suspend-in-water"] = "U";
125 ShortFormMap["translate-mol"] = "t";
126 ShortFormMap["verbose"] = "v";
127 ShortFormMap["verlet-integrate"] = "P";
128 ShortFormMap["version"] = "V";
129
130 // value types for the actions
131 TypeMap["add-atom"] = Atom;
132 TypeMap["bond-file"] = String;
133 TypeMap["bond-table"] = String;
134 TypeMap["boundary"] = Vector;
135 TypeMap["bound-in-box"] = ListOfDoubles;
136 TypeMap["center-in-box"] = ListOfDoubles;
137 TypeMap["change-box"] = ListOfDoubles;
138 TypeMap["change-element"] = Element;
139 TypeMap["change-molname"] = String;
140 TypeMap["convex-envelope"] = Molecule;
141 TypeMap["default-molname"] = String;
142 TypeMap["depth-first-search"] = Double;
143 TypeMap["element-db"] = String;
144 TypeMap["end-mol"] = Molecule;
145 TypeMap["fastparsing"] = Boolean;
146 TypeMap["fill-molecule"] = String;
147 TypeMap["fragment-mol"] = Molecule;
148 TypeMap["input"] = String;
149 TypeMap["linear-interpolate"] = String;
150 TypeMap["molecular-volume"] = Molecule;
151 TypeMap["nonconvex-envelope"] = Molecule;
152 TypeMap["parse-xyz"] = String;
153 TypeMap["principal-axis-system"] = Axis;
154 TypeMap["remove-atom"] = Atom;
155 TypeMap["remove-sphere"] = Atom;
156 TypeMap["repeat-box"] = ListOfInts;
157 TypeMap["rotate-to-pas"] = Molecule;
158 TypeMap["save-adjacency"] = String;
159 TypeMap["save-bonds"] = String;
160 TypeMap["save-temperature"] = String;
161 TypeMap["scale-box"] = Vector;
162 TypeMap["set-basis"] = String;
163 TypeMap["start-mol"] = Molecule;
164 TypeMap["suspend-in-water"] = Molecule;
165 TypeMap["translate-mol"] = Vector;
166 TypeMap["verlet-integrate"] = String;
167 TypeMap["verbose"] = Integer;
168 // value types for the values
169 TypeMap["bin-output-file"] = String;
170 TypeMap["bin-end"] = Double;
171 TypeMap["bin-start"] = Double;
172 TypeMap["distance"] = Double;
173 TypeMap["distances"] = ListOfDoubles;
174 TypeMap["elements"] = Element;
175 TypeMap["elements"] = ListOfElements;
176 TypeMap["length"] = Double;
177 TypeMap["lengths"] = ListOfDoubles;
178 TypeMap["MaxDistance"] = Double;
179 TypeMap["molecule-by-id"] = Molecule;
180 TypeMap["output-file"] = String;
181 TypeMap["periodic"] = Boolean;
182 TypeMap["position"] = Vector;
183
184 // list of generic actions
185// generic.insert("add-atom");
186// generic.insert("bond-file");
187// generic.insert("bond-table");
188// generic.insert("boundary");
189// generic.insert("bound-in-box");
190// generic.insert("center-edge");
191// generic.insert("center-in-box");
192 generic.insert("change-box");
193// generic.insert("change-molname");
194// generic.insert("change-element");
195// generic.insert("convex-envelope");
196// generic.insert("default-molname");
197// generic.insert("depth-first-search");
198// generic.insert("element-db");
199// generic.insert("fastparsing");
200// generic.insert("fill-molecule");
201// generic.insert("fragment-mol");
202 generic.insert("help");
203// generic.insert("linear-interpolate");
204// generic.insert("molecular-volume");
205// generic.insert("nonconvex-envelope");
206// generic.insert("pair-correlation");
207// generic.insert("pair-correlation-point");
208// generic.insert("pair-correlation-surface");
209// generic.insert("parse-xyz");
210// generic.insert("principal-axis-system");
211// generic.insert("remove-atom");
212// generic.insert("remove-sphere");
213// generic.insert("rotate-to-pas");
214// generic.insert("save-adjacency");
215// generic.insert("save-bonds");
216// generic.insert("save-temperature");
217// generic.insert("scale-box");
218// generic.insert("set-basis");
219// generic.insert("subspace-dissect");
220// generic.insert("suspend-in-water");
221// generic.insert("translate-mol");
222 generic.insert("verbose");
223// generic.insert("verlet-integrate");
224 generic.insert("version");
225// // list of generic values
226// generic.insert("bin-output-file");
227// generic.insert("bin-end");
228// generic.insert("bin-start");
229// generic.insert("distance");
230// generic.insert("distances");
231// generic.insert("element");
232// generic.insert("end-mol");
233 generic.insert("input");
234// generic.insert("length");
235// generic.insert("lengths");
236// generic.insert("MaxDistance");
237// generic.insert("molecule-by-id");
238// generic.insert("output-file");
239// generic.insert("periodic");
240// generic.insert("position");
241// generic.insert("start-mol");
242
243 // positional arguments
244 inputfile.insert("input");
245}
246
247/** Destructor of class MapOfActions.
248 *
249 */
250MapOfActions::~MapOfActions()
251{
252 DescriptionMap.clear();
253}
254
255/** Adds all options to the CommandLineParser.
256 *
257 */
258void MapOfActions::AddOptionsToParser()
259{
260 // add other options
261 for (map< set<string>*, po::options_description* >::iterator ListRunner = CmdParserLookup.begin(); ListRunner != CmdParserLookup.end(); ++ListRunner) {
262 for (set<string>::iterator OptionRunner = ListRunner->first->begin(); OptionRunner != ListRunner->first->end(); ++OptionRunner) {
263 if (hasValue(*OptionRunner)) {
264 DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " with type " << TypeMap[*OptionRunner] << " to CommandLineParser." << endl);
265 switch((enum OptionTypes) TypeMap[*OptionRunner]) {
266 default:
267 case None:
268 ListRunner->second->add_options()
269 (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
270 ;
271 break;
272 case Boolean:
273 ListRunner->second->add_options()
274 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< bool >(), getDescription(*OptionRunner).c_str())
275 ;
276 break;
277 case Integer:
278 ListRunner->second->add_options()
279 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< int >(), getDescription(*OptionRunner).c_str())
280 ;
281 break;
282 case ListOfInts:
283 ListRunner->second->add_options()
284 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< vector<int> >()->multitoken(), getDescription(*OptionRunner).c_str())
285 ;
286 break;
287 case Double:
288 ListRunner->second->add_options()
289 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< double >(), getDescription(*OptionRunner).c_str())
290 ;
291 break;
292 case ListOfDoubles:
293 ListRunner->second->add_options()
294 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< vector<double> >()->multitoken(), getDescription(*OptionRunner).c_str())
295 ;
296 break;
297 case String:
298 ListRunner->second->add_options()
299 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< std::string >(), getDescription(*OptionRunner).c_str())
300 ;
301 break;
302 case Axis:
303 ListRunner->second->add_options()
304 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< int >(), getDescription(*OptionRunner).c_str())
305 ;
306 break;
307 case Vector:
308 ListRunner->second->add_options()
309 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< vector<double> >(), getDescription(*OptionRunner).c_str())
310 ;
311 break;
312 case Box:
313 ListRunner->second->add_options()
314 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< vector<double> >(), getDescription(*OptionRunner).c_str())
315 ;
316 break;
317 case Molecule:
318 ListRunner->second->add_options()
319 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< int >(), getDescription(*OptionRunner).c_str())
320 ;
321 break;
322 case ListOfMolecules:
323 ListRunner->second->add_options()
324 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< vector<int> >()->multitoken(), getDescription(*OptionRunner).c_str())
325 ;
326 break;
327 case Atom:
328 ListRunner->second->add_options()
329 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< int >(), getDescription(*OptionRunner).c_str())
330 ;
331 break;
332 case ListOfAtoms:
333 ListRunner->second->add_options()
334 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< vector<int> >()->multitoken(), getDescription(*OptionRunner).c_str())
335 ;
336 break;
337 case Element:
338 ListRunner->second->add_options()
339 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< int >(), getDescription(*OptionRunner).c_str())
340 ;
341 break;
342 case ListOfElements:
343 ListRunner->second->add_options()
344 (getKeyAndShortForm(*OptionRunner).c_str(), po::value< vector<int> >()->multitoken(), getDescription(*OptionRunner).c_str())
345 ;
346 break;
347 }
348 } else {
349 DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " to CommandLineParser." << endl);
350 ListRunner->second->add_options()
351 (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
352 ;
353 }
354 }
355 }
356 // add positional arguments
357 for (set<string>::iterator OptionRunner = inputfile.begin(); OptionRunner != inputfile.end(); ++OptionRunner) {
358 DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " to positional CommandLineParser." << endl);
359 CommandLineParser::getInstance().inputfile.add((*OptionRunner).c_str(), -1);
360 }
361 cout << "Name for position 1: " << CommandLineParser::getInstance().inputfile.name_for_position(1) << endl;
362}
363
364/** Getter for MapOfActions:DescriptionMap.
365 * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
366 * \param actionname name of the action to lookup
367 * \return Description of the action
368 */
369std::string MapOfActions::getDescription(string actionname)
370{
371 ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescription");
372 return DescriptionMap[actionname];
373}
374
375/** Specific Getter for a MapOfActions:ShortFormMap.
376 * If action has a short for, then combination is as "actionname,ShortForm" (this is
377 * the desired format for boost::program_options). If no short form exists in the map,
378 * just actionname will be returned
379 * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
380 * \param actionname name of the action to lookup
381 * \return actionname,ShortForm or Description of the action
382 */
383std::string MapOfActions::getKeyAndShortForm(string actionname)
384{
385 stringstream output;
386 ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescriptionAndShortForm");
387 output << actionname;
388 if (ShortFormMap.find(actionname) != DescriptionMap.end())
389 output << "," << ShortFormMap[actionname];
390 return output.str();
391}
392
393/** Getter for MapOfActions:ShortFormMap.
394 * Note that we assert when action does not exist CommandLineParser::ShortFormMap.
395 * \param actionname name of the action to lookup
396 * \return ShortForm of the action
397 */
398std::string MapOfActions::getShortForm(string actionname)
399{
400 ASSERT(ShortFormMap.find(actionname) != ShortFormMap.end(), "Unknown action name passed to MapOfActions::getShortForm");
401 return ShortFormMap[actionname];
402}
403
404/** Returns whether the given action needs a value or not.
405 * \param actionname name of the action to look up
406 * \return true - value is needed, false - no value is stored in MapOfActions::TypeMap
407 */
408bool MapOfActions::hasValue(string actionname)
409{
410 return (TypeMap.find(actionname) != TypeMap.end());
411}
412
413/** Getter for MapOfActions::TypeMap.
414 * \param actionname name of the action to look up
415 * \return type of the action
416 */
417enum MapOfActions::OptionTypes MapOfActions::getValueType(string actionname)
418{
419 return TypeMap[actionname];
420}
421
422/** Searches whether action is registered with CommandLineParser.
423 * Note that this method is only meant transitionally for ParseCommandLineOptions' removal.
424 * I.e. All actions that are already handled by the new CommandLineUIFactory can be checked
425 * by this function.
426 * \param shortform command short form to look for
427 * \return true - action has been registered, false - action has not been registered.
428 */
429bool MapOfActions::isShortFormPresent(string shortform)
430{
431 bool result = false;
432 string actionname;
433 for (map<std::string, std::string>::iterator ShortFormRunner = ShortFormMap.begin(); ShortFormRunner != ShortFormMap.end(); ++ShortFormRunner)
434 if (ShortFormRunner->second == shortform) {
435 actionname = ShortFormRunner->first;
436 break;
437 }
438 result = result || (generic.find(actionname) != generic.end());
439 result = result || (config.find(actionname) != config.end());
440 result = result || (hidden.find(actionname) != hidden.end());
441 result = result || (visible.find(actionname) != visible.end());
442 result = result || (inputfile.find(actionname) != inputfile.end());
443 return result;
444}
445
446
447
448CONSTRUCT_SINGLETON(MapOfActions)
Note: See TracBrowser for help on using the repository browser.