source: src/Actions/MapOfActions.cpp@ f30490

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

Added (un)select-molecule-by-formula/..-atom-by-element actions..

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