source: src/Actions/MapOfActions.cpp@ c7f5c2

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

Changed RotateAroundOriginByAngleAction from acting on molecules to acting on selected atoms.

  • Property mode set to 100644
File size: 49.1 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 "Actions/MapOfActions.hpp"
13#include "Descriptors/AtomIdDescriptor.hpp"
14#include "Descriptors/MoleculeIdDescriptor.hpp"
15#include "Helpers/Assert.hpp"
16#include "Patterns/Singleton_impl.hpp"
17
18#include <boost/lexical_cast.hpp>
19#include <boost/optional.hpp>
20#include <boost/program_options.hpp>
21
22#include <iostream>
23
24#include "atom.hpp"
25#include "Box.hpp"
26#include "CommandLineParser.hpp"
27#include "element.hpp"
28#include "Helpers/Log.hpp"
29#include "LinearAlgebra/Matrix.hpp"
30#include "molecule.hpp"
31#include "periodentafel.hpp"
32#include "LinearAlgebra/Vector.hpp"
33#include "Helpers/Verbose.hpp"
34
35#include "Actions/ActionRegistry.hpp"
36#include "Actions/AnalysisAction/MolecularVolumeAction.hpp"
37#include "Actions/AnalysisAction/PairCorrelationAction.hpp"
38#include "Actions/AnalysisAction/PointCorrelationAction.hpp"
39#include "Actions/AnalysisAction/PrincipalAxisSystemAction.hpp"
40#include "Actions/AnalysisAction/SurfaceCorrelationAction.hpp"
41#include "Actions/AtomAction/AddAction.hpp"
42#include "Actions/AtomAction/ChangeElementAction.hpp"
43#include "Actions/AtomAction/RemoveAction.hpp"
44#include "Actions/AtomAction/RotateAroundOriginByAngleAction.hpp"
45#include "Actions/AtomAction/TranslateAction.hpp"
46#include "Actions/CmdAction/BondLengthTableAction.hpp"
47#include "Actions/CmdAction/ElementDbAction.hpp"
48#include "Actions/CmdAction/FastParsingAction.hpp"
49#include "Actions/CmdAction/HelpAction.hpp"
50#include "Actions/CmdAction/VerboseAction.hpp"
51#include "Actions/CmdAction/VersionAction.hpp"
52#include "Actions/FragmentationAction/DepthFirstSearchAction.hpp"
53#include "Actions/FragmentationAction/SubgraphDissectionAction.hpp"
54#include "Actions/FragmentationAction/FragmentationAction.hpp"
55#include "Actions/MoleculeAction/BondFileAction.hpp"
56#include "Actions/MoleculeAction/ChangeNameAction.hpp"
57#include "Actions/MoleculeAction/FillWithMoleculeAction.hpp"
58#include "Actions/MoleculeAction/LinearInterpolationofTrajectoriesAction.hpp"
59#include "Actions/MoleculeAction/RotateAroundSelfByAngleAction.hpp"
60#include "Actions/MoleculeAction/RotateToPrincipalAxisSystemAction.hpp"
61#include "Actions/MoleculeAction/SaveAdjacencyAction.hpp"
62#include "Actions/MoleculeAction/SaveBondsAction.hpp"
63#include "Actions/MoleculeAction/SaveTemperatureAction.hpp"
64#include "Actions/MoleculeAction/SuspendInWaterAction.hpp"
65#include "Actions/MoleculeAction/VerletIntegrationAction.hpp"
66#include "Actions/ParserAction/LoadXyzAction.hpp"
67#include "Actions/ParserAction/SaveXyzAction.hpp"
68#include "Actions/SelectionAction/AllAtomsAction.hpp"
69#include "Actions/SelectionAction/AllAtomsOfMoleculeAction.hpp"
70#include "Actions/SelectionAction/AllMoleculesAction.hpp"
71#include "Actions/SelectionAction/AtomByIdAction.hpp"
72#include "Actions/SelectionAction/ClearAllAtomsAction.hpp"
73#include "Actions/SelectionAction/ClearAllMoleculesAction.hpp"
74#include "Actions/SelectionAction/MoleculeByIdAction.hpp"
75#include "Actions/SelectionAction/MoleculeOfAtomAction.hpp"
76#include "Actions/SelectionAction/NotAllAtomsAction.hpp"
77#include "Actions/SelectionAction/NotAllAtomsOfMoleculeAction.hpp"
78#include "Actions/SelectionAction/NotAllMoleculesAction.hpp"
79#include "Actions/SelectionAction/NotAtomByIdAction.hpp"
80#include "Actions/SelectionAction/NotMoleculeByIdAction.hpp"
81#include "Actions/SelectionAction/NotMoleculeOfAtomAction.hpp"
82#include "Actions/TesselationAction/ConvexEnvelopeAction.hpp"
83#include "Actions/TesselationAction/NonConvexEnvelopeAction.hpp"
84#include "Actions/WorldAction/AddEmptyBoundaryAction.hpp"
85#include "Actions/WorldAction/BoundInBoxAction.hpp"
86#include "Actions/WorldAction/CenterInBoxAction.hpp"
87#include "Actions/WorldAction/CenterOnEdgeAction.hpp"
88#include "Actions/WorldAction/ChangeBoxAction.hpp"
89#include "Actions/WorldAction/InputAction.hpp"
90#include "Actions/WorldAction/OutputAction.hpp"
91#include "Actions/WorldAction/RemoveSphereOfAtomsAction.hpp"
92#include "Actions/WorldAction/RepeatBoxAction.hpp"
93#include "Actions/WorldAction/ScaleBoxAction.hpp"
94#include "Actions/WorldAction/SetDefaultNameAction.hpp"
95#include "Actions/WorldAction/SetGaussianBasisAction.hpp"
96#include "Actions/WorldAction/SetOutputFormatsAction.hpp"
97#include "Actions/Values.hpp"
98
99void validate(boost::any& v, const std::vector<std::string>& values, VectorValue *, int)
100{
101 VectorValue VV;
102 std::vector<std::string> components;
103
104 // split comma-separated values
105 if (values.size() != 1) {
106 cerr << "Not one vector but " << components.size() << " given " << endl;
107 throw boost::program_options::validation_error("Unequal to one vector given");
108 }
109 std::string argument(values.at(0));
110 std::string::iterator Aiter = argument.begin();
111 std::string::iterator Biter = argument.begin();
112 for (; Aiter != argument.end(); ++Aiter) {
113 if (*Aiter == ',') {
114 components.push_back(string(Biter,Aiter));
115 do {
116 Aiter++;
117 } while (*Aiter == ' ' || *Aiter == '\t');
118 Biter = Aiter;
119 }
120 }
121 components.push_back(string(Biter,argument.end()));
122
123 if (components.size() != 3) {
124 cerr << "Specified vector does not have three components but " << components.size() << endl;
125 throw boost::program_options::validation_error("Specified vector does not have three components");
126 }
127 VV.x = boost::lexical_cast<double>(components.at(0));
128 VV.y = boost::lexical_cast<double>(components.at(1));
129 VV.z = boost::lexical_cast<double>(components.at(2));
130 v = boost::any(VectorValue(VV));
131}
132
133void validate(boost::any& v, const std::vector<std::string>& values, BoxValue *, int)
134{
135 BoxValue BV;
136 std::vector<std::string> components;
137
138 // split comma-separated values
139 if (values.size() != 1) {
140 cerr << "Not one vector but " << components.size() << " given " << endl;
141 throw boost::program_options::validation_error("Unequal to one vector given");
142 }
143 std::string argument(values.at(0));
144 std::string::iterator Aiter = argument.begin();
145 std::string::iterator Biter = argument.begin();
146 for (; Aiter != argument.end(); ++Aiter) {
147 if (*Aiter == ',') {
148 components.push_back(string(Biter,Aiter));
149 do {
150 Aiter++;
151 } while (*Aiter == ' ' || *Aiter == '\t');
152 Biter = Aiter;
153 }
154 }
155 components.push_back(string(Biter,argument.end()));
156
157 if (components.size() != 6) {
158 cerr << "Specified vector does not have three components but " << components.size() << endl;
159 throw boost::program_options::validation_error("Specified symmetric box matrix does not have six components");
160 }
161 BV.xx = boost::lexical_cast<double>(components.at(0));
162 BV.yx = boost::lexical_cast<double>(components.at(1));
163 BV.yy = boost::lexical_cast<double>(components.at(2));
164 BV.zx = boost::lexical_cast<double>(components.at(3));
165 BV.zy = boost::lexical_cast<double>(components.at(4));
166 BV.zz = boost::lexical_cast<double>(components.at(5));
167 v = boost::any(BoxValue(BV));
168}
169
170/** Constructor of class MapOfActions.
171 *
172 */
173MapOfActions::MapOfActions()
174{
175 // initialise lookup map
176 CmdParserLookup[&generic] = &(CommandLineParser::getInstance().generic);
177 CmdParserLookup[&config] = &(CommandLineParser::getInstance().config);
178 CmdParserLookup[&hidden] = &(CommandLineParser::getInstance().hidden);
179 CmdParserLookup[&visible] = &(CommandLineParser::getInstance().visible);
180
181 // keys for actions
182 DescriptionMap["add-atom"] = "add atom of specified element";
183 DescriptionMap["bond-table"] = "setting name of the bond length table file";
184 DescriptionMap["bond-file"] = "name of the bond file";
185 DescriptionMap["boundary"] = "change box to add an empty boundary around all atoms";
186 DescriptionMap["bound-in-box"] = "bound all atoms in the domain";
187 DescriptionMap["center-edge"] = "center edge of all atoms on (0,0,0)";
188 DescriptionMap["center-in-box"] = "center all atoms in the domain";
189 DescriptionMap["change-box"] = "change the symmetrc matrix of the simulation domain";
190 DescriptionMap["change-element"] = "change the element of an atom";
191 DescriptionMap["change-molname"] = "change the name of a molecule";
192 DescriptionMap["clear-atom-selection"] = "clear the atom selection";
193 DescriptionMap["clear-molecule-selection"] = "clear the molecule selection";
194 DescriptionMap["convex-envelope"] = "create the convex envelope for a molecule";
195 DescriptionMap["default-molname"] = "set the default name of new molecules";
196 DescriptionMap["depth-first-search"] = "Depth-First Search analysis of the molecular system";
197 DescriptionMap["element-db"] = "setting the path where the element databases can be found";
198 DescriptionMap["fastparsing"] = "setting whether trajectories shall be parsed completely (n) or just first step (y)";
199 DescriptionMap["fill-molecule"] = "fill empty space of box with a filler molecule";
200 DescriptionMap["fragment-mol"] = "create for a given molecule into fragments up to given order";
201 DescriptionMap["help"] = "Give this help screen";
202 DescriptionMap["input"] = "specify input files";
203 DescriptionMap["linear-interpolate"] = "linear interpolation in discrete steps between start and end position of a molecule";
204 DescriptionMap["molecular-volume"] = "calculate the volume of a given molecule";
205 DescriptionMap["nonconvex-envelope"] = "create the non-convex envelope for a molecule";
206 DescriptionMap["output"] = "write output files";
207 DescriptionMap["set-output"] = "specify output formats";
208 DescriptionMap["pair-correlation"] = "pair correlation analysis between two elements";
209 DescriptionMap["parse-xyz"] = "parse xyz file into World";
210 DescriptionMap["point-correlation"] = "pair correlation analysis between element and point";
211 DescriptionMap["principal-axis-system"] = "calculate the principal axis system of the specified molecule";
212 DescriptionMap["remove-atom"] = "remove a specified atom";
213 DescriptionMap["remove-sphere"] = "remove sphere of atoms of around a specified atom";
214 DescriptionMap["repeat-box"] = "create periodic copies of the simulation box per axis";
215 DescriptionMap["rotate-origin"] = "rotate selected atoms by a specific angle around origin";
216 DescriptionMap["rotate-self"] = "rotates molecules by a specific angle around own center of gravity";
217 DescriptionMap["rotate-to-pas"] = "calculate the principal axis system of the specified molecule and rotate specified axis to align with main axis";
218 DescriptionMap["save-adjacency"] = "name of the adjacency file to write to";
219 DescriptionMap["save-bonds"] = "name of the bonds file to write to";
220 DescriptionMap["save-temperature"] = "name of the temperature file to write to";
221 DescriptionMap["SaveXyz"] = "save world as xyz file";
222 DescriptionMap["scale-box"] = "scale box and atomic positions inside";
223 DescriptionMap["select-all-atoms"] = "select all atoms";
224 DescriptionMap["select-all-molecules"] = "select all molecules";
225 DescriptionMap["select-atom-by-id"] = "select an atom by index";
226 DescriptionMap["select-molecule-by-id"] = "select a molecule by index";
227 DescriptionMap["select-molecule-of-atom"] = "select a molecule to which a given atom belongs";
228 DescriptionMap["select-molecules-atoms"] = "select all atoms of a molecule";
229 DescriptionMap["set-basis"] = "set the name of the gaussian basis set for MPQC";
230 DescriptionMap["set-output"] = "specify output formats";
231 DescriptionMap["subgraph-dissect"] = "dissect the molecular system into molecules representing disconnected subgraphs";
232 DescriptionMap["surface-correlation"] = "pair correlation analysis between element and surface";
233 DescriptionMap["suspend-in-water"] = "suspend the given molecule in water such that in the domain the mean density is as specified";
234 DescriptionMap["translate-atoms"] = "translate all selected atoms by given vector";
235 DescriptionMap["unselect-all-atoms"] = "unselect all atoms";
236 DescriptionMap["unselect-all-molecules"] = "unselect all molecules";
237 DescriptionMap["unselect-atom-by-id"] = "unselect an atom by index";
238 DescriptionMap["unselect-molecule-by-id"] = "unselect a molecule by index";
239 DescriptionMap["unselect-molecule-of-atom"] = "unselect a molecule to which a given atom belongs";
240 DescriptionMap["unselect-molecules-atoms"] = "unselect all atoms of a molecule";
241 DescriptionMap["verbose"] = "set verbosity level";
242 DescriptionMap["verlet-integrate"] = "perform verlet integration of a given force file";
243 DescriptionMap["version"] = "show version";
244 // keys for values
245 DescriptionMap["bin-output-file"] = "name of the bin output file";
246 DescriptionMap["bin-end"] = "start of the last bin";
247 DescriptionMap["bin-start"] = "start of the first bin";
248 DescriptionMap["bin-width"] = "width of the bins";
249 DescriptionMap["convex-file"] = "filename of the non-convex envelope";
250 DescriptionMap["distance"] = "distance in space";
251 DescriptionMap["distances"] = "list of three of distances in space, one for each axis direction";
252 DescriptionMap["DoRotate"] = "whether to rotate or just report angles";
253 DescriptionMap["element"] = "single element";
254 DescriptionMap["elements"] = "set of elements";
255 DescriptionMap["end-step"] = "last or end step";
256 DescriptionMap["id-mapping"] = "whether the identity shall be used in mapping atoms onto atoms or some closest distance measure shall be used";
257 DescriptionMap["input"] = "name of input file";
258 DescriptionMap["length"] = "length in space";
259 DescriptionMap["lengths"] = "list of three of lengths in space, one for each axis direction";
260 DescriptionMap["MaxDistance"] = "maximum distance in space";
261 DescriptionMap["molecule-by-id"] = "index of a molecule";
262 DescriptionMap["nonconvex-file"] = "filename of the non-convex envelope";
263 DescriptionMap["order"] = "order of a discretization, dissection, ...";
264 DescriptionMap["output-file"] = "name of the output file";
265 DescriptionMap["periodic"] = "system is constraint to periodic boundary conditions (y/n)";
266 DescriptionMap["position"] = "position in R^3 space";
267 DescriptionMap["start-step"] = "first or start step";
268
269 // short forms for the actions
270 ShortFormMap["add-atom"] = "a";
271 ShortFormMap["bond-table"] = "g";
272 ShortFormMap["bond-file"] = "A";
273 ShortFormMap["boundary"] = "c";
274 ShortFormMap["change-box"] = "B";
275 ShortFormMap["center-edge"] = "O";
276 ShortFormMap["center-in-box"] = "b";
277 ShortFormMap["change-element"] = "E";
278// ShortFormMap["convex-envelope"] = "x";
279 ShortFormMap["default-molname"] = "X";
280 ShortFormMap["depth-first-search"] = "D";
281 ShortFormMap["element-db"] = "e";
282 ShortFormMap["fastparsing"] = "n";
283 ShortFormMap["fill-molecule"] = "F";
284 ShortFormMap["fragment-mol"] = "f";
285 ShortFormMap["help"] = "h";
286 ShortFormMap["input"] = "i";
287 ShortFormMap["linear-interpolate"] = "L";
288 ShortFormMap["nonconvex-envelope"] = "N";
289// ShortFormMap["output"] = "o";
290// ShortFormMap["pair-correlation"] = "C";
291 ShortFormMap["parse-xyz"] = "p";
292 ShortFormMap["remove-atom"] = "r";
293 ShortFormMap["remove-sphere"] = "R";
294 ShortFormMap["repeat-box"] = "d";
295 ShortFormMap["rotate-to-pas"] = "m";
296 ShortFormMap["save-adjacency"] = "J";
297 ShortFormMap["save-bonds"] = "j";
298 ShortFormMap["save-temperature"] = "S";
299 ShortFormMap["scale-box"] = "s";
300 ShortFormMap["set-basis"] = "M";
301 ShortFormMap["set-output"] = "o";
302 ShortFormMap["subgraph-dissect"] = "I";
303 ShortFormMap["suspend-in-water"] = "u";
304 ShortFormMap["translate-atoms"] = "t";
305 ShortFormMap["verbose"] = "v";
306 ShortFormMap["verlet-integrate"] = "P";
307 ShortFormMap["version"] = "V";
308
309 // value types for the actions
310 TypeMap["add-atom"] = &typeid(element);
311 TypeMap["bond-file"] = &typeid(std::string);
312 TypeMap["bond-table"] = &typeid(std::string);
313 TypeMap["boundary"] = &typeid(VectorValue);
314 TypeMap["center-in-box"] = &typeid(BoxValue);
315 TypeMap["change-box"] = &typeid(BoxValue);
316 TypeMap["change-element"] = &typeid(element);
317 TypeMap["change-molname"] = &typeid(std::string);
318 TypeMap["clear-atom-selection"] = &typeid(void);
319 TypeMap["clear-molecule-selection"] = &typeid(void);
320 TypeMap["convex-envelope"] = &typeid(void);
321 TypeMap["default-molname"] = &typeid(std::string);
322 TypeMap["depth-first-search"] = &typeid(double);
323 TypeMap["element-db"] = &typeid(std::string);
324 TypeMap["fastparsing"] = &typeid(bool);
325 TypeMap["fill-molecule"] = &typeid(std::string);
326 TypeMap["fragment-mol"] = &typeid(std::string);
327 TypeMap["input"] = &typeid(std::string);
328 TypeMap["linear-interpolate"] = &typeid(std::string);
329 TypeMap["molecular-volume"] = &typeid(molecule);
330 TypeMap["nonconvex-envelope"] = &typeid(double);
331 TypeMap["output"] = &typeid(void);
332 TypeMap["parse-xyz"] = &typeid(std::string);
333 TypeMap["pair-correlation"] = &typeid(void);
334 TypeMap["point-correlation"] = &typeid(void);
335 TypeMap["principal-axis-system"] = &typeid(void);
336 TypeMap["remove-atom"] = &typeid(void);
337 TypeMap["remove-sphere"] = &typeid(double);
338 TypeMap["repeat-box"] = &typeid(VectorValue);
339 TypeMap["rotate-origin"] = &typeid(double);
340 TypeMap["rotate-self"] = &typeid(double);
341 TypeMap["rotate-to-pas"] = &typeid(VectorValue);
342 TypeMap["save-adjacency"] = &typeid(std::string);
343 TypeMap["save-bonds"] = &typeid(std::string);
344 TypeMap["save-temperature"] = &typeid(std::string);
345 TypeMap["scale-box"] = &typeid(VectorValue);
346 TypeMap["select-all-atoms"] = &typeid(void);
347 TypeMap["select-all-molecules"] = &typeid(void);
348 TypeMap["select-atom-by-id"] = &typeid(atom);
349 TypeMap["select-molecule-by-id"] = &typeid(molecule);
350 TypeMap["select-molecule-of-atom"] = &typeid(atom);
351 TypeMap["select-molecules-atoms"] = &typeid(molecule);
352 TypeMap["set-basis"] = &typeid(std::string);
353 TypeMap["set-output"] = &typeid(std::vector<std::string>);
354 TypeMap["subgraph-dissect"] = &typeid(void);
355 TypeMap["surface-correlation"] = &typeid(void);
356 TypeMap["suspend-in-water"] = &typeid(double);
357 TypeMap["translate-atoms"] = &typeid(VectorValue);
358 TypeMap["unselect-all-atoms"] = &typeid(void);
359 TypeMap["unselect-all-molecules"] = &typeid(void);
360 TypeMap["unselect-atom-by-id"] = &typeid(atom);
361 TypeMap["unselect-molecule-by-id"] = &typeid(molecule);
362 TypeMap["unselect-molecule-of-atom"] = &typeid(atom);
363 TypeMap["unselect-molecules-atoms"] = &typeid(molecule);
364 TypeMap["verlet-integrate"] = &typeid(std::string);
365 TypeMap["verbose"] = &typeid(int);
366
367 // value types for the values
368 TypeMap["bin-output-file"] = &typeid(std::string);
369 TypeMap["bin-end"] = &typeid(double);
370 TypeMap["bin-start"] = &typeid(double);
371 TypeMap["bin-width"] = &typeid(double);
372 TypeMap["convex-file"] = &typeid(std::string);
373 TypeMap["distance"] = &typeid(double);
374 TypeMap["distances"] = &typeid(VectorValue);
375 TypeMap["DoRotate"] = &typeid(bool);
376 TypeMap["element"] = &typeid(element);
377 TypeMap["elements"] = &typeid(std::vector<element *>);
378 TypeMap["end-step"] = &typeid(int);
379 TypeMap["id-mapping"] = &typeid(bool);
380 TypeMap["length"] = &typeid(double);
381 TypeMap["lengths"] = &typeid(VectorValue);
382 TypeMap["MaxDistance"] = &typeid(double);
383 TypeMap["molecule-by-id"] = &typeid(molecule);
384 TypeMap["nonconvex-file"] = &typeid(std::string);
385 TypeMap["order"] = &typeid(int);
386 TypeMap["output-file"] = &typeid(std::string);
387 TypeMap["periodic"] = &typeid(bool);
388 TypeMap["position"] = &typeid(VectorValue);
389 TypeMap["start-step"] = &typeid(int);
390
391 TypeEnumMap[&typeid(void)] = None;
392 TypeEnumMap[&typeid(bool)] = Boolean;
393 TypeEnumMap[&typeid(int)] = Integer;
394 TypeEnumMap[&typeid(std::vector<int>)] = ListOfIntegers;
395 TypeEnumMap[&typeid(double)] = Double;
396 TypeEnumMap[&typeid(std::vector<double>)] = ListOfDoubles;
397 TypeEnumMap[&typeid(std::string)] = String;
398 TypeEnumMap[&typeid(std::vector<std::string>)] = ListOfStrings;
399 TypeEnumMap[&typeid(VectorValue)] = Vector;
400 TypeEnumMap[&typeid(std::vector<VectorValue>)] = ListOfVectors;
401 TypeEnumMap[&typeid(BoxValue)] = Box;
402 TypeEnumMap[&typeid(molecule)] = Molecule;
403 TypeEnumMap[&typeid(std::vector<molecule *>)] = ListOfMolecules;
404 TypeEnumMap[&typeid(atom)] = Atom;
405 TypeEnumMap[&typeid(std::vector<atom *>)] = ListOfAtoms;
406 TypeEnumMap[&typeid(element)] = Element;
407 TypeEnumMap[&typeid(std::vector<element *>)] = ListOfElements;
408
409 // default values for any action that needs one (always string!)
410 CurrentValue["bin-width"] = "0.5";
411 CurrentValue["fastparsing"] = "0";
412 CurrentValue["periodic"] = "0";
413
414 // put action into each menu category
415 MenuDescription["analysis"] = pair<std::string,std::string>("Analysis (pair correlation, volume)", "Analysis");
416 MenuDescription["atom"] = pair<std::string,std::string>("Edit atoms", "Atoms");
417 MenuDescription["command"] = pair<std::string,std::string>("Configuration", "configuration options");
418 MenuDescription["fragmentation"] = pair<std::string,std::string>("Fragmentation", "Fragmentation");
419 MenuDescription["molecule"] = pair<std::string,std::string>("Parse files into system", "Molecules");
420 MenuDescription["parser"] = pair<std::string,std::string>("Edit molecules (load, parse, save)", "Input/Output");
421 MenuDescription["selection"] = pair<std::string,std::string>("Select atoms/molecules", "Selection");
422 MenuDescription["tesselation"] = pair<std::string,std::string>("Tesselate molecules", "Tesselation");
423 MenuDescription["world"] = pair<std::string,std::string>("Edit world", "Globals");
424
425 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "molecular-volume") );
426 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "pair-correlation") );
427 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "point-correlation") );
428 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "surface-correlation") );
429 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "principal-axis-system") );
430
431 MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "add-atom") );
432 MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "change-element") );
433 MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "remove-atom") );
434 MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "translate-atoms") );
435
436 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "bond-table") );
437 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "element-db") );
438 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "fastparsing") );
439 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "verbose") );
440 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "version") );
441
442 MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "depth-first-search") );
443 MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "fragment-mol") );
444 MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "subgraph-dissect") );
445
446 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "bond-file") );
447 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "change-molname") );
448 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "fill-molecule") );
449 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "linear-interpolate") );
450 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "rotate-origin") );
451 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "rotate-self") );
452 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "rotate-to-pas") );
453 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "save-adjacency") );
454 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "save-bonds") );
455 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "save-temperature") );
456 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "suspend-in-water") );
457 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "verlet-integrate") );
458
459 MenuContainsActionMap.insert( pair<std::string, std::string> ("parser", "parse-xyz") );
460 MenuContainsActionMap.insert( pair<std::string, std::string> ("parser", "SaveXyz") );
461
462 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "clear-atom-selection") );
463 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "clear-molecule-selection") );
464 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "select-all-atoms") );
465 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "select-all-molecules") );
466 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "select-atom-by-id") );
467 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "select-molecule-by-id") );
468 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "select-molecule-of-atom") );
469 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "select-molecules-atoms") );
470 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "unselect-all-atoms") );
471 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "unselect-all-molecules") );
472 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "unselect-atom-by-id") );
473 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "unselect-molecule-by-id") );
474 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "unselect-molecule-of-atom") );
475 MenuContainsActionMap.insert( pair<std::string, std::string> ("selection", "unselect-molecules-atoms") );
476
477 MenuContainsActionMap.insert( pair<std::string, std::string> ("tesselation", "convex-envelope") );
478 MenuContainsActionMap.insert( pair<std::string, std::string> ("tesselation", "nonconvex-envelope") );
479
480 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "boundary") );
481 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "bound-in-box") );
482 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "center-in-box") );
483 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "center-edge") );
484 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "change-box") );
485 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "input") );
486 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "output") );
487 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "remove-sphere") );
488 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "repeat-box") );
489 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "scale-box") );
490 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "default-molname") );
491 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "set-basis") );
492 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "set-output") );
493
494 // put actions into command line category
495 generic.insert("add-atom");
496 generic.insert("bond-file");
497 generic.insert("bond-table");
498 generic.insert("boundary");
499// generic.insert("bound-in-box");
500 generic.insert("center-edge");
501 generic.insert("center-in-box");
502 generic.insert("change-box");
503// generic.insert("change-molname");
504 generic.insert("change-element");
505 generic.insert("clear-atom-selection");
506 generic.insert("clear-molecule-selection");
507 generic.insert("convex-envelope");
508 generic.insert("default-molname");
509 generic.insert("depth-first-search");
510 generic.insert("element-db");
511 generic.insert("fastparsing");
512 generic.insert("fill-molecule");
513 generic.insert("fragment-mol");
514 generic.insert("help");
515 generic.insert("input");
516 generic.insert("linear-interpolate");
517// generic.insert("molecular-volume");
518 generic.insert("nonconvex-envelope");
519 generic.insert("output");
520 generic.insert("pair-correlation");
521 generic.insert("parse-xyz");
522 generic.insert("point-correlation");
523// generic.insert("principal-axis-system");
524 generic.insert("remove-atom");
525 generic.insert("remove-sphere");
526 generic.insert("repeat-box");
527 generic.insert("rotate-origin");
528 generic.insert("rotate-self");
529 generic.insert("rotate-to-pas");
530 generic.insert("save-adjacency");
531 generic.insert("save-bonds");
532 generic.insert("save-temperature");
533 generic.insert("scale-box");
534 generic.insert("select-all-atoms");
535 generic.insert("select-all-molecules");
536 generic.insert("select-atom-by-id");
537 generic.insert("select-molecule-by-id");
538 generic.insert("select-molecule-of-atom");
539 generic.insert("select-molecules-atoms");
540 generic.insert("set-basis");
541 generic.insert("set-output");
542 generic.insert("subgraph-dissect");
543 generic.insert("surface-correlation");
544 generic.insert("suspend-in-water");
545 generic.insert("translate-atoms");
546 generic.insert("unselect-all-atoms");
547 generic.insert("unselect-all-molecules");
548 generic.insert("unselect-atom-by-id");
549 generic.insert("unselect-molecule-by-id");
550 generic.insert("unselect-molecule-of-atom");
551 generic.insert("unselect-molecules-atoms");
552 generic.insert("verbose");
553 generic.insert("verlet-integrate");
554 generic.insert("version");
555
556 // positional arguments
557 generic.insert("input");
558
559 // hidden arguments
560 hidden.insert("bin-end");
561 hidden.insert("bin-output-file");
562 hidden.insert("bin-start");
563 hidden.insert("bin-width");
564 hidden.insert("convex-file");
565 hidden.insert("distance");
566 hidden.insert("DoRotate");
567 hidden.insert("distances");
568 hidden.insert("element");
569 hidden.insert("elements");
570 hidden.insert("end-step");
571 hidden.insert("id-mapping");
572 hidden.insert("lengths");
573 hidden.insert("MaxDistance");
574 hidden.insert("molecule-by-id");
575 hidden.insert("nonconvex-file");
576 hidden.insert("order");
577 hidden.insert("output-file");
578 hidden.insert("periodic");
579 hidden.insert("position");
580 hidden.insert("start-step");
581}
582
583/** Destructor of class MapOfActions.
584 *
585 */
586MapOfActions::~MapOfActions()
587{
588 DescriptionMap.clear();
589}
590
591void MapOfActions::queryCurrentValue(const char * name, class atom * &_T)
592{
593 int atomID = -1;
594 if (typeid( atom ) == *TypeMap[name]) {
595 if (CurrentValue.find(name) == CurrentValue.end())
596 throw MissingValueException(__FILE__, __LINE__);
597 atomID = lexical_cast<int>(CurrentValue[name].c_str());
598 CurrentValue.erase(name);
599 } else
600 throw IllegalTypeException(__FILE__,__LINE__);
601 _T = World::getInstance().getAtom(AtomById(atomID));
602}
603
604void MapOfActions::queryCurrentValue(const char * name, class element * &_T) {
605 int Z = -1;
606 if (typeid( element ) == *TypeMap[name]) {
607 if (CurrentValue.find(name) == CurrentValue.end())
608 throw MissingValueException(__FILE__, __LINE__);
609 Z = lexical_cast<int>(CurrentValue[name].c_str());
610 CurrentValue.erase(name);
611 } else
612 throw IllegalTypeException(__FILE__,__LINE__);
613 _T = World::getInstance().getPeriode()->FindElement(Z);
614}
615
616void MapOfActions::queryCurrentValue(const char * name, class molecule * &_T) {
617 int molID = -1;
618 if (typeid( molecule ) == *TypeMap[name]) {
619 if (CurrentValue.find(name) == CurrentValue.end())
620 throw MissingValueException(__FILE__, __LINE__);
621 molID = lexical_cast<int>(CurrentValue[name].c_str());
622 CurrentValue.erase(name);
623 } else
624 throw IllegalTypeException(__FILE__,__LINE__);
625 _T = World::getInstance().getMolecule(MoleculeById(molID));
626}
627
628void MapOfActions::queryCurrentValue(const char * name, class Box &_T) {
629 Matrix M;
630 double tmp;
631 if (typeid( BoxValue ) == *TypeMap[name]) {
632 if (CurrentValue.find(name) == CurrentValue.end())
633 throw MissingValueException(__FILE__, __LINE__);
634 std::istringstream stream(CurrentValue[name]);
635 stream >> tmp;
636 M.set(0,0,tmp);
637 stream >> tmp;
638 M.set(0,1,tmp);
639 M.set(1,0,tmp);
640 stream >> tmp;
641 M.set(0,2,tmp);
642 M.set(2,0,tmp);
643 stream >> tmp;
644 M.set(1,1,tmp);
645 stream >> tmp;
646 M.set(1,2,tmp);
647 M.set(2,1,tmp);
648 stream >> tmp;
649 M.set(2,2,tmp);
650 _T = M;
651 CurrentValue.erase(name);
652 } else
653 throw IllegalTypeException(__FILE__,__LINE__);
654}
655
656void MapOfActions::queryCurrentValue(const char * name, class Vector &_T) {
657 if (typeid( VectorValue ) == *TypeMap[name]) {
658 std::istringstream stream(CurrentValue[name]);
659 CurrentValue.erase(name);
660 stream >> _T[0];
661 stream >> _T[1];
662 stream >> _T[2];
663 } else
664 throw IllegalTypeException(__FILE__,__LINE__);
665}
666
667void MapOfActions::queryCurrentValue(const char * name, std::vector<atom *>&_T)
668{
669 int atomID = -1;
670 atom *Walker = NULL;
671 if (typeid( std::vector<atom *> ) == *TypeMap[name]) {
672 if (CurrentValue.find(name) == CurrentValue.end())
673 throw MissingValueException(__FILE__, __LINE__);
674 std::istringstream stream(CurrentValue[name]);
675 CurrentValue.erase(name);
676 while (!stream.fail()) {
677 stream >> atomID >> ws;
678 Walker = World::getInstance().getAtom(AtomById(atomID));
679 if (Walker != NULL)
680 _T.push_back(Walker);
681 atomID = -1;
682 Walker = NULL;
683 }
684 } else
685 throw IllegalTypeException(__FILE__,__LINE__);
686}
687
688void MapOfActions::queryCurrentValue(const char * name, std::vector<element *>&_T)
689{
690 int Z = -1;
691 element *elemental = NULL;
692 if (typeid( std::vector<element *> ) == *TypeMap[name]) {
693 if (CurrentValue.find(name) == CurrentValue.end())
694 throw MissingValueException(__FILE__, __LINE__);
695 std::istringstream stream(CurrentValue[name]);
696 CurrentValue.erase(name);
697 while (!stream.fail()) {
698 stream >> Z >> ws;
699 elemental = World::getInstance().getPeriode()->FindElement(Z);
700 if (elemental != NULL)
701 _T.push_back(elemental);
702 Z = -1;
703 }
704 } else
705 throw IllegalTypeException(__FILE__,__LINE__);
706}
707
708void MapOfActions::queryCurrentValue(const char * name, std::vector<molecule *>&_T)
709{
710 int molID = -1;
711 molecule *mol = NULL;
712 if (typeid( std::vector<molecule *> ) == *TypeMap[name]) {
713 if (CurrentValue.find(name) == CurrentValue.end())
714 throw MissingValueException(__FILE__, __LINE__);
715 std::istringstream stream(CurrentValue[name]);
716 CurrentValue.erase(name);
717 while (!stream.fail()) {
718 stream >> molID >> ws;
719 mol = World::getInstance().getMolecule(MoleculeById(molID));
720 if (mol != NULL)
721 _T.push_back(mol);
722 molID = -1;
723 mol = NULL;
724 }
725 } else
726 throw IllegalTypeException(__FILE__,__LINE__);
727}
728
729
730void MapOfActions::setCurrentValue(const char * name, class atom * &_T)
731{
732 if (typeid( atom ) == *TypeMap[name]) {
733 std::ostringstream stream;
734 stream << _T->getId();
735 CurrentValue[name] = stream.str();
736 } else
737 throw IllegalTypeException(__FILE__,__LINE__);
738}
739
740void MapOfActions::setCurrentValue(const char * name, class element * &_T)
741{
742 if (typeid( element ) == *TypeMap[name]) {
743 std::ostringstream stream;
744 stream << _T->Z;
745 CurrentValue[name] = stream.str();
746 } else
747 throw IllegalTypeException(__FILE__,__LINE__);
748}
749
750void MapOfActions::setCurrentValue(const char * name, class molecule * &_T)
751{
752 if (typeid( molecule ) == *TypeMap[name]) {
753 std::ostringstream stream;
754 stream << _T->getId();
755 CurrentValue[name] = stream.str();
756 } else
757 throw IllegalTypeException(__FILE__,__LINE__);
758}
759
760void MapOfActions::setCurrentValue(const char * name, class Box &_T)
761{
762 const Matrix &M = _T.getM();
763 if (typeid( BoxValue ) == *TypeMap[name]) {
764 std::ostringstream stream;
765 stream << M.at(0,0) << " ";
766 stream << M.at(0,1) << " ";
767 stream << M.at(0,2) << " ";
768 stream << M.at(1,1) << " ";
769 stream << M.at(1,2) << " ";
770 stream << M.at(2,2) << " ";
771 CurrentValue[name] = stream.str();
772 } else
773 throw IllegalTypeException(__FILE__,__LINE__);
774}
775
776void MapOfActions::setCurrentValue(const char * name, class Vector &_T)
777{
778 if (typeid( VectorValue ) == *TypeMap[name]){
779 std::ostringstream stream;
780 stream << _T[0] << " ";
781 stream << _T[1] << " ";
782 stream << _T[2] << " ";
783 CurrentValue[name] = stream.str();
784 } else
785 throw IllegalTypeException(__FILE__,__LINE__);
786}
787
788void MapOfActions::setCurrentValue(const char * name, std::vector<atom *>&_T)
789{
790 if (typeid( std::vector<atom *> ) == *TypeMap[name]) {
791 std::ostringstream stream;
792 for (std::vector<atom *>::iterator iter = _T.begin(); iter != _T.end(); ++iter) {
793 stream << (*iter)->getId() << " ";
794 }
795 CurrentValue[name] = stream.str();
796 } else
797 throw IllegalTypeException(__FILE__,__LINE__);
798}
799
800void MapOfActions::setCurrentValue(const char * name, std::vector<element *>&_T)
801{
802 if (typeid( std::vector<element *> ) == *TypeMap[name]) {
803 std::ostringstream stream;
804 for (std::vector<element *>::iterator iter = _T.begin(); iter != _T.end(); ++iter) {
805 stream << (*iter)->Z << " ";
806 }
807 CurrentValue[name] = stream.str();
808 } else
809 throw IllegalTypeException(__FILE__,__LINE__);
810}
811
812void MapOfActions::setCurrentValue(const char * name, std::vector<molecule *>&_T)
813{
814 if (typeid( std::vector<molecule *> ) == *TypeMap[name]) {
815 std::ostringstream stream;
816 for (std::vector<molecule *>::iterator iter = _T.begin(); iter != _T.end(); ++iter) {
817 stream << (*iter)->getId() << " ";
818 }
819 CurrentValue[name] = stream.str();
820 } else
821 throw IllegalTypeException(__FILE__,__LINE__);
822}
823
824
825
826void MapOfActions::populateActions()
827{
828 new AnalysisMolecularVolumeAction();
829 new AnalysisPairCorrelationAction();
830 new AnalysisPointCorrelationAction();
831 new AnalysisPrincipalAxisSystemAction();
832 new AnalysisSurfaceCorrelationAction();
833
834 new AtomAddAction();
835 new AtomChangeElementAction();
836 new AtomRemoveAction();
837 new AtomRotateAroundOriginByAngleAction();
838 new AtomTranslateAction();
839
840 new CommandLineBondLengthTableAction();
841 new CommandLineElementDbAction();
842 new CommandLineFastParsingAction();
843 new CommandLineHelpAction();
844 new CommandLineVerboseAction();
845 new CommandLineVersionAction();
846
847 new FragmentationDepthFirstSearchAction();
848 new FragmentationFragmentationAction();
849 new FragmentationSubgraphDissectionAction();
850
851 new MoleculeBondFileAction();
852 new MoleculeChangeNameAction();
853 new MoleculeFillWithMoleculeAction();
854 new MoleculeLinearInterpolationofTrajectoriesAction();
855 new MoleculeRotateAroundSelfByAngleAction();
856 new MoleculeRotateToPrincipalAxisSystemAction();
857 new MoleculeSaveAdjacencyAction();
858 new MoleculeSaveBondsAction();
859 new MoleculeSaveTemperatureAction();
860 new MoleculeSuspendInWaterAction();
861 new MoleculeVerletIntegrationAction();
862
863 new ParserLoadXyzAction();
864 new ParserSaveXyzAction();
865
866 new SelectionClearAllAtomsAction();
867 new SelectionClearAllMoleculesAction();
868 new SelectionAllAtomsAction();
869 new SelectionAllAtomsOfMoleculeAction();
870 new SelectionAllMoleculesAction();
871 new SelectionAtomByIdAction();
872 new SelectionMoleculeByIdAction();
873 new SelectionMoleculeOfAtomAction();
874 new SelectionNotAllAtomsAction();
875 new SelectionNotAllAtomsOfMoleculeAction();
876 new SelectionNotAllMoleculesAction();
877 new SelectionNotAtomByIdAction();
878 new SelectionNotMoleculeByIdAction();
879 new SelectionNotMoleculeOfAtomAction();
880
881 new TesselationConvexEnvelopeAction();
882 new TesselationNonConvexEnvelopeAction();
883
884 new WorldAddEmptyBoundaryAction();
885 new WorldBoundInBoxAction();
886 new WorldCenterInBoxAction();
887 new WorldCenterOnEdgeAction();
888 new WorldChangeBoxAction();
889 new WorldInputAction();
890 new WorldOutputAction();
891 new WorldRemoveSphereOfAtomsAction();
892 new WorldRepeatBoxAction();
893 new WorldScaleBoxAction();
894 new WorldSetDefaultNameAction();
895 new WorldSetGaussianBasisAction();
896 new WorldSetOutputFormatsAction();
897}
898
899/** Adds all options to the CommandLineParser.
900 *
901 */
902void MapOfActions::AddOptionsToParser()
903{
904 // add other options
905 for (map< set<string>*, po::options_description* >::iterator ListRunner = CmdParserLookup.begin(); ListRunner != CmdParserLookup.end(); ++ListRunner) {
906 for (set<string>::iterator OptionRunner = ListRunner->first->begin(); OptionRunner != ListRunner->first->end(); ++OptionRunner) {
907 if (hasValue(*OptionRunner)) {
908 DoLog(1) && (Log() << Verbose(1) << "Adding option " << *OptionRunner << " with type " << TypeMap[*OptionRunner]->name() << " to CommandLineParser." << endl);
909 switch(TypeEnumMap[TypeMap[*OptionRunner]]) {
910 default:
911 case None:
912 ListRunner->second->add_options()
913 (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
914 ;
915 break;
916 case Boolean:
917 ListRunner->second->add_options()
918 (getKeyAndShortForm(*OptionRunner).c_str(),
919 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
920 po::value< bool >()->default_value(lexical_cast<int>(CurrentValue[*OptionRunner].c_str())) :
921 po::value< bool >(),
922 getDescription(*OptionRunner).c_str())
923 ;
924 break;
925 case Box:
926 ListRunner->second->add_options()
927 (getKeyAndShortForm(*OptionRunner).c_str(),
928 po::value<BoxValue>(),
929 getDescription(*OptionRunner).c_str())
930 ;
931 break;
932 case Integer:
933 ListRunner->second->add_options()
934 (getKeyAndShortForm(*OptionRunner).c_str(),
935 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
936 po::value< int >()->default_value(lexical_cast<int>(CurrentValue[*OptionRunner].c_str())) :
937 po::value< int >(),
938 getDescription(*OptionRunner).c_str())
939 ;
940 break;
941 case ListOfIntegers:
942 ListRunner->second->add_options()
943 (getKeyAndShortForm(*OptionRunner).c_str(),
944 po::value< vector<int> >()->multitoken(),
945 getDescription(*OptionRunner).c_str())
946 ;
947 break;
948 case Double:
949 ListRunner->second->add_options()
950 (getKeyAndShortForm(*OptionRunner).c_str(),
951 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
952 po::value< double >()->default_value(lexical_cast<double>(CurrentValue[*OptionRunner].c_str())) :
953 po::value< double >(),
954 getDescription(*OptionRunner).c_str())
955 ;
956 break;
957 case ListOfDoubles:
958 ListRunner->second->add_options()
959 (getKeyAndShortForm(*OptionRunner).c_str(),
960 po::value< vector<double> >()->multitoken(),
961 getDescription(*OptionRunner).c_str())
962 ;
963 break;
964 case String:
965 ListRunner->second->add_options()
966 (getKeyAndShortForm(*OptionRunner).c_str(),
967 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
968 po::value< std::string >()->default_value(CurrentValue[*OptionRunner]) :
969 po::value< std::string >(),
970 getDescription(*OptionRunner).c_str())
971 ;
972 break;
973 case ListOfStrings:
974 ListRunner->second->add_options()
975 (getKeyAndShortForm(*OptionRunner).c_str(),
976 po::value< vector<std::string> >()->multitoken(),
977 getDescription(*OptionRunner).c_str())
978 ;
979 break;
980 case Vector:
981 ListRunner->second->add_options()
982 (getKeyAndShortForm(*OptionRunner).c_str(),
983 po::value<VectorValue>(),
984 getDescription(*OptionRunner).c_str())
985 ;
986 break;
987 case ListOfVectors:
988 ListRunner->second->add_options()
989 (getKeyAndShortForm(*OptionRunner).c_str(),
990 po::value< vector<VectorValue> >()->multitoken(),
991 getDescription(*OptionRunner).c_str())
992 ;
993 break;
994 case Molecule:
995 ListRunner->second->add_options()
996 (getKeyAndShortForm(*OptionRunner).c_str(),
997 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
998 po::value< int >()->default_value(lexical_cast<int>(CurrentValue[*OptionRunner].c_str())) :
999 po::value< int >(),
1000 getDescription(*OptionRunner).c_str())
1001 ;
1002 break;
1003 case ListOfMolecules:
1004 ListRunner->second->add_options()
1005 (getKeyAndShortForm(*OptionRunner).c_str(),
1006 po::value< vector<int> >()->multitoken(),
1007 getDescription(*OptionRunner).c_str())
1008 ;
1009 break;
1010 case Atom:
1011 ListRunner->second->add_options()
1012 (getKeyAndShortForm(*OptionRunner).c_str(),
1013 CurrentValue.find(*OptionRunner) != CurrentValue.end() ?
1014 po::value< int >()->default_value(lexical_cast<int>(CurrentValue[*OptionRunner].c_str())) :
1015 po::value< int >(),
1016 getDescription(*OptionRunner).c_str())
1017 ;
1018 break;
1019 case ListOfAtoms:
1020 ListRunner->second->add_options()
1021 (getKeyAndShortForm(*OptionRunner).c_str(),
1022 po::value< vector<int> >()->multitoken(),
1023 getDescription(*OptionRunner).c_str())
1024 ;
1025 break;
1026 case Element:
1027 ListRunner->second->add_options()
1028 (getKeyAndShortForm(*OptionRunner).c_str(),
1029 po::value< int >(),
1030 getDescription(*OptionRunner).c_str())
1031 ;
1032 break;
1033 case ListOfElements:
1034 ListRunner->second->add_options()
1035 (getKeyAndShortForm(*OptionRunner).c_str(),
1036 po::value< vector<int> >()->multitoken(),
1037 getDescription(*OptionRunner).c_str())
1038 ;
1039 break;
1040 }
1041 } else {
1042 DoLog(3) && (Log() << Verbose(3) << "Adding option " << *OptionRunner << " to CommandLineParser." << endl);
1043 ListRunner->second->add_options()
1044 (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
1045 ;
1046 }
1047 }
1048 }
1049}
1050
1051/** Getter for MapOfActions:DescriptionMap.
1052 * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
1053 * \param actionname name of the action to lookup
1054 * \return Description of the action
1055 */
1056std::string MapOfActions::getDescription(string actionname)
1057{
1058 ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescription");
1059 return DescriptionMap[actionname];
1060}
1061
1062/** Specific Getter for a MapOfActions:ShortFormMap.
1063 * If action has a short for, then combination is as "actionname,ShortForm" (this is
1064 * the desired format for boost::program_options). If no short form exists in the map,
1065 * just actionname will be returned
1066 * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
1067 * \param actionname name of the action to lookup
1068 * \return actionname,ShortForm or Description of the action
1069 */
1070std::string MapOfActions::getKeyAndShortForm(string actionname)
1071{
1072 stringstream output;
1073 ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescriptionAndShortForm");
1074 output << actionname;
1075 if (ShortFormMap.find(actionname) != DescriptionMap.end())
1076 output << "," << ShortFormMap[actionname];
1077 return output.str();
1078}
1079
1080/** Getter for MapOfActions:ShortFormMap.
1081 * Note that we assert when action does not exist CommandLineParser::ShortFormMap.
1082 * \param actionname name of the action to lookup
1083 * \return ShortForm of the action
1084 */
1085std::string MapOfActions::getShortForm(string actionname)
1086{
1087 ASSERT(ShortFormMap.find(actionname) != ShortFormMap.end(), "Unknown action name passed to MapOfActions::getShortForm");
1088 return ShortFormMap[actionname];
1089}
1090
1091/** Returns whether the given action needs a value or not.
1092 * \param actionname name of the action to look up
1093 * \return true - value is needed, false - no value is stored in MapOfActions::TypeMap
1094 */
1095bool MapOfActions::hasValue(string actionname)
1096{
1097 return (TypeMap.find(actionname) != TypeMap.end());
1098}
1099
1100/** Getter for MapOfActions::TypeMap.
1101 * \param actionname name of the action to look up
1102 * \return type of the action
1103 */
1104std::string MapOfActions::getValueType(string actionname)
1105{
1106 return TypeMap[actionname]->name();
1107}
1108
1109/** Searches whether action is registered with CommandLineParser.
1110 * Note that this method is only meant transitionally for ParseCommandLineOptions' removal.
1111 * I.e. All actions that are already handled by the new CommandLineUIFactory can be checked
1112 * by this function.
1113 * \param shortform command short form to look for
1114 * \return true - action has been registered, false - action has not been registered.
1115 */
1116bool MapOfActions::isShortFormPresent(string shortform)
1117{
1118 bool result = false;
1119 string actionname;
1120 for (map<std::string, std::string>::iterator ShortFormRunner = ShortFormMap.begin(); ShortFormRunner != ShortFormMap.end(); ++ShortFormRunner)
1121 if (ShortFormRunner->second == shortform) {
1122 actionname = ShortFormRunner->first;
1123 break;
1124 }
1125 result = result || (generic.find(actionname) != generic.end());
1126 result = result || (config.find(actionname) != config.end());
1127 result = result || (hidden.find(actionname) != hidden.end());
1128 result = result || (visible.find(actionname) != visible.end());
1129 result = result || (inputfile.find(actionname) != inputfile.end());
1130 return result;
1131}
1132
1133/** Returns the inverse to MapOfActions::ShortFormMap, i.e. lookup actionname for its short form.
1134 * \return map from short form of action to name of action
1135 */
1136map <std::string, std::string> MapOfActions::getShortFormToActionMap()
1137{
1138 map <std::string, std::string> result;
1139
1140 for (map<std::string, std::string>::iterator iter = ShortFormMap.begin(); iter != ShortFormMap.end(); ++iter)
1141 result[iter->second] = iter->first;
1142
1143 return result;
1144}
1145
1146
1147CONSTRUCT_SINGLETON(MapOfActions)
Note: See TracBrowser for help on using the repository browser.