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