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