source: src/Actions/MapOfActions.cpp@ dc1d9e

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 dc1d9e was 1a7fd2, checked in by Frederik Heber <heber@…>, 15 years ago

New Action MoleculeAction/CopyAction.

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