source: src/Actions/MapOfActions.cpp@ b540f3

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since b540f3 was b540f3, checked in by Frederik Heber <heber@…>, 15 years ago

changed validate() for VectorValue, parsing not 10. 10. 10. but "10., 10., 10." to allow for negative values.

  • i.e. we now parse a single string and tokenize it ourselves.
  • TESTFIX: alle test cases asking the user for vectors had to be changed accordingly.
  • Property mode set to 100644
File size: 34.6 KB
Line 
1/*
2 * MapOfActions.cpp
3 *
4 * Created on: 10.05.2010
5 * Author: heber
6 */
7
8#include "Helpers/MemDebug.hpp"
9
10using namespace std;
11
12#include "Patterns/Singleton_impl.hpp"
13#include "Actions/MapOfActions.hpp"
14#include "Helpers/Assert.hpp"
15
16#include <boost/lexical_cast.hpp>
17#include <boost/optional.hpp>
18#include <boost/program_options.hpp>
19
20#include "CommandLineParser.hpp"
21#include "log.hpp"
22#include "verbose.hpp"
23
24#include "Actions/ActionRegistry.hpp"
25#include "Actions/AnalysisAction/MolecularVolumeAction.hpp"
26#include "Actions/AnalysisAction/PairCorrelationAction.hpp"
27#include "Actions/AnalysisAction/PrincipalAxisSystemAction.hpp"
28#include "Actions/AtomAction/AddAction.hpp"
29#include "Actions/AtomAction/ChangeElementAction.hpp"
30#include "Actions/AtomAction/RemoveAction.hpp"
31#include "Actions/CmdAction/BondLengthTableAction.hpp"
32#include "Actions/CmdAction/ElementDbAction.hpp"
33#include "Actions/CmdAction/FastParsingAction.hpp"
34#include "Actions/CmdAction/HelpAction.hpp"
35#include "Actions/CmdAction/VerboseAction.hpp"
36#include "Actions/CmdAction/VersionAction.hpp"
37#include "Actions/FragmentationAction/DepthFirstSearchAction.hpp"
38#include "Actions/FragmentationAction/SubgraphDissectionAction.hpp"
39#include "Actions/FragmentationAction/FragmentationAction.hpp"
40#include "Actions/MoleculeAction/BondFileAction.hpp"
41#include "Actions/MoleculeAction/ChangeNameAction.hpp"
42#include "Actions/MoleculeAction/FillWithMoleculeAction.hpp"
43#include "Actions/MoleculeAction/LinearInterpolationofTrajectoriesAction.hpp"
44#include "Actions/MoleculeAction/RotateToPrincipalAxisSystemAction.hpp"
45#include "Actions/MoleculeAction/SaveAdjacencyAction.hpp"
46#include "Actions/MoleculeAction/SaveBondsAction.hpp"
47#include "Actions/MoleculeAction/SaveTemperatureAction.hpp"
48#include "Actions/MoleculeAction/SuspendInWaterAction.hpp"
49#include "Actions/MoleculeAction/TranslateAction.hpp"
50#include "Actions/MoleculeAction/VerletIntegrationAction.hpp"
51#include "Actions/ParserAction/LoadXyzAction.hpp"
52#include "Actions/ParserAction/SaveXyzAction.hpp"
53#include "Actions/TesselationAction/ConvexEnvelopeAction.hpp"
54#include "Actions/TesselationAction/NonConvexEnvelopeAction.hpp"
55#include "Actions/WorldAction/AddEmptyBoundaryAction.hpp"
56#include "Actions/WorldAction/BoundInBoxAction.hpp"
57#include "Actions/WorldAction/CenterInBoxAction.hpp"
58#include "Actions/WorldAction/CenterOnEdgeAction.hpp"
59#include "Actions/WorldAction/ChangeBoxAction.hpp"
60#include "Actions/WorldAction/InputAction.hpp"
61#include "Actions/WorldAction/OutputAction.hpp"
62#include "Actions/WorldAction/RemoveSphereOfAtomsAction.hpp"
63#include "Actions/WorldAction/RepeatBoxAction.hpp"
64#include "Actions/WorldAction/ScaleBoxAction.hpp"
65#include "Actions/WorldAction/SetDefaultNameAction.hpp"
66#include "Actions/WorldAction/SetGaussianBasisAction.hpp"
67#include "Actions/WorldAction/SetOutputFormatsAction.hpp"
68#include "Actions/Values.hpp"
69
70void validate(boost::any& v, const std::vector<std::string>& values, VectorValue *, int)
71{
72 VectorValue VV;
73 std::vector<std::string> components;
74
75 // split comma-separated values
76 if (values.size() != 1) {
77 cerr << "Not one vector but " << components.size() << " given " << endl;
78 throw boost::program_options::validation_error("Unequal to one vector given");
79 }
80 std::string argument(values.at(0));
81 std::string::iterator Aiter = argument.begin();
82 std::string::iterator Biter = argument.begin();
83 for (; Aiter != argument.end(); ++Aiter) {
84 if (*Aiter == ',') {
85 components.push_back(string(Biter,Aiter));
86 do {
87 Aiter++;
88 } while (*Aiter == ' ' || *Aiter == '\t');
89 Biter = Aiter;
90 }
91 }
92 components.push_back(string(Biter,argument.end()));
93
94 if (components.size() != 3) {
95 cerr << "Specified vector does not have three components but " << components.size() << endl;
96 throw boost::program_options::validation_error("Specified vector does not have three components");
97 }
98 VV.x = boost::lexical_cast<double>(components.at(0));
99 VV.y = boost::lexical_cast<double>(components.at(1));
100 VV.z = boost::lexical_cast<double>(components.at(2));
101 v = boost::any(VectorValue(VV));
102}
103
104void validate(boost::any& v, const std::vector<std::string>& values, BoxValue *, int)
105{
106 BoxValue BV;
107 std::vector<std::string> components;
108
109 // split comma-separated values
110 if (values.size() != 1) {
111 cerr << "Not one vector but " << components.size() << " given " << endl;
112 throw boost::program_options::validation_error("Unequal to one vector given");
113 }
114 std::string argument(values.at(0));
115 std::string::iterator Aiter = argument.begin();
116 std::string::iterator Biter = argument.begin();
117 for (; Aiter != argument.end(); ++Aiter) {
118 if (*Aiter == ',') {
119 components.push_back(string(Biter,Aiter));
120 do {
121 Aiter++;
122 } while (*Aiter == ' ' || *Aiter == '\t');
123 Biter = Aiter;
124 }
125 }
126 components.push_back(string(Biter,argument.end()));
127
128 if (components.size() != 6) {
129 cerr << "Specified vector does not have three components but " << components.size() << endl;
130 throw boost::program_options::validation_error("Specified symmetric box matrix does not have six components");
131 }
132 BV.xx = boost::lexical_cast<double>(components.at(0));
133 BV.xy = boost::lexical_cast<double>(components.at(1));
134 BV.xz = boost::lexical_cast<double>(components.at(2));
135 BV.yy = boost::lexical_cast<double>(components.at(3));
136 BV.yz = boost::lexical_cast<double>(components.at(4));
137 BV.zz = boost::lexical_cast<double>(components.at(5));
138 v = boost::any(BoxValue(BV));
139}
140
141/** Constructor of class MapOfActions.
142 *
143 */
144MapOfActions::MapOfActions()
145{
146 // initialise lookup map
147 CmdParserLookup[&generic] = &(CommandLineParser::getInstance().generic);
148 CmdParserLookup[&config] = &(CommandLineParser::getInstance().config);
149 CmdParserLookup[&hidden] = &(CommandLineParser::getInstance().hidden);
150 CmdParserLookup[&visible] = &(CommandLineParser::getInstance().visible);
151
152 // keys for actions
153 DescriptionMap["add-atom"] = "add atom of specified element";
154 DescriptionMap["bond-table"] = "setting name of the bond length table file";
155 DescriptionMap["bond-file"] = "name of the bond file";
156 DescriptionMap["boundary"] = "change box to add an empty boundary around all atoms";
157 DescriptionMap["bound-in-box"] = "bound all atoms in the domain";
158 DescriptionMap["center-edge"] = "center edge of all atoms on (0,0,0)";
159 DescriptionMap["center-in-box"] = "center all atoms in the domain";
160 DescriptionMap["change-box"] = "change the symmetrc matrix of the simulation domain";
161 DescriptionMap["change-element"] = "change the element of an atom";
162 DescriptionMap["change-molname"] = "change the name of a molecule";
163 DescriptionMap["convex-envelope"] = "create the convex envelope for a molecule";
164 DescriptionMap["default-molname"] = "set the default name of new molecules";
165 DescriptionMap["depth-first-search"] = "Depth-First Search analysis of the molecular system";
166 DescriptionMap["element-db"] = "setting the path where the element databases can be found";
167 DescriptionMap["fastparsing"] = "setting whether trajectories shall be parsed completely (n) or just first step (y)";
168 DescriptionMap["fill-molecule"] = "fill empty space of box with a filler molecule";
169 DescriptionMap["fragment-mol"] = "create for a given molecule into fragments up to given order";
170 DescriptionMap["help"] = "Give this help screen";
171 DescriptionMap["input"] = "specify input files";
172 DescriptionMap["linear-interpolate"] = "linear interpolation in discrete steps between start and end position of a molecule";
173 DescriptionMap["molecular-volume"] = "calculate the volume of a given molecule";
174 DescriptionMap["nonconvex-envelope"] = "create the non-convex envelope for a molecule";
175 DescriptionMap["output"] = "write output files";
176 DescriptionMap["set-output"] = "specify output formats";
177 DescriptionMap["pair-correlation"] = "pair correlation analysis between two elements, element and point or element and surface";
178 DescriptionMap["parse-xyz"] = "parse xyz file into World";
179 DescriptionMap["principal-axis-system"] = "calculate the principal axis system of the specified molecule";
180 DescriptionMap["remove-atom"] = "remove a specified atom";
181 DescriptionMap["remove-sphere"] = "remove sphere of atoms of around a specified atom";
182 DescriptionMap["repeat-box"] = "create periodic copies of the simulation box per axis";
183 DescriptionMap["rotate-to-pas"] = "calculate the principal axis system of the specified molecule and rotate specified axis to align with main axis";
184 DescriptionMap["save-adjacency"] = "name of the adjacency file to write to";
185 DescriptionMap["save-bonds"] = "name of the bonds file to write to";
186 DescriptionMap["save-temperature"] = "name of the temperature file to write to";
187 DescriptionMap["SaveXyz"] = "save world as xyz file";
188 DescriptionMap["scale-box"] = "scale box and atomic positions inside";
189 DescriptionMap["set-basis"] = "set the name of the gaussian basis set for MPQC";
190 DescriptionMap["set-output"] = "specify output formats";
191 DescriptionMap["subgraph-dissect"] = "dissect the molecular system into molecules representing disconnected subgraphs";
192 DescriptionMap["suspend-in-water"] = "suspend the given molecule in water such that in the domain the mean density is as specified";
193 DescriptionMap["translate-mol"] = "translate molecule by given vector";
194 DescriptionMap["verbose"] = "set verbosity level";
195 DescriptionMap["verlet-integrate"] = "perform verlet integration of a given force file";
196 DescriptionMap["version"] = "show version";
197 // keys for values
198 DescriptionMap["atom-by-id"] = "index of an atom";
199 DescriptionMap["bin-output-file"] = "name of the bin output file";
200 DescriptionMap["bin-end"] = "start of the last bin";
201 DescriptionMap["bin-start"] = "start of the first bin";
202 DescriptionMap["bin-width"] = "width of the bins";
203 DescriptionMap["convex-file"] = "filename of the non-convex envelope";
204 DescriptionMap["distance"] = "distance in space";
205 DescriptionMap["distances"] = "list of three of distances in space, one for each axis direction";
206 DescriptionMap["DoRotate"] = "whether to rotate or just report angles";
207 DescriptionMap["element"] = "single element";
208 DescriptionMap["elements"] = "set of elements";
209 DescriptionMap["end-step"] = "last or end step";
210 DescriptionMap["id-mapping"] = "whether the identity shall be used in mapping atoms onto atoms or some closest distance measure shall be used";
211 DescriptionMap["input"] = "name of input file";
212 DescriptionMap["length"] = "length in space";
213 DescriptionMap["lengths"] = "list of three of lengths in space, one for each axis direction";
214 DescriptionMap["MaxDistance"] = "maximum distance in space";
215 DescriptionMap["molecule-by-id"] = "index of a molecule";
216 DescriptionMap["molecule-by-name"] = "name of a molecule";
217 DescriptionMap["nonconvex-file"] = "filename of the non-convex envelope";
218 DescriptionMap["order"] = "order of a discretization, dissection, ...";
219 DescriptionMap["output-file"] = "name of the output file";
220 DescriptionMap["periodic"] = "system is constraint to periodic boundary conditions (y/n)";
221 DescriptionMap["position"] = "position in R^3 space";
222 DescriptionMap["sphere-radius"] = "radius of tesselation sphere";
223 DescriptionMap["start-step"] = "first or start step";
224
225 // short forms for the actions
226 ShortFormMap["add-atom"] = "a";
227 ShortFormMap["bond-table"] = "g";
228 ShortFormMap["bond-file"] = "A";
229 ShortFormMap["boundary"] = "c";
230 ShortFormMap["change-box"] = "B";
231 ShortFormMap["center-edge"] = "O";
232 ShortFormMap["center-in-box"] = "b";
233 ShortFormMap["change-element"] = "E";
234// ShortFormMap["convex-envelope"] = "x";
235 ShortFormMap["default-molname"] = "X";
236 ShortFormMap["depth-first-search"] = "D";
237 ShortFormMap["element-db"] = "e";
238 ShortFormMap["fastparsing"] = "n";
239 ShortFormMap["fill-molecule"] = "F";
240 ShortFormMap["fragment-mol"] = "f";
241 ShortFormMap["help"] = "h";
242 ShortFormMap["input"] = "i";
243 ShortFormMap["linear-interpolate"] = "L";
244 ShortFormMap["nonconvex-envelope"] = "N";
245// ShortFormMap["output"] = "o";
246 ShortFormMap["pair-correlation"] = "C";
247 ShortFormMap["parse-xyz"] = "p";
248 ShortFormMap["remove-atom"] = "r";
249 ShortFormMap["remove-sphere"] = "R";
250 ShortFormMap["repeat-box"] = "d";
251 ShortFormMap["rotate-to-pas"] = "m";
252 ShortFormMap["save-adjacency"] = "J";
253 ShortFormMap["save-bonds"] = "j";
254 ShortFormMap["save-temperature"] = "S";
255 ShortFormMap["scale-box"] = "s";
256 ShortFormMap["set-basis"] = "M";
257 ShortFormMap["set-output"] = "o";
258 ShortFormMap["subgraph-dissect"] = "I";
259 ShortFormMap["suspend-in-water"] = "u";
260 ShortFormMap["translate-mol"] = "t";
261 ShortFormMap["verbose"] = "v";
262 ShortFormMap["verlet-integrate"] = "P";
263 ShortFormMap["version"] = "V";
264
265 // value types for the actions
266 TypeMap["add-atom"] = Element;
267 TypeMap["bond-file"] = String;
268 TypeMap["bond-table"] = String;
269 TypeMap["boundary"] = Vector;
270 TypeMap["center-in-box"] = Box;
271 TypeMap["change-box"] = Box;
272 TypeMap["change-element"] = Atom;
273 TypeMap["change-molname"] = String;
274 TypeMap["convex-envelope"] = Molecule;
275 TypeMap["default-molname"] = String;
276 TypeMap["depth-first-search"] = Double;
277 TypeMap["element-db"] = String;
278 TypeMap["fastparsing"] = Boolean;
279 TypeMap["fill-molecule"] = String;
280 TypeMap["fragment-mol"] = String;
281 TypeMap["input"] = String;
282 TypeMap["linear-interpolate"] = String;
283 TypeMap["molecular-volume"] = Molecule;
284 TypeMap["nonconvex-envelope"] = Molecule;
285 TypeMap["output"] = None;
286 TypeMap["parse-xyz"] = String;
287 TypeMap["pair-correlation"] = String;
288 TypeMap["principal-axis-system"] = Molecule;
289 TypeMap["remove-atom"] = Atom;
290 TypeMap["remove-sphere"] = Double;
291 TypeMap["repeat-box"] = Vector;
292 TypeMap["rotate-to-pas"] = Molecule;
293 TypeMap["save-adjacency"] = String;
294 TypeMap["save-bonds"] = String;
295 TypeMap["save-temperature"] = String;
296 TypeMap["scale-box"] = Vector;
297 TypeMap["set-basis"] = String;
298 TypeMap["set-output"] = ListOfString;
299 TypeMap["subgraph-dissect"] = None;
300 TypeMap["suspend-in-water"] = Double;
301 TypeMap["translate-mol"] = Vector;
302 TypeMap["verlet-integrate"] = String;
303 TypeMap["verbose"] = Integer;
304
305 // value types for the values
306 TypeMap["atom-by-id"] = Atom;
307 TypeMap["bin-output-file"] = String;
308 TypeMap["bin-end"] = Double;
309 TypeMap["bin-start"] = Double;
310 TypeMap["bin-width"] = Double;
311 TypeMap["convex-file"] = String;
312 TypeMap["distance"] = Double;
313 TypeMap["distances"] = Vector;
314 TypeMap["DoRotate"] = Boolean;
315 TypeMap["element"] = Element;
316 TypeMap["elements"] = ListOfElements;
317 TypeMap["end-step"] = Integer;
318 TypeMap["id-mapping"] = Boolean;
319 TypeMap["length"] = Double;
320 TypeMap["lengths"] = Vector;
321 TypeMap["MaxDistance"] = Double;
322 TypeMap["molecule-by-id"] = Molecule;
323 TypeMap["molecule-by-name"] = Molecule;
324 TypeMap["nonconvex-file"] = String;
325 TypeMap["order"] = Integer;
326 TypeMap["output-file"] = String;
327 TypeMap["periodic"] = Boolean;
328 TypeMap["position"] = Vector;
329 TypeMap["sphere-radius"] = Double;
330 TypeMap["start-step"] = Integer;
331
332 // default values for any action that needs one (always string!)
333 DefaultValue["bin-width"] = "0.5";
334 DefaultValue["fastparsing"] = "0";
335 DefaultValue["atom-by-id"] = "-1";
336 DefaultValue["molecule-by-id"] = "-1";
337 DefaultValue["periodic"] = "0";
338
339 // put action into each menu category
340 MenuDescription["analysis"] = pair<std::string,std::string>("Analysis (pair correlation, volume)", "Analysis");
341 MenuDescription["atom"] = pair<std::string,std::string>("Edit atoms", "Edit atoms");
342 MenuDescription["command"] = pair<std::string,std::string>("Configuration", "Configuration");
343 MenuDescription["fragmentation"] = pair<std::string,std::string>("Fragmentation", "Fragmentation");
344 MenuDescription["molecule"] = pair<std::string,std::string>("Parse files into system", "Parse files");
345 MenuDescription["parser"] = pair<std::string,std::string>("Edit molecules (load, parse, save)", "Edit molecules");
346 MenuDescription["tesselation"] = pair<std::string,std::string>("Tesselate molecules", "Tesselate molecules");
347 MenuDescription["world"] = pair<std::string,std::string>("Edit world", "Edit world");
348
349 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "molecular-volume") );
350 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "pair-correlation") );
351 MenuContainsActionMap.insert( pair<std::string, std::string> ("analysis", "principal-axis-system") );
352
353 MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "add-atom") );
354 MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "change-element") );
355 MenuContainsActionMap.insert( pair<std::string, std::string> ("atom", "remove-atom") );
356
357 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "bond-table") );
358 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "element-db") );
359 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "fastparsing") );
360 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "verbose") );
361 MenuContainsActionMap.insert( pair<std::string, std::string> ("command", "version") );
362
363 MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "depth-first-search") );
364 MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "fragment-mol") );
365 MenuContainsActionMap.insert( pair<std::string, std::string> ("fragmentation", "subgraph-dissect") );
366
367 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "bond-file") );
368 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "change-molname") );
369 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "fill-molecule") );
370 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "linear-interpolate") );
371 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "rotate-to-pas") );
372 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "save-adjacency") );
373 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "save-bonds") );
374 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "save-temperature") );
375 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "suspend-in-water") );
376 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "translate-mol") );
377 MenuContainsActionMap.insert( pair<std::string, std::string> ("molecule", "verlet-integrate") );
378
379 MenuContainsActionMap.insert( pair<std::string, std::string> ("parser", "parse-xyz") );
380 MenuContainsActionMap.insert( pair<std::string, std::string> ("parser", "SaveXyz") );
381
382 MenuContainsActionMap.insert( pair<std::string, std::string> ("tesselation", "convex-envelope") );
383 MenuContainsActionMap.insert( pair<std::string, std::string> ("tesselation", "nonconvex-envelope") );
384
385 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "boundary") );
386 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "bound-in-box") );
387 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "center-in-box") );
388 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "center-edge") );
389 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "change-box") );
390 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "input") );
391 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "output") );
392 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "remove-sphere") );
393 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "repeat-box") );
394 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "scale-box") );
395 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "default-molname") );
396 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "set-basis") );
397 MenuContainsActionMap.insert( pair<std::string, std::string> ("world", "set-output") );
398
399 // put actions into command line category
400 generic.insert("add-atom");
401 generic.insert("bond-file");
402 generic.insert("bond-table");
403 generic.insert("boundary");
404// generic.insert("bound-in-box");
405 generic.insert("center-edge");
406 generic.insert("center-in-box");
407 generic.insert("change-box");
408// generic.insert("change-molname");
409 generic.insert("change-element");
410 generic.insert("convex-envelope");
411 generic.insert("default-molname");
412 generic.insert("depth-first-search");
413 generic.insert("element-db");
414 generic.insert("fastparsing");
415 generic.insert("fill-molecule");
416 generic.insert("fragment-mol");
417 generic.insert("help");
418 generic.insert("input");
419 generic.insert("linear-interpolate");
420// generic.insert("molecular-volume");
421 generic.insert("nonconvex-envelope");
422 generic.insert("output");
423 generic.insert("pair-correlation");
424 generic.insert("parse-xyz");
425// generic.insert("principal-axis-system");
426 generic.insert("remove-atom");
427 generic.insert("remove-sphere");
428 generic.insert("repeat-box");
429 generic.insert("rotate-to-pas");
430 generic.insert("save-adjacency");
431 generic.insert("save-bonds");
432 generic.insert("save-temperature");
433 generic.insert("scale-box");
434 generic.insert("set-basis");
435 generic.insert("set-output");
436 generic.insert("subgraph-dissect");
437 generic.insert("suspend-in-water");
438 generic.insert("translate-mol");
439 generic.insert("verbose");
440 generic.insert("verlet-integrate");
441 generic.insert("version");
442
443 // positional arguments
444 generic.insert("input");
445 inputfile.insert("input");
446
447 // hidden arguments
448 generic.insert("atom-by-id");
449 generic.insert("bin-end");
450 generic.insert("bin-output-file");
451 generic.insert("bin-start");
452 generic.insert("bin-width");
453 generic.insert("convex-file");
454 generic.insert("distance");
455 generic.insert("DoRotate");
456 generic.insert("distances");
457 generic.insert("element");
458 generic.insert("elements");
459 generic.insert("end-step");
460 generic.insert("id-mapping");
461 generic.insert("lengths");
462 generic.insert("MaxDistance");
463 generic.insert("molecule-by-id");
464 generic.insert("molecule-by-name");
465 generic.insert("nonconvex-file");
466 generic.insert("order");
467 generic.insert("output-file");
468 generic.insert("periodic");
469 generic.insert("position");
470 generic.insert("sphere-radius");
471 generic.insert("start-step");
472}
473
474/** Destructor of class MapOfActions.
475 *
476 */
477MapOfActions::~MapOfActions()
478{
479 DescriptionMap.clear();
480}
481
482
483void MapOfActions::populateActions()
484{
485 new AnalysisMolecularVolumeAction();
486 new AnalysisPairCorrelationAction();
487 new AnalysisPrincipalAxisSystemAction();
488
489 new AtomAddAction();
490 new AtomChangeElementAction();
491 new AtomRemoveAction();
492
493 new CommandLineBondLengthTableAction();
494 new CommandLineElementDbAction();
495 new CommandLineFastParsingAction();
496 new CommandLineHelpAction();
497 new CommandLineVerboseAction();
498 new CommandLineVersionAction();
499
500 new FragmentationDepthFirstSearchAction();
501 new FragmentationFragmentationAction();
502 new FragmentationSubgraphDissectionAction();
503
504 new MoleculeBondFileAction();
505 new MoleculeChangeNameAction();
506 new MoleculeFillWithMoleculeAction();
507 new MoleculeLinearInterpolationofTrajectoriesAction();
508 new MoleculeRotateToPrincipalAxisSystemAction();
509 new MoleculeSaveAdjacencyAction();
510 new MoleculeSaveBondsAction();
511 new MoleculeSaveTemperatureAction();
512 new MoleculeSuspendInWaterAction();
513 new MoleculeTranslateAction();
514 new MoleculeVerletIntegrationAction();
515
516 new ParserLoadXyzAction();
517 new ParserSaveXyzAction();
518
519 new TesselationConvexEnvelopeAction();
520 new TesselationNonConvexEnvelopeAction();
521
522 new WorldAddEmptyBoundaryAction();
523 new WorldBoundInBoxAction();
524 new WorldCenterInBoxAction();
525 new WorldCenterOnEdgeAction();
526 new WorldChangeBoxAction();
527 new WorldInputAction();
528 new WorldOutputAction();
529 new WorldRemoveSphereOfAtomsAction();
530 new WorldRepeatBoxAction();
531 new WorldScaleBoxAction();
532 new WorldSetDefaultNameAction();
533 new WorldSetGaussianBasisAction();
534 new WorldSetOutputFormatsAction();
535}
536
537
538/** Adds all options to the CommandLineParser.
539 *
540 */
541void MapOfActions::AddOptionsToParser()
542{
543 // add other options
544 for (map< set<string>*, po::options_description* >::iterator ListRunner = CmdParserLookup.begin(); ListRunner != CmdParserLookup.end(); ++ListRunner) {
545 for (set<string>::iterator OptionRunner = ListRunner->first->begin(); OptionRunner != ListRunner->first->end(); ++OptionRunner) {
546 if (hasValue(*OptionRunner)) {
547 DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " with type " << TypeMap[*OptionRunner] << " to CommandLineParser." << endl);
548 switch((enum OptionTypes) TypeMap[*OptionRunner]) {
549 default:
550 case None:
551 ListRunner->second->add_options()
552 (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
553 ;
554 break;
555 case Boolean:
556 ListRunner->second->add_options()
557 (getKeyAndShortForm(*OptionRunner).c_str(),
558 DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
559 po::value< bool >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) :
560 po::value< bool >(),
561 getDescription(*OptionRunner).c_str())
562 ;
563 break;
564 case Box:
565 ListRunner->second->add_options()
566 (getKeyAndShortForm(*OptionRunner).c_str(),
567 po::value<BoxValue>()->multitoken(),
568 getDescription(*OptionRunner).c_str())
569 ;
570 break;
571 case Integer:
572 ListRunner->second->add_options()
573 (getKeyAndShortForm(*OptionRunner).c_str(),
574 DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
575 po::value< int >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) :
576 po::value< int >(),
577 getDescription(*OptionRunner).c_str())
578 ;
579 break;
580 case ListOfInts:
581 ListRunner->second->add_options()
582 (getKeyAndShortForm(*OptionRunner).c_str(),
583 po::value< vector<int> >()->multitoken(),
584 getDescription(*OptionRunner).c_str())
585 ;
586 break;
587 case Double:
588 ListRunner->second->add_options()
589 (getKeyAndShortForm(*OptionRunner).c_str(),
590 DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
591 po::value< double >()->default_value(atof(DefaultValue[*OptionRunner].c_str())) :
592 po::value< double >(),
593 getDescription(*OptionRunner).c_str())
594 ;
595 break;
596 case ListOfDoubles:
597 ListRunner->second->add_options()
598 (getKeyAndShortForm(*OptionRunner).c_str(),
599 po::value< vector<double> >()->multitoken(),
600 getDescription(*OptionRunner).c_str())
601 ;
602 break;
603 case String:
604 ListRunner->second->add_options()
605 (getKeyAndShortForm(*OptionRunner).c_str(),
606 DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
607 po::value< std::string >()->default_value(DefaultValue[*OptionRunner]) :
608 po::value< std::string >(),
609 getDescription(*OptionRunner).c_str())
610 ;
611 break;
612 case ListOfString:
613 ListRunner->second->add_options()
614 (getKeyAndShortForm(*OptionRunner).c_str(),
615 po::value< vector<std::string> >()->multitoken(),
616 getDescription(*OptionRunner).c_str())
617 ;
618 break;
619 case Axis:
620 ListRunner->second->add_options()
621 (getKeyAndShortForm(*OptionRunner).c_str(),
622 DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
623 po::value< int >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) :
624 po::value< int >(),
625 getDescription(*OptionRunner).c_str())
626 ;
627 break;
628 case Vector:
629 ListRunner->second->add_options()
630 (getKeyAndShortForm(*OptionRunner).c_str(),
631 po::value<VectorValue>(),
632 getDescription(*OptionRunner).c_str())
633 ;
634 break;
635 case Molecule:
636 ListRunner->second->add_options()
637 (getKeyAndShortForm(*OptionRunner).c_str(),
638 DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
639 po::value< int >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) :
640 po::value< int >(),
641 getDescription(*OptionRunner).c_str())
642 ;
643 break;
644 case ListOfMolecules:
645 ListRunner->second->add_options()
646 (getKeyAndShortForm(*OptionRunner).c_str(),
647 po::value< vector<int> >()->multitoken(),
648 getDescription(*OptionRunner).c_str())
649 ;
650 break;
651 case Atom:
652 ListRunner->second->add_options()
653 (getKeyAndShortForm(*OptionRunner).c_str(),
654 DefaultValue.find(*OptionRunner) != DefaultValue.end() ?
655 po::value< int >()->default_value(atoi(DefaultValue[*OptionRunner].c_str())) :
656 po::value< int >(),
657 getDescription(*OptionRunner).c_str())
658 ;
659 break;
660 case ListOfAtoms:
661 ListRunner->second->add_options()
662 (getKeyAndShortForm(*OptionRunner).c_str(),
663 po::value< vector<int> >()->multitoken(),
664 getDescription(*OptionRunner).c_str())
665 ;
666 break;
667 case Element:
668 ListRunner->second->add_options()
669 (getKeyAndShortForm(*OptionRunner).c_str(),
670 po::value< vector<int> >(),
671 getDescription(*OptionRunner).c_str())
672 ;
673 break;
674 case ListOfElements:
675 ListRunner->second->add_options()
676 (getKeyAndShortForm(*OptionRunner).c_str(),
677 po::value< vector<int> >()->multitoken(),
678 getDescription(*OptionRunner).c_str())
679 ;
680 break;
681 }
682 } else {
683 DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " to CommandLineParser." << endl);
684 ListRunner->second->add_options()
685 (getKeyAndShortForm(*OptionRunner).c_str(), getDescription(*OptionRunner).c_str())
686 ;
687 }
688 }
689 }
690 // add positional arguments
691 for (set<string>::iterator OptionRunner = inputfile.begin(); OptionRunner != inputfile.end(); ++OptionRunner) {
692 DoLog(0) && (Log() << Verbose(0) << "Adding option " << *OptionRunner << " to positional CommandLineParser." << endl);
693 CommandLineParser::getInstance().inputfile.add((*OptionRunner).c_str(), -1);
694 }
695 cout << "Name for position 1: " << CommandLineParser::getInstance().inputfile.name_for_position(1) << endl;
696}
697
698/** Getter for MapOfActions:DescriptionMap.
699 * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
700 * \param actionname name of the action to lookup
701 * \return Description of the action
702 */
703std::string MapOfActions::getDescription(string actionname)
704{
705 ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescription");
706 return DescriptionMap[actionname];
707}
708
709/** Specific Getter for a MapOfActions:ShortFormMap.
710 * If action has a short for, then combination is as "actionname,ShortForm" (this is
711 * the desired format for boost::program_options). If no short form exists in the map,
712 * just actionname will be returned
713 * Note that we assert when action does not exist in CommandLineParser::DescriptionMap.
714 * \param actionname name of the action to lookup
715 * \return actionname,ShortForm or Description of the action
716 */
717std::string MapOfActions::getKeyAndShortForm(string actionname)
718{
719 stringstream output;
720 ASSERT(DescriptionMap.find(actionname) != DescriptionMap.end(), "Unknown action name passed to MapOfActions::getDescriptionAndShortForm");
721 output << actionname;
722 if (ShortFormMap.find(actionname) != DescriptionMap.end())
723 output << "," << ShortFormMap[actionname];
724 return output.str();
725}
726
727/** Getter for MapOfActions:ShortFormMap.
728 * Note that we assert when action does not exist CommandLineParser::ShortFormMap.
729 * \param actionname name of the action to lookup
730 * \return ShortForm of the action
731 */
732std::string MapOfActions::getShortForm(string actionname)
733{
734 ASSERT(ShortFormMap.find(actionname) != ShortFormMap.end(), "Unknown action name passed to MapOfActions::getShortForm");
735 return ShortFormMap[actionname];
736}
737
738/** Returns whether the given action needs a value or not.
739 * \param actionname name of the action to look up
740 * \return true - value is needed, false - no value is stored in MapOfActions::TypeMap
741 */
742bool MapOfActions::hasValue(string actionname)
743{
744 return (TypeMap.find(actionname) != TypeMap.end());
745}
746
747/** Getter for MapOfActions::TypeMap.
748 * \param actionname name of the action to look up
749 * \return type of the action
750 */
751enum MapOfActions::OptionTypes MapOfActions::getValueType(string actionname)
752{
753 return TypeMap[actionname];
754}
755
756/** Searches whether action is registered with CommandLineParser.
757 * Note that this method is only meant transitionally for ParseCommandLineOptions' removal.
758 * I.e. All actions that are already handled by the new CommandLineUIFactory can be checked
759 * by this function.
760 * \param shortform command short form to look for
761 * \return true - action has been registered, false - action has not been registered.
762 */
763bool MapOfActions::isShortFormPresent(string shortform)
764{
765 bool result = false;
766 string actionname;
767 for (map<std::string, std::string>::iterator ShortFormRunner = ShortFormMap.begin(); ShortFormRunner != ShortFormMap.end(); ++ShortFormRunner)
768 if (ShortFormRunner->second == shortform) {
769 actionname = ShortFormRunner->first;
770 break;
771 }
772 result = result || (generic.find(actionname) != generic.end());
773 result = result || (config.find(actionname) != config.end());
774 result = result || (hidden.find(actionname) != hidden.end());
775 result = result || (visible.find(actionname) != visible.end());
776 result = result || (inputfile.find(actionname) != inputfile.end());
777 return result;
778}
779
780/** Returns the inverse to MapOfActions::ShortFormMap, i.e. lookup actionname for its short form.
781 * \return map from short form of action to name of action
782 */
783map <std::string, std::string> MapOfActions::getShortFormToActionMap()
784{
785 map <std::string, std::string> result;
786
787 for (map<std::string, std::string>::iterator iter = ShortFormMap.begin(); iter != ShortFormMap.end(); ++iter)
788 result[iter->second] = iter->first;
789
790 return result;
791}
792
793
794CONSTRUCT_SINGLETON(MapOfActions)
Note: See TracBrowser for help on using the repository browser.