source: src/menu.cpp@ 820a42

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 820a42 was 820a42, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Extracted all methods from MergeMolecules Menu

  • Added new action that only displays an errorMessage
  • Property mode set to 100644
File size: 46.9 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
742void oldmenu::duplicateCell(MoleculeListClass *molecules, config *configuration) {
743 molecule *mol = NULL;
744 int axis,faktor,count,j;
745 atom *first = NULL;
746 element **Elements;
747 Vector x,y;
748 Vector **vectors;
749
750 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
751 if ((*ListRunner)->ActiveFlag) {
752 mol = *ListRunner;
753 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
754 Log() << Verbose(0) << "State the axis [(+-)123]: ";
755 cin >> axis;
756 Log() << Verbose(0) << "State the factor: ";
757 cin >> faktor;
758
759 mol->CountAtoms(); // recount atoms
760 if (mol->AtomCount != 0) { // if there is more than none
761 count = mol->AtomCount; // is changed becausing of adding, thus has to be stored away beforehand
762 Elements = new element *[count];
763 vectors = new Vector *[count];
764 j = 0;
765 first = mol->start;
766 while (first->next != mol->end) { // make a list of all atoms with coordinates and element
767 first = first->next;
768 Elements[j] = first->type;
769 vectors[j] = &first->x;
770 j++;
771 }
772 if (count != j)
773 eLog() << Verbose(1) << "AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl;
774 x.Zero();
775 y.Zero();
776 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
777 for (int i=1;i<faktor;i++) { // then add this list with respective translation factor times
778 x.AddVector(&y); // per factor one cell width further
779 for (int k=count;k--;) { // go through every atom of the original cell
780 first = new atom(); // create a new body
781 first->x.CopyVector(vectors[k]); // use coordinate of original atom
782 first->x.AddVector(&x); // translate the coordinates
783 first->type = Elements[k]; // insert original element
784 mol->AddAtom(first); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)
785 }
786 }
787 if (mol->first->next != mol->last) // if connect matrix is present already, redo it
788 mol->CreateAdjacencyList(mol->BondDistance, configuration->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
789 // free memory
790 delete[](Elements);
791 delete[](vectors);
792 // correct cell size
793 if (axis < 0) { // if sign was negative, we have to translate everything
794 x.Zero();
795 x.AddVector(&y);
796 x.Scale(-(faktor-1));
797 mol->Translate(&x);
798 }
799 mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;
800 }
801 }
802}
803
804/** Submenu for manipulating molecules.
805 * \param *periode periodentafel
806 * \param *molecules list of molecule to manipulate
807 */
808void oldmenu::ManipulateMolecules(periodentafel *periode, MoleculeListClass *molecules, config *configuration)
809{
810 atom *first = NULL;
811 Vector x,y,z,n; // coordinates for absolute point in cell volume
812 int j, axis, count, faktor;
813 char choice; // menu choice char
814 molecule *mol = NULL;
815 element **Elements;
816 Vector **vectors;
817 MoleculeLeafClass *Subgraphs = NULL;
818
819 Log() << Verbose(0) << "=========MANIPULATE GLOBALLY===================" << endl;
820 Log() << Verbose(0) << "c - scale by unit transformation" << endl;
821 Log() << Verbose(0) << "d - duplicate molecule/periodic cell" << endl;
822 Log() << Verbose(0) << "f - fragment molecule many-body bond order style" << endl;
823 Log() << Verbose(0) << "g - center atoms in box" << endl;
824 Log() << Verbose(0) << "i - realign molecule" << endl;
825 Log() << Verbose(0) << "m - mirror all molecules" << endl;
826 Log() << Verbose(0) << "o - create connection matrix" << endl;
827 Log() << Verbose(0) << "t - translate molecule by vector" << endl;
828 Log() << Verbose(0) << "all else - go back" << endl;
829 Log() << Verbose(0) << "===============================================" << endl;
830 if (molecules->NumberOfActiveMolecules() > 1)
831 eLog() << Verbose(2) << "There is more than one molecule active! Atoms will be added to each." << endl;
832 Log() << Verbose(0) << "INPUT: ";
833 cin >> choice;
834
835 switch (choice) {
836 default:
837 Log() << Verbose(0) << "Not a valid choice." << endl;
838 break;
839
840 case 'd': // duplicate the periodic cell along a given axis, given times
841 duplicateCell(molecules, configuration);
842 break;
843
844 case 'f':
845 FragmentAtoms(mol, configuration);
846 break;
847
848 case 'g': // center the atoms
849 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
850 if ((*ListRunner)->ActiveFlag) {
851 mol = *ListRunner;
852 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
853 CenterAtoms(mol);
854 }
855 break;
856
857 case 'i': // align all atoms
858 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
859 if ((*ListRunner)->ActiveFlag) {
860 mol = *ListRunner;
861 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
862 AlignAtoms(periode, mol);
863 }
864 break;
865
866 case 'm': // mirror atoms along a given axis
867 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
868 if ((*ListRunner)->ActiveFlag) {
869 mol = *ListRunner;
870 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
871 MirrorAtoms(mol);
872 }
873 break;
874
875 case 'o': // create the connection matrix
876 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
877 if ((*ListRunner)->ActiveFlag) {
878 mol = *ListRunner;
879 double bonddistance;
880 clock_t start,end;
881 Log() << Verbose(0) << "What's the maximum bond distance: ";
882 cin >> bonddistance;
883 start = clock();
884 mol->CreateAdjacencyList(bonddistance, configuration->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
885 end = clock();
886 Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
887 }
888 break;
889
890 case 't': // translate all atoms
891 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
892 if ((*ListRunner)->ActiveFlag) {
893 mol = *ListRunner;
894 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
895 Log() << Verbose(0) << "Enter translation vector." << endl;
896 x.AskPosition(mol->cell_size,0);
897 mol->Center.AddVector((const Vector *)&x);
898 }
899 break;
900 }
901 // Free all
902 if (Subgraphs != NULL) { // free disconnected subgraph list of DFS analysis was performed
903 while (Subgraphs->next != NULL) {
904 Subgraphs = Subgraphs->next;
905 delete(Subgraphs->previous);
906 }
907 delete(Subgraphs);
908 }
909};
910
911
912void oldmenu::SimpleAddMolecules(MoleculeListClass *molecules) {
913 int src, dest;
914 molecule *srcmol = NULL, *destmol = NULL;
915 {
916 do {
917 Log() << Verbose(0) << "Enter index of destination molecule: ";
918 cin >> dest;
919 destmol = molecules->ReturnIndex(dest);
920 } while ((destmol == NULL) && (dest != -1));
921 do {
922 Log() << Verbose(0) << "Enter index of source molecule to add from: ";
923 cin >> src;
924 srcmol = molecules->ReturnIndex(src);
925 } while ((srcmol == NULL) && (src != -1));
926 if ((src != -1) && (dest != -1))
927 molecules->SimpleAdd(srcmol, destmol);
928 }
929}
930
931void oldmenu::embeddMolecules(MoleculeListClass *molecules) {
932 int src, dest;
933 molecule *srcmol = NULL, *destmol = NULL;
934 do {
935 Log() << Verbose(0) << "Enter index of matrix molecule (the variable one): ";
936 cin >> src;
937 srcmol = molecules->ReturnIndex(src);
938 } while ((srcmol == NULL) && (src != -1));
939 do {
940 Log() << Verbose(0) << "Enter index of molecule to merge into (the fixed one): ";
941 cin >> dest;
942 destmol = molecules->ReturnIndex(dest);
943 } while ((destmol == NULL) && (dest != -1));
944 if ((src != -1) && (dest != -1))
945 molecules->EmbedMerge(destmol, srcmol);
946}
947
948void oldmenu::multiMergeMolecules(MoleculeListClass *molecules) {
949 int nr;
950 molecule *mol = NULL;
951 do {
952 Log() << Verbose(0) << "Enter index of molecule to merge into: ";
953 cin >> nr;
954 mol = molecules->ReturnIndex(nr);
955 } while ((mol == NULL) && (nr != -1));
956 if (nr != -1) {
957 int N = molecules->ListOfMolecules.size()-1;
958 int *src = new int(N);
959 for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
960 if ((*ListRunner)->IndexNr != nr)
961 src[N++] = (*ListRunner)->IndexNr;
962 molecules->SimpleMultiMerge(mol, src, N);
963 delete[](src);
964 }
965}
966
967void oldmenu::simpleMergeMolecules(MoleculeListClass *molecules) {
968 int src, dest;
969 molecule *srcmol = NULL, *destmol = NULL;
970 {
971 do {
972 Log() << Verbose(0) << "Enter index of destination molecule: ";
973 cin >> dest;
974 destmol = molecules->ReturnIndex(dest);
975 } while ((destmol == NULL) && (dest != -1));
976 do {
977 Log() << Verbose(0) << "Enter index of source molecule to merge into: ";
978 cin >> src;
979 srcmol = molecules->ReturnIndex(src);
980 } while ((srcmol == NULL) && (src != -1));
981 if ((src != -1) && (dest != -1))
982 molecules->SimpleMerge(srcmol, destmol);
983 }
984}
985
986/** Submenu for merging molecules.
987 * \param *periode periodentafel
988 * \param *molecules list of molecules to add to
989 */
990void oldmenu::MergeMolecules(periodentafel *periode, MoleculeListClass *molecules)
991{
992 char choice; // menu choice char
993
994 Log() << Verbose(0) << "===========MERGE MOLECULES=====================" << endl;
995 Log() << Verbose(0) << "a - simple add of one molecule to another" << endl;
996 Log() << Verbose(0) << "e - embedding merge of two molecules" << endl;
997 Log() << Verbose(0) << "m - multi-merge of all molecules" << endl;
998 Log() << Verbose(0) << "s - scatter merge of two molecules" << endl;
999 Log() << Verbose(0) << "t - simple merge of two molecules" << endl;
1000 Log() << Verbose(0) << "all else - go back" << endl;
1001 Log() << Verbose(0) << "===============================================" << endl;
1002 Log() << Verbose(0) << "INPUT: ";
1003 cin >> choice;
1004
1005 switch (choice) {
1006 default:
1007 Log() << Verbose(0) << "Not a valid choice." << endl;
1008 break;
1009
1010 case 'a':
1011 SimpleAddMolecules(molecules);
1012 break;
1013
1014 case 'e':
1015 embeddMolecules(molecules);
1016 break;
1017
1018 case 'm':
1019 multiMergeMolecules(molecules);
1020 break;
1021
1022 case 's':
1023 Log() << Verbose(0) << "Not implemented yet." << endl;
1024 break;
1025
1026 case 't':
1027 simpleMergeMolecules(molecules);
1028 break;
1029 }
1030};
1031
1032
1033/********************************************** Test routine **************************************/
1034
1035/** Is called always as option 'T' in the menu.
1036 * \param *molecules list of molecules
1037 */
1038void oldmenu::testroutine(MoleculeListClass *molecules)
1039{
1040 // the current test routine checks the functionality of the KeySet&Graph concept:
1041 // We want to have a multiindex (the KeySet) describing a unique subgraph
1042 int i, comp, counter=0;
1043
1044 // create a clone
1045 molecule *mol = NULL;
1046 if (molecules->ListOfMolecules.size() != 0) // clone
1047 mol = (molecules->ListOfMolecules.front())->CopyMolecule();
1048 else {
1049 eLog() << Verbose(0) << "I don't have anything to test on ... ";
1050 performCriticalExit();
1051 return;
1052 }
1053 atom *Walker = mol->start;
1054
1055 // generate some KeySets
1056 Log() << Verbose(0) << "Generating KeySets." << endl;
1057 KeySet TestSets[mol->AtomCount+1];
1058 i=1;
1059 while (Walker->next != mol->end) {
1060 Walker = Walker->next;
1061 for (int j=0;j<i;j++) {
1062 TestSets[j].insert(Walker->nr);
1063 }
1064 i++;
1065 }
1066 Log() << Verbose(0) << "Testing insertion of already present item in KeySets." << endl;
1067 KeySetTestPair test;
1068 test = TestSets[mol->AtomCount-1].insert(Walker->nr);
1069 if (test.second) {
1070 Log() << Verbose(1) << "Insertion worked?!" << endl;
1071 } else {
1072 Log() << Verbose(1) << "Insertion rejected: Present object is " << (*test.first) << "." << endl;
1073 }
1074 TestSets[mol->AtomCount].insert(mol->end->previous->nr);
1075 TestSets[mol->AtomCount].insert(mol->end->previous->previous->previous->nr);
1076
1077 // constructing Graph structure
1078 Log() << Verbose(0) << "Generating Subgraph class." << endl;
1079 Graph Subgraphs;
1080
1081 // insert KeySets into Subgraphs
1082 Log() << Verbose(0) << "Inserting KeySets into Subgraph class." << endl;
1083 for (int j=0;j<mol->AtomCount;j++) {
1084 Subgraphs.insert(GraphPair (TestSets[j],pair<int, double>(counter++, 1.)));
1085 }
1086 Log() << Verbose(0) << "Testing insertion of already present item in Subgraph." << endl;
1087 GraphTestPair test2;
1088 test2 = Subgraphs.insert(GraphPair (TestSets[mol->AtomCount],pair<int, double>(counter++, 1.)));
1089 if (test2.second) {
1090 Log() << Verbose(1) << "Insertion worked?!" << endl;
1091 } else {
1092 Log() << Verbose(1) << "Insertion rejected: Present object is " << (*(test2.first)).second.first << "." << endl;
1093 }
1094
1095 // show graphs
1096 Log() << Verbose(0) << "Showing Subgraph's contents, checking that it's sorted." << endl;
1097 Graph::iterator A = Subgraphs.begin();
1098 while (A != Subgraphs.end()) {
1099 Log() << Verbose(0) << (*A).second.first << ": ";
1100 KeySet::iterator key = (*A).first.begin();
1101 comp = -1;
1102 while (key != (*A).first.end()) {
1103 if ((*key) > comp)
1104 Log() << Verbose(0) << (*key) << " ";
1105 else
1106 Log() << Verbose(0) << (*key) << "! ";
1107 comp = (*key);
1108 key++;
1109 }
1110 Log() << Verbose(0) << endl;
1111 A++;
1112 }
1113 delete(mol);
1114};
1115
1116oldmenu::oldmenu()
1117{
1118 // TODO Auto-generated constructor stub
1119}
1120
1121oldmenu::~oldmenu()
1122{
1123 // TODO Auto-generated destructor stub
1124}
1125
1126void oldmenu::notImplementedYet() {
1127 Log() << Verbose(0) << "This method has not yet been moved to an appropriate class." << endl;
1128}
1129
1130void oldmenu::perform(MoleculeListClass *molecules, config *configuration, periodentafel *periode, char *ConfigFileName)
1131{
1132
1133 // build the main menu
1134 TextMenu *main_menu = new TextMenu(Log() << Verbose(0), "Main Menu");
1135
1136 StringView *moleculeView = new StreamStringView(boost::bind(&MoleculeListClass::Enumerate,molecules,_1));
1137 new DisplayMenuItem(main_menu,moleculeView,"Molecule List");
1138
1139 new SeperatorItem(main_menu);
1140
1141 Action *setMoleculeAction = new MethodAction(boost::bind(&MoleculeListClass::flipChosen,molecules));
1142 new ActionMenuItem('a',"set molecule (in)active",main_menu,setMoleculeAction);
1143
1144 TextMenu *edit_molecules_menu = new TextMenu(Log() << Verbose(0), "Edit Molecules");
1145 new SubMenuItem('e',"edit molecules (load, parse, save)",main_menu,edit_molecules_menu);
1146
1147 Action *manipulateMoleculeAction = new MethodAction(boost::bind(&oldmenu::ManipulateMolecules,this,periode, molecules, configuration));
1148 new ActionMenuItem('g',"globally manipulate atoms in molecule",main_menu,manipulateMoleculeAction);
1149
1150 Action *mergeMoleculeAction = new MethodAction(boost::bind(&oldmenu::MergeMolecules,this,periode, molecules));
1151 new ActionMenuItem('M',"Merge molecules",main_menu,mergeMoleculeAction);
1152
1153 Action *manipulateAtomsAction = new MethodAction(boost::bind(&oldmenu::ManipulateAtoms,this,periode, molecules, configuration));
1154 new ActionMenuItem('m',"manipulate atoms",main_menu,manipulateAtomsAction);
1155
1156 new SeperatorItem(main_menu);
1157
1158 Action *editConfigAction = new MethodAction(boost::bind(&config::Edit,configuration));
1159 new ActionMenuItem('c',"edit the current configuration",main_menu,editConfigAction);
1160
1161 new SeperatorItem(main_menu);
1162
1163 Action *saveConfigAction = new MethodAction(boost::bind(&config::SaveAll,configuration, ConfigFileName, periode, molecules));
1164 new ActionMenuItem('s',"save current setup to config file",main_menu,saveConfigAction);
1165
1166 Action *doTestAction = new MethodAction(boost::bind(&oldmenu::testroutine,this,molecules));
1167 new ActionMenuItem('T',"call the current test routine",main_menu,doTestAction);
1168
1169 Action *quitAction = new MethodAction(boost::bind(&TextMenu::doQuit,main_menu));
1170 new ActionMenuItem('q',"quit",main_menu,quitAction);
1171
1172
1173
1174 // build the EditMoleculesMenu
1175 Action *createMoleculeAction = new MethodAction(boost::bind(&MoleculeListClass::createNewMolecule,molecules,periode));
1176 new ActionMenuItem('c',"create new molecule",edit_molecules_menu,createMoleculeAction);
1177
1178 Action *loadMoleculeAction = new MethodAction(boost::bind(&MoleculeListClass::loadFromXYZ,molecules,periode));
1179 new ActionMenuItem('l',"load molecule from xyz file",edit_molecules_menu,loadMoleculeAction);
1180
1181 Action *changeFilenameAction = new MethodAction(boost::bind(&MoleculeListClass::changeName,molecules));
1182 new ActionMenuItem('n',"change molecule's name",edit_molecules_menu,changeFilenameAction);
1183
1184 Action *giveFilenameAction = new MethodAction(boost::bind(&MoleculeListClass::setMoleculeFilename,molecules));
1185 new ActionMenuItem('N',"give molecules filename",edit_molecules_menu,giveFilenameAction);
1186
1187 Action *parseAtomsAction = new MethodAction(boost::bind(&MoleculeListClass::parseXYZIntoMolecule,molecules));
1188 new ActionMenuItem('p',"parse atoms in xyz file into molecule",edit_molecules_menu,parseAtomsAction);
1189
1190 Action *eraseMoleculeAction = new MethodAction(boost::bind(&MoleculeListClass::eraseMolecule,molecules));
1191 new ActionMenuItem('r',"remove a molecule",edit_molecules_menu,eraseMoleculeAction);
1192
1193 Action *returnAction = new MethodAction(boost::bind(&TextMenu::doQuit,edit_molecules_menu));
1194 MenuItem *returnItem = new ActionMenuItem('q',"return to Main menu",edit_molecules_menu,returnAction);
1195
1196 edit_molecules_menu->addDefault(returnItem);
1197
1198 main_menu->display();
1199
1200
1201 delete main_menu;
1202
1203 // delete all actions and views contained in Menu
1204 // TODO: find a better way to handle this
1205
1206 delete moleculeView;
1207
1208 delete setMoleculeAction;
1209 delete manipulateMoleculeAction;
1210 delete mergeMoleculeAction;
1211 delete manipulateAtomsAction;
1212 delete editConfigAction;
1213 delete saveConfigAction;
1214 delete doTestAction;
1215 delete quitAction;
1216
1217 delete createMoleculeAction;
1218 delete loadMoleculeAction;
1219 delete changeFilenameAction;
1220 delete giveFilenameAction;
1221 delete parseAtomsAction;
1222 delete eraseMoleculeAction;
1223 delete returnAction;
1224};
Note: See TracBrowser for help on using the repository browser.