source: src/Legacy/oldmenu.cpp@ edb454

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

MEMFIXES: Tesselation routines were leaking memory.

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

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