source: src/Actions/MapOfActions.cpp@ 36166d

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

Introduced a MenuBar and Menus to the QT interface.

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