source: src/menu.cpp@ 21c246

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

Rebuild the main menu using the new structure as far as possible. Signed-off-by: Tillmann Crueger <crueger@…>

  • Property mode set to 100644
File size: 55.2 KB
Line 
1/** \file menu.cpp
2 * The class in this file is responsible for displaying the menu and enabling choices.
3 *
4 * This class is currently being refactored. Functions were copied from builder.cpp and are
5 * to be imported into the menu class.
6 *
7 */
8
9#include "menu.hpp"
10#include "analysis_correlation.hpp"
11#include "atom.hpp"
12#include "bond.hpp"
13#include "bondgraph.hpp"
14#include "boundary.hpp"
15#include "config.hpp"
16#include "element.hpp"
17#include "ellipsoid.hpp"
18#include "helpers.hpp"
19#include "leastsquaremin.hpp"
20#include "linkedcell.hpp"
21#include "log.hpp"
22#include "memoryusageobserverunittest.hpp"
23#include "molecule.hpp"
24#include "periodentafel.hpp"
25
26#include "Menu/Menu.hpp"
27#include "Menu/TextMenu.hpp"
28#include "Menu/ActionMenuItem.hpp"
29#include "Menu/SeperatorItem.hpp"
30#include "Actions/MethodAction.hpp"
31
32
33#include <boost/bind.hpp>
34
35/* copied methods for refactoring */
36/*TODO: Move these methods inside menu class
37 * and restructure menu class*/
38
39/********************************************* Subsubmenu routine ************************************/
40
41/** Submenu for adding atoms to the molecule.
42 * \param *periode periodentafel
43 * \param *molecule molecules with atoms
44 */
45void oldmenu::AddAtoms(periodentafel *periode, molecule *mol)
46{
47 atom *first, *second, *third, *fourth;
48 Vector **atoms;
49 Vector x,y,z,n; // coordinates for absolute point in cell volume
50 double a,b,c;
51 char choice; // menu choice char
52 bool valid;
53
54 Log() << Verbose(0) << "===========ADD ATOM============================" << endl;
55 Log() << Verbose(0) << " a - state absolute coordinates of atom" << endl;
56 Log() << Verbose(0) << " b - state relative coordinates of atom wrt to reference point" << endl;
57 Log() << Verbose(0) << " c - state relative coordinates of atom wrt to already placed atom" << endl;
58 Log() << Verbose(0) << " d - state two atoms, two angles and a distance" << endl;
59 Log() << Verbose(0) << " e - least square distance position to a set of atoms" << endl;
60 Log() << Verbose(0) << "all else - go back" << endl;
61 Log() << Verbose(0) << "===============================================" << endl;
62 Log() << Verbose(0) << "Note: Specifiy angles in degrees not multiples of Pi!" << endl;
63 Log() << Verbose(0) << "INPUT: ";
64 cin >> choice;
65
66 switch (choice) {
67 default:
68 eLog() << Verbose(2) << "Not a valid choice." << endl;
69 break;
70 case 'a': // absolute coordinates of atom
71 Log() << Verbose(0) << "Enter absolute coordinates." << endl;
72 first = new atom;
73 first->x.AskPosition(mol->cell_size, false);
74 first->type = periode->AskElement(); // give type
75 mol->AddAtom(first); // add to molecule
76 break;
77
78 case 'b': // relative coordinates of atom wrt to reference point
79 first = new atom;
80 valid = true;
81 do {
82 if (!valid) eLog() << Verbose(2) << "Resulting position out of cell." << endl;
83 Log() << Verbose(0) << "Enter reference coordinates." << endl;
84 x.AskPosition(mol->cell_size, true);
85 Log() << Verbose(0) << "Enter relative coordinates." << endl;
86 first->x.AskPosition(mol->cell_size, false);
87 first->x.AddVector((const Vector *)&x);
88 Log() << Verbose(0) << "\n";
89 } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
90 first->type = periode->AskElement(); // give type
91 mol->AddAtom(first); // add to molecule
92 break;
93
94 case 'c': // relative coordinates of atom wrt to already placed atom
95 first = new atom;
96 valid = true;
97 do {
98 if (!valid) eLog() << Verbose(2) << "Resulting position out of cell." << endl;
99 second = mol->AskAtom("Enter atom number: ");
100 Log() << Verbose(0) << "Enter relative coordinates." << endl;
101 first->x.AskPosition(mol->cell_size, false);
102 for (int i=NDIM;i--;) {
103 first->x.x[i] += second->x.x[i];
104 }
105 } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
106 first->type = periode->AskElement(); // give type
107 mol->AddAtom(first); // add to molecule
108 break;
109
110 case 'd': // two atoms, two angles and a distance
111 first = new atom;
112 valid = true;
113 do {
114 if (!valid) {
115 eLog() << Verbose(2) << "Resulting coordinates out of cell - " << first->x << endl;
116 }
117 Log() << Verbose(0) << "First, we need two atoms, the first atom is the central, while the second is the outer one." << endl;
118 second = mol->AskAtom("Enter central atom: ");
119 third = mol->AskAtom("Enter second atom (specifying the axis for first angle): ");
120 fourth = mol->AskAtom("Enter third atom (specifying a plane for second angle): ");
121 a = ask_value("Enter distance between central (first) and new atom: ");
122 b = ask_value("Enter angle between new, first and second atom (degrees): ");
123 b *= M_PI/180.;
124 bound(&b, 0., 2.*M_PI);
125 c = ask_value("Enter second angle between new and normal vector of plane defined by first, second and third atom (degrees): ");
126 c *= M_PI/180.;
127 bound(&c, -M_PI, M_PI);
128 Log() << Verbose(0) << "radius: " << a << "\t phi: " << b*180./M_PI << "\t theta: " << c*180./M_PI << endl;
129/*
130 second->Output(1,1,(ofstream *)&cout);
131 third->Output(1,2,(ofstream *)&cout);
132 fourth->Output(1,3,(ofstream *)&cout);
133 n.MakeNormalvector((const vector *)&second->x, (const vector *)&third->x, (const vector *)&fourth->x);
134 x.Copyvector(&second->x);
135 x.SubtractVector(&third->x);
136 x.Copyvector(&fourth->x);
137 x.SubtractVector(&third->x);
138
139 if (!z.SolveSystem(&x,&y,&n, b, c, a)) {
140 Log() << Verbose(0) << "Failure solving self-dependent linear system!" << endl;
141 continue;
142 }
143 Log() << Verbose(0) << "resulting relative coordinates: ";
144 z.Output();
145 Log() << Verbose(0) << endl;
146 */
147 // calc axis vector
148 x.CopyVector(&second->x);
149 x.SubtractVector(&third->x);
150 x.Normalize();
151 Log() << Verbose(0) << "x: ",
152 x.Output();
153 Log() << Verbose(0) << endl;
154 z.MakeNormalVector(&second->x,&third->x,&fourth->x);
155 Log() << Verbose(0) << "z: ",
156 z.Output();
157 Log() << Verbose(0) << endl;
158 y.MakeNormalVector(&x,&z);
159 Log() << Verbose(0) << "y: ",
160 y.Output();
161 Log() << Verbose(0) << endl;
162
163 // rotate vector around first angle
164 first->x.CopyVector(&x);
165 first->x.RotateVector(&z,b - M_PI);
166 Log() << Verbose(0) << "Rotated vector: ",
167 first->x.Output();
168 Log() << Verbose(0) << endl;
169 // remove the projection onto the rotation plane of the second angle
170 n.CopyVector(&y);
171 n.Scale(first->x.ScalarProduct(&y));
172 Log() << Verbose(0) << "N1: ",
173 n.Output();
174 Log() << Verbose(0) << endl;
175 first->x.SubtractVector(&n);
176 Log() << Verbose(0) << "Subtracted vector: ",
177 first->x.Output();
178 Log() << Verbose(0) << endl;
179 n.CopyVector(&z);
180 n.Scale(first->x.ScalarProduct(&z));
181 Log() << Verbose(0) << "N2: ",
182 n.Output();
183 Log() << Verbose(0) << endl;
184 first->x.SubtractVector(&n);
185 Log() << Verbose(0) << "2nd subtracted vector: ",
186 first->x.Output();
187 Log() << Verbose(0) << endl;
188
189 // rotate another vector around second angle
190 n.CopyVector(&y);
191 n.RotateVector(&x,c - M_PI);
192 Log() << Verbose(0) << "2nd Rotated vector: ",
193 n.Output();
194 Log() << Verbose(0) << endl;
195
196 // add the two linear independent vectors
197 first->x.AddVector(&n);
198 first->x.Normalize();
199 first->x.Scale(a);
200 first->x.AddVector(&second->x);
201
202 Log() << Verbose(0) << "resulting coordinates: ";
203 first->x.Output();
204 Log() << Verbose(0) << endl;
205 } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
206 first->type = periode->AskElement(); // give type
207 mol->AddAtom(first); // add to molecule
208 break;
209
210 case 'e': // least square distance position to a set of atoms
211 first = new atom;
212 atoms = new (Vector*[128]);
213 valid = true;
214 for(int i=128;i--;)
215 atoms[i] = NULL;
216 int i=0, j=0;
217 Log() << Verbose(0) << "Now we need at least three molecules.\n";
218 do {
219 Log() << Verbose(0) << "Enter " << i+1 << "th atom: ";
220 cin >> j;
221 if (j != -1) {
222 second = mol->FindAtom(j);
223 atoms[i++] = &(second->x);
224 }
225 } while ((j != -1) && (i<128));
226 if (i >= 2) {
227 first->x.LSQdistance((const Vector **)atoms, i);
228
229 first->x.Output();
230 first->type = periode->AskElement(); // give type
231 mol->AddAtom(first); // add to molecule
232 } else {
233 delete first;
234 Log() << Verbose(0) << "Please enter at least two vectors!\n";
235 }
236 break;
237 };
238};
239
240/** Submenu for centering the atoms in the molecule.
241 * \param *mol molecule with all the atoms
242 */
243void oldmenu::CenterAtoms(molecule *mol)
244{
245 Vector x, y, helper;
246 char choice; // menu choice char
247
248 Log() << Verbose(0) << "===========CENTER ATOMS=========================" << endl;
249 Log() << Verbose(0) << " a - on origin" << endl;
250 Log() << Verbose(0) << " b - on center of gravity" << endl;
251 Log() << Verbose(0) << " c - within box with additional boundary" << endl;
252 Log() << Verbose(0) << " d - within given simulation box" << endl;
253 Log() << Verbose(0) << "all else - go back" << endl;
254 Log() << Verbose(0) << "===============================================" << endl;
255 Log() << Verbose(0) << "INPUT: ";
256 cin >> choice;
257
258 switch (choice) {
259 default:
260 Log() << Verbose(0) << "Not a valid choice." << endl;
261 break;
262 case 'a':
263 Log() << Verbose(0) << "Centering atoms in config file on origin." << endl;
264 mol->CenterOrigin();
265 break;
266 case 'b':
267 Log() << Verbose(0) << "Centering atoms in config file on center of gravity." << endl;
268 mol->CenterPeriodic();
269 break;
270 case 'c':
271 Log() << Verbose(0) << "Centering atoms in config file within given additional boundary." << endl;
272 for (int i=0;i<NDIM;i++) {
273 Log() << Verbose(0) << "Enter axis " << i << " boundary: ";
274 cin >> y.x[i];
275 }
276 mol->CenterEdge(&x); // make every coordinate positive
277 mol->Center.AddVector(&y); // translate by boundary
278 helper.CopyVector(&y);
279 helper.Scale(2.);
280 helper.AddVector(&x);
281 mol->SetBoxDimension(&helper); // update Box of atoms by boundary
282 break;
283 case 'd':
284 Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl;
285 for (int i=0;i<NDIM;i++) {
286 Log() << Verbose(0) << "Enter axis " << i << " boundary: ";
287 cin >> x.x[i];
288 }
289 // update Box of atoms by boundary
290 mol->SetBoxDimension(&x);
291 // center
292 mol->CenterInBox();
293 break;
294 }
295};
296
297/** Submenu for aligning the atoms in the molecule.
298 * \param *periode periodentafel
299 * \param *mol molecule with all the atoms
300 */
301void oldmenu::AlignAtoms(periodentafel *periode, molecule *mol)
302{
303 atom *first, *second, *third;
304 Vector x,n;
305 char choice; // menu choice char
306
307 Log() << Verbose(0) << "===========ALIGN ATOMS=========================" << endl;
308 Log() << Verbose(0) << " a - state three atoms defining align plane" << endl;
309 Log() << Verbose(0) << " b - state alignment vector" << endl;
310 Log() << Verbose(0) << " c - state two atoms in alignment direction" << endl;
311 Log() << Verbose(0) << " d - align automatically by least square fit" << endl;
312 Log() << Verbose(0) << "all else - go back" << endl;
313 Log() << Verbose(0) << "===============================================" << endl;
314 Log() << Verbose(0) << "INPUT: ";
315 cin >> choice;
316
317 switch (choice) {
318 default:
319 case 'a': // three atoms defining mirror plane
320 first = mol->AskAtom("Enter first atom: ");
321 second = mol->AskAtom("Enter second atom: ");
322 third = mol->AskAtom("Enter third atom: ");
323
324 n.MakeNormalVector((const Vector *)&first->x,(const Vector *)&second->x,(const Vector *)&third->x);
325 break;
326 case 'b': // normal vector of mirror plane
327 Log() << Verbose(0) << "Enter normal vector of mirror plane." << endl;
328 n.AskPosition(mol->cell_size,0);
329 n.Normalize();
330 break;
331 case 'c': // three atoms defining mirror plane
332 first = mol->AskAtom("Enter first atom: ");
333 second = mol->AskAtom("Enter second atom: ");
334
335 n.CopyVector((const Vector *)&first->x);
336 n.SubtractVector((const Vector *)&second->x);
337 n.Normalize();
338 break;
339 case 'd':
340 char shorthand[4];
341 Vector a;
342 struct lsq_params param;
343 do {
344 fprintf(stdout, "Enter the element of atoms to be chosen: ");
345 fscanf(stdin, "%3s", shorthand);
346 } while ((param.type = periode->FindElement(shorthand)) == NULL);
347 Log() << Verbose(0) << "Element is " << param.type->name << endl;
348 mol->GetAlignvector(&param);
349 for (int i=NDIM;i--;) {
350 x.x[i] = gsl_vector_get(param.x,i);
351 n.x[i] = gsl_vector_get(param.x,i+NDIM);
352 }
353 gsl_vector_free(param.x);
354 Log() << Verbose(0) << "Offset vector: ";
355 x.Output();
356 Log() << Verbose(0) << endl;
357 n.Normalize();
358 break;
359 };
360 Log() << Verbose(0) << "Alignment vector: ";
361 n.Output();
362 Log() << Verbose(0) << endl;
363 mol->Align(&n);
364};
365
366/** Submenu for mirroring the atoms in the molecule.
367 * \param *mol molecule with all the atoms
368 */
369void oldmenu::MirrorAtoms(molecule *mol)
370{
371 atom *first, *second, *third;
372 Vector n;
373 char choice; // menu choice char
374
375 Log() << Verbose(0) << "===========MIRROR ATOMS=========================" << endl;
376 Log() << Verbose(0) << " a - state three atoms defining mirror plane" << endl;
377 Log() << Verbose(0) << " b - state normal vector of mirror plane" << endl;
378 Log() << Verbose(0) << " c - state two atoms in normal direction" << endl;
379 Log() << Verbose(0) << "all else - go back" << endl;
380 Log() << Verbose(0) << "===============================================" << endl;
381 Log() << Verbose(0) << "INPUT: ";
382 cin >> choice;
383
384 switch (choice) {
385 default:
386 case 'a': // three atoms defining mirror plane
387 first = mol->AskAtom("Enter first atom: ");
388 second = mol->AskAtom("Enter second atom: ");
389 third = mol->AskAtom("Enter third atom: ");
390
391 n.MakeNormalVector((const Vector *)&first->x,(const Vector *)&second->x,(const Vector *)&third->x);
392 break;
393 case 'b': // normal vector of mirror plane
394 Log() << Verbose(0) << "Enter normal vector of mirror plane." << endl;
395 n.AskPosition(mol->cell_size,0);
396 n.Normalize();
397 break;
398 case 'c': // three atoms defining mirror plane
399 first = mol->AskAtom("Enter first atom: ");
400 second = mol->AskAtom("Enter second atom: ");
401
402 n.CopyVector((const Vector *)&first->x);
403 n.SubtractVector((const Vector *)&second->x);
404 n.Normalize();
405 break;
406 };
407 Log() << Verbose(0) << "Normal vector: ";
408 n.Output();
409 Log() << Verbose(0) << endl;
410 mol->Mirror((const Vector *)&n);
411};
412
413/** Submenu for removing the atoms from the molecule.
414 * \param *mol molecule with all the atoms
415 */
416void oldmenu::RemoveAtoms(molecule *mol)
417{
418 atom *first, *second;
419 int axis;
420 double tmp1, tmp2;
421 char choice; // menu choice char
422
423 Log() << Verbose(0) << "===========REMOVE ATOMS=========================" << endl;
424 Log() << Verbose(0) << " a - state atom for removal by number" << endl;
425 Log() << Verbose(0) << " b - keep only in radius around atom" << endl;
426 Log() << Verbose(0) << " c - remove this with one axis greater value" << endl;
427 Log() << Verbose(0) << "all else - go back" << endl;
428 Log() << Verbose(0) << "===============================================" << endl;
429 Log() << Verbose(0) << "INPUT: ";
430 cin >> choice;
431
432 switch (choice) {
433 default:
434 case 'a':
435 if (mol->RemoveAtom(mol->AskAtom("Enter number of atom within molecule: ")))
436 Log() << Verbose(1) << "Atom removed." << endl;
437 else
438 Log() << Verbose(1) << "Atom not found." << endl;
439 break;
440 case 'b':
441 second = mol->AskAtom("Enter number of atom as reference point: ");
442 Log() << Verbose(0) << "Enter radius: ";
443 cin >> tmp1;
444 first = mol->start;
445 second = first->next;
446 while(second != mol->end) {
447 first = second;
448 second = first->next;
449 if (first->x.DistanceSquared((const Vector *)&second->x) > tmp1*tmp1) // distance to first above radius ...
450 mol->RemoveAtom(first);
451 }
452 break;
453 case 'c':
454 Log() << Verbose(0) << "Which axis is it: ";
455 cin >> axis;
456 Log() << Verbose(0) << "Lower boundary: ";
457 cin >> tmp1;
458 Log() << Verbose(0) << "Upper boundary: ";
459 cin >> tmp2;
460 first = mol->start;
461 second = first->next;
462 while(second != mol->end) {
463 first = second;
464 second = first->next;
465 if ((first->x.x[axis] < tmp1) || (first->x.x[axis] > tmp2)) {// out of boundary ...
466 //Log() << Verbose(0) << "Atom " << *first << " with " << first->x.x[axis] << " on axis " << axis << " is out of bounds [" << tmp1 << "," << tmp2 << "]." << endl;
467 mol->RemoveAtom(first);
468 }
469 }
470 break;
471 };
472 //mol->Output();
473 choice = 'r';
474};
475
476/** Submenu for measuring out the atoms in the molecule.
477 * \param *periode periodentafel
478 * \param *mol molecule with all the atoms
479 */
480void oldmenu::MeasureAtoms(periodentafel *periode, molecule *mol, config *configuration)
481{
482 atom *first, *second, *third;
483 Vector x,y;
484 double min[256], tmp1, tmp2, tmp3;
485 int Z;
486 char choice; // menu choice char
487
488 Log() << Verbose(0) << "===========MEASURE ATOMS=========================" << endl;
489 Log() << Verbose(0) << " a - calculate bond length between one atom and all others" << endl;
490 Log() << Verbose(0) << " b - calculate bond length between two atoms" << endl;
491 Log() << Verbose(0) << " c - calculate bond angle" << endl;
492 Log() << Verbose(0) << " d - calculate principal axis of the system" << endl;
493 Log() << Verbose(0) << " e - calculate volume of the convex envelope" << endl;
494 Log() << Verbose(0) << " f - calculate temperature from current velocity" << endl;
495 Log() << Verbose(0) << " g - output all temperatures per step from velocities" << endl;
496 Log() << Verbose(0) << "all else - go back" << endl;
497 Log() << Verbose(0) << "===============================================" << endl;
498 Log() << Verbose(0) << "INPUT: ";
499 cin >> choice;
500
501 switch(choice) {
502 default:
503 Log() << Verbose(1) << "Not a valid choice." << endl;
504 break;
505 case 'a':
506 first = mol->AskAtom("Enter first atom: ");
507 for (int i=MAX_ELEMENTS;i--;)
508 min[i] = 0.;
509
510 second = mol->start;
511 while ((second->next != mol->end)) {
512 second = second->next; // advance
513 Z = second->type->Z;
514 tmp1 = 0.;
515 if (first != second) {
516 x.CopyVector((const Vector *)&first->x);
517 x.SubtractVector((const Vector *)&second->x);
518 tmp1 = x.Norm();
519 }
520 if ((tmp1 != 0.) && ((min[Z] == 0.) || (tmp1 < min[Z]))) min[Z] = tmp1;
521 //Log() << Verbose(0) << "Bond length between Atom " << first->nr << " and " << second->nr << ": " << tmp1 << " a.u." << endl;
522 }
523 for (int i=MAX_ELEMENTS;i--;)
524 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;
525 break;
526
527 case 'b':
528 first = mol->AskAtom("Enter first atom: ");
529 second = mol->AskAtom("Enter second atom: ");
530 for (int i=NDIM;i--;)
531 min[i] = 0.;
532 x.CopyVector((const Vector *)&first->x);
533 x.SubtractVector((const Vector *)&second->x);
534 tmp1 = x.Norm();
535 Log() << Verbose(1) << "Distance vector is ";
536 x.Output();
537 Log() << Verbose(0) << "." << endl << "Norm of distance is " << tmp1 << "." << endl;
538 break;
539
540 case 'c':
541 Log() << Verbose(0) << "Evaluating bond angle between three - first, central, last - atoms." << endl;
542 first = mol->AskAtom("Enter first atom: ");
543 second = mol->AskAtom("Enter central atom: ");
544 third = mol->AskAtom("Enter last atom: ");
545 tmp1 = tmp2 = tmp3 = 0.;
546 x.CopyVector((const Vector *)&first->x);
547 x.SubtractVector((const Vector *)&second->x);
548 y.CopyVector((const Vector *)&third->x);
549 y.SubtractVector((const Vector *)&second->x);
550 Log() << Verbose(0) << "Bond angle between first atom Nr." << first->nr << ", central atom Nr." << second->nr << " and last atom Nr." << third->nr << ": ";
551 Log() << Verbose(0) << (acos(x.ScalarProduct((const Vector *)&y)/(y.Norm()*x.Norm()))/M_PI*180.) << " degrees" << endl;
552 break;
553 case 'd':
554 Log() << Verbose(0) << "Evaluating prinicipal axis." << endl;
555 Log() << Verbose(0) << "Shall we rotate? [0/1]: ";
556 cin >> Z;
557 if ((Z >=0) && (Z <=1))
558 mol->PrincipalAxisSystem((bool)Z);
559 else
560 mol->PrincipalAxisSystem(false);
561 break;
562 case 'e':
563 {
564 Log() << Verbose(0) << "Evaluating volume of the convex envelope.";
565 class Tesselation *TesselStruct = NULL;
566 const LinkedCell *LCList = NULL;
567 LCList = new LinkedCell(mol, 10.);
568 FindConvexBorder(mol, TesselStruct, LCList, NULL);
569 double clustervolume = VolumeOfConvexEnvelope(TesselStruct, configuration);
570 Log() << Verbose(0) << "The tesselated surface area is " << clustervolume << "." << endl;\
571 delete(LCList);
572 delete(TesselStruct);
573 }
574 break;
575 case 'f':
576 mol->OutputTemperatureFromTrajectories((ofstream *)&cout, mol->MDSteps-1, mol->MDSteps);
577 break;
578 case 'g':
579 {
580 char filename[255];
581 Log() << Verbose(0) << "Please enter filename: " << endl;
582 cin >> filename;
583 Log() << Verbose(1) << "Storing temperatures in " << filename << "." << endl;
584 ofstream *output = new ofstream(filename, ios::trunc);
585 if (!mol->OutputTemperatureFromTrajectories(output, 0, mol->MDSteps))
586 Log() << Verbose(2) << "File could not be written." << endl;
587 else
588 Log() << Verbose(2) << "File stored." << endl;
589 output->close();
590 delete(output);
591 }
592 break;
593 }
594};
595
596/** Submenu for measuring out the atoms in the molecule.
597 * \param *mol molecule with all the atoms
598 * \param *configuration configuration structure for the to be written config files of all fragments
599 */
600void oldmenu::FragmentAtoms(molecule *mol, config *configuration)
601{
602 int Order1;
603 clock_t start, end;
604
605 Log() << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl;
606 Log() << Verbose(0) << "What's the desired bond order: ";
607 cin >> Order1;
608 if (mol->first->next != mol->last) { // there are bonds
609 start = clock();
610 mol->FragmentMolecule(Order1, configuration);
611 end = clock();
612 Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
613 } else
614 Log() << Verbose(0) << "Connection matrix has not yet been generated!" << endl;
615};
616
617/********************************************** Submenu routine **************************************/
618
619/** Submenu for manipulating atoms.
620 * \param *periode periodentafel
621 * \param *molecules list of molecules whose atoms are to be manipulated
622 */
623void oldmenu::ManipulateAtoms(periodentafel *periode, MoleculeListClass *molecules, config *configuration)
624{
625 atom *first, *second;
626 molecule *mol = NULL;
627 Vector x,y,z,n; // coordinates for absolute point in cell volume
628 double *factor; // unit factor if desired
629 double bond, minBond;
630 char choice; // menu choice char
631 bool valid;
632
633 Log() << Verbose(0) << "=========MANIPULATE ATOMS======================" << endl;
634 Log() << Verbose(0) << "a - add an atom" << endl;
635 Log() << Verbose(0) << "r - remove an atom" << endl;
636 Log() << Verbose(0) << "b - scale a bond between atoms" << endl;
637 Log() << Verbose(0) << "u - change an atoms element" << endl;
638 Log() << Verbose(0) << "l - measure lengths, angles, ... for an atom" << endl;
639 Log() << Verbose(0) << "all else - go back" << endl;
640 Log() << Verbose(0) << "===============================================" << endl;
641 if (molecules->NumberOfActiveMolecules() > 1)
642 eLog() << Verbose(2) << "There is more than one molecule active! Atoms will be added to each." << endl;
643 Log() << Verbose(0) << "INPUT: ";
644 cin >> choice;
645
646 switch (choice) {
647 default:
648 Log() << Verbose(0) << "Not a valid choice." << endl;
649 break;
650
651 case 'a': // add atom
652 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
653 if ((*ListRunner)->ActiveFlag) {
654 mol = *ListRunner;
655 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
656 AddAtoms(periode, mol);
657 }
658 break;
659
660 case 'b': // scale a bond
661 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
662 if ((*ListRunner)->ActiveFlag) {
663 mol = *ListRunner;
664 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
665 Log() << Verbose(0) << "Scaling bond length between two atoms." << endl;
666 first = mol->AskAtom("Enter first (fixed) atom: ");
667 second = mol->AskAtom("Enter second (shifting) atom: ");
668 minBond = 0.;
669 for (int i=NDIM;i--;)
670 minBond += (first->x.x[i]-second->x.x[i])*(first->x.x[i] - second->x.x[i]);
671 minBond = sqrt(minBond);
672 Log() << Verbose(0) << "Current Bond length between " << first->type->name << " Atom " << first->nr << " and " << second->type->name << " Atom " << second->nr << ": " << minBond << " a.u." << endl;
673 Log() << Verbose(0) << "Enter new bond length [a.u.]: ";
674 cin >> bond;
675 for (int i=NDIM;i--;) {
676 second->x.x[i] -= (second->x.x[i]-first->x.x[i])/minBond*(minBond-bond);
677 }
678 //Log() << Verbose(0) << "New coordinates of Atom " << second->nr << " are: ";
679 //second->Output(second->type->No, 1);
680 }
681 break;
682
683 case 'c': // unit scaling of the metric
684 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
685 if ((*ListRunner)->ActiveFlag) {
686 mol = *ListRunner;
687 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
688 Log() << Verbose(0) << "Angstroem -> Bohrradius: 1.8897261\t\tBohrradius -> Angstroem: 0.52917721" << endl;
689 Log() << Verbose(0) << "Enter three factors: ";
690 factor = new double[NDIM];
691 cin >> factor[0];
692 cin >> factor[1];
693 cin >> factor[2];
694 valid = true;
695 mol->Scale((const double ** const)&factor);
696 delete[](factor);
697 }
698 break;
699
700 case 'l': // measure distances or angles
701 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
702 if ((*ListRunner)->ActiveFlag) {
703 mol = *ListRunner;
704 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
705 MeasureAtoms(periode, mol, configuration);
706 }
707 break;
708
709 case 'r': // remove atom
710 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
711 if ((*ListRunner)->ActiveFlag) {
712 mol = *ListRunner;
713 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
714 RemoveAtoms(mol);
715 }
716 break;
717
718 case 'u': // change an atom's element
719 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
720 if ((*ListRunner)->ActiveFlag) {
721 int Z;
722 mol = *ListRunner;
723 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
724 first = NULL;
725 do {
726 Log() << Verbose(0) << "Change the element of which atom: ";
727 cin >> Z;
728 } while ((first = mol->FindAtom(Z)) == NULL);
729 Log() << Verbose(0) << "New element by atomic number Z: ";
730 cin >> Z;
731 first->type = periode->FindElement(Z);
732 Log() << Verbose(0) << "Atom " << first->nr << "'s element is " << first->type->name << "." << endl;
733 }
734 break;
735 }
736};
737
738/** Submenu for manipulating molecules.
739 * \param *periode periodentafel
740 * \param *molecules list of molecule to manipulate
741 */
742void oldmenu::ManipulateMolecules(periodentafel *periode, MoleculeListClass *molecules, config *configuration)
743{
744 atom *first = NULL;
745 Vector x,y,z,n; // coordinates for absolute point in cell volume
746 int j, axis, count, faktor;
747 char choice; // menu choice char
748 molecule *mol = NULL;
749 element **Elements;
750 Vector **vectors;
751 MoleculeLeafClass *Subgraphs = NULL;
752
753 Log() << Verbose(0) << "=========MANIPULATE GLOBALLY===================" << endl;
754 Log() << Verbose(0) << "c - scale by unit transformation" << endl;
755 Log() << Verbose(0) << "d - duplicate molecule/periodic cell" << endl;
756 Log() << Verbose(0) << "f - fragment molecule many-body bond order style" << endl;
757 Log() << Verbose(0) << "g - center atoms in box" << endl;
758 Log() << Verbose(0) << "i - realign molecule" << endl;
759 Log() << Verbose(0) << "m - mirror all molecules" << endl;
760 Log() << Verbose(0) << "o - create connection matrix" << endl;
761 Log() << Verbose(0) << "t - translate molecule by vector" << endl;
762 Log() << Verbose(0) << "all else - go back" << endl;
763 Log() << Verbose(0) << "===============================================" << endl;
764 if (molecules->NumberOfActiveMolecules() > 1)
765 eLog() << Verbose(2) << "There is more than one molecule active! Atoms will be added to each." << endl;
766 Log() << Verbose(0) << "INPUT: ";
767 cin >> choice;
768
769 switch (choice) {
770 default:
771 Log() << Verbose(0) << "Not a valid choice." << endl;
772 break;
773
774 case 'd': // duplicate the periodic cell along a given axis, given times
775 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
776 if ((*ListRunner)->ActiveFlag) {
777 mol = *ListRunner;
778 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
779 Log() << Verbose(0) << "State the axis [(+-)123]: ";
780 cin >> axis;
781 Log() << Verbose(0) << "State the factor: ";
782 cin >> faktor;
783
784 mol->CountAtoms(); // recount atoms
785 if (mol->AtomCount != 0) { // if there is more than none
786 count = mol->AtomCount; // is changed becausing of adding, thus has to be stored away beforehand
787 Elements = new element *[count];
788 vectors = new Vector *[count];
789 j = 0;
790 first = mol->start;
791 while (first->next != mol->end) { // make a list of all atoms with coordinates and element
792 first = first->next;
793 Elements[j] = first->type;
794 vectors[j] = &first->x;
795 j++;
796 }
797 if (count != j)
798 eLog() << Verbose(1) << "AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl;
799 x.Zero();
800 y.Zero();
801 y.x[abs(axis)-1] = mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude
802 for (int i=1;i<faktor;i++) { // then add this list with respective translation factor times
803 x.AddVector(&y); // per factor one cell width further
804 for (int k=count;k--;) { // go through every atom of the original cell
805 first = new atom(); // create a new body
806 first->x.CopyVector(vectors[k]); // use coordinate of original atom
807 first->x.AddVector(&x); // translate the coordinates
808 first->type = Elements[k]; // insert original element
809 mol->AddAtom(first); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)
810 }
811 }
812 if (mol->first->next != mol->last) // if connect matrix is present already, redo it
813 mol->CreateAdjacencyList(mol->BondDistance, configuration->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
814 // free memory
815 delete[](Elements);
816 delete[](vectors);
817 // correct cell size
818 if (axis < 0) { // if sign was negative, we have to translate everything
819 x.Zero();
820 x.AddVector(&y);
821 x.Scale(-(faktor-1));
822 mol->Translate(&x);
823 }
824 mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;
825 }
826 }
827 break;
828
829 case 'f':
830 FragmentAtoms(mol, configuration);
831 break;
832
833 case 'g': // center the atoms
834 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
835 if ((*ListRunner)->ActiveFlag) {
836 mol = *ListRunner;
837 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
838 CenterAtoms(mol);
839 }
840 break;
841
842 case 'i': // align all atoms
843 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
844 if ((*ListRunner)->ActiveFlag) {
845 mol = *ListRunner;
846 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
847 AlignAtoms(periode, mol);
848 }
849 break;
850
851 case 'm': // mirror atoms along a given axis
852 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
853 if ((*ListRunner)->ActiveFlag) {
854 mol = *ListRunner;
855 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
856 MirrorAtoms(mol);
857 }
858 break;
859
860 case 'o': // create the connection matrix
861 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
862 if ((*ListRunner)->ActiveFlag) {
863 mol = *ListRunner;
864 double bonddistance;
865 clock_t start,end;
866 Log() << Verbose(0) << "What's the maximum bond distance: ";
867 cin >> bonddistance;
868 start = clock();
869 mol->CreateAdjacencyList(bonddistance, configuration->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
870 end = clock();
871 Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
872 }
873 break;
874
875 case 't': // translate all atoms
876 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
877 if ((*ListRunner)->ActiveFlag) {
878 mol = *ListRunner;
879 Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
880 Log() << Verbose(0) << "Enter translation vector." << endl;
881 x.AskPosition(mol->cell_size,0);
882 mol->Center.AddVector((const Vector *)&x);
883 }
884 break;
885 }
886 // Free all
887 if (Subgraphs != NULL) { // free disconnected subgraph list of DFS analysis was performed
888 while (Subgraphs->next != NULL) {
889 Subgraphs = Subgraphs->next;
890 delete(Subgraphs->previous);
891 }
892 delete(Subgraphs);
893 }
894};
895
896
897/** Submenu for creating new molecules.
898 * \param *periode periodentafel
899 * \param *molecules list of molecules to add to
900 */
901void oldmenu::EditMolecules(periodentafel *periode, MoleculeListClass *molecules)
902{
903 char choice; // menu choice char
904 Vector center;
905 int nr, count;
906 molecule *mol = NULL;
907
908 Log() << Verbose(0) << "==========EDIT MOLECULES=====================" << endl;
909 Log() << Verbose(0) << "c - create new molecule" << endl;
910 Log() << Verbose(0) << "l - load molecule from xyz file" << endl;
911 Log() << Verbose(0) << "n - change molecule's name" << endl;
912 Log() << Verbose(0) << "N - give molecules filename" << endl;
913 Log() << Verbose(0) << "p - parse atoms in xyz file into molecule" << endl;
914 Log() << Verbose(0) << "r - remove a molecule" << endl;
915 Log() << Verbose(0) << "all else - go back" << endl;
916 Log() << Verbose(0) << "===============================================" << endl;
917 Log() << Verbose(0) << "INPUT: ";
918 cin >> choice;
919
920 switch (choice) {
921 default:
922 Log() << Verbose(0) << "Not a valid choice." << endl;
923 break;
924 case 'c':
925 mol = new molecule(periode);
926 molecules->insert(mol);
927 break;
928
929 case 'l': // load from XYZ file
930 {
931 char filename[MAXSTRINGSIZE];
932 Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
933 mol = new molecule(periode);
934 do {
935 Log() << Verbose(0) << "Enter file name: ";
936 cin >> filename;
937 } while (!mol->AddXYZFile(filename));
938 mol->SetNameFromFilename(filename);
939 // center at set box dimensions
940 mol->CenterEdge(&center);
941 mol->cell_size[0] = center.x[0];
942 mol->cell_size[1] = 0;
943 mol->cell_size[2] = center.x[1];
944 mol->cell_size[3] = 0;
945 mol->cell_size[4] = 0;
946 mol->cell_size[5] = center.x[2];
947 molecules->insert(mol);
948 }
949 break;
950
951 case 'n':
952 {
953 char filename[MAXSTRINGSIZE];
954 do {
955 Log() << Verbose(0) << "Enter index of molecule: ";
956 cin >> nr;
957 mol = molecules->ReturnIndex(nr);
958 } while (mol == NULL);
959 Log() << Verbose(0) << "Enter name: ";
960 cin >> filename;
961 strcpy(mol->name, filename);
962 }
963 break;
964
965 case 'N':
966 {
967 char filename[MAXSTRINGSIZE];
968 do {
969 Log() << Verbose(0) << "Enter index of molecule: ";
970 cin >> nr;
971 mol = molecules->ReturnIndex(nr);
972 } while (mol == NULL);
973 Log() << Verbose(0) << "Enter name: ";
974 cin >> filename;
975 mol->SetNameFromFilename(filename);
976 }
977 break;
978
979 case 'p': // parse XYZ file
980 {
981 char filename[MAXSTRINGSIZE];
982 mol = NULL;
983 do {
984 Log() << Verbose(0) << "Enter index of molecule: ";
985 cin >> nr;
986 mol = molecules->ReturnIndex(nr);
987 } while (mol == NULL);
988 Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
989 do {
990 Log() << Verbose(0) << "Enter file name: ";
991 cin >> filename;
992 } while (!mol->AddXYZFile(filename));
993 mol->SetNameFromFilename(filename);
994 }
995 break;
996
997 case 'r':
998 Log() << Verbose(0) << "Enter index of molecule: ";
999 cin >> nr;
1000 count = 1;
1001 for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
1002 if (nr == (*ListRunner)->IndexNr) {
1003 mol = *ListRunner;
1004 molecules->ListOfMolecules.erase(ListRunner);
1005 delete(mol);
1006 break;
1007 }
1008 break;
1009 }
1010};
1011
1012
1013/** Submenu for merging molecules.
1014 * \param *periode periodentafel
1015 * \param *molecules list of molecules to add to
1016 */
1017void oldmenu::MergeMolecules(periodentafel *periode, MoleculeListClass *molecules)
1018{
1019 char choice; // menu choice char
1020
1021 Log() << Verbose(0) << "===========MERGE MOLECULES=====================" << endl;
1022 Log() << Verbose(0) << "a - simple add of one molecule to another" << endl;
1023 Log() << Verbose(0) << "e - embedding merge of two molecules" << endl;
1024 Log() << Verbose(0) << "m - multi-merge of all molecules" << endl;
1025 Log() << Verbose(0) << "s - scatter merge of two molecules" << endl;
1026 Log() << Verbose(0) << "t - simple merge of two molecules" << endl;
1027 Log() << Verbose(0) << "all else - go back" << endl;
1028 Log() << Verbose(0) << "===============================================" << endl;
1029 Log() << Verbose(0) << "INPUT: ";
1030 cin >> choice;
1031
1032 switch (choice) {
1033 default:
1034 Log() << Verbose(0) << "Not a valid choice." << endl;
1035 break;
1036
1037 case 'a':
1038 {
1039 int src, dest;
1040 molecule *srcmol = NULL, *destmol = NULL;
1041 {
1042 do {
1043 Log() << Verbose(0) << "Enter index of destination molecule: ";
1044 cin >> dest;
1045 destmol = molecules->ReturnIndex(dest);
1046 } while ((destmol == NULL) && (dest != -1));
1047 do {
1048 Log() << Verbose(0) << "Enter index of source molecule to add from: ";
1049 cin >> src;
1050 srcmol = molecules->ReturnIndex(src);
1051 } while ((srcmol == NULL) && (src != -1));
1052 if ((src != -1) && (dest != -1))
1053 molecules->SimpleAdd(srcmol, destmol);
1054 }
1055 }
1056 break;
1057
1058 case 'e':
1059 {
1060 int src, dest;
1061 molecule *srcmol = NULL, *destmol = NULL;
1062 do {
1063 Log() << Verbose(0) << "Enter index of matrix molecule (the variable one): ";
1064 cin >> src;
1065 srcmol = molecules->ReturnIndex(src);
1066 } while ((srcmol == NULL) && (src != -1));
1067 do {
1068 Log() << Verbose(0) << "Enter index of molecule to merge into (the fixed one): ";
1069 cin >> dest;
1070 destmol = molecules->ReturnIndex(dest);
1071 } while ((destmol == NULL) && (dest != -1));
1072 if ((src != -1) && (dest != -1))
1073 molecules->EmbedMerge(destmol, srcmol);
1074 }
1075 break;
1076
1077 case 'm':
1078 {
1079 int nr;
1080 molecule *mol = NULL;
1081 do {
1082 Log() << Verbose(0) << "Enter index of molecule to merge into: ";
1083 cin >> nr;
1084 mol = molecules->ReturnIndex(nr);
1085 } while ((mol == NULL) && (nr != -1));
1086 if (nr != -1) {
1087 int N = molecules->ListOfMolecules.size()-1;
1088 int *src = new int(N);
1089 for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
1090 if ((*ListRunner)->IndexNr != nr)
1091 src[N++] = (*ListRunner)->IndexNr;
1092 molecules->SimpleMultiMerge(mol, src, N);
1093 delete[](src);
1094 }
1095 }
1096 break;
1097
1098 case 's':
1099 Log() << Verbose(0) << "Not implemented yet." << endl;
1100 break;
1101
1102 case 't':
1103 {
1104 int src, dest;
1105 molecule *srcmol = NULL, *destmol = NULL;
1106 {
1107 do {
1108 Log() << Verbose(0) << "Enter index of destination molecule: ";
1109 cin >> dest;
1110 destmol = molecules->ReturnIndex(dest);
1111 } while ((destmol == NULL) && (dest != -1));
1112 do {
1113 Log() << Verbose(0) << "Enter index of source molecule to merge into: ";
1114 cin >> src;
1115 srcmol = molecules->ReturnIndex(src);
1116 } while ((srcmol == NULL) && (src != -1));
1117 if ((src != -1) && (dest != -1))
1118 molecules->SimpleMerge(srcmol, destmol);
1119 }
1120 }
1121 break;
1122 }
1123};
1124
1125
1126/********************************************** Test routine **************************************/
1127
1128/** Is called always as option 'T' in the menu.
1129 * \param *molecules list of molecules
1130 */
1131void oldmenu::testroutine(MoleculeListClass *molecules)
1132{
1133 // the current test routine checks the functionality of the KeySet&Graph concept:
1134 // We want to have a multiindex (the KeySet) describing a unique subgraph
1135 int i, comp, counter=0;
1136
1137 // create a clone
1138 molecule *mol = NULL;
1139 if (molecules->ListOfMolecules.size() != 0) // clone
1140 mol = (molecules->ListOfMolecules.front())->CopyMolecule();
1141 else {
1142 eLog() << Verbose(0) << "I don't have anything to test on ... ";
1143 performCriticalExit();
1144 return;
1145 }
1146 atom *Walker = mol->start;
1147
1148 // generate some KeySets
1149 Log() << Verbose(0) << "Generating KeySets." << endl;
1150 KeySet TestSets[mol->AtomCount+1];
1151 i=1;
1152 while (Walker->next != mol->end) {
1153 Walker = Walker->next;
1154 for (int j=0;j<i;j++) {
1155 TestSets[j].insert(Walker->nr);
1156 }
1157 i++;
1158 }
1159 Log() << Verbose(0) << "Testing insertion of already present item in KeySets." << endl;
1160 KeySetTestPair test;
1161 test = TestSets[mol->AtomCount-1].insert(Walker->nr);
1162 if (test.second) {
1163 Log() << Verbose(1) << "Insertion worked?!" << endl;
1164 } else {
1165 Log() << Verbose(1) << "Insertion rejected: Present object is " << (*test.first) << "." << endl;
1166 }
1167 TestSets[mol->AtomCount].insert(mol->end->previous->nr);
1168 TestSets[mol->AtomCount].insert(mol->end->previous->previous->previous->nr);
1169
1170 // constructing Graph structure
1171 Log() << Verbose(0) << "Generating Subgraph class." << endl;
1172 Graph Subgraphs;
1173
1174 // insert KeySets into Subgraphs
1175 Log() << Verbose(0) << "Inserting KeySets into Subgraph class." << endl;
1176 for (int j=0;j<mol->AtomCount;j++) {
1177 Subgraphs.insert(GraphPair (TestSets[j],pair<int, double>(counter++, 1.)));
1178 }
1179 Log() << Verbose(0) << "Testing insertion of already present item in Subgraph." << endl;
1180 GraphTestPair test2;
1181 test2 = Subgraphs.insert(GraphPair (TestSets[mol->AtomCount],pair<int, double>(counter++, 1.)));
1182 if (test2.second) {
1183 Log() << Verbose(1) << "Insertion worked?!" << endl;
1184 } else {
1185 Log() << Verbose(1) << "Insertion rejected: Present object is " << (*(test2.first)).second.first << "." << endl;
1186 }
1187
1188 // show graphs
1189 Log() << Verbose(0) << "Showing Subgraph's contents, checking that it's sorted." << endl;
1190 Graph::iterator A = Subgraphs.begin();
1191 while (A != Subgraphs.end()) {
1192 Log() << Verbose(0) << (*A).second.first << ": ";
1193 KeySet::iterator key = (*A).first.begin();
1194 comp = -1;
1195 while (key != (*A).first.end()) {
1196 if ((*key) > comp)
1197 Log() << Verbose(0) << (*key) << " ";
1198 else
1199 Log() << Verbose(0) << (*key) << "! ";
1200 comp = (*key);
1201 key++;
1202 }
1203 Log() << Verbose(0) << endl;
1204 A++;
1205 }
1206 delete(mol);
1207};
1208
1209oldmenu::oldmenu()
1210{
1211 // TODO Auto-generated constructor stub
1212}
1213
1214oldmenu::~oldmenu()
1215{
1216 // TODO Auto-generated destructor stub
1217}
1218
1219void oldmenu::notImplementedYet() {
1220 Log() << Verbose(0) << "This method has not yet been moved to an appropriate class." << endl;
1221}
1222
1223void oldmenu::perform(MoleculeListClass *molecules, config *configuration, periodentafel *periode, char *ConfigFileName)
1224{
1225 TextMenu *main_menu = new TextMenu(Log() << Verbose(0), "Main Menu");
1226
1227 MethodAction *setMoleculeAction = new MethodAction(boost::bind(&oldmenu::notImplementedYet,this));
1228 new ActionMenuItem('a',"set molecule (in)active",main_menu,setMoleculeAction);
1229
1230 MethodAction *editMoleculeAction = new MethodAction(boost::bind(&oldmenu::EditMolecules,this,periode, molecules));
1231 new ActionMenuItem('e',"edit molecules (load, parse, save)",main_menu,editMoleculeAction);
1232
1233 MethodAction *manipulateMoleculeAction = new MethodAction(boost::bind(&oldmenu::ManipulateMolecules,this,periode, molecules, configuration));
1234 new ActionMenuItem('g',"globally manipulate atoms in molecule",main_menu,manipulateMoleculeAction);
1235
1236 MethodAction *mergeMoleculeAction = new MethodAction(boost::bind(&oldmenu::MergeMolecules,this,periode, molecules));
1237 new ActionMenuItem('M',"Merge molecules",main_menu,mergeMoleculeAction);
1238
1239 MethodAction *manipulateAtomsAction = new MethodAction(boost::bind(&oldmenu::ManipulateAtoms,this,periode, molecules, configuration));
1240 new ActionMenuItem('m',"manipulate atoms",main_menu,manipulateAtomsAction);
1241
1242 new SeperatorItem(main_menu);
1243
1244 MethodAction *editConfigAction = new MethodAction(boost::bind(&config::Edit,configuration));
1245 new ActionMenuItem('c',"edit the current configuration",main_menu,editConfigAction);
1246
1247 new SeperatorItem(main_menu);
1248
1249 MethodAction *saveConfigAction = new MethodAction(boost::bind(&oldmenu::SaveConfig,this,ConfigFileName, configuration, periode, molecules));
1250 new ActionMenuItem('s',"save current setup to config file",main_menu,saveConfigAction);
1251
1252 MethodAction *doTestAction = new MethodAction(boost::bind(&oldmenu::testroutine,this,molecules));
1253 new ActionMenuItem('T',"call the current test routine",main_menu,doTestAction);
1254
1255 MethodAction *quitAction = new MethodAction(boost::bind(&TextMenu::doQuit,main_menu));
1256 new ActionMenuItem('q',"quit",main_menu,quitAction);
1257
1258
1259 main_menu->display();
1260
1261
1262 delete setMoleculeAction;
1263 delete editMoleculeAction;
1264 delete manipulateMoleculeAction;
1265 delete mergeMoleculeAction;
1266 delete manipulateAtomsAction;
1267 delete editConfigAction;
1268 delete saveConfigAction;
1269 delete doTestAction;
1270 delete quitAction;
1271
1272#if 0
1273 char choice;
1274 int j;
1275 Log() << Verbose(0) << endl << "Now comes the real construction..." << endl;
1276 do {
1277 Log() << Verbose(0) << endl << endl;
1278 Log() << Verbose(0) << "============Molecule list=======================" << endl;
1279 molecules->Enumerate((ofstream *)&cout);
1280 Log() << Verbose(0) << "============Menu===============================" << endl;
1281 Log() << Verbose(0) << "a - set molecule (in)active" << endl; //to be moved
1282 Log() << Verbose(0) << "e - edit molecules (load, parse, save)" << endl; // done
1283 Log() << Verbose(0) << "g - globally manipulate atoms in molecule" << endl;
1284 Log() << Verbose(0) << "M - Merge molecules" << endl;
1285 Log() << Verbose(0) << "m - manipulate atoms" << endl;
1286 Log() << Verbose(0) << "-----------------------------------------------" << endl;
1287 Log() << Verbose(0) << "c - edit the current configuration" << endl;
1288 Log() << Verbose(0) << "-----------------------------------------------" << endl;
1289 Log() << Verbose(0) << "s - save current setup to config file" << endl;
1290 Log() << Verbose(0) << "T - call the current test routine" << endl;
1291 Log() << Verbose(0) << "q - quit" << endl; //done
1292 Log() << Verbose(0) << "===============================================" << endl;
1293 Log() << Verbose(0) << "Input: ";
1294 cin >> choice;
1295
1296 switch (choice) {
1297 case 'a': // (in)activate molecule
1298 {
1299 Log() << Verbose(0) << "Enter index of molecule: ";
1300 cin >> j;
1301 for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
1302 if ((*ListRunner)->IndexNr == j)
1303 (*ListRunner)->ActiveFlag = !(*ListRunner)->ActiveFlag;
1304 }
1305 break;
1306
1307 case 'c': // edit each field of the configuration
1308 configuration->Edit();
1309 break;
1310
1311 case 'e': // create molecule
1312 EditMolecules(periode, molecules);
1313 break;
1314
1315 case 'g': // manipulate molecules
1316 ManipulateMolecules(periode, molecules, configuration);
1317 break;
1318
1319 case 'M': // merge molecules
1320 MergeMolecules(periode, molecules);
1321 break;
1322
1323 case 'm': // manipulate atoms
1324 ManipulateAtoms(periode, molecules, configuration);
1325 break;
1326
1327 case 'q': // quit
1328 break;
1329
1330 case 's': // save to config file
1331 SaveConfig(ConfigFileName, configuration, periode, molecules);
1332 break;
1333
1334 case 'T':
1335 testroutine(molecules);
1336 break;
1337
1338 default:
1339 break;
1340 };
1341 } while (choice != 'q');
1342#endif
1343};
1344
1345/** Tries given filename or standard on saving the config file.
1346 * \param *ConfigFileName name of file
1347 * \param *configuration pointer to configuration structure with all the values
1348 * \param *periode pointer to periodentafel structure with all the elements
1349 * \param *molecules list of molecules structure with all the atoms and coordinates
1350 */
1351void oldmenu::SaveConfig(char *ConfigFileName, config *configuration, periodentafel *periode, MoleculeListClass *molecules)
1352{
1353 char filename[MAXSTRINGSIZE];
1354 ofstream output;
1355 molecule *mol = new molecule(periode);
1356
1357 if (!strcmp(configuration->configpath, configuration->GetDefaultPath())) {
1358 eLog() << Verbose(2) << "config is found under different path then stated in config file::defaultpath!" << endl;
1359 }
1360
1361
1362 // first save as PDB data
1363 if (ConfigFileName != NULL)
1364 strcpy(filename, ConfigFileName);
1365 else
1366 strcpy(filename,"main_pcp_linux");
1367 Log() << Verbose(0) << "Saving as pdb input ";
1368 if (configuration->SavePDB(filename, molecules))
1369 Log() << Verbose(0) << "done." << endl;
1370 else
1371 Log() << Verbose(0) << "failed." << endl;
1372
1373 // then save as tremolo data file
1374 if (ConfigFileName != NULL)
1375 strcpy(filename, ConfigFileName);
1376 else
1377 strcpy(filename,"main_pcp_linux");
1378 Log() << Verbose(0) << "Saving as tremolo data input ";
1379 if (configuration->SaveTREMOLO(filename, molecules))
1380 Log() << Verbose(0) << "done." << endl;
1381 else
1382 Log() << Verbose(0) << "failed." << endl;
1383
1384 // translate each to its center and merge all molecules in MoleculeListClass into this molecule
1385 int N = molecules->ListOfMolecules.size();
1386 int *src = new int[N];
1387 N=0;
1388 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
1389 src[N++] = (*ListRunner)->IndexNr;
1390 (*ListRunner)->Translate(&(*ListRunner)->Center);
1391 }
1392 molecules->SimpleMultiAdd(mol, src, N);
1393 delete[](src);
1394
1395 // ... and translate back
1396 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
1397 (*ListRunner)->Center.Scale(-1.);
1398 (*ListRunner)->Translate(&(*ListRunner)->Center);
1399 (*ListRunner)->Center.Scale(-1.);
1400 }
1401
1402 Log() << Verbose(0) << "Storing configuration ... " << endl;
1403 // get correct valence orbitals
1404 mol->CalculateOrbitals(*configuration);
1405 configuration->InitMaxMinStopStep = configuration->MaxMinStopStep = configuration->MaxPsiDouble;
1406 if (ConfigFileName != NULL) { // test the file name
1407 strcpy(filename, ConfigFileName);
1408 output.open(filename, ios::trunc);
1409 } else if (strlen(configuration->configname) != 0) {
1410 strcpy(filename, configuration->configname);
1411 output.open(configuration->configname, ios::trunc);
1412 } else {
1413 strcpy(filename, DEFAULTCONFIG);
1414 output.open(DEFAULTCONFIG, ios::trunc);
1415 }
1416 output.close();
1417 output.clear();
1418 Log() << Verbose(0) << "Saving of config file ";
1419 if (configuration->Save(filename, periode, mol))
1420 Log() << Verbose(0) << "successful." << endl;
1421 else
1422 Log() << Verbose(0) << "failed." << endl;
1423
1424 // and save to xyz file
1425 if (ConfigFileName != NULL) {
1426 strcpy(filename, ConfigFileName);
1427 strcat(filename, ".xyz");
1428 output.open(filename, ios::trunc);
1429 }
1430 else {
1431 strcpy(filename,"main_pcp_linux");
1432 strcat(filename, ".xyz");
1433 output.open(filename, ios::trunc);
1434 }
1435 Log() << Verbose(0) << "Saving of XYZ file ";
1436 if (mol->MDSteps <= 1) {
1437 if (mol->OutputXYZ(&output))
1438 Log() << Verbose(0) << "successful." << endl;
1439 else
1440 Log() << Verbose(0) << "failed." << endl;
1441 } else {
1442 if (mol->OutputTrajectoriesXYZ(&output))
1443 Log() << Verbose(0) << "successful." << endl;
1444 else
1445 Log() << Verbose(0) << "failed." << endl;
1446 }
1447 output.close();
1448 output.clear();
1449
1450 // and save as MPQC configuration
1451 if (ConfigFileName != NULL)
1452 strcpy(filename, ConfigFileName);
1453 else
1454 strcpy(filename,"main_pcp_linux");
1455 Log() << Verbose(0) << "Saving as mpqc input ";
1456 if (configuration->SaveMPQC(filename, mol))
1457 Log() << Verbose(0) << "done." << endl;
1458 else
1459 Log() << Verbose(0) << "failed." << endl;
1460
1461 if (!strcmp(configuration->configpath, configuration->GetDefaultPath())) {
1462 eLog() << Verbose(2) << "config is found under different path then stated in config file::defaultpath!" << endl;
1463 }
1464
1465 delete(mol);
1466};
Note: See TracBrowser for help on using the repository browser.