source: src/Actions/MapOfActions.cpp@ eee966

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

New Action FillVoidWithMoleculeAction.

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