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