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