source: src/builder.cpp@ 57066a

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

Implemenation of embedding merge, untested. LinearInterpolation now has switch for using identity map.

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