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