source: src/builder.cpp@ 492279

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 492279 was e6317b, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Broken: Merge commit 'Gitosis/stable' into stable

Conflicts:

molecuilder/src/Actions/AnalysisAction/PairCorrelationToPointAction.cpp
molecuilder/src/Actions/AnalysisAction/PairCorrelationToSurfaceAction.cpp
molecuilder/src/Makefile.am

  • Property mode set to 100755
File size: 93.5 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 if ((argptr >= argc) || (argv[argptr][0] == '-')) {
1534 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments for specifying verbosity: -v <level>" << endl);
1535 performCriticalExit();
1536 } else {
1537 setVerbosity(atoi(argv[argptr]));
1538 ArgcList.insert(argptr-1);
1539 ArgcList.insert(argptr);
1540 argptr++;
1541 }
1542 break;
1543 case 'V':
1544 ArgcList.insert(argptr-1);
1545 return(1);
1546 break;
1547 case 'B':
1548 if (ExitFlag == 0) ExitFlag = 1;
1549 if ((argptr+5 >= argc)) {
1550 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments for setting Box: -B <xx> <<xy> <<xz> <yy> <yz> <zz>" << endl);
1551 performCriticalExit();
1552 } else {
1553 ArgcList.insert(argptr-1);
1554 ArgcList.insert(argptr);
1555 ArgcList.insert(argptr+1);
1556 ArgcList.insert(argptr+2);
1557 ArgcList.insert(argptr+3);
1558 ArgcList.insert(argptr+4);
1559 ArgcList.insert(argptr+5);
1560 argptr+=6;
1561 }
1562 break;
1563 case 'e':
1564 if ((argptr >= argc) || (argv[argptr][0] == '-')) {
1565 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments for specifying element db: -e <db file>" << endl);
1566 performCriticalExit();
1567 } else {
1568 ArgcList.insert(argptr-1);
1569 ArgcList.insert(argptr);
1570 argptr+=1;
1571 }
1572 break;
1573 case 'g':
1574 if ((argptr >= argc) || (argv[argptr][0] == '-')) {
1575 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments for specifying bond length table: -g <table file>" << endl);
1576 performCriticalExit();
1577 } else {
1578 ArgcList.insert(argptr-1);
1579 ArgcList.insert(argptr);
1580 argptr+=1;
1581 }
1582 break;
1583 case 'M':
1584 if ((argptr >= argc) || (argv[argptr][0] == '-')) {
1585 ExitFlag = 255;
1586 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for setting MPQC basis: -M <basis name>" << endl);
1587 performCriticalExit();
1588 } else {
1589 ArgcList.insert(argptr-1);
1590 ArgcList.insert(argptr);
1591 argptr+=1;
1592 }
1593 break;
1594 case 'n':
1595 if ((argptr >= argc) || (argv[argptr][0] == '-')) {
1596 ExitFlag = 255;
1597 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for setting fast-parsing: -n <0/1>" << endl);
1598 performCriticalExit();
1599 } else {
1600 ArgcList.insert(argptr-1);
1601 ArgcList.insert(argptr);
1602 argptr+=1;
1603 }
1604 break;
1605 case 'X':
1606 if ((argptr >= argc) || (argv[argptr][0] == '-')) {
1607 ExitFlag = 255;
1608 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for setting default molecule name: -X <name>" << endl);
1609 performCriticalExit();
1610 } else {
1611 ArgcList.insert(argptr-1);
1612 ArgcList.insert(argptr);
1613 argptr+=1;
1614 }
1615 break;
1616 default: // no match? Step on
1617 argptr++;
1618 break;
1619 }
1620 } else
1621 argptr++;
1622 } while (argptr < argc);
1623
1624 // 3b. Find config file name and parse if possible, also BondGraphFileName
1625 if (argv[1][0] != '-') {
1626 // simply create a new molecule, wherein the config file is loaded and the manipulation takes place
1627 DoLog(0) && (Log() << Verbose(0) << "Config file given." << endl);
1628 test.open(argv[1], ios::in);
1629 if (test == NULL) {
1630 //return (1);
1631 output.open(argv[1], ios::out);
1632 if (output == NULL) {
1633 DoLog(1) && (Log() << Verbose(1) << "Specified config file " << argv[1] << " not found." << endl);
1634 configPresent = absent;
1635 } else {
1636 DoLog(0) && (Log() << Verbose(0) << "Empty configuration file." << endl);
1637 strcpy(*ConfigFileName, argv[1]);
1638 configPresent = empty;
1639 output.close();
1640 }
1641 } else {
1642 test.close();
1643 strcpy(*ConfigFileName, argv[1]);
1644 DoLog(1) && (Log() << Verbose(1) << "Specified config file found, parsing ... ");
1645 switch (configuration.TestSyntax(*ConfigFileName, periode)) {
1646 case 1:
1647 DoLog(0) && (Log() << Verbose(0) << "new syntax." << endl);
1648 configuration.Load(*ConfigFileName, BondGraphFileName, periode, molecules);
1649 configPresent = present;
1650 break;
1651 case 0:
1652 DoLog(0) && (Log() << Verbose(0) << "old syntax." << endl);
1653 configuration.LoadOld(*ConfigFileName, BondGraphFileName, periode, molecules);
1654 configPresent = present;
1655 break;
1656 default:
1657 DoLog(0) && (Log() << Verbose(0) << "Unknown syntax or empty, yet present file." << endl);
1658 configPresent = empty;
1659 }
1660 }
1661 } else
1662 configPresent = absent;
1663 // set mol to first active molecule
1664 if (molecules->ListOfMolecules.size() != 0) {
1665 for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
1666 if ((*ListRunner)->ActiveFlag) {
1667 mol = *ListRunner;
1668 break;
1669 }
1670 }
1671 if (mol == NULL) {
1672 mol = World::getInstance().createMolecule();
1673 mol->ActiveFlag = true;
1674 if (*ConfigFileName != NULL)
1675 mol->SetNameFromFilename(*ConfigFileName);
1676 molecules->insert(mol);
1677 }
1678
1679 // 4. parse again through options, now for those depending on elements db and config presence
1680 argptr = 1;
1681 do {
1682 DoLog(0) && (Log() << Verbose(0) << "Current Command line argument: " << argv[argptr] << "." << endl);
1683 if (argv[argptr][0] == '-') {
1684 argptr++;
1685 if ((configPresent == present) || (configPresent == empty)) {
1686 switch(argv[argptr-1][1]) {
1687 case 'p':
1688 if (ExitFlag == 0) ExitFlag = 1;
1689 if ((argptr >= argc) || (argv[argptr][0] == '-')) {
1690 ExitFlag = 255;
1691 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough arguments for parsing: -p <xyz file>" << endl);
1692 performCriticalExit();
1693 } else {
1694 SaveFlag = true;
1695 DoLog(1) && (Log() << Verbose(1) << "Parsing xyz file for new atoms." << endl);
1696 if (!mol->AddXYZFile(argv[argptr]))
1697 DoLog(2) && (Log() << Verbose(2) << "File not found." << endl);
1698 else {
1699 DoLog(2) && (Log() << Verbose(2) << "File found and parsed." << endl);
1700 configPresent = present;
1701 }
1702 }
1703 break;
1704 case 'a':
1705 if (ExitFlag == 0) ExitFlag = 1;
1706 if ((argptr+4 >= argc) || (argv[argptr][0] == '-')) {
1707 ExitFlag = 255;
1708 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough arguments for adding atom: -a <Z> --position <x> <y> <z>" << endl);
1709 performCriticalExit();
1710 } else {
1711 ArgcList.insert(argptr-1);
1712 ArgcList.insert(argptr);
1713 ArgcList.insert(argptr+1);
1714 ArgcList.insert(argptr+2);
1715 ArgcList.insert(argptr+3);
1716 ArgcList.insert(argptr+4);
1717 argptr+=5;
1718 }
1719 break;
1720 default: // no match? Don't step on (this is done in next switch's default)
1721 break;
1722 }
1723 }
1724 if (configPresent == present) {
1725 switch(argv[argptr-1][1]) {
1726 case 'D':
1727 if (ExitFlag == 0) ExitFlag = 1;
1728 if ((argptr >= argc) || (argv[argptr][0] == '-')) {
1729 ExitFlag = 255;
1730 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for depth-first-search analysis: -D <max. bond distance>" << endl);
1731 performCriticalExit();
1732 } else {
1733 ArgcList.insert(argptr-1);
1734 ArgcList.insert(argptr);
1735 argptr+=1;
1736 }
1737 break;
1738 case 'I':
1739 DoLog(1) && (Log() << Verbose(1) << "Dissecting molecular system into a set of disconnected subgraphs ... " << endl);
1740 ArgcList.insert(argptr-1);
1741 argptr+=0;
1742 break;
1743 case 'C':
1744 {
1745 if (ExitFlag == 0) ExitFlag = 1;
1746 if ((argptr+11 >= argc)) {
1747 ExitFlag = 255;
1748 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);
1749 performCriticalExit();
1750 } else {
1751 switch(argv[argptr][0]) {
1752 case 'E':
1753 ArgcList.insert(argptr-1);
1754 ArgcList.insert(argptr);
1755 ArgcList.insert(argptr+1);
1756 ArgcList.insert(argptr+2);
1757 ArgcList.insert(argptr+3);
1758 ArgcList.insert(argptr+4);
1759 ArgcList.insert(argptr+5);
1760 ArgcList.insert(argptr+6);
1761 ArgcList.insert(argptr+7);
1762 ArgcList.insert(argptr+8);
1763 ArgcList.insert(argptr+9);
1764 ArgcList.insert(argptr+10);
1765 ArgcList.insert(argptr+11);
1766 argptr+=12;
1767 break;
1768
1769 case 'P':
1770 ArgcList.insert(argptr-1);
1771 ArgcList.insert(argptr);
1772 ArgcList.insert(argptr+1);
1773 ArgcList.insert(argptr+2);
1774 ArgcList.insert(argptr+3);
1775 ArgcList.insert(argptr+4);
1776 ArgcList.insert(argptr+5);
1777 ArgcList.insert(argptr+6);
1778 ArgcList.insert(argptr+7);
1779 ArgcList.insert(argptr+8);
1780 ArgcList.insert(argptr+9);
1781 ArgcList.insert(argptr+10);
1782 ArgcList.insert(argptr+11);
1783 ArgcList.insert(argptr+12);
1784 ArgcList.insert(argptr+13);
1785 ArgcList.insert(argptr+14);
1786 argptr+=15;
1787 break;
1788
1789 case 'S':
1790 ArgcList.insert(argptr-1);
1791 ArgcList.insert(argptr);
1792 ArgcList.insert(argptr+1);
1793 ArgcList.insert(argptr+2);
1794 ArgcList.insert(argptr+3);
1795 ArgcList.insert(argptr+4);
1796 ArgcList.insert(argptr+5);
1797 ArgcList.insert(argptr+6);
1798 ArgcList.insert(argptr+7);
1799 ArgcList.insert(argptr+8);
1800 ArgcList.insert(argptr+9);
1801 ArgcList.insert(argptr+10);
1802 ArgcList.insert(argptr+11);
1803 ArgcList.insert(argptr+12);
1804 ArgcList.insert(argptr+13);
1805 ArgcList.insert(argptr+14);
1806 argptr+=15;
1807 break;
1808
1809 default:
1810 ExitFlag = 255;
1811 DoeLog(0) && (eLog()<< Verbose(0) << "Invalid type given for pair correlation analysis: -C <type: E/P/S> [more params] <output> <bin output>" << endl);
1812 performCriticalExit();
1813 break;
1814 }
1815 }
1816 break;
1817 }
1818 case 'E':
1819 if (ExitFlag == 0) ExitFlag = 1;
1820 if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr]))) {
1821 ExitFlag = 255;
1822 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for changing element: -E <atom nr.> --element <Z>" << endl);
1823 performCriticalExit();
1824 } else {
1825 ArgcList.insert(argptr-1);
1826 ArgcList.insert(argptr);
1827 ArgcList.insert(argptr+1);
1828 ArgcList.insert(argptr+2);
1829 argptr+=3;
1830 }
1831 break;
1832 case 'F':
1833 if (ExitFlag == 0) ExitFlag = 1;
1834 if ((argptr+12 >= argc) || (argv[argptr][0] == '-')) {
1835 ExitFlag = 255;
1836 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);
1837 performCriticalExit();
1838 } else {
1839 ArgcList.insert(argptr-1);
1840 ArgcList.insert(argptr);
1841 ArgcList.insert(argptr+1);
1842 ArgcList.insert(argptr+2);
1843 ArgcList.insert(argptr+3);
1844 ArgcList.insert(argptr+4);
1845 ArgcList.insert(argptr+5);
1846 ArgcList.insert(argptr+6);
1847 ArgcList.insert(argptr+7);
1848 ArgcList.insert(argptr+8);
1849 ArgcList.insert(argptr+9);
1850 ArgcList.insert(argptr+10);
1851 ArgcList.insert(argptr+11);
1852 ArgcList.insert(argptr+12);
1853 argptr+=13;
1854 }
1855 break;
1856 case 'A':
1857 if (ExitFlag == 0) ExitFlag = 1;
1858 if ((argptr+2 >= argc) || (argv[argptr][0] == '-')) {
1859 ExitFlag =255;
1860 DoeLog(0) && (eLog()<< Verbose(0) << "Missing source file for bonds in molecule: -A <bond sourcefile> --molecule-by-id <molecule_id>" << endl);
1861 performCriticalExit();
1862 } else {
1863 ArgcList.insert(argptr-1);
1864 ArgcList.insert(argptr);
1865 ArgcList.insert(argptr+1);
1866 ArgcList.insert(argptr+2);
1867 argptr+=3;
1868 }
1869 break;
1870
1871 case 'J':
1872 if (ExitFlag == 0) ExitFlag = 1;
1873 if ((argptr+2 >= argc) || (argv[argptr][0] == '-')) {
1874 ExitFlag =255;
1875 DoeLog(0) && (eLog()<< Verbose(0) << "Missing path of adjacency file: -J <path> --molecule-by-id <molecule_id>" << endl);
1876 performCriticalExit();
1877 } else {
1878 ArgcList.insert(argptr-1);
1879 ArgcList.insert(argptr);
1880 ArgcList.insert(argptr+1);
1881 ArgcList.insert(argptr+2);
1882 argptr+=3;
1883 }
1884 break;
1885
1886 case 'j':
1887 if (ExitFlag == 0) ExitFlag = 1;
1888 if ((argptr >= argc) || (argv[argptr][0] == '-')) {
1889 ExitFlag =255;
1890 DoeLog(0) && (eLog()<< Verbose(0) << "Missing path of bonds file: -j <path> --molecule-by-id <molecule_id>" << endl);
1891 performCriticalExit();
1892 } else {
1893 ArgcList.insert(argptr-1);
1894 ArgcList.insert(argptr);
1895 ArgcList.insert(argptr+1);
1896 ArgcList.insert(argptr+2);
1897 argptr+=3;
1898 }
1899 break;
1900
1901 case 'N':
1902 if (ExitFlag == 0) ExitFlag = 1;
1903 if ((argptr+4 >= argc) || (argv[argptr][0] == '-')){
1904 ExitFlag = 255;
1905 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);
1906 performCriticalExit();
1907 } else {
1908 ArgcList.insert(argptr-1);
1909 ArgcList.insert(argptr);
1910 ArgcList.insert(argptr+1);
1911 ArgcList.insert(argptr+2);
1912 ArgcList.insert(argptr+3);
1913 ArgcList.insert(argptr+4);
1914 argptr+=5;
1915 }
1916 break;
1917 case 'S':
1918 if (ExitFlag == 0) ExitFlag = 1;
1919 if ((argptr+2 >= argc) || (argv[argptr][0] == '-')) {
1920 ExitFlag = 255;
1921 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for storing tempature: -S <temperature file> --molecule-by-id 0" << endl);
1922 performCriticalExit();
1923 } else {
1924 ArgcList.insert(argptr-1);
1925 ArgcList.insert(argptr);
1926 ArgcList.insert(argptr+1);
1927 ArgcList.insert(argptr+2);
1928 argptr+=3;
1929 }
1930 break;
1931 case 'L':
1932 if (ExitFlag == 0) ExitFlag = 1;
1933 if ((argptr+8 >= argc) || (argv[argptr][0] == '-')) {
1934 ExitFlag = 255;
1935 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);
1936 performCriticalExit();
1937 } else {
1938 ArgcList.insert(argptr-1);
1939 ArgcList.insert(argptr);
1940 ArgcList.insert(argptr+1);
1941 ArgcList.insert(argptr+2);
1942 ArgcList.insert(argptr+3);
1943 ArgcList.insert(argptr+4);
1944 ArgcList.insert(argptr+5);
1945 ArgcList.insert(argptr+6);
1946 ArgcList.insert(argptr+7);
1947 ArgcList.insert(argptr+8);
1948 argptr+=9;
1949 }
1950 break;
1951 case 'P':
1952 if (ExitFlag == 0) ExitFlag = 1;
1953 if ((argptr+2 >= argc) || (argv[argptr][0] == '-')) {
1954 ExitFlag = 255;
1955 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);
1956 performCriticalExit();
1957 } else {
1958 ArgcList.insert(argptr-1);
1959 ArgcList.insert(argptr);
1960 ArgcList.insert(argptr+1);
1961 ArgcList.insert(argptr+2);
1962 argptr+=3;
1963 }
1964 break;
1965 case 'R':
1966 if (ExitFlag == 0) ExitFlag = 1;
1967 if ((argptr+4 >= argc) || (argv[argptr][0] == '-')) {
1968 ExitFlag = 255;
1969 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for removing atoms: -R <distance> --position <x> <y> <z>" << endl);
1970 performCriticalExit();
1971 } else {
1972 ArgcList.insert(argptr-1);
1973 ArgcList.insert(argptr);
1974 ArgcList.insert(argptr+1);
1975 ArgcList.insert(argptr+2);
1976 ArgcList.insert(argptr+3);
1977 ArgcList.insert(argptr+4);
1978 argptr+=5;
1979 }
1980 break;
1981 case 't':
1982 if (ExitFlag == 0) ExitFlag = 1;
1983 if ((argptr+4 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
1984 ExitFlag = 255;
1985 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);
1986 performCriticalExit();
1987 } else {
1988 ArgcList.insert(argptr-1);
1989 ArgcList.insert(argptr);
1990 ArgcList.insert(argptr+1);
1991 ArgcList.insert(argptr+2);
1992 ArgcList.insert(argptr+3);
1993 ArgcList.insert(argptr+4);
1994 ArgcList.insert(argptr+5);
1995 ArgcList.insert(argptr+6);
1996 argptr+=7;
1997 }
1998 break;
1999 case 's':
2000 if (ExitFlag == 0) ExitFlag = 1;
2001 if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
2002 ExitFlag = 255;
2003 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for scaling: -s <factor_x> [factor_y] [factor_z]" << endl);
2004 performCriticalExit();
2005 } else {
2006 ArgcList.insert(argptr-1);
2007 ArgcList.insert(argptr);
2008 ArgcList.insert(argptr+1);
2009 ArgcList.insert(argptr+2);
2010 argptr+=3;
2011 }
2012 break;
2013 case 'b':
2014 if (ExitFlag == 0) ExitFlag = 1;
2015 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])) ) {
2016 ExitFlag = 255;
2017 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for centering in box: -b <xx> <xy> <xz> <yy> <yz> <zz>" << endl);
2018 performCriticalExit();
2019 } else {
2020 ArgcList.insert(argptr-1);
2021 ArgcList.insert(argptr);
2022 ArgcList.insert(argptr+1);
2023 ArgcList.insert(argptr+2);
2024 ArgcList.insert(argptr+3);
2025 ArgcList.insert(argptr+4);
2026 ArgcList.insert(argptr+5);
2027 argptr+=6;
2028 }
2029 break;
2030 case 'B':
2031 if (ExitFlag == 0) ExitFlag = 1;
2032 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])) ) {
2033 ExitFlag = 255;
2034 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for bounding in box: -B <xx> <xy> <xz> <yy> <yz> <zz>" << endl);
2035 performCriticalExit();
2036 } else {
2037 ArgcList.insert(argptr-1);
2038 ArgcList.insert(argptr);
2039 ArgcList.insert(argptr+1);
2040 ArgcList.insert(argptr+2);
2041 ArgcList.insert(argptr+3);
2042 ArgcList.insert(argptr+4);
2043 ArgcList.insert(argptr+5);
2044 argptr+=6;
2045 }
2046 break;
2047 case 'c':
2048 if (ExitFlag == 0) ExitFlag = 1;
2049 if ((argptr+2 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
2050 ExitFlag = 255;
2051 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for centering with boundary: -c <boundary_x> <boundary_y> <boundary_z>" << endl);
2052 performCriticalExit();
2053 } else {
2054 ArgcList.insert(argptr-1);
2055 ArgcList.insert(argptr);
2056 ArgcList.insert(argptr+1);
2057 ArgcList.insert(argptr+2);
2058 argptr+=3;
2059 }
2060 break;
2061 case 'O':
2062 if (ExitFlag == 0) ExitFlag = 1;
2063 ArgcList.insert(argptr-1);
2064 argptr+=0;
2065 break;
2066 case 'r':
2067 if (ExitFlag == 0) ExitFlag = 1;
2068 if ((argptr >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr]))) {
2069 ExitFlag = 255;
2070 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for removing atoms: -r <id>" << endl);
2071 performCriticalExit();
2072 } else {
2073 ArgcList.insert(argptr-1);
2074 ArgcList.insert(argptr);
2075 argptr+=1;
2076 }
2077 break;
2078 case 'f':
2079 if (ExitFlag == 0) ExitFlag = 1;
2080 if ((argptr+1 >= argc) || (argv[argptr][0] == '-')) {
2081 ExitFlag = 255;
2082 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments for fragmentation: -f <max. bond distance> <bond order>" << endl);
2083 performCriticalExit();
2084 } else {
2085 ArgcList.insert(argptr-1);
2086 ArgcList.insert(argptr);
2087 ArgcList.insert(argptr+1);
2088 ArgcList.insert(argptr+2);
2089 ArgcList.insert(argptr+3);
2090 ArgcList.insert(argptr+4);
2091 argptr+=5;
2092 }
2093 break;
2094 case 'm':
2095 if (ExitFlag == 0) ExitFlag = 1;
2096 j = atoi(argv[argptr++]);
2097 if ((j<0) || (j>1)) {
2098 DoeLog(1) && (eLog()<< Verbose(1) << "Argument of '-m' should be either 0 for no-rotate or 1 for rotate." << endl);
2099 j = 0;
2100 }
2101 if (j) {
2102 SaveFlag = true;
2103 DoLog(0) && (Log() << Verbose(0) << "Converting to prinicipal axis system." << endl);
2104 mol->PrincipalAxisSystem((bool)j);
2105 } else
2106 ArgcList.insert(argptr-1);
2107 argptr+=0;
2108 break;
2109 case 'o':
2110 if (ExitFlag == 0) ExitFlag = 1;
2111 if ((argptr+4 >= argc) || (argv[argptr][0] == '-')){
2112 ExitFlag = 255;
2113 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);
2114 performCriticalExit();
2115 } else {
2116 ArgcList.insert(argptr-1);
2117 ArgcList.insert(argptr);
2118 ArgcList.insert(argptr+1);
2119 ArgcList.insert(argptr+2);
2120 ArgcList.insert(argptr+3);
2121 ArgcList.insert(argptr+4);
2122 argptr+=5;
2123 }
2124 break;
2125 case 'U':
2126 if (ExitFlag == 0) ExitFlag = 1;
2127 if ((argptr+1 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) ) {
2128 ExitFlag = 255;
2129 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for suspension with specified volume: -U <volume> <density>" << endl);
2130 performCriticalExit();
2131 } else {
2132 volume = atof(argv[argptr++]);
2133 DoLog(0) && (Log() << Verbose(0) << "Using " << volume << " angstrom^3 as the volume instead of convex envelope one's." << endl);
2134 }
2135 case 'u':
2136 if (ExitFlag == 0) ExitFlag = 1;
2137 if ((argptr >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) ) {
2138 if (volume != -1)
2139 ExitFlag = 255;
2140 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for suspension: -u <density>" << endl);
2141 performCriticalExit();
2142 } else {
2143 ArgcList.insert(argptr-1);
2144 ArgcList.insert(argptr);
2145 argptr+=1;
2146 }
2147 break;
2148 case 'd':
2149 if (ExitFlag == 0) ExitFlag = 1;
2150 if ((argptr+2 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
2151 ExitFlag = 255;
2152 DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for repeating cells: -d <repeat_x> <repeat_y> <repeat_z>" << endl);
2153 performCriticalExit();
2154 } else {
2155 ArgcList.insert(argptr-1);
2156 ArgcList.insert(argptr);
2157 ArgcList.insert(argptr+1);
2158 ArgcList.insert(argptr+2);
2159 argptr+=3;
2160 }
2161 break;
2162 default: // no match? Step on
2163 if ((argptr < argc) && (argv[argptr][0] != '-')) // if it started with a '-' we've already made a step!
2164 argptr++;
2165 break;
2166 }
2167 }
2168 } else argptr++;
2169 } while (argptr < argc);
2170 if (SaveFlag)
2171 configuration.SaveAll(*ConfigFileName, periode, molecules);
2172 } else { // no arguments, hence scan the elements db
2173 if (periode->LoadPeriodentafel(configuration.databasepath))
2174 DoLog(0) && (Log() << Verbose(0) << "Element list loaded successfully." << endl);
2175 else
2176 DoLog(0) && (Log() << Verbose(0) << "Element list loading failed." << endl);
2177 configuration.RetrieveConfigPathAndName("main_pcp_linux");
2178 }
2179 return(ExitFlag);
2180};
2181
2182/********************************************** Main routine **************************************/
2183
2184void cleanUp(){
2185 World::purgeInstance();
2186 logger::purgeInstance();
2187 errorLogger::purgeInstance();
2188 UIFactory::purgeInstance();
2189 MapOfActions::purgeInstance();
2190 CommandLineParser::purgeInstance();
2191 ActionRegistry::purgeInstance();
2192 ActionHistory::purgeInstance();
2193#ifdef LOG_OBSERVER
2194 cout << observerLog().getLog();
2195#endif
2196 Memory::getState();
2197}
2198
2199int main(int argc, char **argv)
2200{
2201 config *configuration = World::getInstance().getConfig();
2202 // while we are non interactive, we want to abort from asserts
2203 //ASSERT_DO(Assert::Abort);
2204 molecule *mol = NULL;
2205 Vector x, y, z, n;
2206 ifstream test;
2207 ofstream output;
2208 string line;
2209 char **Arguments = NULL;
2210 int ArgcSize = 0;
2211 int ExitFlag = 0;
2212 bool ArgumentsCopied = false;
2213 char *ConfigFileName = new char[MAXSTRINGSIZE];
2214
2215 // print version check whether arguments are present at all
2216 cout << ESPACKVersion << endl;
2217 if (argc < 2) {
2218 cout << "Obtain help with " << argv[0] << " -h." << endl;
2219 cleanUp();
2220 Memory::getState();
2221 return(1);
2222 }
2223
2224
2225 setVerbosity(0);
2226 // need to init the history before any action is created
2227 ActionHistory::init();
2228
2229 // In the interactive mode, we can leave the user the choice in case of error
2230 ASSERT_DO(Assert::Ask);
2231
2232 // from this moment on, we need to be sure to deeinitialize in the correct order
2233 // this is handled by the cleanup function
2234 atexit(cleanUp);
2235
2236 // Parse command line options and if present create respective UI
2237 {
2238 set<int> ArgcList;
2239 ArgcList.insert(0); // push back program!
2240 ArgcList.insert(1); // push back config file name
2241 // handle arguments by ParseCommandLineOptions()
2242 ExitFlag = ParseCommandLineOptions(argc,argv,World::getInstance().getMolecules(),World::getInstance().getPeriode(),*World::getInstance().getConfig(), &ConfigFileName, ArgcList);
2243 World::getInstance().setExitFlag(ExitFlag);
2244 // copy all remaining arguments to a new argv
2245 Arguments = new char *[ArgcList.size()];
2246 cout << "The following arguments are handled by CommandLineParser: ";
2247 for (set<int>::iterator ArgcRunner = ArgcList.begin(); ArgcRunner != ArgcList.end(); ++ArgcRunner) {
2248 Arguments[ArgcSize] = new char[strlen(argv[*ArgcRunner])+2];
2249 strcpy(Arguments[ArgcSize], argv[*ArgcRunner]);
2250 cout << " " << argv[*ArgcRunner];
2251 ArgcSize++;
2252 }
2253 cout << endl;
2254 ArgumentsCopied = true;
2255 // handle remaining arguments by CommandLineParser
2256 MapOfActions::getInstance().AddOptionsToParser();
2257 map <std::string, std::string> ShortFormToActionMap = MapOfActions::getInstance().getShortFormToActionMap();
2258 CommandLineParser::getInstance().Run(ArgcSize,Arguments, ShortFormToActionMap);
2259 if (!CommandLineParser::getInstance().isEmpty()) {
2260 DoLog(0) && (Log() << Verbose(0) << "Setting UI to CommandLine." << endl);
2261 UIFactory::makeUserInterface(UIFactory::CommandLine);
2262 } else {
2263 DoLog(0) && (Log() << Verbose(0) << "Setting UI to Text." << endl);
2264 UIFactory::makeUserInterface(UIFactory::Text);
2265 }
2266 }
2267
2268 {
2269 MainWindow *mainWindow = UIFactory::getInstance().makeMainWindow();
2270 mainWindow->display();
2271 delete mainWindow;
2272 }
2273
2274 Log() << Verbose(0) << "Saving to " << ConfigFileName << "." << endl;
2275 World::getInstance().getConfig()->SaveAll(ConfigFileName, World::getInstance().getPeriode(), World::getInstance().getMolecules());
2276
2277 // free the new argv
2278 if (ArgumentsCopied) {
2279 for (int i=0; i<ArgcSize;i++)
2280 delete[](Arguments[i]);
2281 delete[](Arguments);
2282 }
2283 delete[](ConfigFileName);
2284
2285 ExitFlag = World::getInstance().getExitFlag();
2286 return (ExitFlag == 1 ? 0 : ExitFlag);
2287}
2288
2289/********************************************** E N D **************************************************/
Note: See TracBrowser for help on using the repository browser.