1 | /** \file menu.cpp
|
---|
2 | * The class in this file is responsible for displaying the menu and enabling choices.
|
---|
3 | *
|
---|
4 | * This class is currently being refactored. Functions were copied from builder.cpp and are
|
---|
5 | * to be imported into the menu class.
|
---|
6 | *
|
---|
7 | */
|
---|
8 |
|
---|
9 | #include "Legacy/oldmenu.hpp"
|
---|
10 | #include "analysis_correlation.hpp"
|
---|
11 | #include "World.hpp"
|
---|
12 | #include "atom.hpp"
|
---|
13 | #include "bond.hpp"
|
---|
14 | #include "bondgraph.hpp"
|
---|
15 | #include "boundary.hpp"
|
---|
16 | #include "config.hpp"
|
---|
17 | #include "element.hpp"
|
---|
18 | #include "ellipsoid.hpp"
|
---|
19 | #include "helpers.hpp"
|
---|
20 | #include "leastsquaremin.hpp"
|
---|
21 | #include "linkedcell.hpp"
|
---|
22 | #include "log.hpp"
|
---|
23 | #include "memoryusageobserverunittest.hpp"
|
---|
24 | #include "molecule.hpp"
|
---|
25 | #include "periodentafel.hpp"
|
---|
26 | #include "vector_ops.hpp"
|
---|
27 | #include "Plane.hpp"
|
---|
28 | #include "Line.hpp"
|
---|
29 |
|
---|
30 | #include "UIElements/UIFactory.hpp"
|
---|
31 | #include "UIElements/Dialog.hpp"
|
---|
32 | #include "Menu/Menu.hpp"
|
---|
33 | #include "Menu/TextMenu.hpp"
|
---|
34 | #include "Menu/ActionMenuItem.hpp"
|
---|
35 | #include "Menu/SeperatorItem.hpp"
|
---|
36 | #include "Menu/DisplayMenuItem.hpp"
|
---|
37 | #include "Menu/SubMenuItem.hpp"
|
---|
38 | #include "Actions/MapOfActions.hpp"
|
---|
39 | #include "Actions/MethodAction.hpp"
|
---|
40 | #include "Actions/ErrorAction.hpp"
|
---|
41 | #include "Views/StreamStringView.hpp"
|
---|
42 | #include "Views/MethodStringView.hpp"
|
---|
43 |
|
---|
44 |
|
---|
45 | #include <boost/bind.hpp>
|
---|
46 |
|
---|
47 | /* copied methods for refactoring */
|
---|
48 | /*TODO: Move these methods inside menu class
|
---|
49 | * and restructure menu class*/
|
---|
50 |
|
---|
51 | /********************************************* Subsubmenu routine ************************************/
|
---|
52 |
|
---|
53 | /** Submenu for adding atoms to the molecule.
|
---|
54 | * \param *periode periodentafel
|
---|
55 | * \param *molecule molecules with atoms
|
---|
56 | */
|
---|
57 | void oldmenu::AddAtoms(periodentafel *periode, molecule *mol)
|
---|
58 | {
|
---|
59 | atom *first, *second, *third, *fourth;
|
---|
60 | Vector **atoms;
|
---|
61 | Vector x,y,z,n; // coordinates for absolute point in cell volume
|
---|
62 | double a,b,c;
|
---|
63 | char choice; // menu choice char
|
---|
64 | bool valid;
|
---|
65 | bool aborted;
|
---|
66 |
|
---|
67 | Log() << Verbose(0) << "===========ADD ATOM============================" << endl;
|
---|
68 | Log() << Verbose(0) << " a - state absolute coordinates of atom" << endl;
|
---|
69 | Log() << Verbose(0) << " b - state relative coordinates of atom wrt to reference point" << endl;
|
---|
70 | Log() << Verbose(0) << " c - state relative coordinates of atom wrt to already placed atom" << endl;
|
---|
71 | Log() << Verbose(0) << " d - state two atoms, two angles and a distance" << endl;
|
---|
72 | Log() << Verbose(0) << " e - least square distance position to a set of atoms" << endl;
|
---|
73 | Log() << Verbose(0) << "all else - go back" << endl;
|
---|
74 | Log() << Verbose(0) << "===============================================" << endl;
|
---|
75 | Log() << Verbose(0) << "Note: Specifiy angles in degrees not multiples of Pi!" << endl;
|
---|
76 | Log() << Verbose(0) << "INPUT: ";
|
---|
77 | cin >> choice;
|
---|
78 |
|
---|
79 | switch (choice) {
|
---|
80 | default:
|
---|
81 | eLog() << Verbose(2) << "Not a valid choice." << endl;
|
---|
82 | break;
|
---|
83 | case 'a': // absolute coordinates of atom
|
---|
84 | {
|
---|
85 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
86 | first = World::getInstance().createAtom();
|
---|
87 | dialog->queryVector("Please enter coordinates: ",&first->x,World::getInstance().getDomain(), false);
|
---|
88 | dialog->queryElement("Please choose element: ",&first->type);
|
---|
89 | if(dialog->display()){
|
---|
90 | mol->AddAtom(first); // add to molecule
|
---|
91 | }
|
---|
92 | else{
|
---|
93 | World::getInstance().destroyAtom(first);
|
---|
94 | }
|
---|
95 | }
|
---|
96 | break;
|
---|
97 |
|
---|
98 | case 'b': // relative coordinates of atom wrt to reference point
|
---|
99 | first = World::getInstance().createAtom();
|
---|
100 | valid = true;
|
---|
101 | aborted = false;
|
---|
102 | do {
|
---|
103 | if (!valid) eLog() << Verbose(2) << "Resulting position out of cell." << endl;
|
---|
104 | auto_ptr<Dialog> dialog(UIFactory::getInstance().makeDialog());
|
---|
105 | dialog->queryVector("Enter reference coordinates.",&x,World::getInstance().getDomain(), true);
|
---|
106 | dialog->queryVector("Enter relative coordinates.",&first->x,World::getInstance().getDomain(), false);
|
---|
107 | if((aborted = !dialog->display())){
|
---|
108 | continue;
|
---|
109 | }
|
---|
110 | first->x += x;
|
---|
111 | } while (!aborted && !(valid = mol->CheckBounds((const Vector *)&first->x)));
|
---|
112 | if(!aborted){
|
---|
113 | first->type = periode->AskElement(); // give type
|
---|
114 | mol->AddAtom(first); // add to molecule
|
---|
115 | }
|
---|
116 | else{
|
---|
117 | World::getInstance().destroyAtom(first);
|
---|
118 | }
|
---|
119 | break;
|
---|
120 |
|
---|
121 | case 'c': // relative coordinates of atom wrt to already placed atom
|
---|
122 | {
|
---|
123 | first = World::getInstance().createAtom();
|
---|
124 | valid = true;
|
---|
125 | do {
|
---|
126 | if (!valid) eLog() << Verbose(2) << "Resulting position out of cell." << endl;
|
---|
127 | auto_ptr<Dialog> dialog(UIFactory::getInstance().makeDialog());
|
---|
128 | second = mol->AskAtom("Enter atom number: ");
|
---|
129 | dialog->queryVector("Enter relative coordinates.",&first->x,World::getInstance().getDomain(), false);
|
---|
130 | dialog->display();
|
---|
131 | for (int i=NDIM;i--;) {
|
---|
132 | first->x[i] += second->x[i];
|
---|
133 | }
|
---|
134 | } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
|
---|
135 | first->type = periode->AskElement(); // give type
|
---|
136 | mol->AddAtom(first); // add to molecule
|
---|
137 | }
|
---|
138 | break;
|
---|
139 |
|
---|
140 | case 'd': // two atoms, two angles and a distance
|
---|
141 | first = World::getInstance().createAtom();
|
---|
142 | valid = true;
|
---|
143 | do {
|
---|
144 | if (!valid) {
|
---|
145 | eLog() << Verbose(2) << "Resulting coordinates out of cell - " << first->x << endl;
|
---|
146 | }
|
---|
147 | Log() << Verbose(0) << "First, we need two atoms, the first atom is the central, while the second is the outer one." << endl;
|
---|
148 | second = mol->AskAtom("Enter central atom: ");
|
---|
149 | third = mol->AskAtom("Enter second atom (specifying the axis for first angle): ");
|
---|
150 | fourth = mol->AskAtom("Enter third atom (specifying a plane for second angle): ");
|
---|
151 | a = ask_value("Enter distance between central (first) and new atom: ");
|
---|
152 | b = ask_value("Enter angle between new, first and second atom (degrees): ");
|
---|
153 | b *= M_PI/180.;
|
---|
154 | bound(&b, 0., 2.*M_PI);
|
---|
155 | c = ask_value("Enter second angle between new and normal vector of plane defined by first, second and third atom (degrees): ");
|
---|
156 | c *= M_PI/180.;
|
---|
157 | bound(&c, -M_PI, M_PI);
|
---|
158 | Log() << Verbose(0) << "radius: " << a << "\t phi: " << b*180./M_PI << "\t theta: " << c*180./M_PI << endl;
|
---|
159 | /*
|
---|
160 | second->Output(1,1,(ofstream *)&cout);
|
---|
161 | third->Output(1,2,(ofstream *)&cout);
|
---|
162 | fourth->Output(1,3,(ofstream *)&cout);
|
---|
163 | n.MakeNormalvector((const vector *)&second->x, (const vector *)&third->x, (const vector *)&fourth->x);
|
---|
164 | x.Copyvector(&second->x);
|
---|
165 | x.SubtractVector(&third->x);
|
---|
166 | x.Copyvector(&fourth->x);
|
---|
167 | x.SubtractVector(&third->x);
|
---|
168 |
|
---|
169 | if (!z.SolveSystem(&x,&y,&n, b, c, a)) {
|
---|
170 | Log() << Verbose(0) << "Failure solving self-dependent linear system!" << endl;
|
---|
171 | continue;
|
---|
172 | }
|
---|
173 | Log() << Verbose(0) << "resulting relative coordinates: ";
|
---|
174 | z.Output();
|
---|
175 | Log() << Verbose(0) << endl;
|
---|
176 | */
|
---|
177 | // calc axis vector
|
---|
178 | x= second->x - third->x;
|
---|
179 | x.Normalize();
|
---|
180 | Log() << Verbose(0) << "x: " << x << endl;
|
---|
181 | z = Plane(second->x,third->x,fourth->x).getNormal();
|
---|
182 | Log() << Verbose(0) << "z: " << z << endl;
|
---|
183 | y = Plane(x,z,0).getNormal();
|
---|
184 | Log() << Verbose(0) << "y: " << y << endl;
|
---|
185 |
|
---|
186 | // rotate vector around first angle
|
---|
187 | first->x = x;
|
---|
188 | first->x = Line(zeroVec,z).rotateVector(first->x,b - M_PI);
|
---|
189 | Log() << Verbose(0) << "Rotated vector: " << first->x << endl,
|
---|
190 | // remove the projection onto the rotation plane of the second angle
|
---|
191 | n = y;
|
---|
192 | n.Scale(first->x.ScalarProduct(y));
|
---|
193 | Log() << Verbose(0) << "N1: " << n << endl;
|
---|
194 | first->x -= n;
|
---|
195 | Log() << Verbose(0) << "Subtracted vector: " << first->x << endl;
|
---|
196 | n = z;
|
---|
197 | n.Scale(first->x.ScalarProduct(z));
|
---|
198 | Log() << Verbose(0) << "N2: " << n << endl;
|
---|
199 | first->x -= n;
|
---|
200 | Log() << Verbose(0) << "2nd subtracted vector: " << first->x << endl;
|
---|
201 |
|
---|
202 | // rotate another vector around second angle
|
---|
203 | n = y;
|
---|
204 | n = Line(zeroVec,x).rotateVector(n,c - M_PI);
|
---|
205 | Log() << Verbose(0) << "2nd Rotated vector: " << n << endl;
|
---|
206 |
|
---|
207 | // add the two linear independent vectors
|
---|
208 | first->x += n;
|
---|
209 | first->x.Normalize();
|
---|
210 | first->x.Scale(a);
|
---|
211 | first->x += second->x;
|
---|
212 |
|
---|
213 | Log() << Verbose(0) << "resulting coordinates: " << first->x << endl;
|
---|
214 | } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
|
---|
215 | first->type = periode->AskElement(); // give type
|
---|
216 | mol->AddAtom(first); // add to molecule
|
---|
217 | break;
|
---|
218 |
|
---|
219 | case 'e': // least square distance position to a set of atoms
|
---|
220 | first = World::getInstance().createAtom();
|
---|
221 | atoms = new (Vector*[128]);
|
---|
222 | valid = true;
|
---|
223 | for(int i=128;i--;)
|
---|
224 | atoms[i] = NULL;
|
---|
225 | int i=0, j=0;
|
---|
226 | Log() << Verbose(0) << "Now we need at least three molecules.\n";
|
---|
227 | do {
|
---|
228 | Log() << Verbose(0) << "Enter " << i+1 << "th atom: ";
|
---|
229 | cin >> j;
|
---|
230 | if (j != -1) {
|
---|
231 | second = mol->FindAtom(j);
|
---|
232 | atoms[i++] = &(second->x);
|
---|
233 | }
|
---|
234 | } while ((j != -1) && (i<128));
|
---|
235 | if (i >= 2) {
|
---|
236 | LSQdistance(first->x,(const Vector **)atoms, i);
|
---|
237 |
|
---|
238 | Log() << Verbose(0) << first->x;
|
---|
239 | first->type = periode->AskElement(); // give type
|
---|
240 | mol->AddAtom(first); // add to molecule
|
---|
241 | } else {
|
---|
242 | World::getInstance().destroyAtom(first);
|
---|
243 | Log() << Verbose(0) << "Please enter at least two vectors!\n";
|
---|
244 | }
|
---|
245 | break;
|
---|
246 | };
|
---|
247 | };
|
---|
248 |
|
---|
249 | /** Submenu for centering the atoms in the molecule.
|
---|
250 | * \param *mol molecule with all the atoms
|
---|
251 | */
|
---|
252 | void oldmenu::CenterAtoms(molecule *mol)
|
---|
253 | {
|
---|
254 | Vector x, y, helper;
|
---|
255 | char choice; // menu choice char
|
---|
256 |
|
---|
257 | Log() << Verbose(0) << "===========CENTER ATOMS=========================" << endl;
|
---|
258 | Log() << Verbose(0) << " a - on origin" << endl;
|
---|
259 | Log() << Verbose(0) << " b - on center of gravity" << endl;
|
---|
260 | Log() << Verbose(0) << " c - within box with additional boundary" << endl;
|
---|
261 | Log() << Verbose(0) << " d - within given simulation box" << endl;
|
---|
262 | Log() << Verbose(0) << "all else - go back" << endl;
|
---|
263 | Log() << Verbose(0) << "===============================================" << endl;
|
---|
264 | Log() << Verbose(0) << "INPUT: ";
|
---|
265 | cin >> choice;
|
---|
266 |
|
---|
267 | switch (choice) {
|
---|
268 | default:
|
---|
269 | Log() << Verbose(0) << "Not a valid choice." << endl;
|
---|
270 | break;
|
---|
271 | case 'a':
|
---|
272 | Log() << Verbose(0) << "Centering atoms in config file on origin." << endl;
|
---|
273 | mol->CenterOrigin();
|
---|
274 | break;
|
---|
275 | case 'b':
|
---|
276 | Log() << Verbose(0) << "Centering atoms in config file on center of gravity." << endl;
|
---|
277 | mol->CenterPeriodic();
|
---|
278 | break;
|
---|
279 | case 'c':
|
---|
280 | Log() << Verbose(0) << "Centering atoms in config file within given additional boundary." << endl;
|
---|
281 | for (int i=0;i<NDIM;i++) {
|
---|
282 | Log() << Verbose(0) << "Enter axis " << i << " boundary: ";
|
---|
283 | cin >> y[i];
|
---|
284 | }
|
---|
285 | mol->CenterEdge(&x); // make every coordinate positive
|
---|
286 | mol->Center += y; // translate by boundary
|
---|
287 | helper = (2*y)+x;
|
---|
288 | mol->SetBoxDimension(&helper); // update Box of atoms by boundary
|
---|
289 | break;
|
---|
290 | case 'd':
|
---|
291 | Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl;
|
---|
292 | for (int i=0;i<NDIM;i++) {
|
---|
293 | Log() << Verbose(0) << "Enter axis " << i << " boundary: ";
|
---|
294 | cin >> x[i];
|
---|
295 | }
|
---|
296 | // update Box of atoms by boundary
|
---|
297 | mol->SetBoxDimension(&x);
|
---|
298 | // center
|
---|
299 | mol->CenterInBox();
|
---|
300 | break;
|
---|
301 | }
|
---|
302 | };
|
---|
303 |
|
---|
304 | /** Submenu for aligning the atoms in the molecule.
|
---|
305 | * \param *periode periodentafel
|
---|
306 | * \param *mol molecule with all the atoms
|
---|
307 | */
|
---|
308 | void oldmenu::AlignAtoms(periodentafel *periode, molecule *mol)
|
---|
309 | {
|
---|
310 | atom *first, *second, *third;
|
---|
311 | Vector x,n;
|
---|
312 | char choice; // menu choice char
|
---|
313 |
|
---|
314 | Log() << Verbose(0) << "===========ALIGN ATOMS=========================" << endl;
|
---|
315 | Log() << Verbose(0) << " a - state three atoms defining align plane" << endl;
|
---|
316 | Log() << Verbose(0) << " b - state alignment vector" << endl;
|
---|
317 | Log() << Verbose(0) << " c - state two atoms in alignment direction" << endl;
|
---|
318 | Log() << Verbose(0) << " d - align automatically by least square fit" << endl;
|
---|
319 | Log() << Verbose(0) << "all else - go back" << endl;
|
---|
320 | Log() << Verbose(0) << "===============================================" << endl;
|
---|
321 | Log() << Verbose(0) << "INPUT: ";
|
---|
322 | cin >> choice;
|
---|
323 |
|
---|
324 | switch (choice) {
|
---|
325 | default:
|
---|
326 | case 'a': // three atoms defining mirror plane
|
---|
327 | first = mol->AskAtom("Enter first atom: ");
|
---|
328 | second = mol->AskAtom("Enter second atom: ");
|
---|
329 | third = mol->AskAtom("Enter third atom: ");
|
---|
330 |
|
---|
331 | n = Plane(first->x,second->x,third->x).getNormal();
|
---|
332 | break;
|
---|
333 | case 'b': // normal vector of mirror plane
|
---|
334 | {
|
---|
335 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
336 | dialog->queryVector("Enter normal vector of mirror plane.",&n,World::getInstance().getDomain(),false);
|
---|
337 | dialog->display();
|
---|
338 | delete dialog;
|
---|
339 | n.Normalize();
|
---|
340 | }
|
---|
341 | break;
|
---|
342 |
|
---|
343 | case 'c': // three atoms defining mirror plane
|
---|
344 | first = mol->AskAtom("Enter first atom: ");
|
---|
345 | second = mol->AskAtom("Enter second atom: ");
|
---|
346 |
|
---|
347 | n = first->x - second->x;
|
---|
348 | n.Normalize();
|
---|
349 | break;
|
---|
350 | case 'd':
|
---|
351 | char shorthand[4];
|
---|
352 | Vector a;
|
---|
353 | struct lsq_params param;
|
---|
354 | do {
|
---|
355 | fprintf(stdout, "Enter the element of atoms to be chosen: ");
|
---|
356 | fscanf(stdin, "%3s", shorthand);
|
---|
357 | } while ((param.type = periode->FindElement(shorthand)) == NULL);
|
---|
358 | Log() << Verbose(0) << "Element is " << param.type->name << endl;
|
---|
359 | mol->GetAlignvector(¶m);
|
---|
360 | for (int i=NDIM;i--;) {
|
---|
361 | x[i] = gsl_vector_get(param.x,i);
|
---|
362 | n[i] = gsl_vector_get(param.x,i+NDIM);
|
---|
363 | }
|
---|
364 | gsl_vector_free(param.x);
|
---|
365 | Log() << Verbose(0) << "Offset vector: " << x << endl;
|
---|
366 | n.Normalize();
|
---|
367 | break;
|
---|
368 | };
|
---|
369 | Log() << Verbose(0) << "Alignment vector: " << n << endl;
|
---|
370 | mol->Align(&n);
|
---|
371 | };
|
---|
372 |
|
---|
373 | /** Submenu for mirroring the atoms in the molecule.
|
---|
374 | * \param *mol molecule with all the atoms
|
---|
375 | */
|
---|
376 | void oldmenu::MirrorAtoms(molecule *mol)
|
---|
377 | {
|
---|
378 | atom *first, *second, *third;
|
---|
379 | Vector n;
|
---|
380 | char choice; // menu choice char
|
---|
381 |
|
---|
382 | Log() << Verbose(0) << "===========MIRROR ATOMS=========================" << endl;
|
---|
383 | Log() << Verbose(0) << " a - state three atoms defining mirror plane" << endl;
|
---|
384 | Log() << Verbose(0) << " b - state normal vector of mirror plane" << endl;
|
---|
385 | Log() << Verbose(0) << " c - state two atoms in normal direction" << endl;
|
---|
386 | Log() << Verbose(0) << "all else - go back" << endl;
|
---|
387 | Log() << Verbose(0) << "===============================================" << endl;
|
---|
388 | Log() << Verbose(0) << "INPUT: ";
|
---|
389 | cin >> choice;
|
---|
390 |
|
---|
391 | switch (choice) {
|
---|
392 | default:
|
---|
393 | case 'a': // three atoms defining mirror plane
|
---|
394 | first = mol->AskAtom("Enter first atom: ");
|
---|
395 | second = mol->AskAtom("Enter second atom: ");
|
---|
396 | third = mol->AskAtom("Enter third atom: ");
|
---|
397 |
|
---|
398 | n = Plane(first->x,second->x,third->x).getNormal();
|
---|
399 | break;
|
---|
400 | case 'b': // normal vector of mirror plane
|
---|
401 | {
|
---|
402 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
403 | dialog->queryVector("Enter normal vector of mirror plane.",&n,World::getInstance().getDomain(),false);
|
---|
404 | dialog->display();
|
---|
405 | delete dialog;
|
---|
406 | n.Normalize();
|
---|
407 | }
|
---|
408 | break;
|
---|
409 |
|
---|
410 | case 'c': // three atoms defining mirror plane
|
---|
411 | first = mol->AskAtom("Enter first atom: ");
|
---|
412 | second = mol->AskAtom("Enter second atom: ");
|
---|
413 |
|
---|
414 | n = first->x - second->x;
|
---|
415 | n.Normalize();
|
---|
416 | break;
|
---|
417 | };
|
---|
418 | Log() << Verbose(0) << "Normal vector: " << n << endl;
|
---|
419 | mol->Mirror((const Vector *)&n);
|
---|
420 | };
|
---|
421 |
|
---|
422 | /** Submenu for removing the atoms from the molecule.
|
---|
423 | * \param *mol molecule with all the atoms
|
---|
424 | */
|
---|
425 | void oldmenu::RemoveAtoms(molecule *mol)
|
---|
426 | {
|
---|
427 | atom *second;
|
---|
428 | int axis;
|
---|
429 | double tmp1, tmp2;
|
---|
430 | char choice; // menu choice char
|
---|
431 |
|
---|
432 | Log() << Verbose(0) << "===========REMOVE ATOMS=========================" << endl;
|
---|
433 | Log() << Verbose(0) << " a - state atom for removal by number" << endl;
|
---|
434 | Log() << Verbose(0) << " b - keep only in radius around atom" << endl;
|
---|
435 | Log() << Verbose(0) << " c - remove this with one axis greater value" << endl;
|
---|
436 | Log() << Verbose(0) << "all else - go back" << endl;
|
---|
437 | Log() << Verbose(0) << "===============================================" << endl;
|
---|
438 | Log() << Verbose(0) << "INPUT: ";
|
---|
439 | cin >> choice;
|
---|
440 |
|
---|
441 | switch (choice) {
|
---|
442 | default:
|
---|
443 | case 'a':
|
---|
444 | if (mol->RemoveAtom(mol->AskAtom("Enter number of atom within molecule: ")))
|
---|
445 | Log() << Verbose(1) << "Atom removed." << endl;
|
---|
446 | else
|
---|
447 | Log() << Verbose(1) << "Atom not found." << endl;
|
---|
448 | break;
|
---|
449 | case 'b':
|
---|
450 | {
|
---|
451 | second = mol->AskAtom("Enter number of atom as reference point: ");
|
---|
452 | Log() << Verbose(0) << "Enter radius: ";
|
---|
453 | cin >> tmp1;
|
---|
454 | molecule::iterator runner;
|
---|
455 | for (molecule::iterator iter = mol->begin(); iter != mol->end(); ) {
|
---|
456 | runner = iter++;
|
---|
457 | if ((*runner)->x.DistanceSquared((*runner)->x) > tmp1*tmp1) // distance to first above radius ...
|
---|
458 | mol->RemoveAtom((*runner));
|
---|
459 | }
|
---|
460 | }
|
---|
461 | break;
|
---|
462 | case 'c':
|
---|
463 | Log() << Verbose(0) << "Which axis is it: ";
|
---|
464 | cin >> axis;
|
---|
465 | Log() << Verbose(0) << "Lower boundary: ";
|
---|
466 | cin >> tmp1;
|
---|
467 | Log() << Verbose(0) << "Upper boundary: ";
|
---|
468 | cin >> tmp2;
|
---|
469 | molecule::iterator runner;
|
---|
470 | for (molecule::iterator iter = mol->begin(); iter != mol->end(); ) {
|
---|
471 | runner = iter++;
|
---|
472 | if (((*runner)->x[axis] < tmp1) || ((*runner)->x[axis] > tmp2)) {// out of boundary ...
|
---|
473 | //Log() << Verbose(0) << "Atom " << *(*runner) << " with " << (*runner)->x.x[axis] << " on axis " << axis << " is out of bounds [" << tmp1 << "," << tmp2 << "]." << endl;
|
---|
474 | mol->RemoveAtom((*runner));
|
---|
475 | }
|
---|
476 | }
|
---|
477 | break;
|
---|
478 | };
|
---|
479 | //mol->Output();
|
---|
480 | choice = 'r';
|
---|
481 | };
|
---|
482 |
|
---|
483 | /** Submenu for measuring out the atoms in the molecule.
|
---|
484 | * \param *periode periodentafel
|
---|
485 | * \param *mol molecule with all the atoms
|
---|
486 | */
|
---|
487 | void oldmenu::MeasureAtoms(periodentafel *periode, molecule *mol, config *configuration)
|
---|
488 | {
|
---|
489 | atom *first, *second, *third;
|
---|
490 | Vector x,y;
|
---|
491 | double min[256], tmp1, tmp2, tmp3;
|
---|
492 | int Z;
|
---|
493 | char choice; // menu choice char
|
---|
494 |
|
---|
495 | Log() << Verbose(0) << "===========MEASURE ATOMS=========================" << endl;
|
---|
496 | Log() << Verbose(0) << " a - calculate bond length between one atom and all others" << endl;
|
---|
497 | Log() << Verbose(0) << " b - calculate bond length between two atoms" << endl;
|
---|
498 | Log() << Verbose(0) << " c - calculate bond angle" << endl;
|
---|
499 | Log() << Verbose(0) << " d - calculate principal axis of the system" << endl;
|
---|
500 | Log() << Verbose(0) << " e - calculate volume of the convex envelope" << endl;
|
---|
501 | Log() << Verbose(0) << " f - calculate temperature from current velocity" << endl;
|
---|
502 | Log() << Verbose(0) << " g - output all temperatures per step from velocities" << endl;
|
---|
503 | Log() << Verbose(0) << "all else - go back" << endl;
|
---|
504 | Log() << Verbose(0) << "===============================================" << endl;
|
---|
505 | Log() << Verbose(0) << "INPUT: ";
|
---|
506 | cin >> choice;
|
---|
507 |
|
---|
508 | switch(choice) {
|
---|
509 | default:
|
---|
510 | Log() << Verbose(1) << "Not a valid choice." << endl;
|
---|
511 | break;
|
---|
512 | case 'a':
|
---|
513 | first = mol->AskAtom("Enter first atom: ");
|
---|
514 | for (int i=MAX_ELEMENTS;i--;)
|
---|
515 | min[i] = 0.;
|
---|
516 |
|
---|
517 | for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
|
---|
518 | Z = (*iter)->type->Z;
|
---|
519 | tmp1 = 0.;
|
---|
520 | if (first != (*iter)) {
|
---|
521 | x = first->x - (*iter)->x;
|
---|
522 | tmp1 = x.Norm();
|
---|
523 | }
|
---|
524 | if ((tmp1 != 0.) && ((min[Z] == 0.) || (tmp1 < min[Z]))) min[Z] = tmp1;
|
---|
525 | //Log() << Verbose(0) << "Bond length between Atom " << first->nr << " and " << ((*iter)->nr << ": " << tmp1 << " a.u." << endl;
|
---|
526 | }
|
---|
527 | for (int i=MAX_ELEMENTS;i--;)
|
---|
528 | if (min[i] != 0.) Log() << Verbose(0) << "Minimum Bond length between " << first->type->name << " Atom " << first->nr << " and next Ion of type " << (periode->FindElement(i))->name << ": " << min[i] << " a.u." << endl;
|
---|
529 | break;
|
---|
530 |
|
---|
531 | case 'b':
|
---|
532 | first = mol->AskAtom("Enter first atom: ");
|
---|
533 | second = mol->AskAtom("Enter second atom: ");
|
---|
534 | for (int i=NDIM;i--;)
|
---|
535 | min[i] = 0.;
|
---|
536 | x = first->x - second->x;
|
---|
537 | tmp1 = x.Norm();
|
---|
538 | Log() << Verbose(1) << "Distance vector is " << x << "." << "/n"
|
---|
539 | << "Norm of distance is " << tmp1 << "." << endl;
|
---|
540 | break;
|
---|
541 |
|
---|
542 | case 'c':
|
---|
543 | Log() << Verbose(0) << "Evaluating bond angle between three - first, central, last - atoms." << endl;
|
---|
544 | first = mol->AskAtom("Enter first atom: ");
|
---|
545 | second = mol->AskAtom("Enter central atom: ");
|
---|
546 | third = mol->AskAtom("Enter last atom: ");
|
---|
547 | tmp1 = tmp2 = tmp3 = 0.;
|
---|
548 | x = first->x - second->x;
|
---|
549 | y = third->x - second->x;
|
---|
550 | Log() << Verbose(0) << "Bond angle between first atom Nr." << first->nr << ", central atom Nr." << second->nr << " and last atom Nr." << third->nr << ": ";
|
---|
551 | Log() << Verbose(0) << (acos(x.ScalarProduct(y)/(y.Norm()*x.Norm()))/M_PI*180.) << " degrees" << endl;
|
---|
552 | break;
|
---|
553 | case 'd':
|
---|
554 | Log() << Verbose(0) << "Evaluating prinicipal axis." << endl;
|
---|
555 | Log() << Verbose(0) << "Shall we rotate? [0/1]: ";
|
---|
556 | cin >> Z;
|
---|
557 | if ((Z >=0) && (Z <=1))
|
---|
558 | mol->PrincipalAxisSystem((bool)Z);
|
---|
559 | else
|
---|
560 | mol->PrincipalAxisSystem(false);
|
---|
561 | break;
|
---|
562 | case 'e':
|
---|
563 | {
|
---|
564 | Log() << Verbose(0) << "Evaluating volume of the convex envelope.";
|
---|
565 | class Tesselation *TesselStruct = NULL;
|
---|
566 | const LinkedCell *LCList = NULL;
|
---|
567 | LCList = new LinkedCell(mol, 10.);
|
---|
568 | FindConvexBorder(mol, TesselStruct, LCList, NULL);
|
---|
569 | double clustervolume = VolumeOfConvexEnvelope(TesselStruct, configuration);
|
---|
570 | Log() << Verbose(0) << "The tesselated surface area is " << clustervolume << "." << endl;\
|
---|
571 | delete(LCList);
|
---|
572 | delete(TesselStruct);
|
---|
573 | }
|
---|
574 | break;
|
---|
575 | case 'f':
|
---|
576 | mol->OutputTemperatureFromTrajectories((ofstream *)&cout, mol->MDSteps-1, mol->MDSteps);
|
---|
577 | break;
|
---|
578 | case 'g':
|
---|
579 | {
|
---|
580 | char filename[255];
|
---|
581 | Log() << Verbose(0) << "Please enter filename: " << endl;
|
---|
582 | cin >> filename;
|
---|
583 | Log() << Verbose(1) << "Storing temperatures in " << filename << "." << endl;
|
---|
584 | ofstream *output = new ofstream(filename, ios::trunc);
|
---|
585 | if (!mol->OutputTemperatureFromTrajectories(output, 0, mol->MDSteps))
|
---|
586 | Log() << Verbose(2) << "File could not be written." << endl;
|
---|
587 | else
|
---|
588 | Log() << Verbose(2) << "File stored." << endl;
|
---|
589 | output->close();
|
---|
590 | delete(output);
|
---|
591 | }
|
---|
592 | break;
|
---|
593 | }
|
---|
594 | };
|
---|
595 |
|
---|
596 | /** Submenu for measuring out the atoms in the molecule.
|
---|
597 | * \param *mol molecule with all the atoms
|
---|
598 | * \param *configuration configuration structure for the to be written config files of all fragments
|
---|
599 | */
|
---|
600 | void oldmenu::FragmentAtoms(molecule *mol, config *configuration)
|
---|
601 | {
|
---|
602 | int Order1;
|
---|
603 | clock_t start, end;
|
---|
604 |
|
---|
605 | Log() << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl;
|
---|
606 | Log() << Verbose(0) << "What's the desired bond order: ";
|
---|
607 | cin >> Order1;
|
---|
608 | if (mol->hasBondStructure()) {
|
---|
609 | start = clock();
|
---|
610 | mol->FragmentMolecule(Order1, configuration);
|
---|
611 | end = clock();
|
---|
612 | Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
|
---|
613 | } else
|
---|
614 | Log() << Verbose(0) << "Connection matrix has not yet been generated!" << endl;
|
---|
615 | };
|
---|
616 |
|
---|
617 | /********************************************** Submenu routine **************************************/
|
---|
618 |
|
---|
619 | /** Submenu for manipulating atoms.
|
---|
620 | * \param *periode periodentafel
|
---|
621 | * \param *molecules list of molecules whose atoms are to be manipulated
|
---|
622 | */
|
---|
623 | void oldmenu::ManipulateAtoms(periodentafel *periode, MoleculeListClass *molecules, config *configuration)
|
---|
624 | {
|
---|
625 | atom *first, *second;
|
---|
626 | molecule *mol = NULL;
|
---|
627 | Vector x,y,z,n; // coordinates for absolute point in cell volume
|
---|
628 | double *factor; // unit factor if desired
|
---|
629 | double bond, minBond;
|
---|
630 | char choice; // menu choice char
|
---|
631 | bool valid;
|
---|
632 |
|
---|
633 | Log() << Verbose(0) << "=========MANIPULATE ATOMS======================" << endl;
|
---|
634 | Log() << Verbose(0) << "a - add an atom" << endl;
|
---|
635 | Log() << Verbose(0) << "r - remove an atom" << endl;
|
---|
636 | Log() << Verbose(0) << "b - scale a bond between atoms" << endl;
|
---|
637 | Log() << Verbose(0) << "u - change an atoms element" << endl;
|
---|
638 | Log() << Verbose(0) << "l - measure lengths, angles, ... for an atom" << endl;
|
---|
639 | Log() << Verbose(0) << "all else - go back" << endl;
|
---|
640 | Log() << Verbose(0) << "===============================================" << endl;
|
---|
641 | if (molecules->NumberOfActiveMolecules() > 1)
|
---|
642 | eLog() << Verbose(2) << "There is more than one molecule active! Atoms will be added to each." << endl;
|
---|
643 | Log() << Verbose(0) << "INPUT: ";
|
---|
644 | cin >> choice;
|
---|
645 |
|
---|
646 | switch (choice) {
|
---|
647 | default:
|
---|
648 | Log() << Verbose(0) << "Not a valid choice." << endl;
|
---|
649 | break;
|
---|
650 |
|
---|
651 | case 'a': // add atom
|
---|
652 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
653 | if ((*ListRunner)->ActiveFlag) {
|
---|
654 | mol = *ListRunner;
|
---|
655 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
|
---|
656 | AddAtoms(periode, mol);
|
---|
657 | }
|
---|
658 | break;
|
---|
659 |
|
---|
660 | case 'b': // scale a bond
|
---|
661 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
662 | if ((*ListRunner)->ActiveFlag) {
|
---|
663 | mol = *ListRunner;
|
---|
664 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
|
---|
665 | Log() << Verbose(0) << "Scaling bond length between two atoms." << endl;
|
---|
666 | first = mol->AskAtom("Enter first (fixed) atom: ");
|
---|
667 | second = mol->AskAtom("Enter second (shifting) atom: ");
|
---|
668 | minBond = 0.;
|
---|
669 | for (int i=NDIM;i--;)
|
---|
670 | minBond += (first->x[i]-second->x[i])*(first->x[i] - second->x[i]);
|
---|
671 | minBond = sqrt(minBond);
|
---|
672 | Log() << Verbose(0) << "Current Bond length between " << first->type->name << " Atom " << first->nr << " and " << second->type->name << " Atom " << second->nr << ": " << minBond << " a.u." << endl;
|
---|
673 | Log() << Verbose(0) << "Enter new bond length [a.u.]: ";
|
---|
674 | cin >> bond;
|
---|
675 | for (int i=NDIM;i--;) {
|
---|
676 | second->x[i] -= (second->x[i]-first->x[i])/minBond*(minBond-bond);
|
---|
677 | }
|
---|
678 | //Log() << Verbose(0) << "New coordinates of Atom " << second->nr << " are: ";
|
---|
679 | //second->Output(second->type->No, 1);
|
---|
680 | }
|
---|
681 | break;
|
---|
682 |
|
---|
683 | case 'c': // unit scaling of the metric
|
---|
684 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
685 | if ((*ListRunner)->ActiveFlag) {
|
---|
686 | mol = *ListRunner;
|
---|
687 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
|
---|
688 | Log() << Verbose(0) << "Angstroem -> Bohrradius: 1.8897261\t\tBohrradius -> Angstroem: 0.52917721" << endl;
|
---|
689 | Log() << Verbose(0) << "Enter three factors: ";
|
---|
690 | factor = new double[NDIM];
|
---|
691 | cin >> factor[0];
|
---|
692 | cin >> factor[1];
|
---|
693 | cin >> factor[2];
|
---|
694 | valid = true;
|
---|
695 | mol->Scale((const double ** const)&factor);
|
---|
696 | delete[](factor);
|
---|
697 | }
|
---|
698 | break;
|
---|
699 |
|
---|
700 | case 'l': // measure distances or angles
|
---|
701 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
702 | if ((*ListRunner)->ActiveFlag) {
|
---|
703 | mol = *ListRunner;
|
---|
704 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
|
---|
705 | MeasureAtoms(periode, mol, configuration);
|
---|
706 | }
|
---|
707 | break;
|
---|
708 |
|
---|
709 | case 'r': // remove atom
|
---|
710 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
711 | if ((*ListRunner)->ActiveFlag) {
|
---|
712 | mol = *ListRunner;
|
---|
713 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
|
---|
714 | RemoveAtoms(mol);
|
---|
715 | }
|
---|
716 | break;
|
---|
717 |
|
---|
718 | case 'u': // change an atom's element
|
---|
719 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
720 | if ((*ListRunner)->ActiveFlag) {
|
---|
721 | int Z;
|
---|
722 | mol = *ListRunner;
|
---|
723 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
|
---|
724 | first = NULL;
|
---|
725 | do {
|
---|
726 | Log() << Verbose(0) << "Change the element of which atom: ";
|
---|
727 | cin >> Z;
|
---|
728 | } while ((first = mol->FindAtom(Z)) == NULL);
|
---|
729 | Log() << Verbose(0) << "New element by atomic number Z: ";
|
---|
730 | cin >> Z;
|
---|
731 | first->setType(Z);
|
---|
732 | Log() << Verbose(0) << "Atom " << first->nr << "'s element is " << first->type->name << "." << endl;
|
---|
733 | }
|
---|
734 | break;
|
---|
735 | }
|
---|
736 | };
|
---|
737 |
|
---|
738 | void oldmenu::duplicateCell(MoleculeListClass *molecules, config *configuration) {
|
---|
739 | molecule *mol = NULL;
|
---|
740 | int axis,faktor,count,j;
|
---|
741 | atom *first = NULL;
|
---|
742 | const element **Elements;
|
---|
743 | Vector x,y;
|
---|
744 | Vector **vectors;
|
---|
745 |
|
---|
746 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
747 | if ((*ListRunner)->ActiveFlag) {
|
---|
748 | mol = *ListRunner;
|
---|
749 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
|
---|
750 | Log() << Verbose(0) << "State the axis [(+-)123]: ";
|
---|
751 | cin >> axis;
|
---|
752 | Log() << Verbose(0) << "State the factor: ";
|
---|
753 | cin >> faktor;
|
---|
754 | if (mol->getAtomCount() != 0) { // if there is more than none
|
---|
755 | count = mol->getAtomCount(); // is changed becausing of adding, thus has to be stored away beforehand
|
---|
756 | Elements = new const element *[count];
|
---|
757 | vectors = new Vector *[count];
|
---|
758 | j = 0;
|
---|
759 | for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
|
---|
760 | Elements[j] = (*iter)->type;
|
---|
761 | vectors[j] = &(*iter)->x;
|
---|
762 | j++;
|
---|
763 | }
|
---|
764 | if (count != j)
|
---|
765 | eLog() << Verbose(1) << "AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl;
|
---|
766 | x.Zero();
|
---|
767 | y.Zero();
|
---|
768 | y[abs(axis)-1] = World::getInstance().getDomain()[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude
|
---|
769 | for (int i=1;i<faktor;i++) { // then add this list with respective translation factor times
|
---|
770 | x += y; // per factor one cell width further
|
---|
771 | for (int k=count;k--;) { // go through every atom of the original cell
|
---|
772 | first = World::getInstance().createAtom(); // create a new body
|
---|
773 | first->x = (*vectors[k]) + x; // use coordinate of original atom
|
---|
774 | first->type = Elements[k]; // insert original element
|
---|
775 | mol->AddAtom(first); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)
|
---|
776 | }
|
---|
777 | }
|
---|
778 | if (mol->hasBondStructure())
|
---|
779 | mol->CreateAdjacencyList(mol->BondDistance, configuration->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
|
---|
780 | // free memory
|
---|
781 | delete[](Elements);
|
---|
782 | delete[](vectors);
|
---|
783 | // correct cell size
|
---|
784 | if (axis < 0) { // if sign was negative, we have to translate everything
|
---|
785 | x = y;
|
---|
786 | x.Scale(-(faktor-1));
|
---|
787 | mol->Translate(&x);
|
---|
788 | }
|
---|
789 | World::getInstance().getDomain()[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;
|
---|
790 | }
|
---|
791 | }
|
---|
792 | }
|
---|
793 |
|
---|
794 | /** Submenu for manipulating molecules.
|
---|
795 | * \param *periode periodentafel
|
---|
796 | * \param *molecules list of molecule to manipulate
|
---|
797 | */
|
---|
798 | void oldmenu::ManipulateMolecules(periodentafel *periode, MoleculeListClass *molecules, config *configuration)
|
---|
799 | {
|
---|
800 | Vector x,y,z,n; // coordinates for absolute point in cell volume
|
---|
801 | char choice; // menu choice char
|
---|
802 | molecule *mol = NULL;
|
---|
803 | MoleculeLeafClass *Subgraphs = NULL;
|
---|
804 |
|
---|
805 | Log() << Verbose(0) << "=========MANIPULATE GLOBALLY===================" << endl;
|
---|
806 | Log() << Verbose(0) << "c - scale by unit transformation" << endl;
|
---|
807 | Log() << Verbose(0) << "d - duplicate molecule/periodic cell" << endl;
|
---|
808 | Log() << Verbose(0) << "f - fragment molecule many-body bond order style" << endl;
|
---|
809 | Log() << Verbose(0) << "g - center atoms in box" << endl;
|
---|
810 | Log() << Verbose(0) << "i - realign molecule" << endl;
|
---|
811 | Log() << Verbose(0) << "m - mirror all molecules" << endl;
|
---|
812 | Log() << Verbose(0) << "o - create connection matrix" << endl;
|
---|
813 | Log() << Verbose(0) << "t - translate molecule by vector" << endl;
|
---|
814 | Log() << Verbose(0) << "all else - go back" << endl;
|
---|
815 | Log() << Verbose(0) << "===============================================" << endl;
|
---|
816 | if (molecules->NumberOfActiveMolecules() > 1)
|
---|
817 | eLog() << Verbose(2) << "There is more than one molecule active! Atoms will be added to each." << endl;
|
---|
818 | Log() << Verbose(0) << "INPUT: ";
|
---|
819 | cin >> choice;
|
---|
820 |
|
---|
821 | switch (choice) {
|
---|
822 | default:
|
---|
823 | Log() << Verbose(0) << "Not a valid choice." << endl;
|
---|
824 | break;
|
---|
825 |
|
---|
826 | case 'd': // duplicate the periodic cell along a given axis, given times
|
---|
827 | duplicateCell(molecules, configuration);
|
---|
828 | break;
|
---|
829 |
|
---|
830 | case 'f':
|
---|
831 | FragmentAtoms(mol, configuration);
|
---|
832 | break;
|
---|
833 |
|
---|
834 | case 'g': // center the atoms
|
---|
835 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
836 | if ((*ListRunner)->ActiveFlag) {
|
---|
837 | mol = *ListRunner;
|
---|
838 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
|
---|
839 | CenterAtoms(mol);
|
---|
840 | }
|
---|
841 | break;
|
---|
842 |
|
---|
843 | case 'i': // align all atoms
|
---|
844 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
845 | if ((*ListRunner)->ActiveFlag) {
|
---|
846 | mol = *ListRunner;
|
---|
847 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
|
---|
848 | AlignAtoms(periode, mol);
|
---|
849 | }
|
---|
850 | break;
|
---|
851 |
|
---|
852 | case 'm': // mirror atoms along a given axis
|
---|
853 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
854 | if ((*ListRunner)->ActiveFlag) {
|
---|
855 | mol = *ListRunner;
|
---|
856 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
|
---|
857 | MirrorAtoms(mol);
|
---|
858 | }
|
---|
859 | break;
|
---|
860 |
|
---|
861 | case 'o': // create the connection matrix
|
---|
862 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
863 | if ((*ListRunner)->ActiveFlag) {
|
---|
864 | mol = *ListRunner;
|
---|
865 | double bonddistance;
|
---|
866 | clock_t start,end;
|
---|
867 | Log() << Verbose(0) << "What's the maximum bond distance: ";
|
---|
868 | cin >> bonddistance;
|
---|
869 | start = clock();
|
---|
870 | mol->CreateAdjacencyList(bonddistance, configuration->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
|
---|
871 | end = clock();
|
---|
872 | Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
|
---|
873 | }
|
---|
874 | break;
|
---|
875 |
|
---|
876 | case 't': // translate all atoms
|
---|
877 | for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
878 | if ((*ListRunner)->ActiveFlag) {
|
---|
879 | mol = *ListRunner;
|
---|
880 | Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
|
---|
881 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
882 | dialog->queryVector("Enter translation vector.",&x,World::getInstance().getDomain(),false);
|
---|
883 | if(dialog->display()){
|
---|
884 | mol->Center += x;
|
---|
885 | }
|
---|
886 | delete dialog;
|
---|
887 | }
|
---|
888 | break;
|
---|
889 | }
|
---|
890 | // Free all
|
---|
891 | if (Subgraphs != NULL) { // free disconnected subgraph list of DFS analysis was performed
|
---|
892 | while (Subgraphs->next != NULL) {
|
---|
893 | Subgraphs = Subgraphs->next;
|
---|
894 | delete(Subgraphs->previous);
|
---|
895 | }
|
---|
896 | delete(Subgraphs);
|
---|
897 | }
|
---|
898 | };
|
---|
899 |
|
---|
900 |
|
---|
901 | void oldmenu::SimpleAddMolecules(MoleculeListClass *molecules) {
|
---|
902 | molecule *srcmol = NULL, *destmol = NULL;
|
---|
903 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
904 | dialog->queryMolecule("molecule-by-id",&destmol, MapOfActions::getInstance().getDescription("molecule-by-id"));
|
---|
905 | dialog->queryMolecule("molecule-by-id",&srcmol, MapOfActions::getInstance().getDescription("molecule-by-id"));
|
---|
906 | if(dialog->display()) {
|
---|
907 | molecules->SimpleAdd(srcmol, destmol);
|
---|
908 | }
|
---|
909 | else {
|
---|
910 | Log() << Verbose(0) << "Adding of molecules canceled" << endl;
|
---|
911 | }
|
---|
912 | delete dialog;
|
---|
913 | }
|
---|
914 |
|
---|
915 | void oldmenu::embeddMolecules(MoleculeListClass *molecules) {
|
---|
916 | molecule *srcmol = NULL, *destmol = NULL;
|
---|
917 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
918 | dialog->queryMolecule("molecule-by-id",&destmol, MapOfActions::getInstance().getDescription("molecule-by-id"));
|
---|
919 | dialog->queryMolecule("molecule-by-id",&srcmol, MapOfActions::getInstance().getDescription("molecule-by-id"));
|
---|
920 | if(dialog->display()) {
|
---|
921 | molecules->EmbedMerge(destmol, srcmol);
|
---|
922 | }
|
---|
923 | else {
|
---|
924 | Log() << Verbose(0) << "embedding of molecules canceled" << endl;
|
---|
925 | }
|
---|
926 |
|
---|
927 |
|
---|
928 | }
|
---|
929 |
|
---|
930 | void oldmenu::multiMergeMolecules(MoleculeListClass *molecules) {
|
---|
931 | int nr;
|
---|
932 | molecule *mol = NULL;
|
---|
933 | do {
|
---|
934 | Log() << Verbose(0) << "Enter index of molecule to merge into: ";
|
---|
935 | cin >> nr;
|
---|
936 | mol = molecules->ReturnIndex(nr);
|
---|
937 | } while ((mol == NULL) && (nr != -1));
|
---|
938 | if (nr != -1) {
|
---|
939 | int N = molecules->ListOfMolecules.size()-1;
|
---|
940 | int *src = new int(N);
|
---|
941 | for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
|
---|
942 | if ((*ListRunner)->IndexNr != nr)
|
---|
943 | src[N++] = (*ListRunner)->IndexNr;
|
---|
944 | molecules->SimpleMultiMerge(mol, src, N);
|
---|
945 | delete[](src);
|
---|
946 | }
|
---|
947 | }
|
---|
948 |
|
---|
949 | void oldmenu::simpleMergeMolecules(MoleculeListClass *molecules) {
|
---|
950 | int src, dest;
|
---|
951 | molecule *srcmol = NULL, *destmol = NULL;
|
---|
952 | {
|
---|
953 | do {
|
---|
954 | Log() << Verbose(0) << "Enter index of destination molecule: ";
|
---|
955 | cin >> dest;
|
---|
956 | destmol = molecules->ReturnIndex(dest);
|
---|
957 | } while ((destmol == NULL) && (dest != -1));
|
---|
958 | do {
|
---|
959 | Log() << Verbose(0) << "Enter index of source molecule to merge into: ";
|
---|
960 | cin >> src;
|
---|
961 | srcmol = molecules->ReturnIndex(src);
|
---|
962 | } while ((srcmol == NULL) && (src != -1));
|
---|
963 | if ((src != -1) && (dest != -1))
|
---|
964 | molecules->SimpleMerge(srcmol, destmol);
|
---|
965 | }
|
---|
966 | }
|
---|
967 |
|
---|
968 | /** Submenu for merging molecules.
|
---|
969 | * \param *periode periodentafel
|
---|
970 | * \param *molecules list of molecules to add to
|
---|
971 | */
|
---|
972 | void oldmenu::MergeMolecules(periodentafel *periode, MoleculeListClass *molecules)
|
---|
973 | {
|
---|
974 | TextMenu *MergeMoleculesMenu = new TextMenu(Log() << Verbose(0), "Merge Molecules");
|
---|
975 |
|
---|
976 | Action *simpleAddAction = new MethodAction("simpleAddAction",boost::bind(&oldmenu::SimpleAddMolecules,this,molecules),false);
|
---|
977 | new ActionMenuItem('a',"simple add of one molecule to another",MergeMoleculesMenu,simpleAddAction);
|
---|
978 |
|
---|
979 | Action *embeddAction = new MethodAction("embeddAction",boost::bind(&oldmenu::embeddMolecules,this,molecules),false);
|
---|
980 | new ActionMenuItem('e',"embedding merge of two molecules",MergeMoleculesMenu,embeddAction);
|
---|
981 |
|
---|
982 | Action *multiMergeAction = new MethodAction("multiMergeAction",boost::bind(&oldmenu::multiMergeMolecules,this,molecules),false);
|
---|
983 | new ActionMenuItem('m',"multi-merge of all molecules",MergeMoleculesMenu,multiMergeAction);
|
---|
984 |
|
---|
985 | Action *scatterMergeAction = new ErrorAction("scatterMergeAction","Not Implemented yet",false);
|
---|
986 | new ActionMenuItem('s',"scatter merge of two molecules",MergeMoleculesMenu,scatterMergeAction);
|
---|
987 |
|
---|
988 | Action *simpleMergeAction = new MethodAction("simpleMergeAction",boost::bind(&oldmenu::simpleMergeMolecules,this,molecules),false);
|
---|
989 | new ActionMenuItem('t',"simple merge of two molecules",MergeMoleculesMenu,simpleMergeAction);
|
---|
990 |
|
---|
991 | Action *returnAction = new MethodAction("returnAction",boost::bind(&TextMenu::doQuit,MergeMoleculesMenu),false);
|
---|
992 | MenuItem *returnItem = new ActionMenuItem('q',"return to Main menu",MergeMoleculesMenu,returnAction);
|
---|
993 |
|
---|
994 | MergeMoleculesMenu->addDefault(returnItem);
|
---|
995 |
|
---|
996 | MergeMoleculesMenu->display();
|
---|
997 | };
|
---|
998 |
|
---|
999 |
|
---|
1000 | /********************************************** Test routine **************************************/
|
---|
1001 |
|
---|
1002 | /** Is called always as option 'T' in the menu.
|
---|
1003 | * \param *molecules list of molecules
|
---|
1004 | */
|
---|
1005 | void oldmenu::testroutine(MoleculeListClass *molecules)
|
---|
1006 | {
|
---|
1007 | // the current test routine checks the functionality of the KeySet&Graph concept:
|
---|
1008 | // We want to have a multiindex (the KeySet) describing a unique subgraph
|
---|
1009 | int i, comp, counter=0;
|
---|
1010 |
|
---|
1011 | // create a clone
|
---|
1012 | molecule *mol = NULL;
|
---|
1013 | if (molecules->ListOfMolecules.size() != 0) // clone
|
---|
1014 | mol = (molecules->ListOfMolecules.front())->CopyMolecule();
|
---|
1015 | else {
|
---|
1016 | eLog() << Verbose(0) << "I don't have anything to test on ... ";
|
---|
1017 | performCriticalExit();
|
---|
1018 | return;
|
---|
1019 | }
|
---|
1020 |
|
---|
1021 | // generate some KeySets
|
---|
1022 | Log() << Verbose(0) << "Generating KeySets." << endl;
|
---|
1023 | KeySet TestSets[mol->getAtomCount()+1];
|
---|
1024 | i=1;
|
---|
1025 | for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
|
---|
1026 | for (int j=0;j<i;j++) {
|
---|
1027 | TestSets[j].insert((*iter)->nr);
|
---|
1028 | }
|
---|
1029 | i++;
|
---|
1030 | }
|
---|
1031 | Log() << Verbose(0) << "Testing insertion of already present item in KeySets." << endl;
|
---|
1032 | KeySetTestPair test;
|
---|
1033 | molecule::const_iterator iter = mol->begin();
|
---|
1034 | if (iter != mol->end()) {
|
---|
1035 | test = TestSets[mol->getAtomCount()-1].insert((*iter)->nr);
|
---|
1036 | if (test.second) {
|
---|
1037 | Log() << Verbose(1) << "Insertion worked?!" << endl;
|
---|
1038 | } else {
|
---|
1039 | Log() << Verbose(1) << "Insertion rejected: Present object is " << (*test.first) << "." << endl;
|
---|
1040 | }
|
---|
1041 | } else {
|
---|
1042 | eLog() << Verbose(1) << "No atoms to test double insertion." << endl;
|
---|
1043 | }
|
---|
1044 |
|
---|
1045 | // constructing Graph structure
|
---|
1046 | Log() << Verbose(0) << "Generating Subgraph class." << endl;
|
---|
1047 | Graph Subgraphs;
|
---|
1048 |
|
---|
1049 | // insert KeySets into Subgraphs
|
---|
1050 | Log() << Verbose(0) << "Inserting KeySets into Subgraph class." << endl;
|
---|
1051 | for (int j=0;j<mol->getAtomCount();j++) {
|
---|
1052 | Subgraphs.insert(GraphPair (TestSets[j],pair<int, double>(counter++, 1.)));
|
---|
1053 | }
|
---|
1054 | Log() << Verbose(0) << "Testing insertion of already present item in Subgraph." << endl;
|
---|
1055 | GraphTestPair test2;
|
---|
1056 | test2 = Subgraphs.insert(GraphPair (TestSets[mol->getAtomCount()],pair<int, double>(counter++, 1.)));
|
---|
1057 | if (test2.second) {
|
---|
1058 | Log() << Verbose(1) << "Insertion worked?!" << endl;
|
---|
1059 | } else {
|
---|
1060 | Log() << Verbose(1) << "Insertion rejected: Present object is " << (*(test2.first)).second.first << "." << endl;
|
---|
1061 | }
|
---|
1062 |
|
---|
1063 | // show graphs
|
---|
1064 | Log() << Verbose(0) << "Showing Subgraph's contents, checking that it's sorted." << endl;
|
---|
1065 | Graph::iterator A = Subgraphs.begin();
|
---|
1066 | while (A != Subgraphs.end()) {
|
---|
1067 | Log() << Verbose(0) << (*A).second.first << ": ";
|
---|
1068 | KeySet::iterator key = (*A).first.begin();
|
---|
1069 | comp = -1;
|
---|
1070 | while (key != (*A).first.end()) {
|
---|
1071 | if ((*key) > comp)
|
---|
1072 | Log() << Verbose(0) << (*key) << " ";
|
---|
1073 | else
|
---|
1074 | Log() << Verbose(0) << (*key) << "! ";
|
---|
1075 | comp = (*key);
|
---|
1076 | key++;
|
---|
1077 | }
|
---|
1078 | Log() << Verbose(0) << endl;
|
---|
1079 | A++;
|
---|
1080 | }
|
---|
1081 | World::getInstance().destroyMolecule(mol);
|
---|
1082 | };
|
---|
1083 |
|
---|
1084 | oldmenu::oldmenu()
|
---|
1085 | {
|
---|
1086 | // TODO Auto-generated constructor stub
|
---|
1087 | }
|
---|
1088 |
|
---|
1089 | oldmenu::~oldmenu()
|
---|
1090 | {
|
---|
1091 | // TODO Auto-generated destructor stub
|
---|
1092 | }
|
---|