source: src/Legacy/oldmenu.cpp@ b32dbb

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

Changed and added counting of hydrogen bonds to menu.

  • CountHydrogenBonds() now receives two interface elements. This was needed to overcome double-couting in CSH-experiments.
  • Unit test CountHBonds has been changed accordingly, but not test for the new feature has been added.
  • case 'H' in builder.cpp is now used for counting hydrogen bonds not for giving help screen
  • option has been added to MeasureAtoms() menu

Signed-off-by: Frederik Heber <heber@…>

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