source: src/Actions/MapOfActions.cpp@ bd2390

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

BUGFIX: new boost::filesystem led to non-parsing of files.

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