source: src/Actions/MapOfActions.cpp@ 4cf323d

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

Added boost::filesystem usage for input files.

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