source: src/builder.cpp@ a2028e

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

Merge branch 'new-delete-conversion' into CodeRefactoring

Conflicts:

molecuilder/src/Makefile.am
molecuilder/src/helpers.cpp
molecuilder/src/helpers.hpp
molecuilder/src/memoryusageobserver.cpp

  • FIX: performCriticalExit() was declared static but not defined a such.
  • Merge was basically only due to libmolecuilder which was not used in CodeRefactoring branch before.
  • added ActOnAll Unit test to new unittests sub folder and to Makefile.am
  • Property mode set to 100755
File size: 92.7 KB
Line 
1/** \file builder.cpp
2 *
3 * By stating absolute positions or binding angles and distances atomic positions of a molecule can be constructed.
4 * The output is the complete configuration file for PCP for direct use.
5 * Features:
6 * -# Atomic data is retrieved from a file, if not found requested and stored there for later re-use
7 * -# step-by-step construction of the molecule beginning either at a centre of with a certain atom
8 *
9 */
10
11/*! \mainpage Molecuilder - a molecular set builder
12 *
13 * This introductory shall briefly make aquainted with the program, helping in installing and a first run.
14 *
15 * \section about About the Program
16 *
17 * Molecuilder is a short program, written in C++, that enables the construction of a coordinate set for the
18 * atoms making up an molecule by the successive statement of binding angles and distances and referencing to
19 * already constructed atoms.
20 *
21 * A configuration file may be written that is compatible to the format used by PCP - a parallel Car-Parrinello
22 * molecular dynamics implementation.
23 *
24 * \section install Installation
25 *
26 * Installation should without problems succeed as follows:
27 * -# ./configure (or: mkdir build;mkdir run;cd build; ../configure --bindir=../run)
28 * -# make
29 * -# make install
30 *
31 * Further useful commands are
32 * -# make clean uninstall: deletes .o-files and removes executable from the given binary directory\n
33 * -# make doxygen-doc: Creates these html pages out of the documented source
34 *
35 * \section run Running
36 *
37 * The program can be executed by running: ./molecuilder
38 *
39 * Note, that it uses a database, called "elements.db", in the executable's directory. If the file is not found,
40 * it is created and any given data on elements of the periodic table will be stored therein and re-used on
41 * later re-execution.
42 *
43 * \section ref References
44 *
45 * For the special configuration file format, see the documentation of pcp.
46 *
47 */
48
49
50using namespace std;
51
52#include "atom.hpp"
53#include "bond.hpp"
54#include "boundary.hpp"
55#include "config.hpp"
56#include "element.hpp"
57#include "ellipsoid.hpp"
58#include "helpers.hpp"
59#include "leastsquaremin.hpp"
60#include "linkedcell.hpp"
61#include "memoryusageobserverunittest.hpp"
62#include "molecule.hpp"
63#include "periodentafel.hpp"
64
65/********************************************* Subsubmenu routine ************************************/
66
67/** Submenu for adding atoms to the molecule.
68 * \param *periode periodentafel
69 * \param *molecule molecules with atoms
70 */
71static void AddAtoms(periodentafel *periode, molecule *mol)
72{
73 atom *first, *second, *third, *fourth;
74 Vector **atoms;
75 Vector x,y,z,n; // coordinates for absolute point in cell volume
76 double a,b,c;
77 char choice; // menu choice char
78 bool valid;
79
80 cout << Verbose(0) << "===========ADD ATOM============================" << endl;
81 cout << Verbose(0) << " a - state absolute coordinates of atom" << endl;
82 cout << Verbose(0) << " b - state relative coordinates of atom wrt to reference point" << endl;
83 cout << Verbose(0) << " c - state relative coordinates of atom wrt to already placed atom" << endl;
84 cout << Verbose(0) << " d - state two atoms, two angles and a distance" << endl;
85 cout << Verbose(0) << " e - least square distance position to a set of atoms" << endl;
86 cout << Verbose(0) << "all else - go back" << endl;
87 cout << Verbose(0) << "===============================================" << endl;
88 cout << Verbose(0) << "Note: Specifiy angles in degrees not multiples of Pi!" << endl;
89 cout << Verbose(0) << "INPUT: ";
90 cin >> choice;
91
92 switch (choice) {
93 default:
94 cout << Verbose(0) << "Not a valid choice." << endl;
95 break;
96 case 'a': // absolute coordinates of atom
97 cout << Verbose(0) << "Enter absolute coordinates." << endl;
98 first = new atom;
99 first->x.AskPosition(mol->cell_size, false);
100 first->type = periode->AskElement(); // give type
101 mol->AddAtom(first); // add to molecule
102 break;
103
104 case 'b': // relative coordinates of atom wrt to reference point
105 first = new atom;
106 valid = true;
107 do {
108 if (!valid) cout << Verbose(0) << "Resulting position out of cell." << endl;
109 cout << Verbose(0) << "Enter reference coordinates." << endl;
110 x.AskPosition(mol->cell_size, true);
111 cout << Verbose(0) << "Enter relative coordinates." << endl;
112 first->x.AskPosition(mol->cell_size, false);
113 first->x.AddVector((const Vector *)&x);
114 cout << Verbose(0) << "\n";
115 } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
116 first->type = periode->AskElement(); // give type
117 mol->AddAtom(first); // add to molecule
118 break;
119
120 case 'c': // relative coordinates of atom wrt to already placed atom
121 first = new atom;
122 valid = true;
123 do {
124 if (!valid) cout << Verbose(0) << "Resulting position out of cell." << endl;
125 second = mol->AskAtom("Enter atom number: ");
126 cout << Verbose(0) << "Enter relative coordinates." << endl;
127 first->x.AskPosition(mol->cell_size, false);
128 for (int i=NDIM;i--;) {
129 first->x.x[i] += second->x.x[i];
130 }
131 } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
132 first->type = periode->AskElement(); // give type
133 mol->AddAtom(first); // add to molecule
134 break;
135
136 case 'd': // two atoms, two angles and a distance
137 first = new atom;
138 valid = true;
139 do {
140 if (!valid) {
141 cout << Verbose(0) << "Resulting coordinates out of cell - ";
142 first->x.Output((ofstream *)&cout);
143 cout << Verbose(0) << endl;
144 }
145 cout << Verbose(0) << "First, we need two atoms, the first atom is the central, while the second is the outer one." << endl;
146 second = mol->AskAtom("Enter central atom: ");
147 third = mol->AskAtom("Enter second atom (specifying the axis for first angle): ");
148 fourth = mol->AskAtom("Enter third atom (specifying a plane for second angle): ");
149 a = ask_value("Enter distance between central (first) and new atom: ");
150 b = ask_value("Enter angle between new, first and second atom (degrees): ");
151 b *= M_PI/180.;
152 bound(&b, 0., 2.*M_PI);
153 c = ask_value("Enter second angle between new and normal vector of plane defined by first, second and third atom (degrees): ");
154 c *= M_PI/180.;
155 bound(&c, -M_PI, M_PI);
156 cout << Verbose(0) << "radius: " << a << "\t phi: " << b*180./M_PI << "\t theta: " << c*180./M_PI << endl;
157/*
158 second->Output(1,1,(ofstream *)&cout);
159 third->Output(1,2,(ofstream *)&cout);
160 fourth->Output(1,3,(ofstream *)&cout);
161 n.MakeNormalvector((const vector *)&second->x, (const vector *)&third->x, (const vector *)&fourth->x);
162 x.Copyvector(&second->x);
163 x.SubtractVector(&third->x);
164 x.Copyvector(&fourth->x);
165 x.SubtractVector(&third->x);
166
167 if (!z.SolveSystem(&x,&y,&n, b, c, a)) {
168 cout << Verbose(0) << "Failure solving self-dependent linear system!" << endl;
169 continue;
170 }
171 cout << Verbose(0) << "resulting relative coordinates: ";
172 z.Output((ofstream *)&cout);
173 cout << Verbose(0) << endl;
174 */
175 // calc axis vector
176 x.CopyVector(&second->x);
177 x.SubtractVector(&third->x);
178 x.Normalize();
179 cout << "x: ",
180 x.Output((ofstream *)&cout);
181 cout << endl;
182 z.MakeNormalVector(&second->x,&third->x,&fourth->x);
183 cout << "z: ",
184 z.Output((ofstream *)&cout);
185 cout << endl;
186 y.MakeNormalVector(&x,&z);
187 cout << "y: ",
188 y.Output((ofstream *)&cout);
189 cout << endl;
190
191 // rotate vector around first angle
192 first->x.CopyVector(&x);
193 first->x.RotateVector(&z,b - M_PI);
194 cout << "Rotated vector: ",
195 first->x.Output((ofstream *)&cout);
196 cout << endl;
197 // remove the projection onto the rotation plane of the second angle
198 n.CopyVector(&y);
199 n.Scale(first->x.ScalarProduct(&y));
200 cout << "N1: ",
201 n.Output((ofstream *)&cout);
202 cout << endl;
203 first->x.SubtractVector(&n);
204 cout << "Subtracted vector: ",
205 first->x.Output((ofstream *)&cout);
206 cout << endl;
207 n.CopyVector(&z);
208 n.Scale(first->x.ScalarProduct(&z));
209 cout << "N2: ",
210 n.Output((ofstream *)&cout);
211 cout << endl;
212 first->x.SubtractVector(&n);
213 cout << "2nd subtracted vector: ",
214 first->x.Output((ofstream *)&cout);
215 cout << endl;
216
217 // rotate another vector around second angle
218 n.CopyVector(&y);
219 n.RotateVector(&x,c - M_PI);
220 cout << "2nd Rotated vector: ",
221 n.Output((ofstream *)&cout);
222 cout << endl;
223
224 // add the two linear independent vectors
225 first->x.AddVector(&n);
226 first->x.Normalize();
227 first->x.Scale(a);
228 first->x.AddVector(&second->x);
229
230 cout << Verbose(0) << "resulting coordinates: ";
231 first->x.Output((ofstream *)&cout);
232 cout << Verbose(0) << endl;
233 } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
234 first->type = periode->AskElement(); // give type
235 mol->AddAtom(first); // add to molecule
236 break;
237
238 case 'e': // least square distance position to a set of atoms
239 first = new atom;
240 atoms = new (Vector*[128]);
241 valid = true;
242 for(int i=128;i--;)
243 atoms[i] = NULL;
244 int i=0, j=0;
245 cout << Verbose(0) << "Now we need at least three molecules.\n";
246 do {
247 cout << Verbose(0) << "Enter " << i+1 << "th atom: ";
248 cin >> j;
249 if (j != -1) {
250 second = mol->FindAtom(j);
251 atoms[i++] = &(second->x);
252 }
253 } while ((j != -1) && (i<128));
254 if (i >= 2) {
255 first->x.LSQdistance(atoms, i);
256
257 first->x.Output((ofstream *)&cout);
258 first->type = periode->AskElement(); // give type
259 mol->AddAtom(first); // add to molecule
260 } else {
261 delete first;
262 cout << Verbose(0) << "Please enter at least two vectors!\n";
263 }
264 break;
265 };
266};
267
268/** Submenu for centering the atoms in the molecule.
269 * \param *mol molecule with all the atoms
270 */
271static void CenterAtoms(molecule *mol)
272{
273 Vector x, y, helper;
274 char choice; // menu choice char
275
276 cout << Verbose(0) << "===========CENTER ATOMS=========================" << endl;
277 cout << Verbose(0) << " a - on origin" << endl;
278 cout << Verbose(0) << " b - on center of gravity" << endl;
279 cout << Verbose(0) << " c - within box with additional boundary" << endl;
280 cout << Verbose(0) << " d - within given simulation box" << endl;
281 cout << Verbose(0) << "all else - go back" << endl;
282 cout << Verbose(0) << "===============================================" << endl;
283 cout << Verbose(0) << "INPUT: ";
284 cin >> choice;
285
286 switch (choice) {
287 default:
288 cout << Verbose(0) << "Not a valid choice." << endl;
289 break;
290 case 'a':
291 cout << Verbose(0) << "Centering atoms in config file on origin." << endl;
292 mol->CenterOrigin((ofstream *)&cout);
293 break;
294 case 'b':
295 cout << Verbose(0) << "Centering atoms in config file on center of gravity." << endl;
296 mol->CenterPeriodic((ofstream *)&cout);
297 break;
298 case 'c':
299 cout << Verbose(0) << "Centering atoms in config file within given additional boundary." << endl;
300 for (int i=0;i<NDIM;i++) {
301 cout << Verbose(0) << "Enter axis " << i << " boundary: ";
302 cin >> y.x[i];
303 }
304 mol->CenterEdge((ofstream *)&cout, &x); // make every coordinate positive
305 mol->Center.AddVector(&y); // translate by boundary
306 helper.CopyVector(&y);
307 helper.Scale(2.);
308 helper.AddVector(&x);
309 mol->SetBoxDimension(&helper); // update Box of atoms by boundary
310 break;
311 case 'd':
312 cout << Verbose(1) << "Centering atoms in config file within given simulation box." << endl;
313 for (int i=0;i<NDIM;i++) {
314 cout << Verbose(0) << "Enter axis " << i << " boundary: ";
315 cin >> x.x[i];
316 }
317 // update Box of atoms by boundary
318 mol->SetBoxDimension(&x);
319 // center
320 mol->CenterInBox((ofstream *)&cout);
321 break;
322 }
323};
324
325/** Submenu for aligning the atoms in the molecule.
326 * \param *periode periodentafel
327 * \param *mol molecule with all the atoms
328 */
329static void AlignAtoms(periodentafel *periode, molecule *mol)
330{
331 atom *first, *second, *third;
332 Vector x,n;
333 char choice; // menu choice char
334
335 cout << Verbose(0) << "===========ALIGN ATOMS=========================" << endl;
336 cout << Verbose(0) << " a - state three atoms defining align plane" << endl;
337 cout << Verbose(0) << " b - state alignment vector" << endl;
338 cout << Verbose(0) << " c - state two atoms in alignment direction" << endl;
339 cout << Verbose(0) << " d - align automatically by least square fit" << endl;
340 cout << Verbose(0) << "all else - go back" << endl;
341 cout << Verbose(0) << "===============================================" << endl;
342 cout << Verbose(0) << "INPUT: ";
343 cin >> choice;
344
345 switch (choice) {
346 default:
347 case 'a': // three atoms defining mirror plane
348 first = mol->AskAtom("Enter first atom: ");
349 second = mol->AskAtom("Enter second atom: ");
350 third = mol->AskAtom("Enter third atom: ");
351
352 n.MakeNormalVector((const Vector *)&first->x,(const Vector *)&second->x,(const Vector *)&third->x);
353 break;
354 case 'b': // normal vector of mirror plane
355 cout << Verbose(0) << "Enter normal vector of mirror plane." << endl;
356 n.AskPosition(mol->cell_size,0);
357 n.Normalize();
358 break;
359 case 'c': // three atoms defining mirror plane
360 first = mol->AskAtom("Enter first atom: ");
361 second = mol->AskAtom("Enter second atom: ");
362
363 n.CopyVector((const Vector *)&first->x);
364 n.SubtractVector((const Vector *)&second->x);
365 n.Normalize();
366 break;
367 case 'd':
368 char shorthand[4];
369 Vector a;
370 struct lsq_params param;
371 do {
372 fprintf(stdout, "Enter the element of atoms to be chosen: ");
373 fscanf(stdin, "%3s", shorthand);
374 } while ((param.type = periode->FindElement(shorthand)) == NULL);
375 cout << Verbose(0) << "Element is " << param.type->name << endl;
376 mol->GetAlignvector(&param);
377 for (int i=NDIM;i--;) {
378 x.x[i] = gsl_vector_get(param.x,i);
379 n.x[i] = gsl_vector_get(param.x,i+NDIM);
380 }
381 gsl_vector_free(param.x);
382 cout << Verbose(0) << "Offset vector: ";
383 x.Output((ofstream *)&cout);
384 cout << Verbose(0) << endl;
385 n.Normalize();
386 break;
387 };
388 cout << Verbose(0) << "Alignment vector: ";
389 n.Output((ofstream *)&cout);
390 cout << Verbose(0) << endl;
391 mol->Align(&n);
392};
393
394/** Submenu for mirroring the atoms in the molecule.
395 * \param *mol molecule with all the atoms
396 */
397static void MirrorAtoms(molecule *mol)
398{
399 atom *first, *second, *third;
400 Vector n;
401 char choice; // menu choice char
402
403 cout << Verbose(0) << "===========MIRROR ATOMS=========================" << endl;
404 cout << Verbose(0) << " a - state three atoms defining mirror plane" << endl;
405 cout << Verbose(0) << " b - state normal vector of mirror plane" << endl;
406 cout << Verbose(0) << " c - state two atoms in normal direction" << endl;
407 cout << Verbose(0) << "all else - go back" << endl;
408 cout << Verbose(0) << "===============================================" << endl;
409 cout << Verbose(0) << "INPUT: ";
410 cin >> choice;
411
412 switch (choice) {
413 default:
414 case 'a': // three atoms defining mirror plane
415 first = mol->AskAtom("Enter first atom: ");
416 second = mol->AskAtom("Enter second atom: ");
417 third = mol->AskAtom("Enter third atom: ");
418
419 n.MakeNormalVector((const Vector *)&first->x,(const Vector *)&second->x,(const Vector *)&third->x);
420 break;
421 case 'b': // normal vector of mirror plane
422 cout << Verbose(0) << "Enter normal vector of mirror plane." << endl;
423 n.AskPosition(mol->cell_size,0);
424 n.Normalize();
425 break;
426 case 'c': // three atoms defining mirror plane
427 first = mol->AskAtom("Enter first atom: ");
428 second = mol->AskAtom("Enter second atom: ");
429
430 n.CopyVector((const Vector *)&first->x);
431 n.SubtractVector((const Vector *)&second->x);
432 n.Normalize();
433 break;
434 };
435 cout << Verbose(0) << "Normal vector: ";
436 n.Output((ofstream *)&cout);
437 cout << Verbose(0) << endl;
438 mol->Mirror((const Vector *)&n);
439};
440
441/** Submenu for removing the atoms from the molecule.
442 * \param *mol molecule with all the atoms
443 */
444static void RemoveAtoms(molecule *mol)
445{
446 atom *first, *second;
447 int axis;
448 double tmp1, tmp2;
449 char choice; // menu choice char
450
451 cout << Verbose(0) << "===========REMOVE ATOMS=========================" << endl;
452 cout << Verbose(0) << " a - state atom for removal by number" << endl;
453 cout << Verbose(0) << " b - keep only in radius around atom" << endl;
454 cout << Verbose(0) << " c - remove this with one axis greater value" << endl;
455 cout << Verbose(0) << "all else - go back" << endl;
456 cout << Verbose(0) << "===============================================" << endl;
457 cout << Verbose(0) << "INPUT: ";
458 cin >> choice;
459
460 switch (choice) {
461 default:
462 case 'a':
463 if (mol->RemoveAtom(mol->AskAtom("Enter number of atom within molecule: ")))
464 cout << Verbose(1) << "Atom removed." << endl;
465 else
466 cout << Verbose(1) << "Atom not found." << endl;
467 break;
468 case 'b':
469 second = mol->AskAtom("Enter number of atom as reference point: ");
470 cout << Verbose(0) << "Enter radius: ";
471 cin >> tmp1;
472 first = mol->start;
473 second = first->next;
474 while(second != mol->end) {
475 first = second;
476 second = first->next;
477 if (first->x.DistanceSquared((const Vector *)&second->x) > tmp1*tmp1) // distance to first above radius ...
478 mol->RemoveAtom(first);
479 }
480 break;
481 case 'c':
482 cout << Verbose(0) << "Which axis is it: ";
483 cin >> axis;
484 cout << Verbose(0) << "Lower boundary: ";
485 cin >> tmp1;
486 cout << Verbose(0) << "Upper boundary: ";
487 cin >> tmp2;
488 first = mol->start;
489 second = first->next;
490 while(second != mol->end) {
491 first = second;
492 second = first->next;
493 if ((first->x.x[axis] < tmp1) || (first->x.x[axis] > tmp2)) {// out of boundary ...
494 //cout << "Atom " << *first << " with " << first->x.x[axis] << " on axis " << axis << " is out of bounds [" << tmp1 << "," << tmp2 << "]." << endl;
495 mol->RemoveAtom(first);
496 }
497 }
498 break;
499 };
500 //mol->Output((ofstream *)&cout);
501 choice = 'r';
502};
503
504/** Submenu for measuring out the atoms in the molecule.
505 * \param *periode periodentafel
506 * \param *mol molecule with all the atoms
507 */
508static void MeasureAtoms(periodentafel *periode, molecule *mol, config *configuration)
509{
510 atom *first, *second, *third;
511 Vector x,y;
512 double min[256], tmp1, tmp2, tmp3;
513 int Z;
514 char choice; // menu choice char
515
516 cout << Verbose(0) << "===========MEASURE ATOMS=========================" << endl;
517 cout << Verbose(0) << " a - calculate bond length between one atom and all others" << endl;
518 cout << Verbose(0) << " b - calculate bond length between two atoms" << endl;
519 cout << Verbose(0) << " c - calculate bond angle" << endl;
520 cout << Verbose(0) << " d - calculate principal axis of the system" << endl;
521 cout << Verbose(0) << " e - calculate volume of the convex envelope" << endl;
522 cout << Verbose(0) << " f - calculate temperature from current velocity" << endl;
523 cout << Verbose(0) << " g - output all temperatures per step from velocities" << endl;
524 cout << Verbose(0) << "all else - go back" << endl;
525 cout << Verbose(0) << "===============================================" << endl;
526 cout << Verbose(0) << "INPUT: ";
527 cin >> choice;
528
529 switch(choice) {
530 default:
531 cout << Verbose(1) << "Not a valid choice." << endl;
532 break;
533 case 'a':
534 first = mol->AskAtom("Enter first atom: ");
535 for (int i=MAX_ELEMENTS;i--;)
536 min[i] = 0.;
537
538 second = mol->start;
539 while ((second->next != mol->end)) {
540 second = second->next; // advance
541 Z = second->type->Z;
542 tmp1 = 0.;
543 if (first != second) {
544 x.CopyVector((const Vector *)&first->x);
545 x.SubtractVector((const Vector *)&second->x);
546 tmp1 = x.Norm();
547 }
548 if ((tmp1 != 0.) && ((min[Z] == 0.) || (tmp1 < min[Z]))) min[Z] = tmp1;
549 //cout << Verbose(0) << "Bond length between Atom " << first->nr << " and " << second->nr << ": " << tmp1 << " a.u." << endl;
550 }
551 for (int i=MAX_ELEMENTS;i--;)
552 if (min[i] != 0.) cout << 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;
553 break;
554
555 case 'b':
556 first = mol->AskAtom("Enter first atom: ");
557 second = mol->AskAtom("Enter second atom: ");
558 for (int i=NDIM;i--;)
559 min[i] = 0.;
560 x.CopyVector((const Vector *)&first->x);
561 x.SubtractVector((const Vector *)&second->x);
562 tmp1 = x.Norm();
563 cout << Verbose(1) << "Distance vector is ";
564 x.Output((ofstream *)&cout);
565 cout << "." << endl << "Norm of distance is " << tmp1 << "." << endl;
566 break;
567
568 case 'c':
569 cout << Verbose(0) << "Evaluating bond angle between three - first, central, last - atoms." << endl;
570 first = mol->AskAtom("Enter first atom: ");
571 second = mol->AskAtom("Enter central atom: ");
572 third = mol->AskAtom("Enter last atom: ");
573 tmp1 = tmp2 = tmp3 = 0.;
574 x.CopyVector((const Vector *)&first->x);
575 x.SubtractVector((const Vector *)&second->x);
576 y.CopyVector((const Vector *)&third->x);
577 y.SubtractVector((const Vector *)&second->x);
578 cout << Verbose(0) << "Bond angle between first atom Nr." << first->nr << ", central atom Nr." << second->nr << " and last atom Nr." << third->nr << ": ";
579 cout << Verbose(0) << (acos(x.ScalarProduct((const Vector *)&y)/(y.Norm()*x.Norm()))/M_PI*180.) << " degrees" << endl;
580 break;
581 case 'd':
582 cout << Verbose(0) << "Evaluating prinicipal axis." << endl;
583 cout << Verbose(0) << "Shall we rotate? [0/1]: ";
584 cin >> Z;
585 if ((Z >=0) && (Z <=1))
586 mol->PrincipalAxisSystem((ofstream *)&cout, (bool)Z);
587 else
588 mol->PrincipalAxisSystem((ofstream *)&cout, false);
589 break;
590 case 'e':
591 {
592 cout << Verbose(0) << "Evaluating volume of the convex envelope.";
593 LinkedCell LCList(mol, 10.);
594 class Tesselation *TesselStruct = NULL;
595 FindConvexBorder((ofstream *)&cout, mol, &LCList, NULL);
596 double clustervolume = VolumeOfConvexEnvelope((ofstream *)&cout, TesselStruct, configuration);
597 cout << Verbose(0) << "The tesselated surface area is " << clustervolume << "." << endl;
598 delete(TesselStruct);
599 }
600 break;
601 case 'f':
602 mol->OutputTemperatureFromTrajectories((ofstream *)&cout, mol->MDSteps-1, mol->MDSteps, (ofstream *)&cout);
603 break;
604 case 'g':
605 {
606 char filename[255];
607 cout << "Please enter filename: " << endl;
608 cin >> filename;
609 cout << Verbose(1) << "Storing temperatures in " << filename << "." << endl;
610 ofstream *output = new ofstream(filename, ios::trunc);
611 if (!mol->OutputTemperatureFromTrajectories((ofstream *)&cout, 0, mol->MDSteps, output))
612 cout << Verbose(2) << "File could not be written." << endl;
613 else
614 cout << Verbose(2) << "File stored." << endl;
615 output->close();
616 delete(output);
617 }
618 break;
619 }
620};
621
622/** Submenu for measuring out the atoms in the molecule.
623 * \param *mol molecule with all the atoms
624 * \param *configuration configuration structure for the to be written config files of all fragments
625 */
626static void FragmentAtoms(molecule *mol, config *configuration)
627{
628 int Order1;
629 clock_t start, end;
630
631 cout << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl;
632 cout << Verbose(0) << "What's the desired bond order: ";
633 cin >> Order1;
634 if (mol->first->next != mol->last) { // there are bonds
635 start = clock();
636 mol->FragmentMolecule((ofstream *)&cout, Order1, configuration);
637 end = clock();
638 cout << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
639 } else
640 cout << Verbose(0) << "Connection matrix has not yet been generated!" << endl;
641};
642
643/********************************************** Submenu routine **************************************/
644
645/** Submenu for manipulating atoms.
646 * \param *periode periodentafel
647 * \param *molecules list of molecules whose atoms are to be manipulated
648 */
649static void ManipulateAtoms(periodentafel *periode, MoleculeListClass *molecules, config *configuration)
650{
651 atom *first, *second;
652 molecule *mol = NULL;
653 Vector x,y,z,n; // coordinates for absolute point in cell volume
654 double *factor; // unit factor if desired
655 double bond, minBond;
656 char choice; // menu choice char
657 bool valid;
658
659 cout << Verbose(0) << "=========MANIPULATE ATOMS======================" << endl;
660 cout << Verbose(0) << "a - add an atom" << endl;
661 cout << Verbose(0) << "r - remove an atom" << endl;
662 cout << Verbose(0) << "b - scale a bond between atoms" << endl;
663 cout << Verbose(0) << "u - change an atoms element" << endl;
664 cout << Verbose(0) << "l - measure lengths, angles, ... for an atom" << endl;
665 cout << Verbose(0) << "all else - go back" << endl;
666 cout << Verbose(0) << "===============================================" << endl;
667 if (molecules->NumberOfActiveMolecules() > 1)
668 cout << Verbose(0) << "WARNING: There is more than one molecule active! Atoms will be added to each." << endl;
669 cout << Verbose(0) << "INPUT: ";
670 cin >> choice;
671
672 switch (choice) {
673 default:
674 cout << Verbose(0) << "Not a valid choice." << endl;
675 break;
676
677 case 'a': // add atom
678 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
679 if ((*ListRunner)->ActiveFlag) {
680 mol = *ListRunner;
681 cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
682 AddAtoms(periode, mol);
683 }
684 break;
685
686 case 'b': // scale a bond
687 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
688 if ((*ListRunner)->ActiveFlag) {
689 mol = *ListRunner;
690 cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
691 cout << Verbose(0) << "Scaling bond length between two atoms." << endl;
692 first = mol->AskAtom("Enter first (fixed) atom: ");
693 second = mol->AskAtom("Enter second (shifting) atom: ");
694 minBond = 0.;
695 for (int i=NDIM;i--;)
696 minBond += (first->x.x[i]-second->x.x[i])*(first->x.x[i] - second->x.x[i]);
697 minBond = sqrt(minBond);
698 cout << Verbose(0) << "Current Bond length between " << first->type->name << " Atom " << first->nr << " and " << second->type->name << " Atom " << second->nr << ": " << minBond << " a.u." << endl;
699 cout << Verbose(0) << "Enter new bond length [a.u.]: ";
700 cin >> bond;
701 for (int i=NDIM;i--;) {
702 second->x.x[i] -= (second->x.x[i]-first->x.x[i])/minBond*(minBond-bond);
703 }
704 //cout << Verbose(0) << "New coordinates of Atom " << second->nr << " are: ";
705 //second->Output(second->type->No, 1, (ofstream *)&cout);
706 }
707 break;
708
709 case 'c': // unit scaling of the metric
710 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
711 if ((*ListRunner)->ActiveFlag) {
712 mol = *ListRunner;
713 cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
714 cout << Verbose(0) << "Angstroem -> Bohrradius: 1.8897261\t\tBohrradius -> Angstroem: 0.52917721" << endl;
715 cout << Verbose(0) << "Enter three factors: ";
716 factor = new double[NDIM];
717 cin >> factor[0];
718 cin >> factor[1];
719 cin >> factor[2];
720 valid = true;
721 mol->Scale(&factor);
722 delete[](factor);
723 }
724 break;
725
726 case 'l': // measure distances or angles
727 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
728 if ((*ListRunner)->ActiveFlag) {
729 mol = *ListRunner;
730 cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
731 MeasureAtoms(periode, mol, configuration);
732 }
733 break;
734
735 case 'r': // remove atom
736 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
737 if ((*ListRunner)->ActiveFlag) {
738 mol = *ListRunner;
739 cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
740 RemoveAtoms(mol);
741 }
742 break;
743
744 case 'u': // change an atom's element
745 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
746 if ((*ListRunner)->ActiveFlag) {
747 int Z;
748 mol = *ListRunner;
749 cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
750 first = NULL;
751 do {
752 cout << Verbose(0) << "Change the element of which atom: ";
753 cin >> Z;
754 } while ((first = mol->FindAtom(Z)) == NULL);
755 cout << Verbose(0) << "New element by atomic number Z: ";
756 cin >> Z;
757 first->type = periode->FindElement(Z);
758 cout << Verbose(0) << "Atom " << first->nr << "'s element is " << first->type->name << "." << endl;
759 }
760 break;
761 }
762};
763
764/** Submenu for manipulating molecules.
765 * \param *periode periodentafel
766 * \param *molecules list of molecule to manipulate
767 */
768static void ManipulateMolecules(periodentafel *periode, MoleculeListClass *molecules, config *configuration)
769{
770 atom *first = NULL;
771 Vector x,y,z,n; // coordinates for absolute point in cell volume
772 int j, axis, count, faktor;
773 char choice; // menu choice char
774 molecule *mol = NULL;
775 element **Elements;
776 Vector **vectors;
777 MoleculeLeafClass *Subgraphs = NULL;
778
779 cout << Verbose(0) << "=========MANIPULATE GLOBALLY===================" << endl;
780 cout << Verbose(0) << "c - scale by unit transformation" << endl;
781 cout << Verbose(0) << "d - duplicate molecule/periodic cell" << endl;
782 cout << Verbose(0) << "f - fragment molecule many-body bond order style" << endl;
783 cout << Verbose(0) << "g - center atoms in box" << endl;
784 cout << Verbose(0) << "i - realign molecule" << endl;
785 cout << Verbose(0) << "m - mirror all molecules" << endl;
786 cout << Verbose(0) << "o - create connection matrix" << endl;
787 cout << Verbose(0) << "t - translate molecule by vector" << endl;
788 cout << Verbose(0) << "all else - go back" << endl;
789 cout << Verbose(0) << "===============================================" << endl;
790 if (molecules->NumberOfActiveMolecules() > 1)
791 cout << Verbose(0) << "WARNING: There is more than one molecule active! Atoms will be added to each." << endl;
792 cout << Verbose(0) << "INPUT: ";
793 cin >> choice;
794
795 switch (choice) {
796 default:
797 cout << Verbose(0) << "Not a valid choice." << endl;
798 break;
799
800 case 'd': // duplicate the periodic cell along a given axis, given times
801 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
802 if ((*ListRunner)->ActiveFlag) {
803 mol = *ListRunner;
804 cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
805 cout << Verbose(0) << "State the axis [(+-)123]: ";
806 cin >> axis;
807 cout << Verbose(0) << "State the factor: ";
808 cin >> faktor;
809
810 mol->CountAtoms((ofstream *)&cout); // recount atoms
811 if (mol->AtomCount != 0) { // if there is more than none
812 count = mol->AtomCount; // is changed becausing of adding, thus has to be stored away beforehand
813 Elements = new element *[count];
814 vectors = new Vector *[count];
815 j = 0;
816 first = mol->start;
817 while (first->next != mol->end) { // make a list of all atoms with coordinates and element
818 first = first->next;
819 Elements[j] = first->type;
820 vectors[j] = &first->x;
821 j++;
822 }
823 if (count != j)
824 cout << Verbose(0) << "ERROR: AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl;
825 x.Zero();
826 y.Zero();
827 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
828 for (int i=1;i<faktor;i++) { // then add this list with respective translation factor times
829 x.AddVector(&y); // per factor one cell width further
830 for (int k=count;k--;) { // go through every atom of the original cell
831 first = new atom(); // create a new body
832 first->x.CopyVector(vectors[k]); // use coordinate of original atom
833 first->x.AddVector(&x); // translate the coordinates
834 first->type = Elements[k]; // insert original element
835 mol->AddAtom(first); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)
836 }
837 }
838 if (mol->first->next != mol->last) // if connect matrix is present already, redo it
839 mol->CreateAdjacencyList((ofstream *)&cout, mol->BondDistance, configuration->GetIsAngstroem());
840 // free memory
841 delete[](Elements);
842 delete[](vectors);
843 // correct cell size
844 if (axis < 0) { // if sign was negative, we have to translate everything
845 x.Zero();
846 x.AddVector(&y);
847 x.Scale(-(faktor-1));
848 mol->Translate(&x);
849 }
850 mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;
851 }
852 }
853 break;
854
855 case 'f':
856 FragmentAtoms(mol, configuration);
857 break;
858
859 case 'g': // center the atoms
860 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
861 if ((*ListRunner)->ActiveFlag) {
862 mol = *ListRunner;
863 cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
864 CenterAtoms(mol);
865 }
866 break;
867
868 case 'i': // align all atoms
869 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
870 if ((*ListRunner)->ActiveFlag) {
871 mol = *ListRunner;
872 cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
873 AlignAtoms(periode, mol);
874 }
875 break;
876
877 case 'm': // mirror atoms along a given axis
878 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
879 if ((*ListRunner)->ActiveFlag) {
880 mol = *ListRunner;
881 cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
882 MirrorAtoms(mol);
883 }
884 break;
885
886 case 'o': // create the connection matrix
887 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
888 if ((*ListRunner)->ActiveFlag) {
889 mol = *ListRunner;
890 double bonddistance;
891 clock_t start,end;
892 cout << Verbose(0) << "What's the maximum bond distance: ";
893 cin >> bonddistance;
894 start = clock();
895 mol->CreateAdjacencyList((ofstream *)&cout, bonddistance, configuration->GetIsAngstroem());
896 mol->CreateListOfBondsPerAtom((ofstream *)&cout);
897 end = clock();
898 cout << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
899 }
900 break;
901
902 case 't': // translate all atoms
903 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
904 if ((*ListRunner)->ActiveFlag) {
905 mol = *ListRunner;
906 cout << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
907 cout << Verbose(0) << "Enter translation vector." << endl;
908 x.AskPosition(mol->cell_size,0);
909 mol->Center.AddVector((const Vector *)&x);
910 }
911 break;
912 }
913 // Free all
914 if (Subgraphs != NULL) { // free disconnected subgraph list of DFS analysis was performed
915 while (Subgraphs->next != NULL) {
916 Subgraphs = Subgraphs->next;
917 delete(Subgraphs->previous);
918 }
919 delete(Subgraphs);
920 }
921};
922
923
924/** Submenu for creating new molecules.
925 * \param *periode periodentafel
926 * \param *molecules list of molecules to add to
927 */
928static void EditMolecules(periodentafel *periode, MoleculeListClass *molecules)
929{
930 char choice; // menu choice char
931 Vector center;
932 int nr, count;
933 molecule *mol = NULL;
934
935 cout << Verbose(0) << "==========EDIT MOLECULES=====================" << endl;
936 cout << Verbose(0) << "c - create new molecule" << endl;
937 cout << Verbose(0) << "l - load molecule from xyz file" << endl;
938 cout << Verbose(0) << "n - change molecule's name" << endl;
939 cout << Verbose(0) << "N - give molecules filename" << endl;
940 cout << Verbose(0) << "p - parse atoms in xyz file into molecule" << endl;
941 cout << Verbose(0) << "r - remove a molecule" << endl;
942 cout << Verbose(0) << "all else - go back" << endl;
943 cout << Verbose(0) << "===============================================" << endl;
944 cout << Verbose(0) << "INPUT: ";
945 cin >> choice;
946
947 switch (choice) {
948 default:
949 cout << Verbose(0) << "Not a valid choice." << endl;
950 break;
951 case 'c':
952 mol = new molecule(periode);
953 molecules->insert(mol);
954 break;
955
956 case 'l': // load from XYZ file
957 {
958 char filename[MAXSTRINGSIZE];
959 cout << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
960 mol = new molecule(periode);
961 do {
962 cout << Verbose(0) << "Enter file name: ";
963 cin >> filename;
964 } while (!mol->AddXYZFile(filename));
965 mol->SetNameFromFilename(filename);
966 // center at set box dimensions
967 mol->CenterEdge((ofstream *)&cout, &center);
968 mol->cell_size[0] = center.x[0];
969 mol->cell_size[1] = 0;
970 mol->cell_size[2] = center.x[1];
971 mol->cell_size[3] = 0;
972 mol->cell_size[4] = 0;
973 mol->cell_size[5] = center.x[2];
974 molecules->insert(mol);
975 }
976 break;
977
978 case 'n':
979 {
980 char filename[MAXSTRINGSIZE];
981 do {
982 cout << Verbose(0) << "Enter index of molecule: ";
983 cin >> nr;
984 mol = molecules->ReturnIndex(nr);
985 } while (mol == NULL);
986 cout << Verbose(0) << "Enter name: ";
987 cin >> filename;
988 strcpy(mol->name, filename);
989 }
990 break;
991
992 case 'N':
993 {
994 char filename[MAXSTRINGSIZE];
995 do {
996 cout << Verbose(0) << "Enter index of molecule: ";
997 cin >> nr;
998 mol = molecules->ReturnIndex(nr);
999 } while (mol == NULL);
1000 cout << Verbose(0) << "Enter name: ";
1001 cin >> filename;
1002 mol->SetNameFromFilename(filename);
1003 }
1004 break;
1005
1006 case 'p': // parse XYZ file
1007 {
1008 char filename[MAXSTRINGSIZE];
1009 mol = NULL;
1010 do {
1011 cout << Verbose(0) << "Enter index of molecule: ";
1012 cin >> nr;
1013 mol = molecules->ReturnIndex(nr);
1014 } while (mol == NULL);
1015 cout << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
1016 do {
1017 cout << Verbose(0) << "Enter file name: ";
1018 cin >> filename;
1019 } while (!mol->AddXYZFile(filename));
1020 mol->SetNameFromFilename(filename);
1021 }
1022 break;
1023
1024 case 'r':
1025 cout << Verbose(0) << "Enter index of molecule: ";
1026 cin >> nr;
1027 count = 1;
1028 for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
1029 if (nr == (*ListRunner)->IndexNr) {
1030 mol = *ListRunner;
1031 molecules->ListOfMolecules.erase(ListRunner);
1032 delete(mol);
1033 break;
1034 }
1035 break;
1036 }
1037};
1038
1039
1040/** Submenu for merging molecules.
1041 * \param *periode periodentafel
1042 * \param *molecules list of molecules to add to
1043 */
1044static void MergeMolecules(periodentafel *periode, MoleculeListClass *molecules)
1045{
1046 char choice; // menu choice char
1047
1048 cout << Verbose(0) << "===========MERGE MOLECULES=====================" << endl;
1049 cout << Verbose(0) << "a - simple add of one molecule to another" << endl;
1050 cout << Verbose(0) << "e - embedding merge of two molecules" << endl;
1051 cout << Verbose(0) << "m - multi-merge of all molecules" << endl;
1052 cout << Verbose(0) << "s - scatter merge of two molecules" << endl;
1053 cout << Verbose(0) << "t - simple merge of two molecules" << endl;
1054 cout << Verbose(0) << "all else - go back" << endl;
1055 cout << Verbose(0) << "===============================================" << endl;
1056 cout << Verbose(0) << "INPUT: ";
1057 cin >> choice;
1058
1059 switch (choice) {
1060 default:
1061 cout << Verbose(0) << "Not a valid choice." << endl;
1062 break;
1063
1064 case 'a':
1065 {
1066 int src, dest;
1067 molecule *srcmol = NULL, *destmol = NULL;
1068 {
1069 do {
1070 cout << Verbose(0) << "Enter index of destination molecule: ";
1071 cin >> dest;
1072 destmol = molecules->ReturnIndex(dest);
1073 } while ((destmol == NULL) && (dest != -1));
1074 do {
1075 cout << Verbose(0) << "Enter index of source molecule to add from: ";
1076 cin >> src;
1077 srcmol = molecules->ReturnIndex(src);
1078 } while ((srcmol == NULL) && (src != -1));
1079 if ((src != -1) && (dest != -1))
1080 molecules->SimpleAdd(srcmol, destmol);
1081 }
1082 }
1083 break;
1084
1085 case 'e':
1086 {
1087 int src, dest;
1088 molecule *srcmol = NULL, *destmol = NULL;
1089 do {
1090 cout << Verbose(0) << "Enter index of matrix molecule (the variable one): ";
1091 cin >> src;
1092 srcmol = molecules->ReturnIndex(src);
1093 } while ((srcmol == NULL) && (src != -1));
1094 do {
1095 cout << Verbose(0) << "Enter index of molecule to merge into (the fixed one): ";
1096 cin >> dest;
1097 destmol = molecules->ReturnIndex(dest);
1098 } while ((destmol == NULL) && (dest != -1));
1099 if ((src != -1) && (dest != -1))
1100 molecules->EmbedMerge(destmol, srcmol);
1101 }
1102 break;
1103
1104 case 'm':
1105 {
1106 int nr;
1107 molecule *mol = NULL;
1108 do {
1109 cout << Verbose(0) << "Enter index of molecule to merge into: ";
1110 cin >> nr;
1111 mol = molecules->ReturnIndex(nr);
1112 } while ((mol == NULL) && (nr != -1));
1113 if (nr != -1) {
1114 int N = molecules->ListOfMolecules.size()-1;
1115 int *src = new int(N);
1116 for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
1117 if ((*ListRunner)->IndexNr != nr)
1118 src[N++] = (*ListRunner)->IndexNr;
1119 molecules->SimpleMultiMerge(mol, src, N);
1120 delete[](src);
1121 }
1122 }
1123 break;
1124
1125 case 's':
1126 cout << Verbose(0) << "Not implemented yet." << endl;
1127 break;
1128
1129 case 't':
1130 {
1131 int src, dest;
1132 molecule *srcmol = NULL, *destmol = NULL;
1133 {
1134 do {
1135 cout << Verbose(0) << "Enter index of destination molecule: ";
1136 cin >> dest;
1137 destmol = molecules->ReturnIndex(dest);
1138 } while ((destmol == NULL) && (dest != -1));
1139 do {
1140 cout << Verbose(0) << "Enter index of source molecule to merge into: ";
1141 cin >> src;
1142 srcmol = molecules->ReturnIndex(src);
1143 } while ((srcmol == NULL) && (src != -1));
1144 if ((src != -1) && (dest != -1))
1145 molecules->SimpleMerge(srcmol, destmol);
1146 }
1147 }
1148 break;
1149 }
1150};
1151
1152
1153/********************************************** Test routine **************************************/
1154
1155/** Is called always as option 'T' in the menu.
1156 * \param *molecules list of molecules
1157 */
1158static void testroutine(MoleculeListClass *molecules)
1159{
1160 // the current test routine checks the functionality of the KeySet&Graph concept:
1161 // We want to have a multiindex (the KeySet) describing a unique subgraph
1162 int i, comp, counter=0;
1163
1164 // create a clone
1165 molecule *mol = NULL;
1166 if (molecules->ListOfMolecules.size() != 0) // clone
1167 mol = (molecules->ListOfMolecules.front())->CopyMolecule();
1168 else {
1169 cerr << "I don't have anything to test on ... ";
1170 return;
1171 }
1172 atom *Walker = mol->start;
1173
1174 // generate some KeySets
1175 cout << "Generating KeySets." << endl;
1176 KeySet TestSets[mol->AtomCount+1];
1177 i=1;
1178 while (Walker->next != mol->end) {
1179 Walker = Walker->next;
1180 for (int j=0;j<i;j++) {
1181 TestSets[j].insert(Walker->nr);
1182 }
1183 i++;
1184 }
1185 cout << "Testing insertion of already present item in KeySets." << endl;
1186 KeySetTestPair test;
1187 test = TestSets[mol->AtomCount-1].insert(Walker->nr);
1188 if (test.second) {
1189 cout << Verbose(1) << "Insertion worked?!" << endl;
1190 } else {
1191 cout << Verbose(1) << "Insertion rejected: Present object is " << (*test.first) << "." << endl;
1192 }
1193 TestSets[mol->AtomCount].insert(mol->end->previous->nr);
1194 TestSets[mol->AtomCount].insert(mol->end->previous->previous->previous->nr);
1195
1196 // constructing Graph structure
1197 cout << "Generating Subgraph class." << endl;
1198 Graph Subgraphs;
1199
1200 // insert KeySets into Subgraphs
1201 cout << "Inserting KeySets into Subgraph class." << endl;
1202 for (int j=0;j<mol->AtomCount;j++) {
1203 Subgraphs.insert(GraphPair (TestSets[j],pair<int, double>(counter++, 1.)));
1204 }
1205 cout << "Testing insertion of already present item in Subgraph." << endl;
1206 GraphTestPair test2;
1207 test2 = Subgraphs.insert(GraphPair (TestSets[mol->AtomCount],pair<int, double>(counter++, 1.)));
1208 if (test2.second) {
1209 cout << Verbose(1) << "Insertion worked?!" << endl;
1210 } else {
1211 cout << Verbose(1) << "Insertion rejected: Present object is " << (*(test2.first)).second.first << "." << endl;
1212 }
1213
1214 // show graphs
1215 cout << "Showing Subgraph's contents, checking that it's sorted." << endl;
1216 Graph::iterator A = Subgraphs.begin();
1217 while (A != Subgraphs.end()) {
1218 cout << (*A).second.first << ": ";
1219 KeySet::iterator key = (*A).first.begin();
1220 comp = -1;
1221 while (key != (*A).first.end()) {
1222 if ((*key) > comp)
1223 cout << (*key) << " ";
1224 else
1225 cout << (*key) << "! ";
1226 comp = (*key);
1227 key++;
1228 }
1229 cout << endl;
1230 A++;
1231 }
1232 delete(mol);
1233};
1234
1235/** Tries given filename or standard on saving the config file.
1236 * \param *ConfigFileName name of file
1237 * \param *configuration pointer to configuration structure with all the values
1238 * \param *periode pointer to periodentafel structure with all the elements
1239 * \param *molecules list of molecules structure with all the atoms and coordinates
1240 */
1241static void SaveConfig(char *ConfigFileName, config *configuration, periodentafel *periode, MoleculeListClass *molecules)
1242{
1243 char filename[MAXSTRINGSIZE];
1244 ofstream output;
1245 molecule *mol = new molecule(periode);
1246
1247 // translate each to its center and merge all molecules in MoleculeListClass into this molecule
1248 int N = molecules->ListOfMolecules.size();
1249 int *src = new int(N);
1250 N=0;
1251 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
1252 src[N++] = (*ListRunner)->IndexNr;
1253 (*ListRunner)->Translate(&(*ListRunner)->Center);
1254 }
1255 molecules->SimpleMultiAdd(mol, src, N);
1256 delete(src);
1257
1258 // ... and translate back
1259 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++) {
1260 (*ListRunner)->Center.Scale(-1.);
1261 (*ListRunner)->Translate(&(*ListRunner)->Center);
1262 (*ListRunner)->Center.Scale(-1.);
1263 }
1264
1265 cout << Verbose(0) << "Storing configuration ... " << endl;
1266 // get correct valence orbitals
1267 mol->CalculateOrbitals(*configuration);
1268 configuration->InitMaxMinStopStep = configuration->MaxMinStopStep = configuration->MaxPsiDouble;
1269 if (ConfigFileName != NULL) { // test the file name
1270 strcpy(filename, ConfigFileName);
1271 output.open(filename, ios::trunc);
1272 } else if (strlen(configuration->configname) != 0) {
1273 strcpy(filename, configuration->configname);
1274 output.open(configuration->configname, ios::trunc);
1275 } else {
1276 strcpy(filename, DEFAULTCONFIG);
1277 output.open(DEFAULTCONFIG, ios::trunc);
1278 }
1279 output.close();
1280 output.clear();
1281 cout << Verbose(0) << "Saving of config file ";
1282 if (configuration->Save(filename, periode, mol))
1283 cout << "successful." << endl;
1284 else
1285 cout << "failed." << endl;
1286
1287 // and save to xyz file
1288 if (ConfigFileName != NULL) {
1289 strcpy(filename, ConfigFileName);
1290 strcat(filename, ".xyz");
1291 output.open(filename, ios::trunc);
1292 }
1293 if (output == NULL) {
1294 strcpy(filename,"main_pcp_linux");
1295 strcat(filename, ".xyz");
1296 output.open(filename, ios::trunc);
1297 }
1298 cout << Verbose(0) << "Saving of XYZ file ";
1299 if (mol->MDSteps <= 1) {
1300 if (mol->OutputXYZ(&output))
1301 cout << "successful." << endl;
1302 else
1303 cout << "failed." << endl;
1304 } else {
1305 if (mol->OutputTrajectoriesXYZ(&output))
1306 cout << "successful." << endl;
1307 else
1308 cout << "failed." << endl;
1309 }
1310 output.close();
1311 output.clear();
1312
1313 // and save as MPQC configuration
1314 if (ConfigFileName != NULL)
1315 strcpy(filename, ConfigFileName);
1316 if (output == NULL)
1317 strcpy(filename,"main_pcp_linux");
1318 cout << Verbose(0) << "Saving as mpqc input ";
1319 if (configuration->SaveMPQC(filename, mol))
1320 cout << "done." << endl;
1321 else
1322 cout << "failed." << endl;
1323
1324 if (!strcmp(configuration->configpath, configuration->GetDefaultPath())) {
1325 cerr << "WARNING: config is found under different path then stated in config file::defaultpath!" << endl;
1326 }
1327 delete(mol);
1328};
1329
1330/** Parses the command line options.
1331 * \param argc argument count
1332 * \param **argv arguments array
1333 * \param *molecules list of molecules structure
1334 * \param *periode elements structure
1335 * \param configuration config file structure
1336 * \param *ConfigFileName pointer to config file name in **argv
1337 * \param *PathToDatabases pointer to db's path in **argv
1338 * \return exit code (0 - successful, all else - something's wrong)
1339 */
1340static int ParseCommandLineOptions(int argc, char **argv, MoleculeListClass *&molecules, periodentafel *&periode, config& configuration, char *&ConfigFileName)
1341{
1342 Vector x,y,z,n; // coordinates for absolute point in cell volume
1343 double *factor; // unit factor if desired
1344 ifstream test;
1345 ofstream output;
1346 string line;
1347 atom *first;
1348 bool SaveFlag = false;
1349 int ExitFlag = 0;
1350 int j;
1351 double volume = 0.;
1352 enum ConfigStatus configPresent = absent;
1353 clock_t start,end;
1354 int argptr;
1355 molecule *mol = NULL;
1356 strncpy(configuration.databasepath, LocalPath, MAXSTRINGSIZE-1);
1357
1358 if (argc > 1) { // config file specified as option
1359 // 1. : Parse options that just set variables or print help
1360 argptr = 1;
1361 do {
1362 if (argv[argptr][0] == '-') {
1363 cout << Verbose(0) << "Recognized command line argument: " << argv[argptr][1] << ".\n";
1364 argptr++;
1365 switch(argv[argptr-1][1]) {
1366 case 'h':
1367 case 'H':
1368 case '?':
1369 cout << "MoleCuilder suite" << endl << "==================" << endl << endl;
1370 cout << "Usage: " << argv[0] << "[config file] [-{acefpsthH?vfrp}] [further arguments]" << endl;
1371 cout << "or simply " << argv[0] << " without arguments for interactive session." << endl;
1372 cout << "\t-a Z x1 x2 x3\tAdd new atom of element Z at coordinates (x1,x2,x3)." << endl;
1373 cout << "\t-A <source>\tCreate adjacency list from bonds parsed from 'dbond'-style file." <<endl;
1374 cout << "\t-b xx xy xz yy yz zz\tCenter atoms in domain with given symmetric matrix of (xx,xy,xz,yy,yz,zz)." << endl;
1375 cout << "\t-B xx xy xz yy yz zz\tBound atoms by domain with given symmetric matrix of (xx,xy,xz,yy,yz,zz)." << endl;
1376 cout << "\t-c x1 x2 x3\tCenter atoms in domain with a minimum distance to boundary of (x1,x2,x3)." << endl;
1377 cout << "\t-d x1 x2 x3\tDuplicate cell along each axis by given factor." << endl;
1378 cout << "\t-D <bond distance>\tDepth-First-Search Analysis of the molecule, giving cycles and tree/back edges." << endl;
1379 cout << "\t-e <file>\tSets the databases path to be parsed (default: ./)." << endl;
1380 cout << "\t-E <id> <Z>\tChange atom <id>'s element to <Z>, <id> begins at 0." << endl;
1381 cout << "\t-f/F <dist> <order>\tFragments the molecule in BOSSANOVA manner (with/out rings compressed) and stores config files in same dir as config (return code 0 - fragmented, 2 - no fragmentation necessary)." << endl;
1382 cout << "\t-h/-H/-?\tGive this help screen." << endl;
1383 cout << "\t-L <step0> <step1> <prefix>\tStore a linear interpolation between two configurations <step0> and <step1> into single config files with prefix <prefix> and as Trajectories into the current config file." << endl;
1384 cout << "\t-m <0/1>\tCalculate (0)/ Align in(1) PAS with greatest EV along z axis." << endl;
1385 cout << "\t-M <basis>\tSetting basis to store to MPQC config files." << endl;
1386 cout << "\t-n\tFast parsing (i.e. no trajectories are looked for)." << endl;
1387 cout << "\t-N <radius> <file>\tGet non-convex-envelope." << endl;
1388 cout << "\t-o <out>\tGet volume of the convex envelope (and store to tecplot file)." << endl;
1389 cout << "\t-O\tCenter atoms in origin." << endl;
1390 cout << "\t-p <file>\tParse given xyz file and create raw config file from it." << endl;
1391 cout << "\t-P <file>\tParse given forces file and append as an MD step to config file via Verlet." << endl;
1392 cout << "\t-r <id>\t\tRemove an atom with given id." << endl;
1393 cout << "\t-R <id> <radius>\t\tRemove all atoms out of sphere around a given one." << endl;
1394 cout << "\t-s x1 x2 x3\tScale all atom coordinates by this vector (x1,x2,x3)." << endl;
1395 cout << "\t-S <file> Store temperatures from the config file in <file>." << endl;
1396 cout << "\t-t x1 x2 x3\tTranslate all atoms by this vector (x1,x2,x3)." << endl;
1397 cout << "\t-T x1 x2 x3\tTranslate periodically all atoms by this vector (x1,x2,x3)." << endl;
1398 cout << "\t-u rho\tsuspend in water solution and output necessary cell lengths, average density rho and repetition." << endl;
1399 cout << "\t-v/-V\t\tGives version information." << endl;
1400 cout << "Note: config files must not begin with '-' !" << endl;
1401 return (1);
1402 break;
1403 case 'v':
1404 case 'V':
1405 cout << argv[0] << " " << VERSIONSTRING << endl;
1406 cout << "Build your own molecule position set." << endl;
1407 return (1);
1408 break;
1409 case 'e':
1410 if ((argptr >= argc) || (argv[argptr][0] == '-')) {
1411 cerr << "Not enough or invalid arguments for specifying element db: -e <db file>" << endl;
1412 } else {
1413 cout << "Using " << argv[argptr] << " as elements database." << endl;
1414 strncpy (configuration.databasepath, argv[argptr], MAXSTRINGSIZE-1);
1415 argptr+=1;
1416 }
1417 break;
1418 case 'n':
1419 cout << "I won't parse trajectories." << endl;
1420 configuration.FastParsing = true;
1421 break;
1422 default: // no match? Step on
1423 argptr++;
1424 break;
1425 }
1426 } else
1427 argptr++;
1428 } while (argptr < argc);
1429
1430 // 2. Parse the element database
1431 if (periode->LoadPeriodentafel(configuration.databasepath)) {
1432 cout << Verbose(0) << "Element list loaded successfully." << endl;
1433 //periode->Output((ofstream *)&cout);
1434 } else {
1435 cout << Verbose(0) << "Element list loading failed." << endl;
1436 return 1;
1437 }
1438 // 3. Find config file name and parse if possible
1439 if (argv[1][0] != '-') {
1440 // simply create a new molecule, wherein the config file is loaded and the manipulation takes place
1441 mol = new molecule(periode);
1442 mol->ActiveFlag = true;
1443 molecules->insert(mol);
1444
1445 cout << Verbose(0) << "Config file given." << endl;
1446 test.open(argv[1], ios::in);
1447 if (test == NULL) {
1448 //return (1);
1449 output.open(argv[1], ios::out);
1450 if (output == NULL) {
1451 cout << Verbose(1) << "Specified config file " << argv[1] << " not found." << endl;
1452 configPresent = absent;
1453 } else {
1454 cout << "Empty configuration file." << endl;
1455 ConfigFileName = argv[1];
1456 configPresent = empty;
1457 output.close();
1458 }
1459 } else {
1460 test.close();
1461 ConfigFileName = argv[1];
1462 cout << Verbose(1) << "Specified config file found, parsing ... ";
1463 switch (configuration.TestSyntax(ConfigFileName, periode, mol)) {
1464 case 1:
1465 cout << "new syntax." << endl;
1466 configuration.Load(ConfigFileName, periode, mol);
1467 configPresent = present;
1468 break;
1469 case 0:
1470 cout << "old syntax." << endl;
1471 configuration.LoadOld(ConfigFileName, periode, mol);
1472 configPresent = present;
1473 break;
1474 default:
1475 cout << "Unknown syntax or empty, yet present file." << endl;
1476 configPresent = empty;
1477 }
1478 }
1479 } else
1480 configPresent = absent;
1481 // 4. parse again through options, now for those depending on elements db and config presence
1482 argptr = 1;
1483 do {
1484 cout << "Current Command line argument: " << argv[argptr] << "." << endl;
1485 if (argv[argptr][0] == '-') {
1486 argptr++;
1487 if ((configPresent == present) || (configPresent == empty)) {
1488 switch(argv[argptr-1][1]) {
1489 case 'p':
1490 if (ExitFlag == 0) ExitFlag = 1;
1491 if ((argptr >= argc) || (argv[argptr][0] == '-')) {
1492 ExitFlag = 255;
1493 cerr << "Not enough arguments for parsing: -p <xyz file>" << endl;
1494 } else {
1495 SaveFlag = true;
1496 cout << Verbose(1) << "Parsing xyz file for new atoms." << endl;
1497 if (!mol->AddXYZFile(argv[argptr]))
1498 cout << Verbose(2) << "File not found." << endl;
1499 else {
1500 cout << Verbose(2) << "File found and parsed." << endl;
1501 configPresent = present;
1502 }
1503 }
1504 break;
1505 case 'a':
1506 if (ExitFlag == 0) ExitFlag = 1;
1507 if ((argptr >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr+1]))) {
1508 ExitFlag = 255;
1509 cerr << "Not enough or invalid arguments for adding atom: -a <element> <x> <y> <z>" << endl;
1510 } else {
1511 SaveFlag = true;
1512 cout << Verbose(1) << "Adding new atom with element " << argv[argptr] << " at (" << argv[argptr+1] << "," << argv[argptr+2] << "," << argv[argptr+3] << "), ";
1513 first = new atom;
1514 first->type = periode->FindElement(atoi(argv[argptr]));
1515 if (first->type != NULL)
1516 cout << Verbose(2) << "found element " << first->type->name << endl;
1517 for (int i=NDIM;i--;)
1518 first->x.x[i] = atof(argv[argptr+1+i]);
1519 if (first->type != NULL) {
1520 mol->AddAtom(first); // add to molecule
1521 if ((configPresent == empty) && (mol->AtomCount != 0))
1522 configPresent = present;
1523 } else
1524 cerr << Verbose(1) << "Could not find the specified element." << endl;
1525 argptr+=4;
1526 }
1527 break;
1528 default: // no match? Don't step on (this is done in next switch's default)
1529 break;
1530 }
1531 }
1532 if (configPresent == present) {
1533 switch(argv[argptr-1][1]) {
1534 case 'M':
1535 if ((argptr >= argc) || (argv[argptr][0] == '-')) {
1536 ExitFlag = 255;
1537 cerr << "Not enough or invalid arguments given for setting MPQC basis: -B <basis name>" << endl;
1538 } else {
1539 configuration.basis = argv[argptr];
1540 cout << Verbose(1) << "Setting MPQC basis to " << configuration.basis << "." << endl;
1541 argptr+=1;
1542 }
1543 break;
1544 case 'D':
1545 if (ExitFlag == 0) ExitFlag = 1;
1546 {
1547 cout << Verbose(1) << "Depth-First-Search Analysis." << endl;
1548 MoleculeLeafClass *Subgraphs = NULL; // list of subgraphs from DFS analysis
1549 int *MinimumRingSize = new int[mol->AtomCount];
1550 atom ***ListOfLocalAtoms = NULL;
1551 int FragmentCounter = 0;
1552 class StackClass<bond *> *BackEdgeStack = NULL;
1553 class StackClass<bond *> *LocalBackEdgeStack = NULL;
1554 mol->CreateAdjacencyList((ofstream *)&cout, atof(argv[argptr]), configuration.GetIsAngstroem());
1555 mol->CreateListOfBondsPerAtom((ofstream *)&cout);
1556 Subgraphs = mol->DepthFirstSearchAnalysis((ofstream *)&cout, BackEdgeStack);
1557 if (Subgraphs != NULL) {
1558 Subgraphs->next->FillBondStructureFromReference((ofstream *)&cout, mol, (FragmentCounter = 0), ListOfLocalAtoms, false); // we want to keep the created ListOfLocalAtoms
1559 while (Subgraphs->next != NULL) {
1560 Subgraphs = Subgraphs->next;
1561 LocalBackEdgeStack = new StackClass<bond *> (Subgraphs->Leaf->BondCount);
1562 Subgraphs->Leaf->PickLocalBackEdges((ofstream *)&cout, ListOfLocalAtoms[FragmentCounter++], BackEdgeStack, LocalBackEdgeStack);
1563 Subgraphs->Leaf->CyclicStructureAnalysis((ofstream *)&cout, BackEdgeStack, MinimumRingSize);
1564 delete(LocalBackEdgeStack);
1565 delete(Subgraphs->previous);
1566 }
1567 delete(Subgraphs);
1568 for (int i=0;i<FragmentCounter;i++)
1569 Free(&ListOfLocalAtoms[FragmentCounter]);
1570 Free(&ListOfLocalAtoms);
1571 }
1572 delete(BackEdgeStack);
1573 delete[](MinimumRingSize);
1574 }
1575 //argptr+=1;
1576 break;
1577 case 'E':
1578 if (ExitFlag == 0) ExitFlag = 1;
1579 if ((argptr+1 >= argc) || (!IsValidNumber(argv[argptr])) || (argv[argptr+1][0] == '-')) {
1580 ExitFlag = 255;
1581 cerr << "Not enough or invalid arguments given for changing element: -E <atom nr.> <element>" << endl;
1582 } else {
1583 SaveFlag = true;
1584 cout << Verbose(1) << "Changing atom " << argv[argptr] << " to element " << argv[argptr+1] << "." << endl;
1585 first = mol->FindAtom(atoi(argv[argptr]));
1586 first->type = periode->FindElement(atoi(argv[argptr+1]));
1587 argptr+=2;
1588 }
1589 break;
1590 case 'F':
1591 if (ExitFlag == 0) ExitFlag = 1;
1592 if (argptr+5 >=argc) {
1593 ExitFlag = 255;
1594 cerr << "Not enough or invalid arguments given for filling box with water: -F <dist_x> <dist_y> <dist_z> <randatom> <randmol> <DoRotate>" << endl;
1595 } else {
1596 SaveFlag = true;
1597 cout << Verbose(1) << "Filling Box with water molecules." << endl;
1598 // construct water molecule
1599 molecule *filler = new molecule(periode);;
1600 molecule *Filling = NULL;
1601 atom *second = NULL, *third = NULL;
1602 first = new atom();
1603 first->type = periode->FindElement(1);
1604 first->x.Init(0.441, -0.143, 0.);
1605 filler->AddAtom(first);
1606 second = new atom();
1607 second->type = periode->FindElement(1);
1608 second->x.Init(-0.464, 1.137, 0.0);
1609 filler->AddAtom(second);
1610 third = new atom();
1611 third->type = periode->FindElement(8);
1612 third->x.Init(-0.464, 0.177, 0.);
1613 filler->AddAtom(third);
1614 filler->AddBond(first, third, 1);
1615 filler->AddBond(second, third, 1);
1616 // call routine
1617 double distance[NDIM];
1618 for (int i=0;i<NDIM;i++)
1619 distance[i] = atof(argv[argptr+i]);
1620 Filling = FillBoxWithMolecule((ofstream *)&cout, molecules, filler, configuration, distance, atof(argv[argptr+3]), atof(argv[argptr+4]), atoi(argv[argptr+5]));
1621 if (Filling != NULL) {
1622 molecules->insert(Filling);
1623 }
1624 delete(filler);
1625 argptr+=6;
1626 }
1627 break;
1628 case 'A':
1629 if (ExitFlag == 0) ExitFlag = 1;
1630 if ((argptr >= argc) || (argv[argptr][0] == '-')) {
1631 ExitFlag =255;
1632 cerr << "Missing source file for bonds in molecule: -A <bond sourcefile>" << endl;
1633 } else {
1634 cout << "Parsing bonds from " << argv[argptr] << "." << endl;
1635 ifstream *input = new ifstream(argv[argptr]);
1636 mol->CreateAdjacencyList2((ofstream *)&cout, input);
1637 input->close();
1638 argptr+=1;
1639 }
1640 break;
1641 case 'N':
1642 if (ExitFlag == 0) ExitFlag = 1;
1643 if ((argptr+1 >= argc) || (argv[argptr+1][0] == '-')){
1644 ExitFlag = 255;
1645 cerr << "Not enough or invalid arguments given for non-convex envelope: -o <radius> <tecplot output file>" << endl;
1646 } else {
1647 class Tesselation T;
1648 string filename(argv[argptr+1]);
1649 filename.append(".csv");
1650 cout << Verbose(0) << "Evaluating non-convex envelope.";
1651 cout << Verbose(1) << "Using rolling ball of radius " << atof(argv[argptr]) << " and storing tecplot data in " << argv[argptr+1] << "." << endl;
1652 start = clock();
1653 LinkedCell LCList(mol, atof(argv[argptr])*2.);
1654 FindNonConvexBorder((ofstream *)&cout, mol, &LCList, atof(argv[argptr]), argv[argptr+1]);
1655 //FindDistributionOfEllipsoids((ofstream *)&cout, &T, &LCList, N, number, filename.c_str());
1656 end = clock();
1657 cout << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
1658 argptr+=2;
1659 }
1660 break;
1661 case 'S':
1662 if (ExitFlag == 0) ExitFlag = 1;
1663 if ((argptr >= argc) || (argv[argptr][0] == '-')) {
1664 ExitFlag = 255;
1665 cerr << "Not enough or invalid arguments given for storing tempature: -S <temperature file>" << endl;
1666 } else {
1667 cout << Verbose(1) << "Storing temperatures in " << argv[argptr] << "." << endl;
1668 ofstream *output = new ofstream(argv[argptr], ios::trunc);
1669 if (!mol->OutputTemperatureFromTrajectories((ofstream *)&cout, 0, mol->MDSteps, output))
1670 cout << Verbose(2) << "File could not be written." << endl;
1671 else
1672 cout << Verbose(2) << "File stored." << endl;
1673 output->close();
1674 delete(output);
1675 argptr+=1;
1676 }
1677 break;
1678 case 'L':
1679 if (ExitFlag == 0) ExitFlag = 1;
1680 if ((argptr >= argc) || (argv[argptr][0] == '-')) {
1681 ExitFlag = 255;
1682 cerr << "Not enough or invalid arguments given for storing tempature: -L <step0> <step1> <prefix> <identity mapping?>" << endl;
1683 } else {
1684 SaveFlag = true;
1685 cout << Verbose(1) << "Linear interpolation between configuration " << argv[argptr] << " and " << argv[argptr+1] << "." << endl;
1686 if (atoi(argv[argptr+3]) == 1)
1687 cout << Verbose(1) << "Using Identity for the permutation map." << endl;
1688 if (!mol->LinearInterpolationBetweenConfiguration((ofstream *)&cout, atoi(argv[argptr]), atoi(argv[argptr+1]), argv[argptr+2], configuration, atoi(argv[argptr+3])) == 1 ? true : false)
1689 cout << Verbose(2) << "Could not store " << argv[argptr+2] << " files." << endl;
1690 else
1691 cout << Verbose(2) << "Steps created and " << argv[argptr+2] << " files stored." << endl;
1692 argptr+=4;
1693 }
1694 break;
1695 case 'P':
1696 if (ExitFlag == 0) ExitFlag = 1;
1697 if ((argptr >= argc) || (argv[argptr][0] == '-')) {
1698 ExitFlag = 255;
1699 cerr << "Not enough or invalid arguments given for parsing and integrating forces: -P <forces file>" << endl;
1700 } else {
1701 SaveFlag = true;
1702 cout << Verbose(1) << "Parsing forces file and Verlet integrating." << endl;
1703 if (!mol->VerletForceIntegration((ofstream *)&cout, argv[argptr], configuration))
1704 cout << Verbose(2) << "File not found." << endl;
1705 else
1706 cout << Verbose(2) << "File found and parsed." << endl;
1707 argptr+=1;
1708 }
1709 break;
1710 case 'R':
1711 if (ExitFlag == 0) ExitFlag = 1;
1712 if ((argptr+1 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1]))) {
1713 ExitFlag = 255;
1714 cerr << "Not enough or invalid arguments given for removing atoms: -R <id> <distance>" << endl;
1715 } else {
1716 SaveFlag = true;
1717 cout << Verbose(1) << "Removing atoms around " << argv[argptr] << " with radius " << argv[argptr+1] << "." << endl;
1718 double tmp1 = atof(argv[argptr+1]);
1719 atom *third = mol->FindAtom(atoi(argv[argptr]));
1720 atom *first = mol->start;
1721 if ((third != NULL) && (first != mol->end)) {
1722 atom *second = first->next;
1723 while(second != mol->end) {
1724 first = second;
1725 second = first->next;
1726 if (first->x.DistanceSquared((const Vector *)&third->x) > tmp1*tmp1) // distance to first above radius ...
1727 mol->RemoveAtom(first);
1728 }
1729 } else {
1730 cerr << "Removal failed due to missing atoms on molecule or wrong id." << endl;
1731 }
1732 argptr+=2;
1733 }
1734 break;
1735 case 't':
1736 if (ExitFlag == 0) ExitFlag = 1;
1737 if ((argptr+2 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
1738 ExitFlag = 255;
1739 cerr << "Not enough or invalid arguments given for translation: -t <x> <y> <z>" << endl;
1740 } else {
1741 if (ExitFlag == 0) ExitFlag = 1;
1742 SaveFlag = true;
1743 cout << Verbose(1) << "Translating all ions by given vector." << endl;
1744 for (int i=NDIM;i--;)
1745 x.x[i] = atof(argv[argptr+i]);
1746 mol->Translate((const Vector *)&x);
1747 argptr+=3;
1748 }
1749 break;
1750 case 'T':
1751 if (ExitFlag == 0) ExitFlag = 1;
1752 if ((argptr+2 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
1753 ExitFlag = 255;
1754 cerr << "Not enough or invalid arguments given for periodic translation: -T <x> <y> <z>" << endl;
1755 } else {
1756 if (ExitFlag == 0) ExitFlag = 1;
1757 SaveFlag = true;
1758 cout << Verbose(1) << "Translating all ions periodically by given vector." << endl;
1759 for (int i=NDIM;i--;)
1760 x.x[i] = atof(argv[argptr+i]);
1761 mol->TranslatePeriodically((const Vector *)&x);
1762 argptr+=3;
1763 }
1764 break;
1765 case 's':
1766 if (ExitFlag == 0) ExitFlag = 1;
1767 if ((argptr >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) ) {
1768 ExitFlag = 255;
1769 cerr << "Not enough or invalid arguments given for scaling: -s <factor/[factor_x]> [factor_y] [factor_z]" << endl;
1770 } else {
1771 SaveFlag = true;
1772 j = -1;
1773 cout << Verbose(1) << "Scaling all ion positions by factor." << endl;
1774 factor = new double[NDIM];
1775 factor[0] = atof(argv[argptr]);
1776 if ((argptr < argc) && (IsValidNumber(argv[argptr])))
1777 argptr++;
1778 factor[1] = atof(argv[argptr]);
1779 if ((argptr < argc) && (IsValidNumber(argv[argptr])))
1780 argptr++;
1781 factor[2] = atof(argv[argptr]);
1782 mol->Scale(&factor);
1783 for (int i=0;i<NDIM;i++) {
1784 j += i+1;
1785 x.x[i] = atof(argv[NDIM+i]);
1786 mol->cell_size[j]*=factor[i];
1787 }
1788 delete[](factor);
1789 argptr+=1;
1790 }
1791 break;
1792 case 'b':
1793 if (ExitFlag == 0) ExitFlag = 1;
1794 if ((argptr+5 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) || (!IsValidNumber(argv[argptr+3])) || (!IsValidNumber(argv[argptr+4])) || (!IsValidNumber(argv[argptr+5])) ) {
1795 ExitFlag = 255;
1796 cerr << "Not enough or invalid arguments given for centering in box: -b <xx> <xy> <xz> <yy> <yz> <zz>" << endl;
1797 } else {
1798 SaveFlag = true;
1799 j = -1;
1800 cout << Verbose(1) << "Centering atoms in config file within given simulation box." << endl;
1801 for (int i=0;i<6;i++) {
1802 mol->cell_size[i] = atof(argv[argptr+i]);
1803 }
1804 // center
1805 mol->CenterInBox((ofstream *)&cout);
1806 argptr+=6;
1807 }
1808 break;
1809 case 'B':
1810 if (ExitFlag == 0) ExitFlag = 1;
1811 if ((argptr+5 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) || (!IsValidNumber(argv[argptr+3])) || (!IsValidNumber(argv[argptr+4])) || (!IsValidNumber(argv[argptr+5])) ) {
1812 ExitFlag = 255;
1813 cerr << "Not enough or invalid arguments given for bounding in box: -B <xx> <xy> <xz> <yy> <yz> <zz>" << endl;
1814 } else {
1815 SaveFlag = true;
1816 j = -1;
1817 cout << Verbose(1) << "Centering atoms in config file within given simulation box." << endl;
1818 for (int i=0;i<6;i++) {
1819 mol->cell_size[i] = atof(argv[argptr+i]);
1820 }
1821 // center
1822 mol->BoundInBox((ofstream *)&cout);
1823 argptr+=6;
1824 }
1825 break;
1826 case 'c':
1827 if (ExitFlag == 0) ExitFlag = 1;
1828 if ((argptr+2 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
1829 ExitFlag = 255;
1830 cerr << "Not enough or invalid arguments given for centering with boundary: -c <boundary_x> <boundary_y> <boundary_z>" << endl;
1831 } else {
1832 SaveFlag = true;
1833 j = -1;
1834 cout << Verbose(1) << "Centering atoms in config file within given additional boundary." << endl;
1835 // make every coordinate positive
1836 mol->CenterEdge((ofstream *)&cout, &x);
1837 // update Box of atoms by boundary
1838 mol->SetBoxDimension(&x);
1839 // translate each coordinate by boundary
1840 j=-1;
1841 for (int i=0;i<NDIM;i++) {
1842 j += i+1;
1843 x.x[i] = atof(argv[argptr+i]);
1844 mol->cell_size[j] += x.x[i]*2.;
1845 }
1846 mol->Translate((const Vector *)&x);
1847 argptr+=3;
1848 }
1849 break;
1850 case 'O':
1851 if (ExitFlag == 0) ExitFlag = 1;
1852 SaveFlag = true;
1853 cout << Verbose(1) << "Centering atoms on edge and setting box dimensions." << endl;
1854 x.Zero();
1855 mol->CenterEdge((ofstream *)&cout, &x);
1856 mol->SetBoxDimension(&x);
1857 argptr+=0;
1858 break;
1859 case 'r':
1860 if (ExitFlag == 0) ExitFlag = 1;
1861 if ((argptr >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr]))) {
1862 ExitFlag = 255;
1863 cerr << "Not enough or invalid arguments given for removing atoms: -r <id>" << endl;
1864 } else {
1865 SaveFlag = true;
1866 cout << Verbose(1) << "Removing atom " << argv[argptr] << "." << endl;
1867 atom *first = mol->FindAtom(atoi(argv[argptr]));
1868 mol->RemoveAtom(first);
1869 argptr+=1;
1870 }
1871 break;
1872 case 'f':
1873 if (ExitFlag == 0) ExitFlag = 1;
1874 if ((argptr+1 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1]))) {
1875 ExitFlag = 255;
1876 cerr << "Not enough or invalid arguments for fragmentation: -f <max. bond distance> <bond order>" << endl;
1877 } else {
1878 cout << "Fragmenting molecule with bond distance " << argv[argptr] << " angstroem, order of " << argv[argptr+1] << "." << endl;
1879 cout << Verbose(0) << "Creating connection matrix..." << endl;
1880 start = clock();
1881 mol->CreateAdjacencyList((ofstream *)&cout, atof(argv[argptr++]), configuration.GetIsAngstroem());
1882 cout << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl;
1883 if (mol->first->next != mol->last) {
1884 ExitFlag = mol->FragmentMolecule((ofstream *)&cout, atoi(argv[argptr]), &configuration);
1885 }
1886 end = clock();
1887 cout << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
1888 argptr+=2;
1889 }
1890 break;
1891 case 'm':
1892 if (ExitFlag == 0) ExitFlag = 1;
1893 j = atoi(argv[argptr++]);
1894 if ((j<0) || (j>1)) {
1895 cerr << Verbose(1) << "ERROR: Argument of '-m' should be either 0 for no-rotate or 1 for rotate." << endl;
1896 j = 0;
1897 }
1898 if (j) {
1899 SaveFlag = true;
1900 cout << Verbose(0) << "Converting to prinicipal axis system." << endl;
1901 } else
1902 cout << Verbose(0) << "Evaluating prinicipal axis." << endl;
1903 mol->PrincipalAxisSystem((ofstream *)&cout, (bool)j);
1904 break;
1905 case 'o':
1906 if (ExitFlag == 0) ExitFlag = 1;
1907 if ((argptr+1 >= argc) || (argv[argptr][0] == '-')){
1908 ExitFlag = 255;
1909 cerr << "Not enough or invalid arguments given for convex envelope: -o <convex output file> <non-convex output file>" << endl;
1910 } else {
1911 cout << Verbose(0) << "Evaluating volume of the convex envelope.";
1912 cout << Verbose(1) << "Storing tecplot convex data in " << argv[argptr] << "." << endl;
1913 cout << Verbose(1) << "Storing tecplot non-convex data in " << argv[argptr+1] << "." << endl;
1914 LinkedCell LCList(mol, 10.);
1915 //FindConvexBorder((ofstream *)&cout, mol, &LCList, argv[argptr]);
1916 FindNonConvexBorder((ofstream *)&cout, mol, &LCList, 5., argv[argptr+1]);
1917// RemoveAllBoundaryPoints((ofstream *)&cout, mol->TesselStruct, mol, argv[argptr]);
1918 double volumedifference = ConvexizeNonconvexEnvelope((ofstream *)&cout, mol->TesselStruct, mol, argv[argptr]);
1919 double clustervolume = VolumeOfConvexEnvelope((ofstream *)&cout, mol->TesselStruct, &configuration);
1920 cout << Verbose(0) << "The tesselated volume area is " << clustervolume << " " << (configuration.GetIsAngstroem() ? "angstrom" : "atomiclength") << "^3." << endl;
1921 cout << Verbose(0) << "The non-convex tesselated volume area is " << clustervolume-volumedifference << " " << (configuration.GetIsAngstroem() ? "angstrom" : "atomiclength") << "^3." << endl;
1922 argptr+=2;
1923 }
1924 break;
1925 case 'U':
1926 if (ExitFlag == 0) ExitFlag = 1;
1927 if ((argptr+1 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) ) {
1928 ExitFlag = 255;
1929 cerr << "Not enough or invalid arguments given for suspension with specified volume: -U <volume> <density>" << endl;
1930 volume = -1; // for case 'u': don't print error again
1931 } else {
1932 volume = atof(argv[argptr++]);
1933 cout << Verbose(0) << "Using " << volume << " angstrom^3 as the volume instead of convex envelope one's." << endl;
1934 }
1935 case 'u':
1936 if (ExitFlag == 0) ExitFlag = 1;
1937 if ((argptr >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) ) {
1938 if (volume != -1)
1939 ExitFlag = 255;
1940 cerr << "Not enough arguments given for suspension: -u <density>" << endl;
1941 } else {
1942 double density;
1943 SaveFlag = true;
1944 cout << Verbose(0) << "Evaluating necessary cell volume for a cluster suspended in water.";
1945 density = atof(argv[argptr++]);
1946 if (density < 1.0) {
1947 cerr << Verbose(0) << "Density must be greater than 1.0g/cm^3 !" << endl;
1948 density = 1.3;
1949 }
1950// for(int i=0;i<NDIM;i++) {
1951// repetition[i] = atoi(argv[argptr++]);
1952// if (repetition[i] < 1)
1953// cerr << Verbose(0) << "ERROR: repetition value must be greater 1!" << endl;
1954// repetition[i] = 1;
1955// }
1956 PrepareClustersinWater((ofstream *)&cout, &configuration, mol, volume, density); // if volume == 0, will calculate from ConvexEnvelope
1957 }
1958 break;
1959 case 'd':
1960 if (ExitFlag == 0) ExitFlag = 1;
1961 if ((argptr+2 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
1962 ExitFlag = 255;
1963 cerr << "Not enough or invalid arguments given for repeating cells: -d <repeat_x> <repeat_y> <repeat_z>" << endl;
1964 } else {
1965 SaveFlag = true;
1966 for (int axis = 1; axis <= NDIM; axis++) {
1967 int faktor = atoi(argv[argptr++]);
1968 int count;
1969 element ** Elements;
1970 Vector ** vectors;
1971 if (faktor < 1) {
1972 cerr << Verbose(0) << "ERROR: Repetition faktor mus be greater than 1!" << endl;
1973 faktor = 1;
1974 }
1975 mol->CountAtoms((ofstream *)&cout); // recount atoms
1976 if (mol->AtomCount != 0) { // if there is more than none
1977 count = mol->AtomCount; // is changed becausing of adding, thus has to be stored away beforehand
1978 Elements = new element *[count];
1979 vectors = new Vector *[count];
1980 j = 0;
1981 first = mol->start;
1982 while (first->next != mol->end) { // make a list of all atoms with coordinates and element
1983 first = first->next;
1984 Elements[j] = first->type;
1985 vectors[j] = &first->x;
1986 j++;
1987 }
1988 if (count != j)
1989 cout << Verbose(0) << "ERROR: AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl;
1990 x.Zero();
1991 y.Zero();
1992 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
1993 for (int i=1;i<faktor;i++) { // then add this list with respective translation factor times
1994 x.AddVector(&y); // per factor one cell width further
1995 for (int k=count;k--;) { // go through every atom of the original cell
1996 first = new atom(); // create a new body
1997 first->x.CopyVector(vectors[k]); // use coordinate of original atom
1998 first->x.AddVector(&x); // translate the coordinates
1999 first->type = Elements[k]; // insert original element
2000 mol->AddAtom(first); // and add to the molecule (which increments ElementsInMolecule, AtomCount, ...)
2001 }
2002 }
2003 // free memory
2004 delete[](Elements);
2005 delete[](vectors);
2006 // correct cell size
2007 if (axis < 0) { // if sign was negative, we have to translate everything
2008 x.Zero();
2009 x.AddVector(&y);
2010 x.Scale(-(faktor-1));
2011 mol->Translate(&x);
2012 }
2013 mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;
2014 }
2015 }
2016 }
2017 break;
2018 default: // no match? Step on
2019 if ((argptr < argc) && (argv[argptr][0] != '-')) // if it started with a '-' we've already made a step!
2020 argptr++;
2021 break;
2022 }
2023 }
2024 } else argptr++;
2025 } while (argptr < argc);
2026 if (SaveFlag)
2027 SaveConfig(ConfigFileName, &configuration, periode, molecules);
2028 } else { // no arguments, hence scan the elements db
2029 if (periode->LoadPeriodentafel(configuration.databasepath))
2030 cout << Verbose(0) << "Element list loaded successfully." << endl;
2031 else
2032 cout << Verbose(0) << "Element list loading failed." << endl;
2033 configuration.RetrieveConfigPathAndName("main_pcp_linux");
2034 }
2035 return(ExitFlag);
2036};
2037
2038/********************************************** Main routine **************************************/
2039
2040int main(int argc, char **argv)
2041{
2042 periodentafel *periode = new periodentafel; // and a period table of all elements
2043 MoleculeListClass *molecules = new MoleculeListClass; // list of all molecules
2044 molecule *mol = NULL;
2045 config configuration;
2046 char choice; // menu choice char
2047 Vector x,y,z,n; // coordinates for absolute point in cell volume
2048 ifstream test;
2049 ofstream output;
2050 string line;
2051 char *ConfigFileName = NULL;
2052 int j;
2053
2054 // =========================== PARSE COMMAND LINE OPTIONS ====================================
2055 j = ParseCommandLineOptions(argc, argv, molecules, periode, configuration, ConfigFileName);
2056 switch(j) {
2057 case 255: // something went wrong
2058 delete(molecules); // also free's all molecules contained
2059 delete(periode);
2060 cout << Verbose(0) << "Maximum of allocated memory: "
2061 << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl;
2062 cout << Verbose(0) << "Remaining non-freed memory: "
2063 << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl;
2064 return j;
2065 break;
2066 case 1: // just for -v and -h options
2067 delete(molecules); // also free's all molecules contained
2068 delete(periode);
2069 cout << Verbose(0) << "Maximum of allocated memory: "
2070 << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl;
2071 cout << Verbose(0) << "Remaining non-freed memory: "
2072 << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl;
2073 return 0;
2074 break;
2075 case 2: // just for -f option
2076 delete(molecules); // also free's all molecules contained
2077 delete(periode);
2078 cout << Verbose(0) << "Maximum of allocated memory: "
2079 << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl;
2080 cout << Verbose(0) << "Remaining non-freed memory: "
2081 << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl;
2082 return 2;
2083 break;
2084 default:
2085 break;
2086 }
2087
2088 // General stuff
2089 if (molecules->ListOfMolecules.size() == 0) {
2090 mol = new molecule(periode);
2091 if (mol->cell_size[0] == 0.) {
2092 cout << Verbose(0) << "enter lower tridiagonal form of basis matrix" << endl << endl;
2093 for (int i=0;i<6;i++) {
2094 cout << Verbose(1) << "Cell size" << i << ": ";
2095 cin >> mol->cell_size[i];
2096 }
2097 }
2098 molecules->insert(mol);
2099 }
2100
2101 // =========================== START INTERACTIVE SESSION ====================================
2102
2103 // now the main construction loop
2104 cout << Verbose(0) << endl << "Now comes the real construction..." << endl;
2105 do {
2106 cout << Verbose(0) << endl << endl;
2107 cout << Verbose(0) << "============Molecule list=======================" << endl;
2108 molecules->Enumerate((ofstream *)&cout);
2109 cout << Verbose(0) << "============Menu===============================" << endl;
2110 cout << Verbose(0) << "a - set molecule (in)active" << endl;
2111 cout << Verbose(0) << "e - edit molecules (load, parse, save)" << endl;
2112 cout << Verbose(0) << "g - globally manipulate atoms in molecule" << endl;
2113 cout << Verbose(0) << "M - Merge molecules" << endl;
2114 cout << Verbose(0) << "m - manipulate atoms" << endl;
2115 cout << Verbose(0) << "-----------------------------------------------" << endl;
2116 cout << Verbose(0) << "c - edit the current configuration" << endl;
2117 cout << Verbose(0) << "-----------------------------------------------" << endl;
2118 cout << Verbose(0) << "s - save current setup to config file" << endl;
2119 cout << Verbose(0) << "T - call the current test routine" << endl;
2120 cout << Verbose(0) << "q - quit" << endl;
2121 cout << Verbose(0) << "===============================================" << endl;
2122 cout << Verbose(0) << "Input: ";
2123 cin >> choice;
2124
2125 switch (choice) {
2126 case 'a': // (in)activate molecule
2127 {
2128 cout << "Enter index of molecule: ";
2129 cin >> j;
2130 for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
2131 if ((*ListRunner)->IndexNr == j)
2132 (*ListRunner)->ActiveFlag = !(*ListRunner)->ActiveFlag;
2133 }
2134 break;
2135
2136 case 'c': // edit each field of the configuration
2137 configuration.Edit();
2138 break;
2139
2140 case 'e': // create molecule
2141 EditMolecules(periode, molecules);
2142 break;
2143
2144 case 'g': // manipulate molecules
2145 ManipulateMolecules(periode, molecules, &configuration);
2146 break;
2147
2148 case 'M': // merge molecules
2149 MergeMolecules(periode, molecules);
2150 break;
2151
2152 case 'm': // manipulate atoms
2153 ManipulateAtoms(periode, molecules, &configuration);
2154 break;
2155
2156 case 'q': // quit
2157 break;
2158
2159 case 's': // save to config file
2160 SaveConfig(ConfigFileName, &configuration, periode, molecules);
2161 break;
2162
2163 case 'T':
2164 testroutine(molecules);
2165 break;
2166
2167 default:
2168 break;
2169 };
2170 } while (choice != 'q');
2171
2172 // save element data base
2173 if (periode->StorePeriodentafel(configuration.databasepath)) //ElementsFileName
2174 cout << Verbose(0) << "Saving of elements.db successful." << endl;
2175 else
2176 cout << Verbose(0) << "Saving of elements.db failed." << endl;
2177
2178 delete(molecules); // also free's all molecules contained
2179 delete(periode);
2180
2181 cout << Verbose(0) << "Maximum of allocated memory: "
2182 << MemoryUsageObserver::getInstance()->getMaximumUsedMemory() << endl;
2183 cout << Verbose(0) << "Remaining non-freed memory: "
2184 << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl;
2185
2186 return (0);
2187}
2188
2189/********************************************** E N D **************************************************/
Note: See TracBrowser for help on using the repository browser.