source: src/Actions/MapOfActions.cpp@ 60896f

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 60896f was 31fb1d, checked in by Frederik Heber <heber@…>, 15 years ago

(un)select-atoms-inside-cuboid: cuboid may be rotated.

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