source: src/builder.cpp@ 6d6b54

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 6d6b54 was 112b09, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Added #include "Helpers/MemDebug.hpp" to all .cpp files

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