source: src/Actions/MapOfActions.cpp@ f30490

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

Added (un)select-molecule-by-formula/..-atom-by-element actions..

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