source: src/Actions/MapOfActions.cpp@ e4decc

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

Added WarrantyAction.

This closed ticket #117.

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