source: molecuilder/src/menu.cpp@ c7dcff

Last change on this file since c7dcff was c7dcff, checked in by Tillmann Crueger <crueger@…>, 16 years ago

Made EditMoleculesMenu a Submenu inside the MainMenu

  • Property mode set to 100644
File size: 53.7 KB
Line 
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 "menu.hpp"
10#include "analysis_correlation.hpp"
11#include "atom.hpp"
12#include "bond.hpp"
13#include "bondgraph.hpp"
14#include "boundary.hpp"
15#include "config.hpp"
16#include "element.hpp"
17#include "ellipsoid.hpp"
18#include "helpers.hpp"
19#include "leastsquaremin.hpp"
20#include "linkedcell.hpp"
21#include "log.hpp"
22#include "memoryusageobserverunittest.hpp"
23#include "molecule.hpp"
24#include "periodentafel.hpp"
25
26#include "Menu/Menu.hpp"
27#include "Menu/TextMenu.hpp"
28#include "Menu/ActionMenuItem.hpp"
29#include "Menu/SeperatorItem.hpp"
30#include "Menu/DisplayMenuItem.hpp"
31#include "Menu/SubMenuItem.hpp"
32#include "Actions/MethodAction.hpp"
33#include "Views/StreamStringView.hpp"
34#include "Views/MethodStringView.hpp"
35
36
37#include <boost/bind.hpp>
38
39/* copied methods for refactoring */
40/*TODO: Move these methods inside menu class
41 * and restructure menu class*/
42
43/********************************************* Subsubmenu routine ************************************/
44
45/** Submenu for adding atoms to the molecule.
46 * \param *periode periodentafel
47 * \param *molecule molecules with atoms
48 */
49void oldmenu::AddAtoms(periodentafel *periode, molecule *mol)
50{
51 atom *first, *second, *third, *fourth;
52 Vector **atoms;
53 Vector x,y,z,n; // coordinates for absolute point in cell volume
54 double a,b,c;
55 char choice; // menu choice char
56 bool valid;
57
58 Log() << Verbose(0) << "===========ADD ATOM============================" << endl;
59 Log() << Verbose(0) << " a - state absolute coordinates of atom" << endl;
60 Log() << Verbose(0) << " b - state relative coordinates of atom wrt to reference point" << endl;
61 Log() << Verbose(0) << " c - state relative coordinates of atom wrt to already placed atom" << endl;
62 Log() << Verbose(0) << " d - state two atoms, two angles and a distance" << endl;
63 Log() << Verbose(0) << " e - least square distance position to a set of atoms" << endl;
64 Log() << Verbose(0) << "all else - go back" << endl;
65 Log() << Verbose(0) << "===============================================" << endl;
66 Log() << Verbose(0) << "Note: Specifiy angles in degrees not multiples of Pi!" << endl;
67 Log() << Verbose(0) << "INPUT: ";
68 cin >> choice;
69
70 switch (choice) {
71 default:
72 eLog() << Verbose(2) << "Not a valid choice." << endl;
73 break;
74 case 'a': // absolute coordinates of atom
75 Log() << Verbose(0) << "Enter absolute coordinates." << endl;
76 first = new atom;
77 first->x.AskPosition(mol->cell_size, false);
78 first->type = periode->AskElement(); // give type
79 mol->AddAtom(first); // add to molecule
80 break;
81
82 case 'b': // relative coordinates of atom wrt to reference point
83 first = new atom;
84 valid = true;
85 do {
86 if (!valid) eLog() << Verbose(2) << "Resulting position out of cell." << endl;
87 Log() << Verbose(0) << "Enter reference coordinates." << endl;
88 x.AskPosition(mol->cell_size, true);
89 Log() << Verbose(0) << "Enter relative coordinates." << endl;
90 first->x.AskPosition(mol->cell_size, false);
91 first->x.AddVector((const Vector *)&x);
92 Log() << Verbose(0) << "\n";
93 } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
94 first->type = periode->AskElement(); // give type
95 mol->AddAtom(first); // add to molecule
96 break;
97
98 case 'c': // relative coordinates of atom wrt to already placed atom
99 first = new atom;
100 valid = true;
101 do {
102 if (!valid) eLog() << Verbose(2) << "Resulting position out of cell." << endl;
103 second = mol->AskAtom("Enter atom number: ");
104 Log() << Verbose(0) << "Enter relative coordinates." << endl;
105 first->x.AskPosition(mol->cell_size, false);
106 for (int i=NDIM;i--;) {
107 first->x.x[i] += second->x.x[i];
108 }
109 } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
110 first->type = periode->AskElement(); // give type
111 mol->AddAtom(first); // add to molecule
112 break;
113
114 case 'd': // two atoms, two angles and a distance
115 first = new atom;
116 valid = true;
117 do {
118 if (!valid) {
119 eLog() << Verbose(2) << "Resulting coordinates out of cell - " << first->x << endl;
120 }
121 Log() << Verbose(0) << "First, we need two atoms, the first atom is the central, while the second is the outer one." << endl;
122 second = mol->AskAtom("Enter central atom: ");
123 third = mol->AskAtom("Enter second atom (specifying the axis for first angle): ");
124 fourth = mol->AskAtom("Enter third atom (specifying a plane for second angle): ");
125 a = ask_value("Enter distance between central (first) and new atom: ");
126 b = ask_value("Enter angle between new, first and second atom (degrees): ");
127 b *= M_PI/180.;
128 bound(&b, 0., 2.*M_PI);
129 c = ask_value("Enter second angle between new and normal vector of plane defined by first, second and third atom (degrees): ");
130 c *= M_PI/180.;
131 bound(&c, -M_PI, M_PI);
132 Log() << Verbose(0) << "radius: " << a << "\t phi: " << b*180./M_PI << "\t theta: " << c*180./M_PI << endl;
133/*
134 second->Output(1,1,(ofstream *)&cout);
135 third->Output(1,2,(ofstream *)&cout);
136 fourth->Output(1,3,(ofstream *)&cout);
137 n.MakeNormalvector((const vector *)&second->x, (const vector *)&third->x, (const vector *)&fourth->x);
138 x.Copyvector(&second->x);
139 x.SubtractVector(&third->x);
140 x.Copyvector(&fourth->x);
141 x.SubtractVector(&third->x);
142
143 if (!z.SolveSystem(&x,&y,&n, b, c, a)) {
144 Log() << Verbose(0) << "Failure solving self-dependent linear system!" << endl;
145 continue;
146 }
147 Log() << Verbose(0) << "resulting relative coordinates: ";
148 z.Output();
149 Log() << Verbose(0) << endl;
150 */
151 // calc axis vector
152 x.CopyVector(&second->x);
153 x.SubtractVector(&third->x);
154 x.Normalize();
155 Log() << Verbose(0) << "x: ",
156 x.Output();
157 Log() << Verbose(0) << endl;
158 z.MakeNormalVector(&second->x,&third->x,&fourth->x);
159 Log() << Verbose(0) << "z: ",
160 z.Output();
161 Log() << Verbose(0) << endl;
162 y.MakeNormalVector(&x,&z);
163 Log() << Verbose(0) << "y: ",
164 y.Output();
165 Log() << Verbose(0) << endl;
166
167 // rotate vector around first angle
168 first->x.CopyVector(&x);
169 first->x.RotateVector(&z,b - M_PI);
170 Log() << Verbose(0) << "Rotated vector: ",
171 first->x.Output();
172 Log() << Verbose(0) << endl;
173 // remove the projection onto the rotation plane of the second angle
174 n.CopyVector(&y);
175 n.Scale(first->x.ScalarProduct(&y));
176 Log() << Verbose(0) << "N1: ",
177 n.Output();
178 Log() << Verbose(0) << endl;
179 first->x.SubtractVector(&n);
180 Log() << Verbose(0) << "Subtracted vector: ",
181 first->x.Output();
182 Log() << Verbose(0) << endl;
183 n.CopyVector(&z);
184 n.Scale(first->x.ScalarProduct(&z));
185 Log() << Verbose(0) << "N2: ",
186 n.Output();
187 Log() << Verbose(0) << endl;
188 first->x.SubtractVector(&n);
189 Log() << Verbose(0) << "2nd subtracted vector: ",
190 first->x.Output();
191 Log() << Verbose(0) << endl;
192
193 // rotate another vector around second angle
194 n.CopyVector(&y);
195 n.RotateVector(&x,c - M_PI);
196 Log() << Verbose(0) << "2nd Rotated vector: ",
197 n.Output();
198 Log() << Verbose(0) << 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: ";
207 first->x.Output();
208 Log() << Verbose(0) << endl;
209 } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
210 first->type = periode->AskElement(); // give type
211 mol->AddAtom(first); // add to molecule
212 break;
213
214 case 'e': // least square distance position to a set of atoms
215 first = new atom;
216 atoms = new (Vector*[128]);
217 valid = true;
218 for(int i=128;i--;)
219 atoms[i] = NULL;
220 int i=0, j=0;
221 Log() << Verbose(0) << "Now we need at least three molecules.\n";
222 do {
223 Log() << Verbose(0) << "Enter " << i+1 << "th atom: ";
224 cin >> j;
225 if (j != -1) {
226 second = mol->FindAtom(j);
227 atoms[i++] = &(second->x);
228 }
229 } while ((j != -1) && (i<128));
230 if (i >= 2) {
231 first->x.LSQdistance((const Vector **)atoms, i);
232
233 first->x.Output();
234 first->type = periode->AskElement(); // give type
235 mol->AddAtom(first); // add to molecule
236 } else {
237 delete first;
238 Log() << Verbose(0) << "Please enter at least two vectors!\n";
239 }
240 break;
241 };
242};
243
244/** Submenu for centering the atoms in the molecule.
245 * \param *mol molecule with all the atoms
246 */
247void oldmenu::CenterAtoms(molecule *mol)
248{
249 Vector x, y, helper;
250 char choice; // menu choice char
251
252 Log() << Verbose(0) << "===========CENTER ATOMS=========================" << endl;
253 Log() << Verbose(0) << " a - on origin" << endl;
254 Log() << Verbose(0) << " b - on center of gravity" << endl;
255 Log() << Verbose(0) << " c - within box with additional boundary" << endl;
256 Log() << Verbose(0) << " d - within given simulation box" << endl;
257 Log() << Verbose(0) << "all else - go back" << endl;
258 Log() << Verbose(0) << "===============================================" << endl;
259 Log() << Verbose(0) << "INPUT: ";
260 cin >> choice;
261
262 switch (choice) {
263 default:
264 Log() << Verbose(0) << "Not a valid choice." << endl;
265 break;
266 case 'a':
267 Log() << Verbose(0) << "Centering atoms in config file on origin." << endl;
268 mol->CenterOrigin();
269 break;
270 case 'b':
271 Log() << Verbose(0) << "Centering atoms in config file on center of gravity." << endl;
272 mol->CenterPeriodic();
273 break;
274 case 'c':
275 Log() << Verbose(0) << "Centering atoms in config file within given additional boundary." << endl;
276 for (int i=0;i<NDIM;i++) {
277 Log() << Verbose(0) << "Enter axis " << i << " boundary: ";
278 cin >> y.x[i];
279 }
280 mol->CenterEdge(&x); // make every coordinate positive
281 mol->Center.AddVector(&y); // translate by boundary
282 helper.CopyVector(&y);
283 helper.Scale(2.);
284 helper.AddVector(&x);
285 mol->SetBoxDimension(&helper); // update Box of atoms by boundary
286 break;
287 case 'd':
288 Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl;
289 for (int i=0;i<NDIM;i++) {
290 Log() << Verbose(0) << "Enter axis " << i << " boundary: ";
291 cin >> x.x[i];
292 }
293 // update Box of atoms by boundary
294 mol->SetBoxDimension(&x);
295 // center
296 mol->CenterInBox();
297 break;
298 }
299};
300
301/** Submenu for aligning the atoms in the molecule.
302 * \param *periode periodentafel
303 * \param *mol molecule with all the atoms
304 */
305void oldmenu::AlignAtoms(periodentafel *periode, molecule *mol)
306{
307 atom *first, *second, *third;
308 Vector x,n;
309 char choice; // menu choice char
310
311 Log() << Verbose(0) << "===========ALIGN ATOMS=========================" << endl;
312 Log() << Verbose(0) << " a - state three atoms defining align plane" << endl;
313 Log() << Verbose(0) << " b - state alignment vector" << endl;
314 Log() << Verbose(0) << " c - state two atoms in alignment direction" << endl;
315 Log() << Verbose(0) << " d - align automatically by least square fit" << endl;
316 Log() << Verbose(0) << "all else - go back" << endl;
317 Log() << Verbose(0) << "===============================================" << endl;
318 Log() << Verbose(0) << "INPUT: ";
319 cin >> choice;
320
321 switch (choice) {
322 default:
323 case 'a': // three atoms defining mirror plane
324 first = mol->AskAtom("Enter first atom: ");
325 second = mol->AskAtom("Enter second atom: ");
326 third = mol->AskAtom("Enter third atom: ");
327
328 n.MakeNormalVector((const Vector *)&first->x,(const Vector *)&second->x,(const Vector *)&third->x);
329 break;
330 case 'b': // normal vector of mirror plane
331 Log() << Verbose(0) << "Enter normal vector of mirror plane." << endl;
332 n.AskPosition(mol->cell_size,0);
333 n.Normalize();
334 break;
335 case 'c': // three atoms defining mirror plane
336 first = mol->AskAtom("Enter first atom: ");
337 second = mol->AskAtom("Enter second atom: ");
338
339 n.CopyVector((const Vector *)&first->x);
340 n.SubtractVector((const Vector *)&second->x);
341 n.Normalize();
342 break;
343 case 'd':
344 char shorthand[4];
345 Vector a;
346 struct lsq_params param;
347 do {
348 fprintf(stdout, "Enter the element of atoms to be chosen: ");
349 fscanf(stdin, "%3s", shorthand);
350 } while ((param.type = periode->FindElement(shorthand)) == NULL);
351 Log() << Verbose(0) << "Element is " << param.type->name << endl;
352 mol->GetAlignvector(&param);
353 for (int i=NDIM;i--;) {
354 x.x[i] = gsl_vector_get(param.x,i);
355 n.x[i] = gsl_vector_get(param.x,i+NDIM);
356 }
357 gsl_vector_free(param.x);
358 Log() << Verbose(0) << "Offset vector: ";
359 x.Output();
360 Log() << Verbose(0) << endl;
361 n.Normalize();
362 break;
363 };
364 Log() << Verbose(0) << "Alignment vector: ";
365 n.Output();
366 Log() << Verbose(0) << endl;
367 mol->Align(&n);
368};
369
370/** Submenu for mirroring the atoms in the molecule.
371 * \param *mol molecule with all the atoms
372 */
373void oldmenu::MirrorAtoms(molecule *mol)
374{
375 atom *first, *second, *third;
376 Vector n;
377 char choice; // menu choice char
378
379 Log() << Verbose(0) << "===========MIRROR ATOMS=========================" << endl;
380 Log() << Verbose(0) << " a - state three atoms defining mirror plane" << endl;
381 Log() << Verbose(0) << " b - state normal vector of mirror plane" << endl;
382 Log() << Verbose(0) << " c - state two atoms in normal direction" << endl;
383 Log() << Verbose(0) << "all else - go back" << endl;
384 Log() << Verbose(0) << "===============================================" << endl;
385 Log() << Verbose(0) << "INPUT: ";
386 cin >> choice;
387
388 switch (choice) {
389 default:
390 case 'a': // three atoms defining mirror plane
391 first = mol->AskAtom("Enter first atom: ");
392 second = mol->AskAtom("Enter second atom: ");
393 third = mol->AskAtom("Enter third atom: ");
394
395 n.MakeNormalVector((const Vector *)&first->x,(const Vector *)&second->x,(const Vector *)&third->x);
396 break;
397 case 'b': // normal vector of mirror plane
398 Log() << Verbose(0) << "Enter normal vector of mirror plane." << endl;
399 n.AskPosition(mol->cell_size,0);
400 n.Normalize();
401 break;
402 case 'c': // three atoms defining mirror plane
403 first = mol->AskAtom("Enter first atom: ");
404 second = mol->AskAtom("Enter second atom: ");
405
406 n.CopyVector((const Vector *)&first->x);
407 n.SubtractVector((const Vector *)&second->x);
408 n.Normalize();
409 break;
410 };
411 Log() << Verbose(0) << "Normal vector: ";
412 n.Output();
413 Log() << Verbose(0) << endl;
414 mol->Mirror((const Vector *)&n);
415};
416
417/** Submenu for removing the atoms from the molecule.
418 * \param *mol molecule with all the atoms
419 */
420void oldmenu::RemoveAtoms(molecule *mol)
421{
422 atom *first, *second;
423 int axis;
424 double tmp1, tmp2;
425 char choice; // menu choice char
426
427 Log() << Verbose(0) << "===========REMOVE ATOMS=========================" << endl;
428 Log() << Verbose(0) << " a - state atom for removal by number" << endl;
429 Log() << Verbose(0) << " b - keep only in radius around atom" << endl;
430 Log() << Verbose(0) << " c - remove this with one axis greater value" << endl;
431 Log() << Verbose(0) << "all else - go back" << endl;
432 Log() << Verbose(0) << "===============================================" << endl;
433 Log() << Verbose(0) << "INPUT: ";
434 cin >> choice;
435
436 switch (choice) {
437 default:
438 case 'a':
439 if (mol->RemoveAtom(mol->AskAtom("Enter number of atom within molecule: ")))
440 Log() << Verbose(1) << "Atom removed." << endl;
441 else
442 Log() << Verbose(1) << "Atom not found." << endl;
443 break;
444 case 'b':
445 second = mol->AskAtom("Enter number of atom as reference point: ");
446 Log() << Verbose(0) << "Enter radius: ";
447 cin >> tmp1;
448 first = mol->start;
449 second = first->next;
450 while(second != mol->end) {
451 first = second;
452 second = first->next;
453 if (first->x.DistanceSquared((const Vector *)&second->x) > tmp1*tmp1) // distance to first above radius ...
454 mol->RemoveAtom(first);
455 }
456 break;
457 case 'c':
458 Log() << Verbose(0) << "Which axis is it: ";
459 cin >> axis;
460 Log() << Verbose(0) << "Lower boundary: ";
461 cin >> tmp1;
462 Log() << Verbose(0) << "Upper boundary: ";
463 cin >> tmp2;
464 first = mol->start;
465 second = first->next;
466 while(second != mol->end) {
467 first = second;
468 second = first->next;
469 if ((first->x.x[axis] < tmp1) || (first->x.x[axis] > tmp2)) {// out of boundary ...
470 //Log() << Verbose(0) << "Atom " << *first << " with " << first->x.x[axis] << " on axis " << axis << " is out of bounds [" << tmp1 << "," << tmp2 << "]." << endl;
471 mol->RemoveAtom(first);
472 }
473 }
474 break;
475 };
476 //mol->Output();
477 choice = 'r';
478};
479
480/** Submenu for measuring out the atoms in the molecule.
481 * \param *periode periodentafel
482 * \param *mol molecule with all the atoms
483 */
484void oldmenu::MeasureAtoms(periodentafel *periode, molecule *mol, config *configuration)
485{
486 atom *first, *second, *third;
487 Vector x,y;
488 double min[256], tmp1, tmp2, tmp3;
489 int Z;
490 char choice; // menu choice char
491
492 Log() << Verbose(0) << "===========MEASURE ATOMS=========================" << endl;
493 Log() << Verbose(0) << " a - calculate bond length between one atom and all others" << endl;
494 Log() << Verbose(0) << " b - calculate bond length between two atoms" << endl;
495 Log() << Verbose(0) << " c - calculate bond angle" << endl;
496 Log() << Verbose(0) << " d - calculate principal axis of the system" << endl;
497 Log() << Verbose(0) << " e - calculate volume of the convex envelope" << endl;
498 Log() << Verbose(0) << " f - calculate temperature from current velocity" << endl;
499 Log() << Verbose(0) << " g - output all temperatures per step from velocities" << endl;
500 Log() << Verbose(0) << "all else - go back" << endl;
501 Log() << Verbose(0) << "===============================================" << endl;
502 Log() << Verbose(0) << "INPUT: ";
503 cin >> choice;
504
505 switch(choice) {
506 default:
507 Log() << Verbose(1) << "Not a valid choice." << endl;
508 break;
509 case 'a':
510 first = mol->AskAtom("Enter first atom: ");
511 for (int i=MAX_ELEMENTS;i--;)
512 min[i] = 0.;
513
514 second = mol->start;
515 while ((second->next != mol->end)) {
516 second = second->next; // advance
517 Z = second->type->Z;
518 tmp1 = 0.;
519 if (first != second) {
520 x.CopyVector((const Vector *)&first->x);
521 x.SubtractVector((const Vector *)&second->x);
522 tmp1 = x.Norm();
523 }
524 if ((tmp1 != 0.) && ((min[Z] == 0.) || (tmp1 < min[Z]))) min[Z] = tmp1;
525 //Log() << Verbose(0) << "Bond length between Atom " << first->nr << " and " << second->nr << ": " << tmp1 << " a.u." << endl;
526 }
527 for (int i=MAX_ELEMENTS;i--;)
528 if (min[i] != 0.) Log() << Verbose(0) << "Minimum Bond length between " << first->type->name << " Atom " << first->nr << " and next Ion of type " << (periode->FindElement(i))->name << ": " << min[i] << " a.u." << endl;
529 break;
530
531 case 'b':
532 first = mol->AskAtom("Enter first atom: ");
533 second = mol->AskAtom("Enter second atom: ");
534 for (int i=NDIM;i--;)
535 min[i] = 0.;
536 x.CopyVector((const Vector *)&first->x);
537 x.SubtractVector((const Vector *)&second->x);
538 tmp1 = x.Norm();
539 Log() << Verbose(1) << "Distance vector is ";
540 x.Output();
541 Log() << Verbose(0) << "." << endl << "Norm of distance is " << tmp1 << "." << endl;
542 break;
543
544 case 'c':
545 Log() << Verbose(0) << "Evaluating bond angle between three - first, central, last - atoms." << endl;
546 first = mol->AskAtom("Enter first atom: ");
547 second = mol->AskAtom("Enter central atom: ");
548 third = mol->AskAtom("Enter last atom: ");
549 tmp1 = tmp2 = tmp3 = 0.;
550 x.CopyVector((const Vector *)&first->x);
551 x.SubtractVector((const Vector *)&second->x);
552 y.CopyVector((const Vector *)&third->x);
553 y.SubtractVector((const Vector *)&second->x);
554 Log() << Verbose(0) << "Bond angle between first atom Nr." << first->nr << ", central atom Nr." << second->nr << " and last atom Nr." << third->nr << ": ";
555 Log() << Verbose(0) << (acos(x.ScalarProduct((const Vector *)&y)/(y.Norm()*x.Norm()))/M_PI*180.) << " degrees" << endl;
556 break;
557 case 'd':
558 Log() << Verbose(0) << "Evaluating prinicipal axis." << endl;
559 Log() << Verbose(0) << "Shall we rotate? [0/1]: ";
560 cin >> Z;
561 if ((Z >=0) && (Z <=1))
562 mol->PrincipalAxisSystem((bool)Z);
563 else
564 mol->PrincipalAxisSystem(false);
565 break;
566 case 'e':
567 {
568 Log() << Verbose(0) << "Evaluating volume of the convex envelope.";
569 class Tesselation *TesselStruct = NULL;
570 const LinkedCell *LCList = NULL;
571 LCList = new LinkedCell(mol, 10.);
572 FindConvexBorder(mol, TesselStruct, LCList, NULL);
573 double clustervolume = VolumeOfConvexEnvelope(TesselStruct, configuration);
574 Log() << Verbose(0) << "The tesselated surface area is " << clustervolume << "." << endl;\
575 delete(LCList);
576 delete(TesselStruct);
577 }
578 break;
579 case 'f':
580 mol->OutputTemperatureFromTrajectories((ofstream *)&cout, mol->MDSteps-1, mol->MDSteps);
581 break;
582 case 'g':
583 {
584 char filename[255];
585 Log() << Verbose(0) << "Please enter filename: " << endl;
586 cin >> filename;
587 Log() << Verbose(1) << "Storing temperatures in " << filename << "." << endl;
588 ofstream *output = new ofstream(filename, ios::trunc);
589 if (!mol->OutputTemperatureFromTrajectories(output, 0, mol->MDSteps))
590 Log() << Verbose(2) << "File could not be written." << endl;
591 else
592 Log() << Verbose(2) << "File stored." << endl;
593 output->close();
594 delete(output);
595 }
596 break;
597 }
598};
599
600/** Submenu for measuring out the atoms in the molecule.
601 * \param *mol molecule with all the atoms
602 * \param *configuration configuration structure for the to be written config files of all fragments
603 */
604void oldmenu::FragmentAtoms(molecule *mol, config *configuration)
605{
606 int Order1;
607 clock_t start, end;
608
609 Log() << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl;
610 Log() << Verbose(0) << "What's the desired bond order: ";
611 cin >> Order1;
612 if (mol->first->next != mol->last) { // there are bonds
613 start = clock();
614 mol->FragmentMolecule(Order1, configuration);
615 end = clock();
616 Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
617 } else
618 Log() << Verbose(0) << "Connection matrix has not yet been generated!" << endl;
619};
620
621/********************************************** Submenu routine **************************************/
622
623/** Submenu for manipulating atoms.
624 * \param *periode periodentafel
625 * \param *molecules list of molecules whose atoms are to be manipulated
626 */
627void oldmenu::ManipulateAtoms(periodentafel *periode, MoleculeListClass *molecules, config *configuration)
628{
629 atom *first, *second;
630 molecule *mol = NULL;
631 Vector x,y,z,n; // coordinates for absolute point in cell volume
632 double *factor; // unit factor if desired
633 double bond, minBond;
634 char choice; // menu choice char
635 bool valid;
636
637 Log() << Verbose(0) << "=========MANIPULATE ATOMS======================" << endl;
638 Log() << Verbose(0) << "a - add an atom" << endl;
639 Log() << Verbose(0) << "r - remove an atom" << endl;
640 Log() << Verbose(0) << "b - scale a bond between atoms" << endl;
641 Log() << Verbose(0) << "u - change an atoms element" << endl;
642 Log() << Verbose(0) << "l - measure lengths, angles, ... for an atom" << endl;
643 Log() << Verbose(0) << "all else - go back" << endl;
644 Log() << Verbose(0) << "===============================================" << endl;
645 if (molecules->NumberOfActiveMolecules() > 1)
646 eLog() << Verbose(2) << "There is more than one molecule active! Atoms will be added to each." << endl;
647 Log() << Verbose(0) << "INPUT: ";
648 cin >> choice;
649
650 switch (choice) {
651 default:
652 Log() << Verbose(0) << "Not a valid choice." << endl;
653 break;
654
655 case 'a': // add atom
656 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
657 if ((*ListRunner)->ActiveFlag) {
658 mol = *ListRunner;
659 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
660 AddAtoms(periode, mol);
661 }
662 break;
663
664 case 'b': // scale a bond
665 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
666 if ((*ListRunner)->ActiveFlag) {
667 mol = *ListRunner;
668 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
669 Log() << Verbose(0) << "Scaling bond length between two atoms." << endl;
670 first = mol->AskAtom("Enter first (fixed) atom: ");
671 second = mol->AskAtom("Enter second (shifting) atom: ");
672 minBond = 0.;
673 for (int i=NDIM;i--;)
674 minBond += (first->x.x[i]-second->x.x[i])*(first->x.x[i] - second->x.x[i]);
675 minBond = sqrt(minBond);
676 Log() << Verbose(0) << "Current Bond length between " << first->type->name << " Atom " << first->nr << " and " << second->type->name << " Atom " << second->nr << ": " << minBond << " a.u." << endl;
677 Log() << Verbose(0) << "Enter new bond length [a.u.]: ";
678 cin >> bond;
679 for (int i=NDIM;i--;) {
680 second->x.x[i] -= (second->x.x[i]-first->x.x[i])/minBond*(minBond-bond);
681 }
682 //Log() << Verbose(0) << "New coordinates of Atom " << second->nr << " are: ";
683 //second->Output(second->type->No, 1);
684 }
685 break;
686
687 case 'c': // unit scaling of the metric
688 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
689 if ((*ListRunner)->ActiveFlag) {
690 mol = *ListRunner;
691 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
692 Log() << Verbose(0) << "Angstroem -> Bohrradius: 1.8897261\t\tBohrradius -> Angstroem: 0.52917721" << endl;
693 Log() << Verbose(0) << "Enter three factors: ";
694 factor = new double[NDIM];
695 cin >> factor[0];
696 cin >> factor[1];
697 cin >> factor[2];
698 valid = true;
699 mol->Scale((const double ** const)&factor);
700 delete[](factor);
701 }
702 break;
703
704 case 'l': // measure distances or angles
705 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
706 if ((*ListRunner)->ActiveFlag) {
707 mol = *ListRunner;
708 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
709 MeasureAtoms(periode, mol, configuration);
710 }
711 break;
712
713 case 'r': // remove atom
714 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
715 if ((*ListRunner)->ActiveFlag) {
716 mol = *ListRunner;
717 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
718 RemoveAtoms(mol);
719 }
720 break;
721
722 case 'u': // change an atom's element
723 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
724 if ((*ListRunner)->ActiveFlag) {
725 int Z;
726 mol = *ListRunner;
727 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
728 first = NULL;
729 do {
730 Log() << Verbose(0) << "Change the element of which atom: ";
731 cin >> Z;
732 } while ((first = mol->FindAtom(Z)) == NULL);
733 Log() << Verbose(0) << "New element by atomic number Z: ";
734 cin >> Z;
735 first->type = periode->FindElement(Z);
736 Log() << Verbose(0) << "Atom " << first->nr << "'s element is " << first->type->name << "." << endl;
737 }
738 break;
739 }
740};
741
742/** Submenu for manipulating molecules.
743 * \param *periode periodentafel
744 * \param *molecules list of molecule to manipulate
745 */
746void oldmenu::ManipulateMolecules(periodentafel *periode, MoleculeListClass *molecules, config *configuration)
747{
748 atom *first = NULL;
749 Vector x,y,z,n; // coordinates for absolute point in cell volume
750 int j, axis, count, faktor;
751 char choice; // menu choice char
752 molecule *mol = NULL;
753 element **Elements;
754 Vector **vectors;
755 MoleculeLeafClass *Subgraphs = NULL;
756
757 Log() << Verbose(0) << "=========MANIPULATE GLOBALLY===================" << endl;
758 Log() << Verbose(0) << "c - scale by unit transformation" << endl;
759 Log() << Verbose(0) << "d - duplicate molecule/periodic cell" << endl;
760 Log() << Verbose(0) << "f - fragment molecule many-body bond order style" << endl;
761 Log() << Verbose(0) << "g - center atoms in box" << endl;
762 Log() << Verbose(0) << "i - realign molecule" << endl;
763 Log() << Verbose(0) << "m - mirror all molecules" << endl;
764 Log() << Verbose(0) << "o - create connection matrix" << endl;
765 Log() << Verbose(0) << "t - translate molecule by vector" << endl;
766 Log() << Verbose(0) << "all else - go back" << endl;
767 Log() << Verbose(0) << "===============================================" << endl;
768 if (molecules->NumberOfActiveMolecules() > 1)
769 eLog() << Verbose(2) << "There is more than one molecule active! Atoms will be added to each." << endl;
770 Log() << Verbose(0) << "INPUT: ";
771 cin >> choice;
772
773 switch (choice) {
774 default:
775 Log() << Verbose(0) << "Not a valid choice." << endl;
776 break;
777
778 case 'd': // duplicate the periodic cell along a given axis, given times
779 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
780 if ((*ListRunner)->ActiveFlag) {
781 mol = *ListRunner;
782 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
783 Log() << Verbose(0) << "State the axis [(+-)123]: ";
784 cin >> axis;
785 Log() << Verbose(0) << "State the factor: ";
786 cin >> faktor;
787
788 mol->CountAtoms(); // recount atoms
789 if (mol->AtomCount != 0) { // if there is more than none
790 count = mol->AtomCount; // is changed becausing of adding, thus has to be stored away beforehand
791 Elements = new element *[count];
792 vectors = new Vector *[count];
793 j = 0;
794 first = mol->start;
795 while (first->next != mol->end) { // make a list of all atoms with coordinates and element
796 first = first->next;
797 Elements[j] = first->type;
798 vectors[j] = &first->x;
799 j++;
800 }
801 if (count != j)
802 eLog() << Verbose(1) << "AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl;
803 x.Zero();
804 y.Zero();
805 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
806 for (int i=1;i<faktor;i++) { // then add this list with respective translation factor times
807 x.AddVector(&y); // per factor one cell width further
808 for (int k=count;k--;) { // go through every atom of the original cell
809 first = new atom(); // create a new body
810 first->x.CopyVector(vectors[k]); // use coordinate of original atom
811 first->x.AddVector(&x); // translate the coordinates
812 first->type = Elements[k]; // insert original element
813 mol->AddAtom(first); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)
814 }
815 }
816 if (mol->first->next != mol->last) // if connect matrix is present already, redo it
817 mol->CreateAdjacencyList(mol->BondDistance, configuration->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
818 // free memory
819 delete[](Elements);
820 delete[](vectors);
821 // correct cell size
822 if (axis < 0) { // if sign was negative, we have to translate everything
823 x.Zero();
824 x.AddVector(&y);
825 x.Scale(-(faktor-1));
826 mol->Translate(&x);
827 }
828 mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;
829 }
830 }
831 break;
832
833 case 'f':
834 FragmentAtoms(mol, configuration);
835 break;
836
837 case 'g': // center the atoms
838 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
839 if ((*ListRunner)->ActiveFlag) {
840 mol = *ListRunner;
841 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
842 CenterAtoms(mol);
843 }
844 break;
845
846 case 'i': // align all atoms
847 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
848 if ((*ListRunner)->ActiveFlag) {
849 mol = *ListRunner;
850 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
851 AlignAtoms(periode, mol);
852 }
853 break;
854
855 case 'm': // mirror atoms along a given axis
856 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
857 if ((*ListRunner)->ActiveFlag) {
858 mol = *ListRunner;
859 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
860 MirrorAtoms(mol);
861 }
862 break;
863
864 case 'o': // create the connection matrix
865 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
866 if ((*ListRunner)->ActiveFlag) {
867 mol = *ListRunner;
868 double bonddistance;
869 clock_t start,end;
870 Log() << Verbose(0) << "What's the maximum bond distance: ";
871 cin >> bonddistance;
872 start = clock();
873 mol->CreateAdjacencyList(bonddistance, configuration->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
874 end = clock();
875 Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
876 }
877 break;
878
879 case 't': // translate all atoms
880 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
881 if ((*ListRunner)->ActiveFlag) {
882 mol = *ListRunner;
883 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
884 Log() << Verbose(0) << "Enter translation vector." << endl;
885 x.AskPosition(mol->cell_size,0);
886 mol->Center.AddVector((const Vector *)&x);
887 }
888 break;
889 }
890 // Free all
891 if (Subgraphs != NULL) { // free disconnected subgraph list of DFS analysis was performed
892 while (Subgraphs->next != NULL) {
893 Subgraphs = Subgraphs->next;
894 delete(Subgraphs->previous);
895 }
896 delete(Subgraphs);
897 }
898};
899
900
901void oldmenu::createNewMolecule(periodentafel *periode,MoleculeListClass *molecules) {
902 molecule *mol = NULL;
903 mol = new molecule(periode);
904 molecules->insert(mol);
905};
906
907void oldmenu::loadFromXYZ(periodentafel *periode,MoleculeListClass *molecules){
908 molecule *mol = NULL;
909 Vector center;
910 char filename[MAXSTRINGSIZE];
911 Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
912 mol = new molecule(periode);
913 do {
914 Log() << Verbose(0) << "Enter file name: ";
915 cin >> filename;
916 } while (!mol->AddXYZFile(filename));
917 mol->SetNameFromFilename(filename);
918 // center at set box dimensions
919 mol->CenterEdge(&center);
920 mol->cell_size[0] = center.x[0];
921 mol->cell_size[1] = 0;
922 mol->cell_size[2] = center.x[1];
923 mol->cell_size[3] = 0;
924 mol->cell_size[4] = 0;
925 mol->cell_size[5] = center.x[2];
926 molecules->insert(mol);
927}
928
929void oldmenu::changeName(MoleculeListClass *molecules){
930 char filename[MAXSTRINGSIZE];
931 molecule *mol = NULL;
932 int nr;
933 do {
934 Log() << Verbose(0) << "Enter index of molecule: ";
935 cin >> nr;
936 mol = molecules->ReturnIndex(nr);
937 } while (mol == NULL);
938 Log() << Verbose(0) << "Enter name: ";
939 cin >> filename;
940 strcpy(mol->name, filename);
941}
942
943void oldmenu::setMoleculeFilename(MoleculeListClass *molecules) {
944 char filename[MAXSTRINGSIZE];
945 int nr;
946 molecule *mol = NULL;
947 do {
948 Log() << Verbose(0) << "Enter index of molecule: ";
949 cin >> nr;
950 mol = molecules->ReturnIndex(nr);
951 } while (mol == NULL);
952 Log() << Verbose(0) << "Enter name: ";
953 cin >> filename;
954 mol->SetNameFromFilename(filename);
955}
956
957void oldmenu::parseXYZIntoMolecule(MoleculeListClass *molecules){
958 char filename[MAXSTRINGSIZE];
959 int nr;
960 molecule *mol = NULL;
961 mol = NULL;
962 do {
963 Log() << Verbose(0) << "Enter index of molecule: ";
964 cin >> nr;
965 mol = molecules->ReturnIndex(nr);
966 } while (mol == NULL);
967 Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
968 do {
969 Log() << Verbose(0) << "Enter file name: ";
970 cin >> filename;
971 } while (!mol->AddXYZFile(filename));
972 mol->SetNameFromFilename(filename);
973};
974
975void oldmenu::eraseMolecule(MoleculeListClass *molecules){
976 int nr;
977 molecule *mol = NULL;
978 Log() << Verbose(0) << "Enter index of molecule: ";
979 cin >> nr;
980 for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
981 if (nr == (*ListRunner)->IndexNr) {
982 mol = *ListRunner;
983 molecules->ListOfMolecules.erase(ListRunner);
984 delete(mol);
985 break;
986 }
987};
988
989/** Submenu for merging molecules.
990 * \param *periode periodentafel
991 * \param *molecules list of molecules to add to
992 */
993void oldmenu::MergeMolecules(periodentafel *periode, MoleculeListClass *molecules)
994{
995 char choice; // menu choice char
996
997 Log() << Verbose(0) << "===========MERGE MOLECULES=====================" << endl;
998 Log() << Verbose(0) << "a - simple add of one molecule to another" << endl;
999 Log() << Verbose(0) << "e - embedding merge of two molecules" << endl;
1000 Log() << Verbose(0) << "m - multi-merge of all molecules" << endl;
1001 Log() << Verbose(0) << "s - scatter merge of two molecules" << endl;
1002 Log() << Verbose(0) << "t - simple merge of two molecules" << endl;
1003 Log() << Verbose(0) << "all else - go back" << endl;
1004 Log() << Verbose(0) << "===============================================" << endl;
1005 Log() << Verbose(0) << "INPUT: ";
1006 cin >> choice;
1007
1008 switch (choice) {
1009 default:
1010 Log() << Verbose(0) << "Not a valid choice." << endl;
1011 break;
1012
1013 case 'a':
1014 {
1015 int src, dest;
1016 molecule *srcmol = NULL, *destmol = NULL;
1017 {
1018 do {
1019 Log() << Verbose(0) << "Enter index of destination molecule: ";
1020 cin >> dest;
1021 destmol = molecules->ReturnIndex(dest);
1022 } while ((destmol == NULL) && (dest != -1));
1023 do {
1024 Log() << Verbose(0) << "Enter index of source molecule to add from: ";
1025 cin >> src;
1026 srcmol = molecules->ReturnIndex(src);
1027 } while ((srcmol == NULL) && (src != -1));
1028 if ((src != -1) && (dest != -1))
1029 molecules->SimpleAdd(srcmol, destmol);
1030 }
1031 }
1032 break;
1033
1034 case 'e':
1035 {
1036 int src, dest;
1037 molecule *srcmol = NULL, *destmol = NULL;
1038 do {
1039 Log() << Verbose(0) << "Enter index of matrix molecule (the variable one): ";
1040 cin >> src;
1041 srcmol = molecules->ReturnIndex(src);
1042 } while ((srcmol == NULL) && (src != -1));
1043 do {
1044 Log() << Verbose(0) << "Enter index of molecule to merge into (the fixed one): ";
1045 cin >> dest;
1046 destmol = molecules->ReturnIndex(dest);
1047 } while ((destmol == NULL) && (dest != -1));
1048 if ((src != -1) && (dest != -1))
1049 molecules->EmbedMerge(destmol, srcmol);
1050 }
1051 break;
1052
1053 case 'm':
1054 {
1055 int nr;
1056 molecule *mol = NULL;
1057 do {
1058 Log() << Verbose(0) << "Enter index of molecule to merge into: ";
1059 cin >> nr;
1060 mol = molecules->ReturnIndex(nr);
1061 } while ((mol == NULL) && (nr != -1));
1062 if (nr != -1) {
1063 int N = molecules->ListOfMolecules.size()-1;
1064 int *src = new int(N);
1065 for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
1066 if ((*ListRunner)->IndexNr != nr)
1067 src[N++] = (*ListRunner)->IndexNr;
1068 molecules->SimpleMultiMerge(mol, src, N);
1069 delete[](src);
1070 }
1071 }
1072 break;
1073
1074 case 's':
1075 Log() << Verbose(0) << "Not implemented yet." << endl;
1076 break;
1077
1078 case 't':
1079 {
1080 int src, dest;
1081 molecule *srcmol = NULL, *destmol = NULL;
1082 {
1083 do {
1084 Log() << Verbose(0) << "Enter index of destination molecule: ";
1085 cin >> dest;
1086 destmol = molecules->ReturnIndex(dest);
1087 } while ((destmol == NULL) && (dest != -1));
1088 do {
1089 Log() << Verbose(0) << "Enter index of source molecule to merge into: ";
1090 cin >> src;
1091 srcmol = molecules->ReturnIndex(src);
1092 } while ((srcmol == NULL) && (src != -1));
1093 if ((src != -1) && (dest != -1))
1094 molecules->SimpleMerge(srcmol, destmol);
1095 }
1096 }
1097 break;
1098 }
1099};
1100
1101
1102/********************************************** Test routine **************************************/
1103
1104/** Is called always as option 'T' in the menu.
1105 * \param *molecules list of molecules
1106 */
1107void oldmenu::testroutine(MoleculeListClass *molecules)
1108{
1109 // the current test routine checks the functionality of the KeySet&Graph concept:
1110 // We want to have a multiindex (the KeySet) describing a unique subgraph
1111 int i, comp, counter=0;
1112
1113 // create a clone
1114 molecule *mol = NULL;
1115 if (molecules->ListOfMolecules.size() != 0) // clone
1116 mol = (molecules->ListOfMolecules.front())->CopyMolecule();
1117 else {
1118 eLog() << Verbose(0) << "I don't have anything to test on ... ";
1119 performCriticalExit();
1120 return;
1121 }
1122 atom *Walker = mol->start;
1123
1124 // generate some KeySets
1125 Log() << Verbose(0) << "Generating KeySets." << endl;
1126 KeySet TestSets[mol->AtomCount+1];
1127 i=1;
1128 while (Walker->next != mol->end) {
1129 Walker = Walker->next;
1130 for (int j=0;j<i;j++) {
1131 TestSets[j].insert(Walker->nr);
1132 }
1133 i++;
1134 }
1135 Log() << Verbose(0) << "Testing insertion of already present item in KeySets." << endl;
1136 KeySetTestPair test;
1137 test = TestSets[mol->AtomCount-1].insert(Walker->nr);
1138 if (test.second) {
1139 Log() << Verbose(1) << "Insertion worked?!" << endl;
1140 } else {
1141 Log() << Verbose(1) << "Insertion rejected: Present object is " << (*test.first) << "." << endl;
1142 }
1143 TestSets[mol->AtomCount].insert(mol->end->previous->nr);
1144 TestSets[mol->AtomCount].insert(mol->end->previous->previous->previous->nr);
1145
1146 // constructing Graph structure
1147 Log() << Verbose(0) << "Generating Subgraph class." << endl;
1148 Graph Subgraphs;
1149
1150 // insert KeySets into Subgraphs
1151 Log() << Verbose(0) << "Inserting KeySets into Subgraph class." << endl;
1152 for (int j=0;j<mol->AtomCount;j++) {
1153 Subgraphs.insert(GraphPair (TestSets[j],pair<int, double>(counter++, 1.)));
1154 }
1155 Log() << Verbose(0) << "Testing insertion of already present item in Subgraph." << endl;
1156 GraphTestPair test2;
1157 test2 = Subgraphs.insert(GraphPair (TestSets[mol->AtomCount],pair<int, double>(counter++, 1.)));
1158 if (test2.second) {
1159 Log() << Verbose(1) << "Insertion worked?!" << endl;
1160 } else {
1161 Log() << Verbose(1) << "Insertion rejected: Present object is " << (*(test2.first)).second.first << "." << endl;
1162 }
1163
1164 // show graphs
1165 Log() << Verbose(0) << "Showing Subgraph's contents, checking that it's sorted." << endl;
1166 Graph::iterator A = Subgraphs.begin();
1167 while (A != Subgraphs.end()) {
1168 Log() << Verbose(0) << (*A).second.first << ": ";
1169 KeySet::iterator key = (*A).first.begin();
1170 comp = -1;
1171 while (key != (*A).first.end()) {
1172 if ((*key) > comp)
1173 Log() << Verbose(0) << (*key) << " ";
1174 else
1175 Log() << Verbose(0) << (*key) << "! ";
1176 comp = (*key);
1177 key++;
1178 }
1179 Log() << Verbose(0) << endl;
1180 A++;
1181 }
1182 delete(mol);
1183};
1184
1185oldmenu::oldmenu()
1186{
1187 // TODO Auto-generated constructor stub
1188}
1189
1190oldmenu::~oldmenu()
1191{
1192 // TODO Auto-generated destructor stub
1193}
1194
1195void oldmenu::notImplementedYet() {
1196 Log() << Verbose(0) << "This method has not yet been moved to an appropriate class." << endl;
1197}
1198
1199void oldmenu::perform(MoleculeListClass *molecules, config *configuration, periodentafel *periode, char *ConfigFileName)
1200{
1201
1202 // build the main menu
1203 TextMenu *main_menu = new TextMenu(Log() << Verbose(0), "Main Menu");
1204
1205 StringView *moleculeView = new StreamStringView(boost::bind(&MoleculeListClass::Enumerate,molecules,_1));
1206 new DisplayMenuItem(main_menu,moleculeView,"Molecule List");
1207
1208 new SeperatorItem(main_menu);
1209
1210 Action *setMoleculeAction = new MethodAction(boost::bind(&MoleculeListClass::flipChosen,molecules));
1211 new ActionMenuItem('a',"set molecule (in)active",main_menu,setMoleculeAction);
1212
1213 TextMenu *edit_molecules_menu = new TextMenu(Log() << Verbose(0), "Edit Molecules");
1214 new SubMenuItem('e',"edit molecules (load, parse, save)",main_menu,edit_molecules_menu);
1215
1216 Action *manipulateMoleculeAction = new MethodAction(boost::bind(&oldmenu::ManipulateMolecules,this,periode, molecules, configuration));
1217 new ActionMenuItem('g',"globally manipulate atoms in molecule",main_menu,manipulateMoleculeAction);
1218
1219 Action *mergeMoleculeAction = new MethodAction(boost::bind(&oldmenu::MergeMolecules,this,periode, molecules));
1220 new ActionMenuItem('M',"Merge molecules",main_menu,mergeMoleculeAction);
1221
1222 Action *manipulateAtomsAction = new MethodAction(boost::bind(&oldmenu::ManipulateAtoms,this,periode, molecules, configuration));
1223 new ActionMenuItem('m',"manipulate atoms",main_menu,manipulateAtomsAction);
1224
1225 new SeperatorItem(main_menu);
1226
1227 Action *editConfigAction = new MethodAction(boost::bind(&config::Edit,configuration));
1228 new ActionMenuItem('c',"edit the current configuration",main_menu,editConfigAction);
1229
1230 new SeperatorItem(main_menu);
1231
1232 Action *saveConfigAction = new MethodAction(boost::bind(&oldmenu::SaveConfig,this,ConfigFileName, configuration, periode, molecules));
1233 new ActionMenuItem('s',"save current setup to config file",main_menu,saveConfigAction);
1234
1235 Action *doTestAction = new MethodAction(boost::bind(&oldmenu::testroutine,this,molecules));
1236 new ActionMenuItem('T',"call the current test routine",main_menu,doTestAction);
1237
1238 Action *quitAction = new MethodAction(boost::bind(&TextMenu::doQuit,main_menu));
1239 new ActionMenuItem('q',"quit",main_menu,quitAction);
1240
1241 // build the EditMoleculesMenu
1242 Action *createMoleculeAction = new MethodAction(boost::bind(&oldmenu::createNewMolecule,this,periode,molecules));
1243 new ActionMenuItem('c',"create new molecule",edit_molecules_menu,createMoleculeAction);
1244
1245 Action *loadMoleculeAction = new MethodAction(boost::bind(&oldmenu::loadFromXYZ,this,periode,molecules));
1246 new ActionMenuItem('l',"load molecule from xyz file",edit_molecules_menu,loadMoleculeAction);
1247
1248 Action *changeFilenameAction = new MethodAction(boost::bind(&oldmenu::changeName,this,molecules));
1249 new ActionMenuItem('n',"change molecule's name",edit_molecules_menu,changeFilenameAction);
1250
1251 Action *giveFilenameAction = new MethodAction(boost::bind(&oldmenu::setMoleculeFilename,this,molecules));
1252 new ActionMenuItem('N',"give molecules filename",edit_molecules_menu,giveFilenameAction);
1253
1254 Action *parseAtomsAction = new MethodAction(boost::bind(&oldmenu::parseXYZIntoMolecule,this,molecules));
1255 new ActionMenuItem('p',"parse atoms in xyz file into molecule",edit_molecules_menu,parseAtomsAction);
1256
1257 Action *eraseMoleculeAction = new MethodAction(boost::bind(&oldmenu::eraseMolecule,this,molecules));
1258 new ActionMenuItem('r',"remove a molecule",edit_molecules_menu,eraseMoleculeAction);
1259
1260 Action *returnAction = new MethodAction(boost::bind(&TextMenu::doQuit,edit_molecules_menu));
1261 MenuItem *returnItem = new ActionMenuItem('q',"return to Main menu",edit_molecules_menu,returnAction);
1262
1263 edit_molecules_menu->addDefault(returnItem);
1264
1265 main_menu->display();
1266
1267
1268 delete main_menu;
1269
1270 // delete all actions and views contained in Menu
1271 // TODO: find a better way to handle this
1272
1273 delete moleculeView;
1274
1275 delete setMoleculeAction;
1276 delete manipulateMoleculeAction;
1277 delete mergeMoleculeAction;
1278 delete manipulateAtomsAction;
1279 delete editConfigAction;
1280 delete saveConfigAction;
1281 delete doTestAction;
1282 delete quitAction;
1283
1284 delete createMoleculeAction;
1285 delete loadMoleculeAction;
1286 delete changeFilenameAction;
1287 delete giveFilenameAction;
1288 delete parseAtomsAction;
1289 delete eraseMoleculeAction;
1290 delete returnAction;
1291};
1292
1293/** Tries given filename or standard on saving the config file.
1294 * \param *ConfigFileName name of file
1295 * \param *configuration pointer to configuration structure with all the values
1296 * \param *periode pointer to periodentafel structure with all the elements
1297 * \param *molecules list of molecules structure with all the atoms and coordinates
1298 */
1299void oldmenu::SaveConfig(char *ConfigFileName, config *configuration, periodentafel *periode, MoleculeListClass *molecules)
1300{
1301 char filename[MAXSTRINGSIZE];
1302 ofstream output;
1303 molecule *mol = new molecule(periode);
1304
1305 if (!strcmp(configuration->configpath, configuration->GetDefaultPath())) {
1306 eLog() << Verbose(2) << "config is found under different path then stated in config file::defaultpath!" << endl;
1307 }
1308
1309
1310 // first save as PDB data
1311 if (ConfigFileName != NULL)
1312 strcpy(filename, ConfigFileName);
1313 else
1314 strcpy(filename,"main_pcp_linux");
1315 Log() << Verbose(0) << "Saving as pdb input ";
1316 if (configuration->SavePDB(filename, molecules))
1317 Log() << Verbose(0) << "done." << endl;
1318 else
1319 Log() << Verbose(0) << "failed." << endl;
1320
1321 // then save as tremolo data file
1322 if (ConfigFileName != NULL)
1323 strcpy(filename, ConfigFileName);
1324 else
1325 strcpy(filename,"main_pcp_linux");
1326 Log() << Verbose(0) << "Saving as tremolo data input ";
1327 if (configuration->SaveTREMOLO(filename, molecules))
1328 Log() << Verbose(0) << "done." << endl;
1329 else
1330 Log() << Verbose(0) << "failed." << endl;
1331
1332 // translate each to its center and merge all molecules in MoleculeListClass into this molecule
1333 int N = molecules->ListOfMolecules.size();
1334 int *src = new int[N];
1335 N=0;
1336 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
1337 src[N++] = (*ListRunner)->IndexNr;
1338 (*ListRunner)->Translate(&(*ListRunner)->Center);
1339 }
1340 molecules->SimpleMultiAdd(mol, src, N);
1341 delete[](src);
1342
1343 // ... and translate back
1344 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
1345 (*ListRunner)->Center.Scale(-1.);
1346 (*ListRunner)->Translate(&(*ListRunner)->Center);
1347 (*ListRunner)->Center.Scale(-1.);
1348 }
1349
1350 Log() << Verbose(0) << "Storing configuration ... " << endl;
1351 // get correct valence orbitals
1352 mol->CalculateOrbitals(*configuration);
1353 configuration->InitMaxMinStopStep = configuration->MaxMinStopStep = configuration->MaxPsiDouble;
1354 if (ConfigFileName != NULL) { // test the file name
1355 strcpy(filename, ConfigFileName);
1356 output.open(filename, ios::trunc);
1357 } else if (strlen(configuration->configname) != 0) {
1358 strcpy(filename, configuration->configname);
1359 output.open(configuration->configname, ios::trunc);
1360 } else {
1361 strcpy(filename, DEFAULTCONFIG);
1362 output.open(DEFAULTCONFIG, ios::trunc);
1363 }
1364 output.close();
1365 output.clear();
1366 Log() << Verbose(0) << "Saving of config file ";
1367 if (configuration->Save(filename, periode, mol))
1368 Log() << Verbose(0) << "successful." << endl;
1369 else
1370 Log() << Verbose(0) << "failed." << endl;
1371
1372 // and save to xyz file
1373 if (ConfigFileName != NULL) {
1374 strcpy(filename, ConfigFileName);
1375 strcat(filename, ".xyz");
1376 output.open(filename, ios::trunc);
1377 }
1378 else {
1379 strcpy(filename,"main_pcp_linux");
1380 strcat(filename, ".xyz");
1381 output.open(filename, ios::trunc);
1382 }
1383 Log() << Verbose(0) << "Saving of XYZ file ";
1384 if (mol->MDSteps <= 1) {
1385 if (mol->OutputXYZ(&output))
1386 Log() << Verbose(0) << "successful." << endl;
1387 else
1388 Log() << Verbose(0) << "failed." << endl;
1389 } else {
1390 if (mol->OutputTrajectoriesXYZ(&output))
1391 Log() << Verbose(0) << "successful." << endl;
1392 else
1393 Log() << Verbose(0) << "failed." << endl;
1394 }
1395 output.close();
1396 output.clear();
1397
1398 // and save as MPQC configuration
1399 if (ConfigFileName != NULL)
1400 strcpy(filename, ConfigFileName);
1401 else
1402 strcpy(filename,"main_pcp_linux");
1403 Log() << Verbose(0) << "Saving as mpqc input ";
1404 if (configuration->SaveMPQC(filename, mol))
1405 Log() << Verbose(0) << "done." << endl;
1406 else
1407 Log() << Verbose(0) << "failed." << endl;
1408
1409 if (!strcmp(configuration->configpath, configuration->GetDefaultPath())) {
1410 eLog() << Verbose(2) << "config is found under different path then stated in config file::defaultpath!" << endl;
1411 }
1412
1413 delete(mol);
1414};
Note: See TracBrowser for help on using the repository browser.