source: src/UIElements/CommandLineUI/CommandLineDialog.cpp@ bf3817

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

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

  • is now topmost in front of MemDebug.hpp (and any other).
  • Property mode set to 100644
File size: 15.7 KB
Line 
1/*
2 * CommandLineDialog.cpp
3 *
4 * Created on: May 8, 2010
5 * Author: heber
6 */
7
8// include config.h
9#ifdef HAVE_CONFIG_H
10#include <config.h>
11#endif
12
13#include "Helpers/MemDebug.hpp"
14
15#include <iostream>
16#include <vector>
17
18#include <Descriptors/AtomDescriptor.hpp>
19#include <Descriptors/AtomIdDescriptor.hpp>
20#include <Descriptors/MoleculeDescriptor.hpp>
21#include <Descriptors/MoleculeIdDescriptor.hpp>
22#include "CommandLineUI/CommandLineDialog.hpp"
23
24#include "Actions/Values.hpp"
25
26#include "element.hpp"
27#include "periodentafel.hpp"
28#include "CommandLineParser.hpp"
29#include "defs.hpp"
30#include "Helpers/Log.hpp"
31#include "LinearAlgebra/Matrix.hpp"
32#include "periodentafel.hpp"
33#include "Helpers/Verbose.hpp"
34#include "World.hpp"
35#include "Box.hpp"
36
37#include "atom.hpp"
38#include "element.hpp"
39#include "molecule.hpp"
40#include "LinearAlgebra/Vector.hpp"
41
42using namespace std;
43
44
45CommandLineDialog::CommandLineDialog()
46{
47}
48
49CommandLineDialog::~CommandLineDialog()
50{
51}
52
53
54void CommandLineDialog::queryEmpty(const char* title, string _description){
55 registerQuery(new EmptyCommandLineQuery(title, _description));
56}
57
58void CommandLineDialog::queryInt(const char* title, string _description){
59 registerQuery(new IntCommandLineQuery(title, _description));
60}
61
62void CommandLineDialog::queryInts(const char* title, string _description){
63 registerQuery(new IntsCommandLineQuery(title, _description));
64}
65
66void CommandLineDialog::queryBoolean(const char* title, string _description){
67 registerQuery(new BooleanCommandLineQuery(title, _description));
68}
69
70void CommandLineDialog::queryDouble(const char* title, string _description){
71 registerQuery(new DoubleCommandLineQuery(title, _description));
72}
73
74void CommandLineDialog::queryDoubles(const char* title, string _description){
75 registerQuery(new DoublesCommandLineQuery(title, _description));
76}
77
78void CommandLineDialog::queryString(const char* title, string _description){
79 registerQuery(new StringCommandLineQuery(title, _description));
80}
81
82void CommandLineDialog::queryStrings(const char* title, string _description){
83 registerQuery(new StringsCommandLineQuery(title, _description));
84}
85
86void CommandLineDialog::queryAtom(const char* title, string _description) {
87 registerQuery(new AtomCommandLineQuery(title, _description));
88}
89
90void CommandLineDialog::queryAtoms(const char* title, string _description) {
91 registerQuery(new AtomsCommandLineQuery(title, _description));
92}
93
94void CommandLineDialog::queryMolecule(const char* title, string _description) {
95 registerQuery(new MoleculeCommandLineQuery(title, _description));
96}
97
98void CommandLineDialog::queryMolecules(const char* title, string _description) {
99 registerQuery(new MoleculesCommandLineQuery(title, _description));
100}
101
102void CommandLineDialog::queryVector(const char* title, bool check, string _description) {
103 registerQuery(new VectorCommandLineQuery(title,check, _description));
104}
105
106void CommandLineDialog::queryVectors(const char* title, bool check, string _description) {
107 registerQuery(new VectorsCommandLineQuery(title,check, _description));
108}
109
110void CommandLineDialog::queryBox(const char* title, string _description) {
111 registerQuery(new BoxCommandLineQuery(title,_description));
112}
113
114void CommandLineDialog::queryElement(const char* title, string _description){
115 registerQuery(new ElementCommandLineQuery(title, _description));
116}
117
118void CommandLineDialog::queryElements(const char* title, string _description){
119 registerQuery(new ElementsCommandLineQuery(title, _description));
120}
121
122/************************** Query Infrastructure ************************/
123
124CommandLineDialog::EmptyCommandLineQuery::EmptyCommandLineQuery(string title, string _description) :
125 Dialog::EmptyQuery(title, _description)
126{}
127
128CommandLineDialog::EmptyCommandLineQuery::~EmptyCommandLineQuery() {}
129
130bool CommandLineDialog::EmptyCommandLineQuery::handle() {
131 cout << "Message of " << getTitle() << ":\n" << getDescription() << "\n";
132 return true;
133}
134
135CommandLineDialog::IntCommandLineQuery::IntCommandLineQuery(string title, string _description) :
136 Dialog::IntQuery(title, _description)
137{}
138
139CommandLineDialog::IntCommandLineQuery::~IntCommandLineQuery() {}
140
141bool CommandLineDialog::IntCommandLineQuery::handle() {
142 if (CommandLineParser::getInstance().vm.count(getTitle())) {
143 tmp = CommandLineParser::getInstance().vm[getTitle()].as<int>();
144 return true;
145 } else {
146 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing integer for " << getTitle() << "." << endl);
147 return false;
148 }
149}
150
151CommandLineDialog::IntsCommandLineQuery::IntsCommandLineQuery(string title, string _description) :
152 Dialog::IntsQuery(title, _description)
153{}
154
155CommandLineDialog::IntsCommandLineQuery::~IntsCommandLineQuery() {}
156
157bool CommandLineDialog::IntsCommandLineQuery::handle() {
158 if (CommandLineParser::getInstance().vm.count(getTitle())) {
159 tmp = CommandLineParser::getInstance().vm[getTitle()].as< std::vector<int> >();
160 return true;
161 } else {
162 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing integers for " << getTitle() << "." << endl);
163 return false;
164 }
165}
166
167CommandLineDialog::BooleanCommandLineQuery::BooleanCommandLineQuery(string title, string _description) :
168 Dialog::BooleanQuery(title, _description)
169{}
170
171CommandLineDialog::BooleanCommandLineQuery::~BooleanCommandLineQuery() {}
172
173bool CommandLineDialog::BooleanCommandLineQuery::handle() {
174 if (CommandLineParser::getInstance().vm.count(getTitle())) {
175 tmp = CommandLineParser::getInstance().vm[getTitle()].as<bool>();
176 return true;
177 } else {
178 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing boolean for " << getTitle() << "." << endl);
179 return false;
180 }
181}
182
183CommandLineDialog::StringCommandLineQuery::StringCommandLineQuery(string title, string _description) :
184 Dialog::StringQuery(title, _description)
185{}
186
187CommandLineDialog::StringCommandLineQuery::~StringCommandLineQuery() {}
188
189bool CommandLineDialog::StringCommandLineQuery::handle() {
190 if (CommandLineParser::getInstance().vm.count(getTitle())) {
191 tmp = CommandLineParser::getInstance().vm[getTitle()].as<string>();
192 return true;
193 } else {
194 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing string for " << getTitle() << "." << endl);
195 return false;
196 }
197}
198
199CommandLineDialog::StringsCommandLineQuery::StringsCommandLineQuery(string title, string _description) :
200 Dialog::StringsQuery(title, _description)
201{}
202
203CommandLineDialog::StringsCommandLineQuery::~StringsCommandLineQuery() {}
204
205bool CommandLineDialog::StringsCommandLineQuery::handle() {
206 if (CommandLineParser::getInstance().vm.count(getTitle())) {
207 tmp = CommandLineParser::getInstance().vm[getTitle()].as< vector<string> >();
208 return true;
209 } else {
210 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing strings for " << getTitle() << "." << endl);
211 return false;
212 }
213}
214
215CommandLineDialog::DoubleCommandLineQuery::DoubleCommandLineQuery(string title, string _description) :
216 Dialog::DoubleQuery(title, _description)
217{}
218
219CommandLineDialog::DoubleCommandLineQuery::~DoubleCommandLineQuery() {}
220
221bool CommandLineDialog::DoubleCommandLineQuery::handle() {
222 if (CommandLineParser::getInstance().vm.count(getTitle())) {
223 tmp = CommandLineParser::getInstance().vm[getTitle()].as<double>();
224 return true;
225 } else {
226 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing double for " << getTitle() << "." << endl);
227 return false;
228 }
229}
230
231CommandLineDialog::DoublesCommandLineQuery::DoublesCommandLineQuery(string title, string _description) :
232 Dialog::DoublesQuery(title, _description)
233{}
234
235CommandLineDialog::DoublesCommandLineQuery::~DoublesCommandLineQuery() {}
236
237bool CommandLineDialog::DoublesCommandLineQuery::handle() {
238 if (CommandLineParser::getInstance().vm.count(getTitle())) {
239 tmp = CommandLineParser::getInstance().vm[getTitle()].as< std::vector<double> >();
240 return true;
241 } else {
242 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing doubles for " << getTitle() << "." << endl);
243 return false;
244 }
245}
246
247CommandLineDialog::AtomCommandLineQuery::AtomCommandLineQuery(string title, string _description) :
248 Dialog::AtomQuery(title, _description)
249{}
250
251CommandLineDialog::AtomCommandLineQuery::~AtomCommandLineQuery() {}
252
253bool CommandLineDialog::AtomCommandLineQuery::handle() {
254 int IdxOfAtom = -1;
255 if (CommandLineParser::getInstance().vm.count(getTitle())) {
256 IdxOfAtom = CommandLineParser::getInstance().vm[getTitle()].as<int>();
257 tmp = World::getInstance().getAtom(AtomById(IdxOfAtom));
258 return true;
259 } else {
260 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing atom for " << getTitle() << "." << endl);
261 return false;
262 }
263}
264
265CommandLineDialog::AtomsCommandLineQuery::AtomsCommandLineQuery(string title, string _description) :
266 Dialog::AtomsQuery(title, _description)
267{}
268
269CommandLineDialog::AtomsCommandLineQuery::~AtomsCommandLineQuery() {}
270
271bool CommandLineDialog::AtomsCommandLineQuery::handle() {
272 std::vector<int> IdxOfAtom;
273 if (CommandLineParser::getInstance().vm.count(getTitle())) {
274 IdxOfAtom = CommandLineParser::getInstance().vm[getTitle()].as< std::vector<int> >();
275 for (std::vector<int>::iterator iter = IdxOfAtom.begin(); iter != IdxOfAtom.end(); ++iter) {
276 temp = World::getInstance().getAtom(AtomById(*iter));
277 if (temp)
278 tmp.push_back(temp);
279 }
280 return true;
281 } else {
282 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing atoms for " << getTitle() << "." << endl);
283 return false;
284 }
285}
286
287CommandLineDialog::MoleculeCommandLineQuery::MoleculeCommandLineQuery(string title, string _description) :
288 Dialog::MoleculeQuery(title, _description)
289{}
290
291CommandLineDialog::MoleculeCommandLineQuery::~MoleculeCommandLineQuery() {}
292
293bool CommandLineDialog::MoleculeCommandLineQuery::handle() {
294 int IdxOfMol = -1;
295 if (CommandLineParser::getInstance().vm.count(getTitle())) {
296 IdxOfMol = CommandLineParser::getInstance().vm[getTitle()].as<int>();
297 tmp = World::getInstance().getMolecule(MoleculeById(IdxOfMol));
298 return true;
299 } else {
300 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing molecule for " << getTitle() << "." << endl);
301 return false;
302 }
303}
304
305CommandLineDialog::MoleculesCommandLineQuery::MoleculesCommandLineQuery(string title, string _description) :
306 Dialog::MoleculesQuery(title, _description)
307{}
308
309CommandLineDialog::MoleculesCommandLineQuery::~MoleculesCommandLineQuery() {}
310
311bool CommandLineDialog::MoleculesCommandLineQuery::handle() {
312 std::vector<int> IdxOfMol;
313 if (CommandLineParser::getInstance().vm.count(getTitle())) {
314 IdxOfMol = CommandLineParser::getInstance().vm[getTitle()].as< std::vector<int> >();
315 for (std::vector<int>::iterator iter = IdxOfMol.begin(); iter != IdxOfMol.end(); ++iter) {
316 temp = World::getInstance().getMolecule(MoleculeById(*iter));
317 if (temp)
318 tmp.push_back(temp);
319 }
320 return true;
321 } else {
322 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing molecules for " << getTitle() << "." << endl);
323 return false;
324 }
325}
326
327CommandLineDialog::VectorCommandLineQuery::VectorCommandLineQuery(string title, bool _check, string _description) :
328 Dialog::VectorQuery(title,_check, _description)
329{}
330
331CommandLineDialog::VectorCommandLineQuery::~VectorCommandLineQuery()
332{}
333
334bool CommandLineDialog::VectorCommandLineQuery::handle() {
335 VectorValue temp;
336 if (CommandLineParser::getInstance().vm.count(getTitle())) {
337 temp = CommandLineParser::getInstance().vm[getTitle()].as< VectorValue >();
338 tmp[0] = temp.x;
339 tmp[1] = temp.y;
340 tmp[2] = temp.z;
341 if ((check) && (!World::getInstance().getDomain().isInside(tmp))) {
342 DoeLog(1) && (eLog() << Verbose(1) << "Vector " << tmp << " would be outside of box domain." << endl);
343 return false;
344 }
345 return true;
346 } else {
347 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing vector for " << getTitle() << "." << endl);
348 return false;
349 }
350}
351
352CommandLineDialog::VectorsCommandLineQuery::VectorsCommandLineQuery(string title, bool _check, string _description) :
353 Dialog::VectorsQuery(title,_check, _description)
354{}
355
356CommandLineDialog::VectorsCommandLineQuery::~VectorsCommandLineQuery()
357{}
358
359bool CommandLineDialog::VectorsCommandLineQuery::handle() {
360 std::vector<VectorValue> temporary;
361 if (CommandLineParser::getInstance().vm.count(getTitle())) {
362 temporary = CommandLineParser::getInstance().vm[getTitle()].as< std::vector<VectorValue> >();
363 for(std::vector<VectorValue>::iterator iter = temporary.begin(); iter != temporary.end(); ++iter) {
364 temp[0] = (*iter).x;
365 temp[1] = (*iter).y;
366 temp[2] = (*iter).z;
367 if ((!check) || (World::getInstance().getDomain().isInside(temp)))
368 tmp.push_back(temp);
369 else
370 DoeLog(1) && (eLog() << Verbose(1) << "Vector " << temp << " would be outside of box domain." << endl);
371 }
372 return true;
373 } else {
374 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing vectors for " << getTitle() << "." << endl);
375 return false;
376 }
377}
378
379CommandLineDialog::BoxCommandLineQuery::BoxCommandLineQuery(string title, string _description) :
380 Dialog::BoxQuery(title, _description)
381{}
382
383CommandLineDialog::BoxCommandLineQuery::~BoxCommandLineQuery()
384{}
385
386bool CommandLineDialog::BoxCommandLineQuery::handle() {
387 BoxValue temp;
388 if (CommandLineParser::getInstance().vm.count(getTitle())) {
389 temp = CommandLineParser::getInstance().vm[getTitle()].as< BoxValue >();
390 Matrix M;
391 M.set(0,0, temp.xx);
392 M.set(0,1, temp.yx);
393 M.set(0,2, temp.zx);
394 M.set(1,0, temp.yx);
395 M.set(1,1, temp.yy);
396 M.set(1,2, temp.zy);
397 M.set(2,0, temp.zx);
398 M.set(2,1, temp.zy);
399 M.set(2,2, temp.zz);
400 tmp.setM(M);
401 return true;
402 } else {
403 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing symmetric box matrix for " << getTitle() << "." << endl);
404 return false;
405 }
406}
407
408CommandLineDialog::ElementCommandLineQuery::ElementCommandLineQuery(string title, string _description) :
409 Dialog::ElementQuery(title, _description)
410{}
411
412CommandLineDialog::ElementCommandLineQuery::~ElementCommandLineQuery()
413{}
414
415bool CommandLineDialog::ElementCommandLineQuery::handle() {
416 // TODO: vector of ints and removing first is not correctly implemented yet. How to remove from a vector?
417 periodentafel *periode = World::getInstance().getPeriode();
418 if (CommandLineParser::getInstance().vm.count(getTitle())) {
419 int Z = CommandLineParser::getInstance().vm[getTitle()].as< int >();
420 tmp = periode->FindElement(Z);
421 ASSERT(tmp != NULL, "Invalid element specified in ElementCommandLineQuery");
422 return true;
423 } else {
424 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing element for " << getTitle() << "." << endl);
425 return false;
426 }
427}
428
429CommandLineDialog::ElementsCommandLineQuery::ElementsCommandLineQuery(string title, string _description) :
430 Dialog::ElementsQuery(title, _description)
431{}
432
433CommandLineDialog::ElementsCommandLineQuery::~ElementsCommandLineQuery()
434{}
435
436bool CommandLineDialog::ElementsCommandLineQuery::handle() {
437 // TODO: vector of ints and removing first is not correctly implemented yet. How to remove from a vector?
438 periodentafel *periode = World::getInstance().getPeriode();
439 if (CommandLineParser::getInstance().vm.count(getTitle())) {
440 vector<int> AllElements = CommandLineParser::getInstance().vm[getTitle()].as< vector<int> >();
441 for (vector<int>::iterator ZRunner = AllElements.begin(); ZRunner != AllElements.end(); ++ZRunner) {
442 temp = periode->FindElement(*ZRunner);
443 ASSERT(temp != NULL, "Invalid element specified in ElementCommandLineQuery");
444 tmp.push_back(temp);
445 }
446 return true;
447 } else {
448 DoeLog(1) && (eLog() << Verbose(1) << "CommandLineUI parsing error: Missing elements for " << getTitle() << "." << endl);
449 return false;
450 }
451}
Note: See TracBrowser for help on using the repository browser.