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

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

Added copyright note to each .cpp file and an extensive one to builder.cpp.

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