source: src/builder.cpp@ c7b1e7

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

Log() and eLog() are prepended by a DoLog()/DoeLog() construct.

  • Most of the run time (95%) is spent on verbosity that it is discarded anyway due to a low verbosity setting. However, the operator << is evaluated from the right-hand side, hence the whole message is constructed and then thrown away.
  • DoLog() and DoeLog() are new functions that check the verbosity beforehand and are used as follows: DoLog(2) && (Log() << verbose(2) << "message" << endl);

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

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