source: src/Legacy/oldmenu.cpp@ a7c344

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 a7c344 was a7c344, checked in by Frederik Heber <heber@…>, 15 years ago

Merge branch 'StructureRefactoring' of jupiter:espack into StructureRefactoring

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