source: src/UIElements/CommandLineUI/CommandLineDialog.cpp@ 952f38

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

created LibMolecuilderHelpers.

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