source: src/Legacy/oldmenu.cpp@ 35b698

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

BIG CHANGE: config::load and config::save in ParseCommandLineOptions() and main() replaced with FormatParser replacements.

Fragmentation:

  • FIX: MoleculeFillWithMoleculeAction: filler atoms have to be removed before the system can be stored to file.
  • FIX: PcpParser::load() - has to put the molecule also into World's MoleculeListClass (otherwise the name cannot be set right after loading)
  • new Libparser.a
  • all sources from PARSER subdir are compiled into libparser such that only ParserUnitTest is recompiled.

Testfixes:

  • testsuite-fragmentation - changes to due to different -f calling syntax.
  • most of the xyz files had to be replaced due to a single whitespace at the end of each entry: Domain/6, Simple_configuration/2, Simple_configuration/3, Simple_configuration/4, Simple_configuration/5, Simple_configuration/8
  • in many cases were the number orbitals (and thus MaxMinStopStep) wrong: Filling/1, Simple_configuration/4, Simple_configuration/5

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

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