source: src/builder.cpp@ 274d45

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 274d45 was 5f5a7b, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Merge branch 'MenuRefactoring' into stable

Conflicts:

molecuilder/src/UIElements/TextUIFactory.cpp
molecuilder/src/UIElements/UIFactory.cpp
molecuilder/src/UIElements/UIFactory.hpp
molecuilder/src/builder.cpp

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