source: src/Actions/MapOfActions.cpp@ 53d01c

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 53d01c was 53d01c, checked in by Frederik Heber <heber@…>, 14 years ago

Renamed dir Actions/CmdAction -> Actions/CommandAction, renamed class CommandLine... -> Command...

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